简体   繁体   English

测量Kafka Streams中的处理吞吐量

[英]Measure processing throughput in Kafka Streams

I have a stream in java built as (anonimized some variables and classes): 我在java中建立了一个流(匿名化一些变量和类):

    Map<String, Object> props = new HashMap<>();
    Properties config = new Properties();
    config.put(StreamsConfig.APPLICATION_ID_CONFIG, "my-stream-processing-application");
    config.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, "my-kafka-broker:6667");
    config.put(StreamsConfig.KEY_SERDE_CLASS_CONFIG, Serdes.String().getClass());
    config.put(StreamsConfig.VALUE_SERDE_CLASS_CONFIG, Serdes.String().getClass());

    KStreamBuilder builder = new KStreamBuilder();
    KStream<String, String> events = builder.stream("my-topic");

    events.foreach((key, value) -> {
        CustomClass instance = new CustomClass(value);
        for (AnotherCustomClass anotherInstance: someIterator) {
            anotherInstance(instance);
        }
    });

    KafkaStreams streams = new KafkaStreams(builder, config);
    streams.start();

for kafka 0.10.0.0 : 对于kafka 0.10.0.0

compile group: 'org.apache.kafka', name: 'kafka-streams', version: '0.10.0.0'
compile group: 'org.apache.kafka', name: 'kafka-clients', version: '0.10.0.0' 

My question is the following: 我的问题如下:

  • How may I access the KafkaStreams streams.metrics inside the foreach loop? 如何在foreach循环中访问KafkaStreams streams.metrics In order to read and / or print the proccesed messages throughput 为了读取和/或打印处理的消息吞吐量
  • More generally: How may I measure the proceesed messages throughput? 更笼统地说: 我如何测量所处理的消息吞吐量? Where processed means a message such that anotherInstance(instance) has been evaluated “已处理”是指一条消息,表明 已评估 anotherInstance(instance)

Kafka Streams exposes all metrics via JMX (Java Management Extensions) . Kafka Streams通过JMX(Java管理扩展)公开了所有指标。 You can check those metrics by using JConsole or VisualVM . 您可以使用JConsoleVisualVM检查这些指标。 With those tools you can explore all metrics and graph them. 借助这些工具,您可以浏览所有指标并绘制图形。

In order to check how many messages your application is processing have a look at that metric: 为了检查您的应用程序正在处理多少消息,请查看该指标:

MBean: kafka.streams:type=stream-metrics,thread.client-id=[threadId]
Attribute: process-rate

It tells you average number of processed messages per second across all tasks. 它告诉您所有任务每秒平均处理的消息数。

Full list of Kafka Streams metrics can be found in official documentation. Kafka Streams指标的完整列表可以在官方文档中找到

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

相关问题 Kafka Streams 重新平衡高吞吐量 kafka-streams 服务的延迟峰值 - Kafka Streams rebalancing latency spikes on high throughput kafka-streams services Kafka Streams 是否适合触发记录的批处理? - Are Kafka Streams Appropriate for Triggering Batch Processing of Records? 使用Kafka流处理复杂的Avro消息 - Processing Complex Avro messages using Kafka Streams 如何使用 Kafka Streams 和 Spring Kafka Streams 定期(每 5 分钟)暂停和恢复 stream 处理? - How can I pause and resume stream processing periodically(every 5 minutes) using Kafka Streams and Spring Kafka Streams? 添加空处理器时,Kafka Streams的处理速度变慢 - Kafka Streams processing speed slows when empty processor is added Kafka Streams是否对处理时间进行超时? - Do Kafka Streams have a timeout on how long processing can take? 我们可以使用 CompletableFutures 进行并行 Kafka Streams 处理吗 - Can we do parallel Kafka Streams processing with CompletableFutures 使用Kafka Streams来窗口化数据并立即处理每个窗口 - Use Kafka Streams for windowing data and processing each window at once 增加kafka的吞吐量 - Increase the throughput of kafka 如果在处理步骤中发生故障,如何使 Spring 云 stream Kafka 流活页夹重试处理消息? - How to make Spring cloud stream Kafka streams binder retry processing a message if a failure occurs during the processing step?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM