Robert Herhold
Robert Herhold

Reputation: 404

How to minimize latency in a Kafka Streams application?

My Kafka Streams application typically takes about 100ms from the time that a message is sent to the time that a response message is sent on a different topic as a result. What configuration options can I adjust or best-practices can I use to minimize latency?

Upvotes: 4

Views: 4870

Answers (1)

Matthias J. Sax
Matthias J. Sax

Reputation: 62350

This seems to be related to producer config linger.ms.

From (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 sets this value to 100ms (plain producer default value is 0ms) to increase throughput.

You can reduce the value via StreamsConfig parameter producer.linger.ms. It's recommended to prefix producer configs with producer. in Streams to isolate producer/consumer configs. You can use StreamsConfig.producerPrefix(ProducerConfig.LINGER_MS_CONFIG) as parameter name for highest convenience :)

Upvotes: 9

Related Questions