环境:hadoop 3.1.1.3.0.1.0-187 spark 2.4.6

背景:

在saprk on yarn模式提交任务异常如下:
Caused by: org.apache.spark.SparkException: Job aborted due to stage failure: Task 0 in stage 0.0 failed 4 times, most recent failure: Lost task 0.3 in stage 0.0 (TID 5, kde-online4, executor 6): ExecutorLostFailure (executor 6 exited caused by one of the running tasks) Reason: Unable to create executor due to Unable to register with external shuffle server due to : Failed to connect to kde-online4/10.xx.xx.xx:7337

问题定位:

Spark系统在运行含shuffle过程的应用时,Executor进程除了运行task,还要负责写shuffle数据,给其他Executor提供shuffle数据。当Executor进程任务过重,导致GC而不能为其他Executor提供shuffle数据时,会影响任务运行。
External shuffle Service是长期存在于NodeManager进程中的一个辅助服务。通过该服务来抓取shuffle数据,减少了Executor的压力,在Executor GC的时候也不会影响其他Executor的任务运行。

解决方式:

在NodeManager中启动External shuffle Service。

在“yarn-site.xml”中添加如下配置项:

yarn.nodemanager.aux-services
spark_shuffle


yarn.nodemanager.aux-services.spark_shuffle.class
org.apache.spark.network.yarn.YarnShuffleService


spark.shuffle.service.port
7337

在“spark-defaults.conf”中必须添加如下配置项:
spark.shuffle.service.enabled true
spark.shuffle.service.port 7337

配置参数 描述
spark.shuffle.service.enabled NodeManager中一个长期运行的辅助服务,用于提升Shuffle计算性能。默认为false,表示不启用该功能。
spark.shuffle.service.port Shuffle服务监听数据获取请求的端口。可选配置,默认值为“7337”。

参考文档: