org.apache.kafka.tools.ProducerPerformance Kafka的`--num-threads'选项的替代

时间:2019-03-10 11:37:02

标签: apache-kafka kafka-producer-api

Kafka已从Kafka 2.0--num-threads中删除了option of org.apache.kafka.tools.ProducerPerformance的选项

这又是什么解决方案?

1 个答案:

答案 0 :(得分:0)

我们首先需要首先了解--num-threads的用途。

参数pi@raspberrypi:/tmp $ gcc -pedantic -Wextra b.c pi@raspberrypi:/tmp $ ./a.out enter the number of elements 1 enter the array elements 1 1 pi@raspberrypi:/tmp $ ./a.out enter the number of elements 2 enter the array elements 1 2 1 2 pi@raspberrypi:/tmp $ ./a.out enter the number of elements 2 enter the array elements 2 1 1 2 pi@raspberrypi:/tmp $ ./a.out enter the number of elements 4 enter the array elements 4 3 2 1 1 2 3 4 以前用于控制每个线程的消息吞吐量。

类似

--num-threads

但是,现在通过此更改,他们已经取消了节流或控制吞吐量的粗略方法,而是给了您完全取消节流的选项,您可以通过将--throughput设置为值来完成-1

如果仔细看,内部实现现在是这样的

 ProducerPerformanceThread[] producerPerformanceThreads = new ProducerPerformanceThread[numThreads];
        long numRecordsPerThread = numRecords / numThreads;
        int throughputPerThread = throughput <= 0 ? throughput : Math.max(throughput / numThreads, 1);
        int batchSize = 1;

因此,您现在应该只设置吞吐量值,而不用担心线程数。