Improving performance of Kafka Producer

前端 未结 3 1489
囚心锁ツ
囚心锁ツ 2021-01-15 07:55

We\'re running on apache kafka 0.10.0.x and spring 3.x and cannot use spring kafka as it is supported with spring framework version 4.x.

Therefore, we are using the

相关标签:
3条回答
  • 2021-01-15 08:38

    In the below conditions you need to configure batch.size, linger.ms & compression.type properties in your kafka prodocer to increase the performance.

    1) If records are arriving faster than the kafka producer can send.

    2) If you have huge amount of data in the your respective Topic, its really burden to your kafka producer.

    3) if you have a bottlenecks

    batch.size = 16_384 * 4
     linger.ms 200
    compression.type = "snappy"
    
    props.put(ProducerConfig.BATCH_SIZE_CONFIG, 16_384 * 4);
        // Send with little bit buffering
        props.put(ProducerConfig.LINGER_MS_CONFIG, 200);    
      //Use Snappy compression for batch compression.
        props.put(ProducerConfig.COMPRESSION_TYPE_CONFIG, "snappy");
    

    kafka Dzone

    Performance tunning

    Kafka Perforamnce tunning

    0 讨论(0)
  • 2021-01-15 08:43

    Your understanding is partially right.

    As @leshkin pointed out there are configuration parameters to tune how the KafkaProducer will handle buffering of messages to be sent.

    However independently from the buffering strategy, the producer will take care of caching established connections to topic-leader brokers.

    Indeed you can tune for how long the producer will keep such connection around using the connections.max.idle.ms parameter (defaults to 9 minutes).

    So to respond to your original question, the I/O cost of establishing a connection to the broker happens only on the first send invocation and will be amortised over time as long as you have data to send.

    0 讨论(0)
  • 2021-01-15 08:43

    The two important configuration parameters of kafka producer are 'batch.size' and 'linger.ms'. So you basically have a choice: you can wait until the producer batch is full, or the producer time out.

    • batch.size – This is an upper limit of how many messages Kafka Producer will attempt to batch before sending – specified in bytes.

    • linger.ms – How long will the producer wait before sending in order to allow more messages to get accumulated in the same batch.

    It depends on your use case, but I would suggest to take a closer look on these parameters.

    0 讨论(0)
提交回复
热议问题