You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@kafka.apache.org by Rohan Kulkarni <ro...@gmail.com> on 2018/07/03 09:49:25 UTC

How to get best concurrency performance while using KafkaProducer?

KafkaProducer javadoc
<https://archive.apache.org/dist/kafka/1.1.0/javadoc/org/apache/kafka/clients/producer/KafkaProducer.html>
 says that using single instance will give faster performance than using
multiple instances "*The producer is thread safe and sharing a single
producer instance across threads will generally be faster than having
multiple instances.*" - what is the explanation for this?

On the contrary while going through KafkaProducer.send() code flow
<https://github.com/apache/kafka/blob/8250738ae41f6f0a87dc1e21e7623c5d69cae148/clients/src/main/java/org/apache/kafka/clients/producer/internals/RecordAccumulator.java#L196>
 found out that there is a sychronized block on TopicPartition object, so
we should be able achieve better performance if we are using multiple
producer instances...?

Please advise on the recommended approach to achieve best performance with
KafkaProducer.