MapReduce作业,目的是读数据库里面多个表的数据,然后在JAVA中根据具体的业务情况做过滤,并把符合数据的结果写入到HDFS上,在Eclipse里面提交作业进行调试的时候,发现在Reduce阶段,总是抛出Java heap space的异常,这异常明显,就是堆内存溢出造成的,然后散仙仔细看了下业务块的代码,在Reduce里读数据库的时候,有几个表的返回数据量比较大约有50万左右,因为具体的数量不会太大,所以没有采用分页来返回,读完后数据,采用Map集合封装,在业务处理的一段时间里,一直会停留在内存里,原来的mapred-site.xml里面的配置reduce内存比较小,只需调大此处内存即可。
- <property>
- <name>mapreduce.map.memory.mb</name>
- <value>215</value>
- </property>
- <property>
- <name>mapreduce.map.java.opts</name>
- <value>-Xmx215M</value>
- </property>
- <property>
- <name>mapreduce.reduce.memory.mb</name>
- <value>1024</value>
- </property>
- <property>
- <name>mapreduce.reduce.java.opts</name>
- <value>-Xmx1024M</value>
- </property>
<property>
<name>mapreduce.map.memory.mb</name>
<value>215</value>
</property>
<property>
<name>mapreduce.map.java.opts</name>
<value>-Xmx215M</value>
</property>
<property>
<name>mapreduce.reduce.memory.mb</name>
<value>1024</value>
</property>
<property>
<name>mapreduce.reduce.java.opts</name>
<value>-Xmx1024M</value>
</property>
hadoop2.2内存控制的几个重要参数:
- YARN
- yarn.scheduler.minimum-allocation-mb
- yarn.scheduler.maximum-allocation-mb
- yarn.nodemanager.vmem-pmem-ratio
- yarn.nodemanager.resource.memory.mb
- Mapreuce
- Map Memory
- mapreduce.map.java.opts
- mapreduce.map.memory.mb
- Reduce Memory
- mapreduce.reduce.java.opts
- mapreduce.reduce.memory.mb
YARN
yarn.scheduler.minimum-allocation-mb
yarn.scheduler.maximum-allocation-mb
yarn.nodemanager.vmem-pmem-ratio
yarn.nodemanager.resource.memory.mb
Mapreuce
Map Memory
mapreduce.map.java.opts
mapreduce.map.memory.mb
Reduce Memory
mapreduce.reduce.java.opts
mapreduce.reduce.memory.mb
如果出现异常:
- Container [pid=17645,containerID=container_1415210272486_0013_01_000004] is running beyond physical memory limits. Current usage: 1.0 GB of 1 GB physical memory used; 1.6 GB of 2.1 GB virtual memory used. Killing container.
- Dump of the process-tree for container_1415210272486_0013_01_000004 :
Container [pid=17645,containerID=container_1415210272486_0013_01_000004] is running beyond physical memory limits. Current usage: 1.0 GB of 1 GB physical memory used; 1.6 GB of 2.1 GB virtual memory used. Killing container.
Dump of the process-tree for container_1415210272486_0013_01_000004 :
可以调整yarn.nodemanager.vmem-pmem-ratio 的比率,默认是2.1,或者加大程序reduce的运行个数进行尝试,这个比率的控制影响着虚拟内存的使用,当yarn计算出来的虚拟内存,比在mapred-site.xml里的mapreduce.map.memory.mb或mapreduce.reduce.memory.mb的2.1倍还要多时,就会发生上面截图中的异常,而默认的mapreduce.map.memory.mb或
mapreduce.reduce.memory.mb得初始大小为1024M,然后根据异常中的yarn自身根据运行环境推算出来的虚拟内存来做比较,发现比1024*2.1还要大,所以就会由NodeManage守护进程kill掉AM容器,从而导致整个MR作业运行失败,现在我们只需要调大这个比率即可,避免发生这种异常。具体调大多小,可根据具体情况来设置。
最后备注一下,hadoop的环境变量的脚本配置java.sh:
- export PATH=.:$PATH
- export FSE_HOME="/home/search/fse2"
- export FSE_CONF_DIR=$FSE_HOME/conf
- export PATH=$PATH:$FSE_HOME/bin
- user="search"
- export JAVA_HOME="/usr/local/jdk"
- export CLASSPATH=.:$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
- export PATH=$PATH:$JAVA_HOME/bin
- export PATH=$PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sbin
- export HADOOP_HOME=/home/search/hadoop
- export HADOOP_MAPRED_HOME=$HADOOP_HOME
- export HADOOP_COMMON_HOME=$HADOOP_HOME
- export HADOOP_HDFS_HOME=$HADOOP_HOME
- export YARN_HOME=$HADOOP_HOME
- export HADOOP_CONF_DIR=$HADOOP_HOME/etc/hadoop
- export YARN_CONF_DIR=$HADOOP_HOME/etc/hadoop
- export PATH=$PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sbin
- export CLASSPATH=.:$CLASSPATH:$HADOOP_COMMON_HOME:$HADOOP_COMMON_HOMEi/lib:$HADOOP_MAPRED_HOME:$HADOOP_HDFS_HOME:$HADOOP_HDFS_HOME
- #export HADOOP_HOME=/home/$user/hadoop
- #export HADOOP_CONF_DIR=$HADOOP_HOME/etc/hadoop
- #export CLASSPATH=.:$CLASSPATH:$HADOOP_HOME/lib
- #export PATH=$PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sbin
- export ANT_HOME=/usr/local/ant
- export CLASSPATH=$CLASSPATH:$ANT_HOME/lib
- export PATH=$PATH:$ANT_HOME/bin
- export MAVEN_HOME="/usr/local/maven"
- export CLASSPATH=$CLASSPATH:$MAVEN_HOME/lib
- export PATH=$PATH:$MAVEN_HOME/bin