8. Producer
Case1: 将消息一条一条发送到 Broker,发送的延迟是 2ms,那么 1s 可以发送 500 条消息;
Case2: 延迟 8ms 发送消息,假设 8ms 内收集到 20 条消息,那么 1s 可以发送 2000 条消息;
Latency or Throughput?
batch.size: This is an upper limit of how many messages Kafka Producer will attempt to batch before
sending, specified in bytes (default is 16K bytes). Kafka may send batches before this limit is, but will
always send when this limit is reached. Therefore setting this limit too low will hurt throughput
without improving latency. The main reason to set this low is lack of memory – Kafka will always
allocate enough memory for the entire batch size, even if latency requirements cause it to send half-
empty batches.
linger.ms: How long will the producer wait before sending in order to allow more messages to get
accumulated in the same batch. (default is 0). Sometimes we are willing to wait a bit longer in order
to improve the overall throughput at the expense of a little higher latency.