【问题标题】:How to balance load in Cassandra?如何平衡 Cassandra 中的负载?
【发布时间】:2018-12-07 18:39:00
【问题描述】:

我正在使用 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-driver 库将它们发送到 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 个节点的两倍?

谢谢

【问题讨论】:

  • 如果你删除数据并再次插入,你有同样的结果吗?

标签: cql cassandra-3.0 cqlsh elassandra


【解决方案1】:

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

在实践中,这种影响会因令牌数量较多而得到缓解。 如果您想要更好的分布,您可以将num_token 设置为 256。

但是有一个缺点,设置大量的token会增加Elassandra中搜索请求的复杂度,因为token range是用来过滤掉重复结果的。请参阅Elassandra search path documentation 了解更多信息。

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

【讨论】:

    猜你喜欢
    • 2018-06-09
    • 1970-01-01
    • 2011-10-17
    • 2017-09-21
    • 2016-06-21
    • 2014-02-04
    • 2012-07-22
    • 2022-01-10
    • 1970-01-01
    相关资源
    最近更新 更多