-
Notifications
You must be signed in to change notification settings - Fork 224
Producing to Kafka cluster is very slow #291
Description
Hello,
I am using pykafka-2.0.0
In a scenario with single zk/kafka, producing and consuming behave normally, with fast response.
In a scenario with multiple zk/kafka, consuming is normal but producing is very slow. I need to wait 5-6 seconds after calling "producer.produce(msg)" for the message to actually be produced.
Java client and kafka-console-producer.sh both produce with normal speed:
Console producer:
./kafka1/bin/kafka-console-producer.sh --broker-list localhost:9092,localhost:9093 --topic test
With the Java client:
props.put("metadata.broker.list", "0.0.0.0:9092,0.0.0.0:9093");
props.put("serializer.class", "kafka.serializer.StringEncoder");ProducerConfig config = new ProducerConfig(props);
Producer<String, String> producer = new Producer<>(config);String msg = "this is produced by java";
KeyedMessage<String, String> data = new KeyedMessage<>("test", msg);
producer.send(data);
With the pykafka client:
client = KafkaClient(hosts="0.0.0.0:9092,0.0.0.0:9093")
producer = client.topics['test'].get_producer()
producer.produce('this is produced by python')
time.sleep(10)
Java consumer, pykafka consumer, and console-consumer.sh are consuming equally fast.
Console consumer:
./kafka1/bin/kafka-console-consumer.sh --zookeeper 0.0.0.0:2181 --topic test --from-beginning
Pykafka consumer code:
client = KafkaClient(hosts="0.0.0.0:9092,0.0.0.0:9093")
topic = client.topics['test']
consumer = topic.get_balanced_consumer(
consumer_group='cumtime',
zookeeper_connect='0.0.0.0:2181,0.0.0.0:2182',
reset_offset_on_start=True,
auto_offset_reset=OffsetType.LATEST
)
while True:
message=consumer.consume()
print(message.value)
I have seen this behaviour with a cluster on the same machine, or on different machines.
Thanks for any help/advice.