命令如下:
bin/spark-submit --class com.practice1.Tax1 --master yarn --num-executors 4 --driver-memory 1g --executor-memory 1g /opt/software/data/sparkcount.jar hdfs:/data_in/taxi.csv
1、错误如下:
19/07/09 23:34:50 WARN Client: Neither spark.yarn.jars nor spark.yarn.archive is set, falling back to uploading libraries under SPARK_HOME.
19/07/09 23:35:17 ERROR YarnClientSchedulerBackend: Yarn application has already exited with state FINISHED!
19/07/09 23:35:17 ERROR TransportClient: Failed to send RPC 4998521843097147837 to /10.1.18.204:49508: java.nio.channels.ClosedChannelException
java.nio.channels.ClosedChannelException
at io.netty.channel.AbstractChannel$AbstractUnsafe.write(...)(Unknown Source)
19/07/09 23:35:17 ERROR YarnSchedulerBackend$YarnSchedulerEndpoint: Sending RequestExecutors(0,0,Map()) to AM was unsuccessful
java.io.IOException: Failed to send RPC 4998521843097147837 to /10.1.18.204:49508: java.nio.channels.ClosedChannelException
2、可以根据错误看下ResourceMangaer与NodeMangaer的日志,看看里面有什么端倪
有人看到了这句:
Current usage: 360.4 MB of 1 GB physical memory used; 2.4 GB of 2.1 GB virtual memory used. Killing container.
意思是说container使用的虚拟内存超过了设置的2.1G
那么,问题来了,这个虚拟内存的数量从那儿来的呢?
是从yarn-site.xml中配置计算来的,yarn.scheduler.minimum-allocation-mb * yarn.nodemanager.vmem-pmem-ratio = 虚拟内存的总量,如果需要的虚拟内存总量超过这个计算所得的数值,就会出发 Killing container.
此处 我的yarn.scheduler.minimum-allocation-mb值没设置,默认为1G,yarn.nodemanager.vmem-pmem-ratio也没设置,默认为2.1,因此,就有了以上的日志,用了1g里的360M物理内存,用了2.1G里的2.4G虚拟内存。
然后修改yarn-site.xml如下几个配置
<property>
<name>yarn.scheduler.maximum-allocation-mb</name>
<value>9216</value>
<discription>每个任务最多可用内存,单位MB,默认8182MB</discription>
</property>
<property>
<name>yarn.scheduler.minimum-allocation-mb</name>
<value>4000</value>
<discription>每个任务最shao可用内存</discription>
</property>
<property>
<name>yarn.nodemanager.vmem-pmem-ratio</name>
<value>4.1</value>
</property>
重新运行,错误消失
另外好多贴子的解决方法是关闭这个虚拟内存的检测,个人不太建议如此。
在yarn-site.xml配置如下:
<property>
<name>yarn.nodemanager.vmem-check-enabled</name>
<value>false</value>
</property>
部分自清霄修改