【Flink系列二十】Flink Example AsyncIOExample long running 應用程序的應用

Flink AsyncIOExample

Flink 的源碼內有這麼一個AsyncIOExample程序,非常好用,可以用來無限跑流。
用英文說就是long running或者runs forever。

同時可以用來測試checkpoints,metricReporter。

如何找到這個程序

這個程序在源碼內,但很不幸,官方可能忘記加到maven ant插件的構建過程中。

以Flink-1.13.0爲例:

flink-examples/flink-examples-streaming/src/main/java/org/apache/flink/streaming/examples/async/AsyncIOExample.java

使用方法

private static void printUsage() {
        System.out.println(
                "To customize example, use: AsyncIOExample [--fsStatePath <path to fs state>] "
                        + "[--checkpointMode <exactly_once or at_least_once>] "
                        + "[--maxCount <max number of input from source, -1 for infinite input>] "
                        + "[--sleepFactor <interval to sleep for each stream element>] [--failRatio <possibility to throw exception>] "
                        + "[--waitMode <ordered or unordered>] [--waitOperatorParallelism <parallelism for async wait operator>] "
                        + "[--eventType <EventTime or IngestionTime>] [--shutdownWaitTS <milli sec to wait for thread pool>]"
                        + "[--timeout <Timeout for the asynchronous operations>]");
}

爲什麼下載的flink examples文件夾內沒有AsyncIO.jar

flink-examples/flink-examples-streaming/pom.xml

僅僅因爲下方的代碼忘記寫一行copy了。

<!--simplify the name of example JARs for build-target/examples -->
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-antrun-plugin</artifactId>
				<executions>
					<execution>
						<id>rename</id>
						<configuration>
							<target>
								<copy file="${project.basedir}/target/flink-examples-streaming_${scala.binary.version}-${project.version}-Iteration.jar" tofile="${project.basedir}/target/Iteration.jar" />
								<copy file="${project.basedir}/target/flink-examples-streaming_${scala.binary.version}-${project.version}-SessionWindowing.jar" tofile="${project.basedir}/target/SessionWindowing.jar" />
								<copy file="${project.basedir}/target/flink-examples-streaming_${scala.binary.version}-${project.version}-TopSpeedWindowing.jar" tofile="${project.basedir}/target/TopSpeedWindowing.jar" />
								<copy file="${project.basedir}/target/flink-examples-streaming_${scala.binary.version}-${project.version}-WindowJoin.jar" tofile="${project.basedir}/target/WindowJoin.jar" />
								<copy file="${project.basedir}/target/flink-examples-streaming_${scala.binary.version}-${project.version}-WordCount.jar" tofile="${project.basedir}/target/WordCount.jar" />
								<copy file="${project.basedir}/target/flink-examples-streaming_${scala.binary.version}-${project.version}-SocketWindowWordCount.jar" tofile="${project.basedir}/target/SocketWindowWordCount.jar" />
							</target>
						</configuration>
					</execution>
				</executions>
			</plugin>

如何運行

可以直接複製源碼,進行編譯,無需compile任何依賴(可能需要rocksdb的依賴)

編譯完成以後複製到任何位置,例如本應該存在於下方的路徑:

./bin/flink run-application examples/streaming/AsyncIO.jar \
   -D "state.checkpoints.num-retained=5"
   --class org.apache.flink.streaming.examples.async.AsyncIOExample \
    --fsStatePath viewfs://slankka_hdfs/user/slankka/flink_checkpoints \
   --checkpointMode exactly_once \
   --maxCount \
   -1

提示

注意這個程序的流有點快,可能導致打印大量console日誌寫盤,可修改數據源流的間隔時間。

注意 maxCount=-1時,這個程序將長時間運行下去,否則運行一段時間達到maxCount則會FINISHED退出,可根據這個參數選擇是否長時間運行。

注意checkpoint的間隔是1秒一個,如果使用了External Checkpoint Storage,則可能會寫入大量Checkpoint,可以修改checkpoint保留個數。

如果需要測試MetricReporter, 則需要配置相應的flink-conf。

參見:【Flink系列二】構建實時計算平臺——特別篇,用InfluxDb收集Flink Metrics

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章