示例:持续数据自平衡
本文档介绍使用 Kafka CLI 工具对 AutoMQ 集群进行数据自动重平衡测试。其中 Kafka CLI 工具通过 AutoMQ 提供的 docker 镜像运行。
-
创建一个具有多个分区的 Topic,并手动将分区迁移到特定节点,制造出分区分布的不均衡。
-
然后向所有分区发送均衡的负载,观察分区是否会在不同的 Broker 之间自动迁移。
这种自动数据平衡是 AutoMQ 的内置功能,可以确保数据在集群中自动平衡分布。通过监控分区的分布情况和 Broker 的负载情况,可以验证分区自动平衡是否按预期工作。
前置条件
进行分区数据自动重平衡测试前,需要满足如下条件:
完成 AutoMQ 集群的安装部署 ,您可以参考以下方式安装部署 AutoMQ:
如果通过Linux 主机部署多节点集群▸ 或者Kubernetes 部署多节点集群▸ 部署集群,需要确保启动 Controller 时设置 autobalancer.controller.enable 为 true 才能开启数据自动重平衡。
此外,运行测试程序的主机 需要满足如下条件:
-
Linux/Mac/Windows Subsystem for Linux
-
Docker
体验:持续数据自平衡
如果此前的 AutoMQ 集群参考Docker 部署多节点测试集群▸ 部署,则获取的集群 Bootstrap 地址是类似 “server1:9092,server2:9092,server3:9092 ”,且 AutoMQ 集群位于“automq_net ” Docker 网络下。
请根据部署的实际配置,将下方的 bootstrap-server 地址更换成实际集群的地址。
创建 Topic
docker run --network automq_net automqinc/automq:1.5.1 /bin/bash -c "/opt/kafka/kafka/bin/kafka-topics.sh --partitions 8 --create --topic continuous-self-balancing-topic --bootstrap-server server1:9092,server2:9092,server3:9092"
查看分区分布
docker run --network automq_net automqinc/automq:1.5.1 /bin/bash -c "/opt/kafka/kafka/bin/kafka-topics.sh --topic continuous-self-balancing-topic --describe --bootstrap-server server1:9092,server2:9092,server3:9092"
Topic: continuous-self-balancing-topic TopicId: DNZe6gBQTrCOEAruQ_y2tg PartitionCount: 8 ReplicationFactor: 1 Configs: min.insync.replicas=1,segment.bytes=1073741824
Topic: continuous-self-balancing-topic Partition: 0 Leader: 2 Replicas: 2 Isr: 2
Topic: continuous-self-balancing-topic Partition: 1 Leader: 1 Replicas: 1 Isr: 1
Topic: continuous-self-balancing-topic Partition: 2 Leader: 1 Replicas: 1 Isr: 1
Topic: continuous-self-balancing-topic Partition: 3 Leader: 2 Replicas: 2 Isr: 2
Topic: continuous-self-balancing-topic Partition: 4 Leader: 1 Replicas: 1 Isr: 1
Topic: continuous-self-balancing-topic Partition: 5 Leader: 2 Replicas: 2 Isr: 2
Topic: continuous-self-balancing-topic Partition: 6 Leader: 1 Replicas: 1 Isr: 1
Topic: continuous-self-balancing-topic Partition: 7 Leader: 2 Replicas: 2 Isr: 2