Kafka 已从 Kafka 2.0option of org.apache.kafka.tools.ProducerPerformance
中删除--num-threads
选项
从中得出的另一种解决方案是什么?
我们需要首先了解 --num-threads 的用途。
参数--num-threads
以前用于控制每个线程的消息吞吐量。
类似的东西
ProducerPerformanceThread[] producerPerformanceThreads = new ProducerPerformanceThread[numThreads];
long numRecordsPerThread = numRecords / numThreads;
int throughputPerThread = throughput <= 0 ? throughput : Math.max(throughput / numThreads, 1);
int batchSize = 1;
但是,现在通过此更改,他们已经取消了限制或控制吞吐量的粗略方法,而是为您提供了完全取消限制的选项,您可以通过将 --throughput 设置为 -1 值来完成
如果你仔细观察,内部实现现在是这样的
ThroughputThrottler throttler = new ThroughputThrottler(throughput, startMs);
因此,您现在应该只设置吞吐量的值,而不必担心线程数。