Apache Flink的吞吐量和延迟

时间:2017-06-16 11:02:09

标签: java apache-flink latency flink-streaming throughput

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

 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公开了一些指标:

  

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

但我不知道如何使用它们来获得我想要的东西。从链接中我已经读过“米”可用于测量平均吞吐量,但在定义之后,我应该如何使用它?

1 个答案:

答案 0 :(得分:1)

我们正在运行纱线上的生产流工作中运行自定义指标,如米,表。

以下是步骤:

对pom.xml的附加依赖

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

我们使用的是版本1.2.1

然后将米添加到MyMapper类。

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;
        }
    }
}

希望这有帮助。