apache-kafka - 如何最小化 Kafka Streams 应用程序中的延迟?

标签 apache-kafka apache-kafka-streams

我的 Kafka Streams 应用程序通常需要大约 100 毫秒,从发送消息到结果在不同主题上发送响应消息。我可以调整哪些配置选项或使用最佳实践来最大程度地减少延迟?

最佳答案

这似乎与生产者配置linger.ms有关。

发件人(http://kafka.apache.org/documentation/#producerconfigs)

The producer groups together any records that arrive in between request transmissions into a single batched request. Normally this occurs only under load when records arrive faster than they can be sent out. However in some circumstances the client may want to reduce the number of requests even under moderate load. This setting accomplishes this by adding a small amount of artificial delay—that is, rather than immediately sending out a record the producer will wait for up to the given delay to allow other records to be sent so that the sends can be batched together. This can be thought of as analogous to Nagle's algorithm in TCP. This setting gives the upper bound on the delay for batching: once we get batch.size worth of records for a partition it will be sent immediately regardless of this setting, however if we have fewer than this many bytes accumulated for this partition we will 'linger' for the specified time waiting for more records to show up. This setting defaults to 0 (i.e. no delay). Setting linger.ms=5, for example, would have the effect of reducing the number of requests sent but would add up to 5ms of latency to records sent in the absense of load.

Kafka Streams 将此值设置为 100 毫秒(普通生产者默认值为 0 毫秒)以增加吞吐量。

您可以通过 StreamsConfig 参数 producer.linger.ms 减小该值。建议在 Streams 中为生产者配置添加 producer. 前缀,以隔离生产者/消费者配置。您可以使用 StreamsConfig.producerPrefix(ProducerConfig.LINGER_MS_CONFIG) 作为参数名称以获得最大的方便:)

关于apache-kafka - 如何最小化 Kafka Streams 应用程序中的延迟?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44936557/

相关文章:

apache-kafka - 如何更改 Kafka 中特定主题的 TTL

java - 具有 Avro 记录的 Kafka Streams TopologyTestDriver 的架构注册问题

java - Kafka Kstream Json Join 无法转换为 java.lang.String

hbase - 实时流数据分析

java - Apache Camel - Kafka 组件 - 单生产者多消费者

php - 无法解析 'kafka:9092' : Name or service not known - docker/php-rdkafka

java - 消费者失败时的 Kafka 行为

apache-kafka - 增加 KafkaConsumer 单次轮询中读取的记录数

java - 从多个 Kafka 主题消费

java - Kafka Stream 在时间窗口上计数不报告零值