Spring Kafka producers throwing TimeoutExceptions Spring Kafka producers throwing TimeoutExceptions kubernetes kubernetes

Spring Kafka producers throwing TimeoutExceptions


This problem normally occurs when the producer is faster than the brokers, the reason why this happens with your setup seems to be that the SSL needs extra CPU and that may slow down the brokers. But anyway check the following:

  • Check if you are producing message at the same speed, according what you are saying seems that you are having spikes.
  • Another possibility is that other kafka clients in the cluster (producer or consumers), which not necessarily uses the same topic, makes this to happen because overloads the brokers (check brokers cpu/network).

To minimize whatever causes this retention you should increase the buffer-memory to more than 32MB, think that 32MB is the default and you are setting this lower. The lower you have, the easy is that the buffer gets full and if this happens it will block at most max.block.ms, and a request will timeout after request.timeout.ms.

Another parameter that you should increase is batch-size, this parameter is in bytes, not in number of messages. Also linger.ms should be increased, in case this producer messages are created in user request time, do not increase very much, a good choice could be 1-4 ms.

Messages will be send when the batch.size gets full or takes longer than linger.ms to have more data than the batch.size. Big batches increases the throughput in normal cases, but if the linger is too low it doesn't help, because you will send before you have enough data to get the batch.size.

Also recheck on producer logs that the properties are loaded correctly.