cassandra - 查询很慢 - 结果很大
问题描述
这张表:
CREATE TABLE buckets (
year_month text,
source_id uuid,
nano_since_epoch bigint,
max double,
min double,
num_values int,
sum double,
value double,
PRIMARY KEY ((year_month, source_id), nano_since_epoch)
)
这个查询:
select value from buckets where year_month = '2020_9' AND source_id=699ddcc0-5896-4b35-a901-8eec2f221499
它有效,但查询需要约 4 秒。去完成。结果集有 ~48.000 行。集群有 3 个节点在 GCP 上运行,n1-standard-2(2 个 vCPU,7.5 GB 内存)。不使用 SSD。第二个 DC 上的性能几乎相同,只有 1 个节点,在更大的裸机机器上。
表直方图:
Percentile SSTables Write Latency Read Latency Partition Size Cell Count
(micros) (micros) (bytes)
50% 0.00 51.01 73.46 182785 17084
75% 0.00 61.21 182.79 1629722 126934
95% 3.00 182.79 654.95 4055269 315852
98% 3.00 263.21 785.94 4866323 454826
99% 4.00 315.85 943.13 5839588 454826
Min 0.00 4.77 20.50 43 0
Max 4.00 2816.16 943.13 5839588 454826
是否可以加快获取结果的速度,或者结果的大小是这里的限制因素?
编辑: Cassandra 在 VMS 上的 docker 中运行。VM 上的内存利用率约为 50%
Dockerfile:
services:
elassandra:
image: strapdata/elassandra:6.2.3.23
container_name: elassandra
environment:
- CASSANDRA_BROADCAST_ADDRESS=10.164.0.58
- CASSANDRA_SEEDS=10.164.0.58
- CASSANDRA_CLUSTER_NAME=Prod Cluster 2
- CASSANDRA_NUM_TOKENS=256
- CASSANDRA_DC=datacenter-prod
- CASSANDRA_RACK=rack1
- LOCAL_JMX=no
volumes:
- '/opt/elassandra/data:/opt/elassandra/data'
- '/var/log/cassandra:/var/log/cassandra'
- '/var/lib/cassandra:/var/lib/cassandra'
ports:
- 7000:7000
- 7001:7001
- 7199:7199
- 8080:8080
- 8081:8081
- 9042:9042
- 9160:9160
- 9200:9200
- 9300:9300
ulimits:
memlock: -1
nproc: 32768
nofile: 100000
network_mode: "host"
logging:
driver: syslog
options:
tag: cassandra-0
解决方案
推荐阅读
- java - 如何持久化在 docker 内的 tomcat 上运行的 Spring Boot 应用程序的会话
- r - 如何解决 f(x, ...) 中的错误:未使用的参数 (x)
- c - 我们可以在 printf() 中使用“+”运算符吗?
- prestashop - Preastashop hookHeader 显示在正文而不是
- javascript - 如何使用模态视图PHP获取mysql数据
- .net - 以低内存使用处理数千个请求和文件流
- javascript - Javascript Array - 检查 2 个数组中的匹配项
- java - 为什么 EXPAND_FACTOR 在 ImmutableCollections.java 中为 2
- data-warehouse - 如何从此数据库创建雪花模式?
- javascript - element.addEventListener("touchstart", function(e) {}) 在 iphone 上不起作用