haskell-works / hw-kafka-client

Kafka client for Haskell, including auto-rebalancing consumers
MIT License
140 stars 50 forks source link

Improve documentation for callbackPollMode #175

Open kamek-pf opened 3 years ago

kamek-pf commented 3 years ago

I lost a few hours to this, so I figured the extra comment might be useful to someone else. For the record, I was setting up my consumer props like this:

let brokers = brokersList $ map BrokerAddress $ (kafkaBrokers . kafkaConfig) context
    group = groupId $ ConsumerGroupId $ (kafkaGroup . kafkaConfig) context
    logs = logLevel KafkaLogInfo
    commit = autoCommit $ Millis 5000
    pollMode = callbackPollMode CallbackPollModeSync
 in brokers <> group <> pollMode <> commit <> logs

which caused the callbackPollMode to be reset to CallbackPollModeAsync (the default).

For this to work the last line should be brokers <> group <> commit <> logs <> pollMode.

kamek-pf commented 3 years ago

Semi related, and I have no idea how other rdkafka bindings behave, but CallbackPollModeAsync is a surprising default to me. If your processing pipeline can't keep up with the async thread polling Kafka in the background, messages will accumulate in memory and then you lose the main form of backpressure.

Not a huge deal if you're aware of the implications, but I've been using this library for a few months and this definitely went over my head until I started digging into strange memory usage patterns of some services we have.

robinp commented 3 years ago

I'm not very familiar with the rd-variant of Kafka either, but a few cents so far:

But as I said, kind of new to rd_kafka, correct if I'm missing something.