Search code examples
javaasynchronousapache-kafkakafka-producer-api

Asynchronous Kafka Producer batch size a linger.ms


I have a question about optimizing kafka asynchronous producer Throughput: the configuration batch.size and linger.ms have an effect when using asynchronous producer?

I am asking because I think that those parameters will only impact synchronous producer because it will wait for broker acknowledgment.In case of asynchronous producer , this will not have impact?

Also, is there any configuration parameter that can optimize asynchronous producer?


Solution

  • Both the properties have impact on asynchronous Kafka Producer:

    linger.ms-> This instruct the producer upto this configured value(ex:2 millisecond) if batch size is not fill up. There will be latency of 2 ms in case message flow is low.
    
    
    
    batch.size -> Message buffer size that will be send in single request. Higher batch size also request more memory (buffer.memory)
    
    acks=all , Slowest but most durable configuration, wait for acknowledgement of all message sent.
    

    For details, You can go through Kafka document: https://kafka.apache.org/23/javadoc/org/apache/kafka/clients/producer/KafkaProducer.html