如何平衡Cassandra中的负载?

时间:2018-06-28 15:46:35

标签: cql cassandra-3.0 cqlsh elassandra

我正在使用Elassandra 6.2.3 我设置了一个由3个节点组成的集群,并创建了复制因子为2的键空间。

我在Cassandra配置中使用Murmur3Partitionernum_tokens=8

CREATE KEYSPACE mykeyspace WITH replication = {'class': 'NetworkTopologyStrategy', 'DC1': '2'} AND durable_writes = true;

DESC mykeyspace;
CREATE TABLE mykeyspace.mytable(
    f1 text,
    f2 timestamp,
    f3 text,
    f4 text,
    f5 int,
    PRIMARY KEY (f1, f2)
) WITH CLUSTERING ORDER BY (f2 DESC)
    AND bloom_filter_fp_chance = 0.01
    AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
    AND comment = ''
    AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
    AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
    AND crc_check_chance = 1.0
    AND dclocal_read_repair_chance = 0.1
    AND default_time_to_live = 0
    AND gc_grace_seconds = 864000
    AND max_index_interval = 2048
    AND memtable_flush_period_in_ms = 0
    AND min_index_interval = 128
    AND read_repair_chance = 0.0
    AND speculative_retry = '99PERCENTILE';
CREATE CUSTOM INDEX elastic_mytable_idx ON mykeyspace.mytable () USING 'org.elassandra.index.ExtendedElasticSecondaryIndex';

这里是戒指:

$ nodetool ring mykeyspace

Datacenter: DC1
==========
Address    Rack        Status State   Load            Owns                Token
                                                                          8046893569169204194
10.8.0.6   r1          Up     Normal  30.77 GiB       86.15%              -7885825037800730315
10.8.0.1   r1          Up     Normal  17.55 GiB       64.24%              -7261086042602187969
10.8.0.14  r1          Up     Normal  7.36 GiB        49.61%              -7247943966600989463
10.8.0.1   r1          Up     Normal  17.55 GiB       64.24%              -7228717159480176131
10.8.0.1   r1          Up     Normal  17.55 GiB       64.24%              -6939207504674930480
10.8.0.6   r1          Up     Normal  30.77 GiB       86.15%              -6158757762234956967
10.8.0.14  r1          Up     Normal  7.36 GiB        49.61%              -4699623277895141955
10.8.0.14  r1          Up     Normal  7.36 GiB        49.61%              -4269715227726417275
10.8.0.6   r1          Up     Normal  30.77 GiB       86.15%              -3148156422280710025
10.8.0.14  r1          Up     Normal  7.36 GiB        49.61%              -2567971232125784764
10.8.0.14  r1          Up     Normal  7.36 GiB        49.61%              -2187229040967677675
10.8.0.6   r1          Up     Normal  30.77 GiB       86.15%              -2058807466377445130
10.8.0.1   r1          Up     Normal  17.55 GiB       64.24%              -1181919914747129817
10.8.0.6   r1          Up     Normal  30.77 GiB       86.15%              695306942662545127
10.8.0.1   r1          Up     Normal  17.55 GiB       64.24%              1989050017548537421
10.8.0.14  r1          Up     Normal  7.36 GiB        49.61%              2881433693910708029
10.8.0.6   r1          Up     Normal  30.77 GiB       86.15%              3454959670543032324
10.8.0.14  r1          Up     Normal  7.36 GiB        49.61%              3833350227892101457
10.8.0.6   r1          Up     Normal  30.77 GiB       86.15%              4855735318033934682
10.8.0.6   r1          Up     Normal  30.77 GiB       86.15%              6288034337780481749
10.8.0.1   r1          Up     Normal  17.55 GiB       64.24%              6495870875989416002
10.8.0.1   r1          Up     Normal  17.55 GiB       64.24%              6853344637592889364
10.8.0.14  r1          Up     Normal  7.36 GiB        49.61%              6911496393497851249
10.8.0.1   r1          Up     Normal  17.55 GiB       64.24%              8046893569169204194

我创建了一个测试程序,该程序生成1M的随机数据,并通过nodejs的cassandra驱动程序库将其发送到Cassandra。 测试程序使用大约2900个不同的分区键(f1)和不同的群集键(f2)生成数据。

结果是数据是这样分布的:

$ nodetool status mykeyspace
Datacenter: DC1
===============
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
--  Address    Load       Tokens       Owns (effective)  Host ID                               Rack
UN  10.8.0.14  12.47 GiB  8            49.6%             c5a17dbd-40ef-4f58-b132-0d977a92f1a1  r1
UN  10.8.0.1   17.55 GiB  8            64.2%             f088d009-bd97-4e35-9f20-60006a68b363  r1
UN  10.8.0.6   33.49 GiB  8            86.1%             e82191ad-9d9f-459f-9da0-2b0457ad6611  r1

为什么一个节点的负载几乎是其他2个节点的两倍?

谢谢

1 个答案:

答案 0 :(得分:0)

在Cassandra中,vnode令牌是随机分配的,因此生成的令牌范围可能会有所不同。

在实践中,令牌数量多可以减轻这种影响。 如果想要更好的分发,可以将num_token设置为256。

但是有一个缺点,设置大量的令牌会增加Elassandra中搜索请求的复杂性,因为令牌范围用于过滤重复的结果。有关更多信息,请参见Elassandra search path documentation

我建议不要将num_token设置为高于16,最好是对不同设置进行基准测试以满足您的特定需求。