mfontanini / cppkafka

Modern C++ Apache Kafka client library (wrapper for librdkafka)
BSD 2-Clause "Simplified" License
600 stars 206 forks source link

cppkafka example Executive efficiency #185

Open songziqin opened 5 years ago

songziqin commented 5 years ago

I have a question. I have saw the example.the consumer poll one message then will execute consumer.commit(msg). and I think Executive efficiency is very low. I want to know if I want to commit after 100 poll messages and then commit. what can I should do. does I save the 100 messages partitions and offsets and commit use the api commit(const TopicPartitionList& topic_partitions).

accelerated commented 5 years ago

For best performance do: 1) if your application allows it, commit in batches, say every 100 messages. For this to work, you need to keep track of offsets as they are processed inside the application. If you use the commit(partitions) overload, you only need to have one offset per partition in that list (i.e. the last one processed) 2) alternatively, you can use consumer.commit(msg, true) which will commit asynchronously and is fast. 3) You can use the legacy consumer.store_offset() api which is also very fast. See here