運行MapReduce應用:提示物理內存或者虛擬內存超出限制

一、提示物理內存或者虛擬內存超出限制

當運行MapReduce應用的時候,有時候會出現異常信息,提示物理內存或者虛擬內存超出限制,默認情況下:虛擬內存是物理內存的2.1倍。異常信息類似如下:

2020-03-31 03:09:52,133 INFO mapreduce.Job: Task Id : attempt_1585554168048_0018_m_000000_1, Status : FAILED

[2020-03-31 03:09:50.587]Container [pid=16665,containerID=container_1585554168048_0018_01_000003] is running 466938368B beyond the 'VIRTUAL' memory limit. Current usage: 103.0 MB of 1 GB physical memory used; 2.5 GB of 2.1 GB virtual memory used. Killing container.

原因:從機上運行的Container試圖使用過多的內存,而被NodeManager kill掉了。


下圖是運行MapReduce應用出現的情況:虛擬內存超出。

hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-3.1.2.jar wordcount input output

運行MapReduce應用:提示物理內存或者虛擬內存超出限制


二、MapReduce中的參數以及默認值

先了解一下MapReduce中的參數以及默認值:

運行MapReduce應用:提示物理內存或者虛擬內存超出限制


三、解決方案

針對該異常信息,有多種方式進行解決:

第一種:

直接將yarn.nodemanager.pmem-check-enabled和yarn.nodemanager.vmem-check-enabled設置為false,那麼可以杜絕異常信息的產生。

第二種:

如果異常信息提示的是virtual memory不夠,那麼可以將yarn.nodemanager.vmem-pmem-ratio參數改大,那麼也可以避免異常信息的產生。

第三種:

修改mapreduce參數,設置修改如下:

mapreduce.map.memory.mb = (1~2倍) * yarn.scheduler.minimum-allocation-mb

mapreduce.reduce.memory.mb = (1~4倍) * yarn.scheduler.minimum-allocation-mb

1. mapred.child.java.opts = -XmxTm(T數字要小於map和reduce的設置value)

2. mapreduce.map.java.opts=-Xmx(<mapreduce.map.memory.mb>

mapreduce.reduce.java.opts=-Xmx(<mapreduce.reduce.memory.mb>

總結:最終運行參數給定的jvm堆大小必須小於參數指定的map和reduce的memory大小,最好為70%以下。

下面,先停止HDFS和YARN進程,如下所示:

運行MapReduce應用:提示物理內存或者虛擬內存超出限制


然後在yarm-site.xml 配置文件中,添加如下參數設置。也就是採用前面介紹的方案一和方案二,相對而言比較簡單。

運行MapReduce應用:提示物理內存或者虛擬內存超出限制

<property>

<name>yarn.nodemanager.vmem-check-enabled/<name>

<value>false/<value>

<description>Whether virtual memory limits will be enforced for containers/<description>

<property>

<name>yarn.nodemanager.vmem-pmem-ratio/<name>

<value>4/<value>

<description>Ratio between virtual memory to physical memory when setting memory limits for containers/<description>

配置修改完成之後,重啟HDFS和YARN進程,如下所示:

運行MapReduce應用:提示物理內存或者虛擬內存超出限制


此時,再次運行MapReduce應用,就正常了。

hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-3.1.2.jar wordcount input output

"/<mapreduce.reduce.memory.mb>

/<mapreduce.map.memory.mb>


分享到:


相關文章: