title: Kafka producer difference between flush and poll
body: <p>We have a Kafka consumer which will read messages and do so stuff and again publish to Kafka topic using below script</p>
  
  <p>producer config :</p>
  
  <pre><code>{
    "bootstrap.servers": "localhost:9092"
  }
  </code></pre>
  
  <p>I haven't configured any other configuration like <code>queue.buffering.max.messages</code> <code>queue.buffering.max.ms</code> <code>batch.num.messages</code></p>
  
  <p>I am assuming these all will be going to be default values from <a href="https://github.com/edenhill/librdkafka/blob/master/CONFIGURATION.md" rel="noreferrer">configuration</a></p>
  
  <pre><code>queue.buffering.max.messages : 100000
  queue.buffering.max.ms : 0
  batch.num.messages : 10000
  </code></pre>
  
  <p>my understanding : When internal queue reaches either of queue.buffering.max.ms or batch.num.messages messages will get published to Kafka in separate thread. in my configuration queue.buffering.max.ms is 0, so every message will be published as soon as when I call produce(). correct me if I am wrong.</p>
  
  <p>My producer snippet:</p>
  
  <pre><code>def send(topic, message):
      p.produce(topic, json.dumps(message), callback=delivery_callback(err, msg))
      p.flush()
  </code></pre>
  
  <p>from <a href="https://github.com/confluentinc/confluent-kafka-python/issues/137#issuecomment-424600189" rel="noreferrer">this post</a> i understand that using flush after every message, producer is going to be sync producer .  if I use above script it is taking ~ 45ms to publish to Kafka</p>
  
  <p>If I change above snippet to</p>
  
  <pre><code>def send(topic, message):
      p.produce(topic, json.dumps(message), callback=delivery_callback(err, msg))
      p.poll(0)
  </code></pre>
  
  <p>Is there any performance will be improved ? Can you clarify my understanding.</p>
  
  <p>Thanks</p>