简体   繁体   English

全程控制在Apache Kafka

[英]Control throughout in Apache Kafka

I want to run tests to measure the latency and throughout of different frameworks.我想运行测试来测量不同框架的延迟和吞吐量。 I send messages to a kafka topic using an script that reads from a txt file.我使用从 txt 文件读取的脚本向 kafka 主题发送消息。 This frameworks consumes events from this input topic and produces into an output topic.此框架使用来自此输入主题的事件并生成一个 output 主题。 I have two questions about this:我对此有两个问题:

A) Lets say I want to send 400 events per second. A) 假设我想每秒发送 400 个事件。 How do I control that?我该如何控制它? Its something that is controlled by the script that sends the data or it can be configured in Kafka?它是由发送数据的脚本控制的,还是可以在 Kafka 中配置的?

B) If I can control throughput tuning Kafka parameters, how do I gradually increment the amount of events sent (dinamically)? B) 如果我可以控制吞吐量调整 Kafka 参数,我如何逐渐增加发送的事件数量(动态地)?

thank you very much!非常感谢!

Throughput can be controlled in Kafka by enforcing Quotas on clients.可以通过在客户端上强制执行配额来控制 Kafka 中的吞吐量。 But the catch is it's enforced in terms of Bytes/sec and not number of messages per second.但要注意的是,它是根据字节/秒而不是每秒的消息数来强制执行的。

Since it's for testing purposes you can define the quota like this in the Kafka config file (server.properties):由于它是出于测试目的,您可以在 Kafka 配置文件 (server.properties) 中像这样定义配额:

quota.producer.default=100
quota.consumer.default=100

Do note, that this will mean it will apply this throttling on all the topics.请注意,这意味着它将对所有主题应用此限制。 Also, 100 here means 100 bytes.另外,这里的 100 表示 100 个字节。

If you want to enforce quota on specific producer or consumer clients you can do that using:如果你想对特定的生产者或消费者客户强制执行配额,你可以使用:

quota.producer.override="clientA:4M,clientB:6M"

Which means regardless of whatever the default Quota is, producer with client.id "ClientA" can produce at a max of 4Mbps.这意味着无论默认配额是什么,client.id 为“ClientA”的生产者最多可以生产 4Mbps。

As, for the dynamic part, instead of having to set these on the property file manually, you can use the kafka-config.sh file to set these configs:至于动态部分,您可以使用 kafka-config.sh 文件来设置这些配置,而不必手动在属性文件中设置这些配置:

bin/kafka-configs.sh  --bootstrap-server localhost:9092 --alter --add-config 'producer_byte_rate=1024' --entity-name clientA --entity-type clients

Which means, I want to enforce a throttle on a client with clientID "clientA" and the throttling is on produce-limit that needs to be set at max of 1024 bytes.这意味着,我想对 clientID 为“clientA”的客户端实施限制,并且限制是在需要设置为最大 1024 字节的生产限制上。

You can programmatically use this script to increase of decrease quotas dynamically.您可以以编程方式使用此脚本来动态增加或减少配额。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM