卡夫卡生产者配额和超时异常

时间:2020-03-13 03:27:22

标签: apache-kafka kafka-producer-api

我正在尝试提出一种配置,该配置将根据生产者的平均字节率来强制执行生产者配额设置。 我对3节点群集进行了测试。但是,该主题是使用1个分区和1个复制因子创建的,因此只能为1个经纪人(领导经纪人)测量producer_byte_rate。

我将客户端ID为test_producer_quota的producer_byte_rate设置为20480。

我使用kafka-producer-perf-test来测试吞吐量和油门。

kafka-producer-perf-test --producer-props bootstrap.servers=SSL://kafka-broker1:6667 \
client.id=test_producer_quota \
--topic quota_test \
--producer.config /myfolder/client.properties \
--record.size 2048  --num-records 4000 --throughput -1

我希望生产者客户端了解限制因素,并最终使发送给代理的请求变得平滑。取而代之的是,我注意到在超过30秒的时间内有98 rec / sec和21 recs / sec的交替吞吐率。在这段时间内,平均延迟缓慢增加,最终达到120000 ms时,我开始看到如下所示的Timeout异常

org.apache.kafka.common.errors.TimeoutException:quota_test-0的7条记录已过期:自批量创建以来已过去120000 ms。

什么可能导致此问题?

  1. 当延迟达到120秒(delivery.timeout.ms的默认值)时,生产者正在超时。
  2. 为什么生产者不了解节制和配额并放慢速度或退缩 其他哪些生产者配置可以帮助缓解此超时问题?

1 个答案:

答案 0 :(得分:0)

(2048 * 4000) / 20480 = 400 (sec)

这意味着,如果生产者试图全速发送4000条记录(之所以如此,是因为您将吞吐量设置为-1),则它可能会批量处理它们并将它们放入队列中。大概一两秒钟(取决于您的CPU)。

然后,由于您的配额设置(20480),您可以确保代理不会在至少399或398秒之前“完成”这4000条记录的处理。

The broker does not return an error when a client exceeds its quota, but instead attempts to slow the client down. The broker computes the amount of delay needed to bring a client under its quota and delays the response for that amount of time. 

将您的request.timeout.ms设置为120 seconds,然后您会收到此timeoutException。