文章来源于网络收集而来,版权归原创者所有,如有侵权请及时联系!
kafka-python
kafka-python aims to replicate the java client api exactly. This is a key difference with pykafka, which trys to maintains "pythonic" api. In earlier versions of kafka, partition balancing was left to the client. Pykafka was the only python client to implement this feature. However, with kafka 0.9 the broker provides this, so the lack of support within kafka-python is less important.
https://github.com/dpkp/kafka-python
from kafka import KafkaProducer
def python_kafka_producer_performance():
producer = KafkaProducer(bootstrap_servers=bootstrap_servers)
producer_start = time.time()
topic = 'python-kafka-topic'
for i in range(msg_count):
producer.send(topic, msg_payload)
producer.flush() # clear all local buffers and produce pending messages
return time.time() - producer_start
producer_timings['python_kafka_producer'] = python_kafka_producer_performance()
calculate_thoughput(producer_timings['python_kafka_producer'])
Processed 1000000 messsages in 67.86 seconds
1.41 MB/s
14737.12 Msgs/s
from kafka import KafkaConsumer
def python_kafka_consumer_performance():
topic = 'python-kafka-topic'
consumer = KafkaConsumer(
bootstrap_servers=bootstrap_servers,
auto_offset_reset = 'earliest', # start at earliest topic
group_id = None # do no offest commit
)
msg_consumed_count = 0
consumer_start = time.time()
consumer.subscribe([topic])
for msg in consumer:
msg_consumed_count += 1
if msg_consumed_count >= msg_count:
break
consumer_timing = time.time() - consumer_start
consumer.close()
return consumer_timing
_ = python_kafka_consumer_performance()
consumer_timings['python_kafka_consumer'] = python_kafka_consumer_performance()
calculate_thoughput(consumer_timings['python_kafka_consumer'])
Processed 1000000 messsages in 26.55 seconds
3.59 MB/s
37667.97 Msgs/s
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论