我的 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/