IDEA调试Flink任务FAQ

自己写着玩的时候遇到的问题在此整理一下,要能捎带手帮各位看官解了惑那真是倍感荣幸,Flink版本1.12.0

IDEA调试Flink任务时需要WebUI

1.问题描述

在idea进行flink任务开发时,希望可以通过web ui查看一些信息

2.原因定位

在本地调试的时候时通过StreamExecutionEnvironment.createLocalEnvironment()创建执行时上下文,该方法未启动 web monitoring UI,需要通过createLocalEnvironmentWithWebUI(Configuration)方法创建上下文,该方法不仅会创建本地执行环境,同时会启动web monitoring UI

3.解决方法

添加依赖

<dependency>
	<groupId>org.apache.flink</groupId>
	<artifactId>flink-runtime-web_${scala.version}</artifactId>
	<version>${flink.version}</version>
</dependency>

通过createLocalEnvironmentWithWebUI(Configuration)方法创建执行时上下文

Configuration conf = new Configuration();
//set web monitoring ui port
conf.setInteger(RestOptions.PORT, 12345);
StreamExecutionEnvironment env = StreamExecutionEnvironment.createLocalEnvironmentWithWebUI(conf);

如果不指定端口号可不可以?答案是可以!If the configuration key 'rest.port' was set in the configuration, that particular port will be used for the web UI. Otherwise, the default port (8081) will be used.

IDEA调试FLink任务时想看运行日志

1.问题描述

在idea调试flink任务时候想看日志,但是控制台只有三行干巴巴的提示,这时候该怎么办?不要慌,人家都给你链接提示你了

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

2.原因定位

点进链接,我们找到对应的原因,翻译一下就是少包,那咱就加一下
在这里插入图片描述

3.解决方法

添加依赖

<dependency>
	<groupId>org.slf4j</groupId>
	<artifactId>slf4j-simple</artifactId>
	<version>1.7.25</version>
</dependency>

添加完依赖以后,控制台的日志就像便秘以后抹了开塞露,裤衩裤衩都显示出来了。

checkpoint失败

1.问题描述

在本地调试flink任务时,发现状态checkpoint失败
在这里插入图片描述

2.原因定位

查看日志发现状态大小超过默认最大值,由于代码中没有指定StateBackend,因此默认使用MemoryStateBackend,内存中默认为5MB,The default maximal size that the snapshotted memory state may have (5 MiBytes).

java.util.concurrent.ExecutionException: java.io.IOException: Size of the state is larger than the maximum permitted memory-backed state. Size=846910422 , maxSize=5242880 . Consider using a different state backend, like the File System State backend.
	at java.util.concurrent.FutureTask.report(FutureTask.java:122)
	at java.util.concurrent.FutureTask.get(FutureTask.java:192)
	at org.apache.flink.runtime.concurrent.FutureUtils.runIfNotDoneAndGet(FutureUtils.java:583)
	at org.apache.flink.streaming.api.operators.OperatorSnapshotFinalizer.<init>(OperatorSnapshotFinalizer.java:53)
	at org.apache.flink.streaming.runtime.tasks.AsyncCheckpointRunnable.run(AsyncCheckpointRunnable.java:115)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.io.IOException: Size of the state is larger than the maximum permitted memory-backed state. Size=846910422 , maxSize=5242880 . Consider using a different state backend, like the File System State backend.
	at org.apache.flink.runtime.state.memory.MemCheckpointStreamFactory.checkSize(MemCheckpointStreamFactory.java:64)
	at org.apache.flink.runtime.state.memory.MemCheckpointStreamFactory$MemoryCheckpointOutputStream.closeAndGetBytes(MemCheckpointStreamFactory.java:145)
	at org.apache.flink.runtime.state.memory.MemCheckpointStreamFactory$MemoryCheckpointOutputStream.closeAndGetHandle(MemCheckpointStreamFactory.java:126)
	at org.apache.flink.runtime.state.CheckpointStreamWithResultProvider$PrimaryStreamOnly.closeAndFinalizeCheckpointStreamResult(CheckpointStreamWithResultProvider.java:77)
	at org.apache.flink.runtime.state.heap.HeapSnapshotStrategy$1.callInternal(HeapSnapshotStrategy.java:199)
	at org.apache.flink.runtime.state.heap.HeapSnapshotStrategy$1.callInternal(HeapSnapshotStrategy.java:158)
	at org.apache.flink.runtime.state.AsyncSnapshotCallable.call(AsyncSnapshotCallable.java:75)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at org.apache.flink.runtime.concurrent.FutureUtils.runIfNotDoneAndGet(FutureUtils.java:580)
	... 5 more

3.解决方法

MemoryStateBackend类中可以指定maxStateSize大小,可通过MemoryStateBackend(int maxStateSize)方法进行指定,方法如下

StreamExecutionEnvironment env = StreamExecutionEnvironment.createLocalEnvironmentWithWebUI(conf);
env.setStateBackend(new MemoryStateBackend(1048576000));

在进行大状态存储时还是推荐使用其他的StateBackend方式,不建议使用MemoryStateBackend,具体原因可参考官网,不在此处赘述。

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在 IDEA 中使用 Flink,您需要执行以下步骤: 1. 下载和安装 Java Development Kit (JDK)。确保您安装的 JDK 版本符合 Flink 版本的要求。 2. 下载 Flink 安装包并解压缩。 3. 打开 IntelliJ IDEA。 4. 选择 File > New > Project。 5. 选择 Maven 项目类型。 6. 在 ArtifactId 字段中输入项目名称,例如 flink-demo。 7. 在 GroupId 字段中输入组名称,例如 com.example。 8. 单击 Next。 9. 在下一屏幕上,选择 Flink 依赖项。您可以从 Maven 仓库中搜索并添加 Flink 依赖项。例如,您可以添加以下依赖项: ``` <dependency> <groupId>org.apache.flink</groupId> <artifactId>flink-java</artifactId> <version>1.12.2</version> </dependency> ``` 10. 单击 Next。 11. 在下一屏幕上,选择项目的名称和位置。 12. 单击 Finish。 现在,您可以在 IntelliJ IDEA 中开始编写 Flink 应用程序了。您可以创建一个 Java 类,并在其中编写 Flink 代码。例如,以下是一个简单的 Flink 应用程序,它从一个文本文件中读取行并计算行数: ``` import org.apache.flink.api.common.functions.FlatMapFunction; import org.apache.flink.api.java.DataSet; import org.apache.flink.api.java.ExecutionEnvironment; import org.apache.flink.api.java.tuple.Tuple2; import org.apache.flink.util.Collector; public class LineCount { public static void main(String[] args) throws Exception { final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); DataSet<String> text = env.readTextFile("/path/to/file"); DataSet<Tuple2<String, Integer>> counts = text.flatMap(new LineSplitter()) .groupBy(0) .sum(1); counts.print(); } public static final class LineSplitter implements FlatMapFunction<String, Tuple2<String, Integer>> { @Override public void flatMap(String value, Collector<Tuple2<String, Integer>> out) { String[] tokens = value.toLowerCase().split("\\W+"); for (String token : tokens) { if (token.length() > 0) { out.collect(new Tuple2<>(token, 1)); } } } } } ``` 在此代码中,我们使用 Flink 的 ExecutionEnvironment 类来创建一个执行环境,并使用 readTextFile 方法从文本文件中读取行。然后,我们使用 flatMap 函数将行拆分为单词,并使用 groupBy 和 sum 函数计算每个单词的出现次数。最后,我们使用 print 函数打印每个单词的计数。 您可以使用 IntelliJ IDEA调试器来调试 Flink 应用程序,并使用 Maven 构建和运行应用程序。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值