简体   繁体   English

为什么 kafka 生产者(性能测试)具有如此低的吞吐量/高延迟?

[英]why does kafka producer (perf test) have such low throughput / high latency?

I am new to kafka and am running some performance tests.我是 kafka 的新手,正在运行一些性能测试。 I am running a 2 machine cluster consisting of my laptop and a raspberry pi zero W (1 GHz, single-core CPU, 512 MB RAM, 802.11n wireless LAN).我正在运行一个由笔记本电脑和树莓派零 W(1 GHz、单核 CPU、512 MB RAM、802.11n 无线 LAN)组成的 2 机器集群。 eventually the pi will run a single producer (java) that sends binary sensor data (ideally smaller records, eg, 10 kb, as quickly as possible) to kafka which is then read off by a consumer on my laptop or another pi.最终,pi 将运行一个生产者(java),它将二进制传感器数据(理想情况下是尽可能快的较小记录,例如 10 kb)发送到 kafka,然后由我的笔记本电脑或另一个 pi 上的消费者读取。 a separate application later processes the data offline.稍后会有一个单独的应用程序离线处理数据。 i only have 1 topic with 1 partition and no replication.我只有 1 个主题和 1 个分区,没有复制。

i'm currently trying to benchmark the producer performance / get an idea of it's capabilities.我目前正在尝试对生产者的性能进行基准测试/了解它的功能。 this is the output from the kafka-producer-perf-test.sh, showing that there is a pretty large latency and not great throughput.这是来自 kafka-producer-perf-test.sh 的 output,表明存在相当大的延迟且吞吐量不高。 i've played around with the settings (like linger.ms, batch.size, acks, throughput, and record size, it seems like the larger the record size, the higher the throughput (up until ~750 kb, then decreases) but the latency either is about the same or actually decreases.我已经玩过设置(如 linger.ms、batch.size、acks、吞吐量和记录大小,似乎记录大小越大,吞吐量越高(直到 ~750 kb,然后减少)但是延迟要么大致相同,要么实际上减少了。

i've only been able to achieve ~0.6 MB/sec which is WAY too slow for the application i'm working on.我只能达到 ~0.6 MB/秒,这对于我正在处理的应用程序来说太慢了。 when i decreased the record size, the throughput was even worse at ~0.10 MB/sec.当我减小记录大小时,吞吐量甚至更差,约为 0.10 MB/秒。 since i'm new to kafka, i'm wondering is this what I should expect when using the pi zero w or is something suboptimal with my setup / producer properties, etc?因为我是 kafka 的新手,所以我想知道这是我在使用 pi 零 w 时应该期待的还是我的设置/生产者属性等不理想的东西?

pi@raspberrypi:~/Kafka/kafka_2.12-2.4.0 $ bin/kafka-producer-perf-test.sh --topic perf_test --num-records 100 --thughput 1000000 --producer-props bootstrap.servers=192.168.0.170:9092,192.168.0.172:9092 --record-size 750000
OpenJDK Zero VM warning: G1 GC is disabled in this release.
2 records sent, 0.3 records/sec (0.25 MB/sec), 4439.5 ms avg latency, 4607.0 ms max latency.
5 records sent, 0.9 records/sec (0.62 MB/sec), 6909.0 ms avg latency, 9180.0 ms max latency.
5 records sent, 0.8 records/sec (0.58 MB/sec), 12783.4 ms avg latency, 15075.0 ms max latency.
5 records sent, 0.8 records/sec (0.59 MB/sec), 18587.0 ms avg latency, 21165.0 ms max latency.
5 records sent, 0.9 records/sec (0.62 MB/sec), 24551.2 ms avg latency, 26851.0 ms max latency.
4 records sent, 0.8 records/sec (0.55 MB/sec), 30048.0 ms avg latency, 31850.0 ms max latency.
5 records sent, 0.9 records/sec (0.62 MB/sec), 35323.4 ms avg latency, 37657.0 ms max latency.
5 records sent, 0.9 records/sec (0.63 MB/sec), 41030.4 ms avg latency, 43266.0 ms max latency.
5 records sent, 0.8 records/sec (0.59 MB/sec), 46736.6 ms avg latency, 49240.0 ms max latency.
5 records sent, 0.9 records/sec (0.62 MB/sec), 51716.2 ms avg latency, 53756.0 ms max latency.
5 records sent, 0.9 records/sec (0.63 MB/sec), 53765.8 ms avg latency, 53848.0 ms max latency.
5 records sent, 0.9 records/sec (0.61 MB/sec), 53506.2 ms avg latency, 53731.0 ms max latency.
4 records sent, 0.8 records/sec (0.55 MB/sec), 53638.3 ms avg latency, 54029.0 ms max latency.
5 records sent, 0.9 records/sec (0.62 MB/sec), 53690.4 ms avg latency, 54003.0 ms max latency.
5 records sent, 0.9 records/sec (0.64 MB/sec), 53371.6 ms avg latency, 53703.0 ms max latency.
5 records sent, 0.9 records/sec (0.62 MB/sec), 52922.0 ms avg latency, 53008.0 ms max latency.
4 records sent, 0.7 records/sec (0.53 MB/sec), 53774.3 ms avg latency, 53805.0 ms max latency.
5 records sent, 0.9 records/sec (0.63 MB/sec), 53788.6 ms avg latency, 53827.0 ms max latency.
5 records sent, 0.9 records/sec (0.64 MB/sec), 53317.2 ms avg latency, 53698.0 ms max latency.
5 records sent, 0.8 records/sec (0.60 MB/sec), 53373.2 ms avg latency, 53406.0 ms max latency.
5 records sent, 0.9 records/sec (0.63 MB/sec), 53441.8 ms avg latency, 53476.0 ms max latency.
100 records sent, 0.816993 records/sec (0.58 MB/sec), 42056.90 ms avg latency, 54029.00 ms max latency, 52990 ms 50th, 53805 ms 95th, 54029 ms 99th, 54029 ms 99.9th.

Messages are batched before they are sent to Kafka.消息在发送到 Kafka 之前被批处理。 More the number of messages in the batch, more can be sent in a single shot, the higher will be throughput.批处理中的消息数量越多,单次发送的消息越多,吞吐量就越高。

If you are increasing message size, then you also have to increase batch.size so that each batch allocates more number of messages in it.如果您要增加消息大小,那么您还必须增加batch.size以便每个批次在其中分配更多数量的消息。

From the code you have pasted, there is no property of setting batch.size, so it will be default which is 16384 bytes (16KB) which is way less than your message size (750 kb), so that is why you see 0.3 records/sec and so on.从您粘贴的代码中,没有设置 batch.size 的属性,因此默认值为 16384 字节(16KB),远小于您的消息大小(750 kb),这就是您看到 0.3 条记录的原因/秒等。

In batch.size documentationbatch.size 文档中

No attempt will be made to batch records larger than this size.不会尝试批处理大于此大小的记录。

So, you can try increasing your batch.size to allocate more messages, for example to 10Mb or so and check.因此,您可以尝试增加batch.size以分配更多消息,例如 10Mb 左右并检查。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM