The following article is from 石臻臻的杂货铺 Author 石臻臻的杂货铺
CSDN博客之星Top5、Kafka Contributor、LogiKM PMC、华为云MVP。进滴滴技术交流群, 不同技术专家轮流值班, 本号分享Java/大数据/中间件等领域干货和视频
今天我们来讲解一下限流机制。本文提到的限流机制指副本之间的同步限流机制,并不包含生产者 、消费组等其他限流。
那么讲到副本同步,大家都知道,正常情况下我们是不会给副本的同步加上限流值的。因为这样子很可能会导致副本跟不上 ISR(in-sync replica),那么什么情况下我们需要加上这个限流值呢?
分区副本重分配的场景下,我们可能担心大批量的数据进行迁移会占用过多的资源,导致 Kafka 集群压力增大进而影响正常使用。所以,一般情况下我们可能会选择在低峰期进行操作,也会对整个操作做一个限流处理。
--replica-alter-log-dirs-throttle:broker 内部副本跨路径迁移数据流量限制功能,限制数据拷贝从一个目录到另外一个目录带宽上限,单位 bytes/sec;
--throttle:迁移过程中 Broker 之间传输的速率,单位 bytes/sec。
分区副本重分配
sh bin/kafka-reassign-partitions.sh --zookeeper xxxx:2181/src1 --reassignment-json-file config/reassignment-json-file.json --execute --bootstrap-server xxxxxx:9090 --throttle 1048576
{"version": 1,"config": {"leader.replication.throttled.rate": "1048576","follower.replication.throttled.rate": "1048576"}}
leader.replication.throttled.rate:需要对 Leader 端 Fetcher 返回的数据做限流。这里的配置就是限流的阈值;
follower.replication.throttled.rate:需要对 Follower 端去 Leader 副本 Fetcher 数据做限流。这里的配置就是限流的阈值。
{"version": 1,"config": {"leader.replication.throttled.replicas": "1:1,1:0,0:0,0:1","follower.replication.throttled.replicas": "1:2,0:2"}}
leader.replication.throttled.replicas:Leader 端的限流副本,它的格式是分区号:BrokerID。上面配置含义如下:
1:1 - Topic1-1 分区在 Broker-1 上需要做 Leader 限流;
1:0 - Topic1-1 分区在 Broker-0 上需要做 Leader 限流;
0:0 - Topic1-0 分区在 Broker-0 上需要做 Leader 限流;
0:1 - Topic1-0 分区在 Broker-1 上需要做 Leader 限流。
1:2 - Topic1-1 分区在 Broker-2 上需要做 Follower 限流;
0:2 - Topic1-0 分区在 Broker-2 上需要做 Follower 限流。
分区副本重分配限流图
{"version": 1,"config": {"replica.alter.log.dirs.io.max.bytes.per.second": "1048576"}}
是从哪里 Fetch 数据呢?
sh bin/kafka-configs.sh --bootstrap-server xxxxx:9092 --alter --entity-type brokers --entity-name 0 --add-config leader.replication.throttled.rate=1048576,follower.replication.throttled.rate=1048576
{"version": 1,"config": {"leader.replication.throttled.rate": "1048576","follower.replication.throttled.rate": "1048576"}}
sh bin/kafka-configs.sh --bootstrap-server xxxxx:9092 --alter --entity-type brokers --entity-name 0 --add-config leader.replication.throttled.replicas=1:0,follower.replication.throttled.replicas=2:1
{"version": 1,"config": {"leader.replication.throttled.replicas": "1:0","follower.replication.throttled.replicas": "2:1"}}
sh bin/kafka-configs.sh --bootstrap-server xxxxx:9092 --alter --entity-type brokers --entity-name 0 --add-config leader.replication.throttled.replicas=*,follower.replication.throttled.replicas=*
{"version": 1,"config": {"leader.replication.throttled.replicas": "*","follower.replication.throttled.replicas": "*"}}
- EOF -
看完本文有收获?请转发分享给更多人
关注「ImportNew」,提升Java技能
点赞和在看就是最大的支持❤️