首页 > 解决方案 > 查询很慢 - 结果很大

问题描述

这张表:

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

标签: cassandra

解决方案


推荐阅读