kafka topic分区数设定

创建一个 1副本1分区的topic

复制代码
kafka-topics.sh --create --topic test --bootstrap-server localhost:9092 --partitions 1 --replication-factor 1 

对这个topic生产吞吐量测试

复制代码
# 生产者吞吐量测试工具
kafka-producer-perf-test.sh  # 生产者测试
--topic test # topic
--num-records 300000 # 总共300000条数据 
--record-size 1000 # 每条1000字节,约1kb
--throughput 100000 # 每次发送100000条记录
--producer-props bootstrap.servers=localhost:9092 # 指定服务
​
复制代码
[root@dream1 ~]# kafka-producer-perf-test.sh --num-records 300000 --record-size 1000 --topic test --throughput 100000 --producer-props bootstrap.servers=localhost:9092
160273 records sent, 32016.2 records/sec (30.53 MB/sec), 660.6 ms avg latency, 1107.0 ms max latency.
126080 records sent, 25100.5 records/sec (23.94 MB/sec), 1261.6 ms avg latency, 1945.0 ms max latency.
300000 records sent, 28097.780275 records/sec (26.80 MB/sec), 940.64 ms avg latency, 1945.00 ms max latency, 911 ms 50th, 1606 ms 95th, 1883 ms 99th, 1938 ms 99.9th.
# 测试结果:30.53 23.94 26.80
​
​
​
[root@dream1 ~]# kafka-producer-perf-test.sh --num-records 300000 --record-size 1000 --topic test --throughput 50000 --producer-props bootstrap.servers=localhost:9092  
151761 records sent, 30352.2 records/sec (28.95 MB/sec), 632.4 ms avg latency, 1495.0 ms max latency.
133584 records sent, 26716.8 records/sec (25.48 MB/sec), 1322.6 ms avg latency, 1696.0 ms max latency.
300000 records sent, 29571.217348 records/sec (28.20 MB/sec), 934.69 ms avg latency, 1696.00 ms max latency, 957 ms 50th, 1589 ms 95th, 1650 ms 99th, 1692 ms 99.9th.
# 测试结果:28.95 25.48 28.20
​
​
​
[root@dream1 ~]# kafka-producer-perf-test.sh --num-records 300000 --record-size 1000 --topic test --throughput 70000 --producer-props bootstrap.servers=localhost:9092 
167185 records sent, 33437.0 records/sec (31.89 MB/sec), 585.8 ms avg latency, 1241.0 ms max latency.
300000 records sent, 35756.853397 records/sec (34.10 MB/sec), 712.25 ms avg latency, 1318.00 ms max latency, 785 ms 50th, 1202 ms 95th, 1310 ms 99th, 1317 ms 99.9th.
# 测试结果:31.89 34.10   前后对比可以得知,每次发送70000条记录时效率最高,此时吞吐量 70000*1KB/s 70MB/s
​
​
​
[root@dream1 ~]# kafka-producer-perf-test.sh --num-records 300000 --record-size 1000 --topic test --throughput 80000 --producer-props bootstrap.servers=localhost:9092 
154609 records sent, 30500.9 records/sec (29.09 MB/sec), 615.7 ms avg latency, 1852.0 ms max latency.
300000 records sent, 35545.023697 records/sec (33.90 MB/sec), 773.73 ms avg latency, 1878.00 ms max latency, 632 ms 50th, 1521 ms 95th, 1869 ms 99th, 1874 ms 99.9th.
# 测试结果:29.09 33.90

对这个topic消费吞吐量测试

复制代码
# 消费者吞吐量测试工具
kafka-consumer-perf-test.sh # 消费者测试
--topic test # topic
--broker-list localhost:9092 # broker 
--messages 300000 # 总共消费多少数据300000
--threads 6 # 6个线程消费
复制代码
​
[root@dream1 ~]# kafka-consumer-perf-test.sh --topic test --broker-list localhost:9092 --messages 300000 --threads 1
WARNING: option [threads] and [num-fetch-threads] have been deprecated and will be ignored by the test
start.time, end.time, data.consumed.in.MB, MB.sec, data.consumed.in.nMsg, nMsg.sec, rebalance.time.ms, fetch.time.ms, fetch.MB.sec, fetch.nMsg.sec
2024-01-11 09:56:52:402, 2024-01-11 09:56:55:365, 286.1099, 96.5609, 300008, 101251.4344, 817, 2146, 133.3224, 139798.6952
[root@dream1 ~]# kafka-consumer-perf-test.sh --topic test --broker-list localhost:9092 --messages 300000 --threads 3
WARNING: option [threads] and [num-fetch-threads] have been deprecated and will be ignored by the test
start.time, end.time, data.consumed.in.MB, MB.sec, data.consumed.in.nMsg, nMsg.sec, rebalance.time.ms, fetch.time.ms, fetch.MB.sec, fetch.nMsg.sec
2024-01-11 09:57:00:232, 2024-01-11 09:57:03:485, 286.1099, 100.9526, 300008, 92225.0231, 626, 2627, 108.9113, 114201.7510
[root@dream1 ~]# kafka-consumer-perf-test.sh --topic test --broker-list localhost:9092 --messages 300000 --threads 10
WARNING: option [threads] and [num-fetch-threads] have been deprecated and will be ignored by the test
start.time, end.time, data.consumed.in.MB, MB.sec, data.consumed.in.nMsg, nMsg.sec, rebalance.time.ms, fetch.time.ms, fetch.MB.sec, fetch.nMsg.sec
2024-01-11 09:57:39:562, 2024-01-11 09:57:42:293, 286.1099, 104.7638, 300008, 109852.8012, 619, 2112, 135.4687, 142049.2424
[root@dream1 ~]# kafka-consumer-perf-test.sh --topic test --broker-list localhost:9092 --messages 300000 --threads 15
WARNING: option [threads] and [num-fetch-threads] have been deprecated and will be ignored by the test
start.time, end.time, data.consumed.in.MB, MB.sec, data.consumed.in.nMsg, nMsg.sec, rebalance.time.ms, fetch.time.ms, fetch.MB.sec, fetch.nMsg.sec
2024-01-11 09:57:52:771, 2024-01-11 09:57:55:798, 286.1099, 94.5193, 300008, 99110.6706, 579, 2448, 116.8750, 122552.287
​
# 消费者测试的时候只需调整 thread 对MB.sec取平均即可,我的测试结果大约100M

计算分区数

  • 然后假设总的目标吞吐量是Tt,那么分区数=Tt / min(Tp,Tc)
  • 例如:producer吞吐量 = 70m/s;consumer吞吐量 =100m/s,期望吞吐量 300m/s;
  • 分区数 = 300 / 70 = 4或者5个分区
相关推荐
2501_941877983 小时前
Python在微服务高并发异步日志聚合与智能告警分析架构中的实践
kafka
SuperHeroWu76 小时前
【HarmonyOS 6】UIAbility跨设备连接详解(分布式软总线运用)
分布式·华为·harmonyos·鸿蒙·连接·分布式协同·跨设备链接
杜子不疼.6 小时前
【探索实战】从0到1打造分布式云原生平台:Kurator全栈实践指南
分布式·云原生
最笨的羊羊7 小时前
Flink CDC系列之:Kafka CSV 序列化器CsvSerializationSchema
kafka·csv·schema·flink cdc系列·serialization·序列化器
最笨的羊羊8 小时前
Flink CDC系列之:Kafka的Debezium JSON 结构定义类DebeziumJsonStruct
kafka·debezium·flink cdc系列·debezium json·结构定义类·jsonstruct
m***l1159 小时前
集成RabbitMQ+MQ常用操作
分布式·rabbitmq
拾忆,想起10 小时前
Dubbo分组(Group)使用指南:实现服务接口的多版本管理与环境隔离
分布式·微服务·性能优化·架构·dubbo
回家路上绕了弯10 小时前
彻底解决超卖问题:从单体到分布式的全场景技术方案
分布式·后端
拾忆,想起11 小时前
Dubbo动态配置实时生效全攻略:零停机实现配置热更新
分布式·微服务·性能优化·架构·dubbo
每天进步一点_JL1 天前
事务与消息中间件:分布式系统中的可见性边界问题
分布式·后端