本文介绍了Apache Flink 上的吞吐量和延迟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为 Apache Flink 编写了一个非常简单的 java 程序,现在我对测量统计数据感兴趣,例如吞吐量(每秒处理的元组数)和延迟(程序需要处理每个输入元组的时间).

I have written a very simple java program for Apache Flink and now I am interested in measuring statistics such as throughput (number of tuples processed per second) and latency (the time the program needs to process every input tuple).

 StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

env.readTextFile("/home/LizardKing/Documents/Power/Prova.csv")
        .map(new MyMapper().writeAsCsv("/home/LizardKing/Results.csv");

JobExecutionResult res = env.execute();

我知道 Flink 公开了一些指标:

I know that Flink exposes some metrics:

https://ci.apache.org/projects/flink/flink-docs-release-1.2/monitoring/metrics.html

但我不确定如何使用它们来获得我想要的东西.从我读到的链接中可以使用仪表"来测量平均吞吐量,但是在定义它之后,我应该如何使用它?

But I am not sure how to use them in order to obtain what I want. From the link I have read that a "meter" can be used to measure the average throughput but, after having defined it, how should I use it?

推荐答案

我们正在运行在 yarn 上的生产流作业中运行自定义指标,如仪表、仪表.

We are running custom metrics like meter, gauge in our production streaming job running on yarn .

以下是步骤:

对 pom.xml 的附加依赖

Additional dependency to pom.xml

<dependency>
    <groupId>org.apache.flink</groupId>
    <artifactId>flink-metrics-dropwizard</artifactId>
    <version>${flink.version}</version>
</dependency>

我们使用的是 1.2.1 版

We are using version 1.2.1

然后将仪表添加到 MyMapper 类.

Then add meter to MyMapper class .

import org.apache.flink.api.common.JobExecutionResult;
import org.apache.flink.api.common.functions.RichMapFunction;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.dropwizard.metrics.DropwizardMeterWrapper;
import org.apache.flink.metrics.Meter;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;


public class Test {


    public static void main(String[] args) throws Exception {

        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        env
                .readTextFile("/home/LizardKing/Documents/Power/Prova.csv")
                .map(new MyMapper())
                .writeAsCsv("/home/LizardKing/Results.csv");

        JobExecutionResult res = env.execute();
    }


    private static class MyMapper extends RichMapFunction<String, Object> {

        private transient Meter meter;

        @Override
        public void open(Configuration parameters) throws Exception {
            super.open(parameters);
            this.meter = getRuntimeContext()
                    .getMetricGroup()
                    .meter("myMeter", new DropwizardMeterWrapper(new com.codahale.metrics.Meter()));
        }

        @Override
        public Object map(String value) throws Exception {
            this.meter.markEvent();
            return value;
        }
    }
}

希望这会有所帮助.

这篇关于Apache Flink 上的吞吐量和延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 01:18