【问题标题】:How do we understand the Word-Count sample of Apache Flink我们如何理解 Apache Flink 的 Word-Count 示例
【发布时间】:2020-04-28 14:33:50
【问题描述】:

我正在学习 Apache Flink,这里是字数示例: https://ci.apache.org/projects/flink/flink-docs-stable/getting-started/tutorials/local_setup.html

我在工作,但我有些东西看不懂。

Flink 包含三个部分:JobManagerTaskManagerJobClient。据我了解,SocketWindowWordCount 类的 java 代码应该是JobClient 的一部分,这个类应该将它要求做的事情发送到JobClient 然后JobClient 可以将任务发送到JobManager .

我说的对吗?

如果我是对的,我不知道文件SocketWindowWordCount.java 中的哪一部分代码负责将它要求做的事情发送到JobClient

监听端口是否也是任务的一部分,该任务将发送到JobManager,然后发送到TaskManager

// get input data by connecting to the socket
DataStream<String> text = env.socketTextStream("localhost", port, "\n");

// parse the data, group it, window it, and aggregate the counts
DataStream<WordWithCount> windowCounts = text
    .flatMap(new FlatMapFunction<String, WordWithCount>() {
        @Override
        public void flatMap(String value, Collector<WordWithCount> out) {
            for (String word : value.split("\\s")) {
                out.collect(new WordWithCount(word, 1L));
            }
        }
    })
    .keyBy("word")
    .timeWindow(Time.seconds(5), Time.seconds(1))
    .reduce(new ReduceFunction<WordWithCount>() {
        @Override
        public WordWithCount reduce(WordWithCount a, WordWithCount b) {
            return new WordWithCount(a.word, a.count + b.count);
        }
    });

// print the results with a single thread, rather than in parallel
windowCounts.print().setParallelism(1);

上面的所有代码都是任务的一部分吗?

总之,我有点了解 Flink 的架构,但我想了解更多关于 JobClient 工作原理的细节。

【问题讨论】:

    标签: apache-flink


    【解决方案1】:

    从架构的角度来看,您的程序本身就是JobClient。特别是,当您执行 DataStream 时,您对 JobClient 有依赖关系。

    您的所有代码都是被序列化并发送到JobManager 的任务定义,后者将其分发到TaskManager

    你遗漏了程序中“最”重要的部分

    env.execute("套接字窗口字数");

    那其实就是触发JobClient打包DataStream程序发送给配置好的JobManager

    【讨论】:

      猜你喜欢
      • 2016-06-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-11
      • 1970-01-01
      • 2017-02-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多