How to slow down or set given speed on the Kafka stream consumer?

Seweryn Habdank-Wojewódzki picture Seweryn Habdank-Wojewódzki · Jun 29, 2017 · Viewed 7.7k times · Source

I am trying to control number of messages which are consumed by the KStream and I am not very succesful.

I am using: max.poll.interval.ms=100 and max.poll.records=20 to get like 200 messages per second.

But it seems to be not very good, as I see that there are like 500 messages per second also in my statistics.

What else shall I set on the side of the stream consumer?

Answer

Daniccan picture Daniccan · Jun 29, 2017

I am using: max.poll.interval.ms=100 and max.poll.records=20 to get like 200 messages per second.

max.poll.interval.ms and max.poll.records properties do not work this way.

max.poll.interval.ms indicates the maximum time interval in milliseconds the consumer has to wait in between each consumer poll of the topic.

max.poll.records indicates the maximum number of records the consumer can consume during each consumer poll of the topic.

The interval between each poll is not controlled by the above two properties but by the time taken by your consumer to acknowledge the fetched records.

For example, let's say a topic X exists with 1000 records in it, and the time taken by the consumer to acknowledge the fetched records is 20ms. With max.poll.interval.ms = 100 and max.poll.records = 20, the consumer will poll the Kafka topic every 20ms and in every poll, max of 20 records will be fetched. In case, the time taken to acknowledge the fetched records is greater than the max.poll.interval.ms, the polling will be considered as failed and that particular batch will re-polled again from the Kafka topic.