-
RAM (内存数量)
-
CORES ( CPU cores 数量)
-
DISKS (磁盘数量)
YARN 和 MapReduce总共可用的内存,需要考虑到保留的内存,保留的内存是提供给操作系统和hadoop其他的组件来使用的(如Hbase)
保留内存 = 堆栈存储器内存( stack memory) + Hbase内存(如果Hbase和DataNode在相同的节点上)
使用下面的表格内容来决定每个节点的保留内存
每个节点总共的Memory
|
推荐保留的系统内存
|
推荐保留的Hbase内存
|
4 GB
|
1 GB
|
1 GB
|
8 GB
|
2 GB
|
1 GB
|
16 GB
|
2 GB
|
2 GB
|
24 GB
|
4 GB
|
4 GB
|
48 GB
|
6 GB
|
8 GB
|
64 GB
|
8 GB
|
8 GB
|
72 GB
|
8 GB
|
8 GB
|
96 GB
|
12 GB
|
16 GB
|
128 GB
|
24 GB
|
24 GB
|
256 GB
|
32 GB
|
32 GB
|
512 GB
|
64 GB
|
64 GB
|
下一步来计算每个节点上分配的最大containers ,下面的公式可以被使用:
container 数量 = min (2*CORES, 1.8*DISKS, (Total available RAM) / MIN_CONTAINER_SIZE)
假定 container 数量 = numbers
MIN_CONTAINER_SIZE 是最小的container 大小(RAM)。这个值依赖可用的内存数量,在较小内存节点中,container 内存最小值应该会更小,下面的表格显示了推荐的值:
每个节点总共的RAM
|
推荐最小的container 大小
|
少于4 GB
|
256MB
|
4 GB 和 8 GB之间
|
256MB
|
8 GB 和 24 GB之间
|
1024MB
|
24 GB 以上
|
2048MB
|
最终的计算来决定每个container的RAM 数量
每个container RAM = max(MIN_CONTAINER_SIZE, (Total Available RAM) / numbers))
假定 每个container RAM = RAM-unit
经过这些计算,YARN 和 MapReduce可以被设置成的值如下所示:
配置文件
|
配置项
|
计算的值
|
yarn-site.xml
|
yarn.nodemanager.resource.memory-mb
|
=
numbers *
RAM-unit
|
yarn-site.xml
|
yarn.scheduler.minimum-allocation-mb
|
=
RAM-unit
|
yarn-site.xml
|
yarn.scheduler.maximum-allocation-mb
|
=
numbers *
RAM-unit
|
mapred-site.xml
|
mapreduce.map.memory.mb
|
=
RAM-unit
|
mapred-site.xml
|
mapreduce.reduce.memory.mb
|
= 2 *
RAM-unit
|
mapred-site.xml
|
mapreduce.map.java.opts
|
= 0.8 *
RAM-unit
|
mapred-site.xml
|
mapreduce.reduce.java.opts
|
= 0.8 * 2 *
RAM-unit
|
yarn-site.xml (check)
|
yarn.app.mapreduce.am.resource.mb
|
= 2 *
RAM-unit
|
yarn-site.xml (check)
|
yarn.app.mapreduce.am.command-opts
|
= 0.8 * 2 *
RAM-unit
|
举个例子
集群节点有12个CPU cores,48 GB RAM 和 12 个磁盘.
保留的内存=6 GB系统使用 + (如果有Hbase)8 GB HBase使用
最小container 大小 = 2GB
如果没有Hbase:
numbers = container 数量 = min (2*12, 1.8* 12, (48-6)/2) = min (24, 21.6, 21) = 21
RAM-unit = 每个container RAM = max (2, (48-6)/21) = max (2, 2) = 2
配置
项
|
计算的值
|
yarn.nodemanager.resource.memory-mb
|
=
21 *
2 = 42GB
|
yarn.scheduler.minimum-allocation-mb
|
=
2 GB
|
yarn.scheduler.maximum-allocation-mb
|
=
21 *
2 = 42GB
|
mapreduce.map.memory.mb
|
=
2GB
|
mapreduce.reduce.memory.mb
|
= 2 *
2 = 4GB
|
mapreduce.map.java.opts
|
= 0.8 * 2 = 1.6GB
|
mapreduce.reduce.java.opts
|
= 0.8 * 2 *
2 = 3.2GB
|
yarn.app.mapreduce.am.resource.mb
|
= 2 *
2 = 4GB
|
yarn.app.mapreduce.am.command-opts
|
= 0.8 * 2 *
2 = 3.2GB
|
如果包含了Hbase:
container 数量 = min (2*12, 1.8* 12, (48-6-8)/2) = min (24, 21.6, 17) = 17
每个container RAM = max (2, (48-6-8)/17) = max (2, 2) = 2
配置
项
|
计算的值
|
yarn.nodemanager.resource.memory-mb
|
=
17 *
2 = 34GB
|
yarn.scheduler.minimum-allocation-mb
|
=
2 GB
|
yarn.scheduler.maximum-allocation-mb
|
=
17 *
2 = 34GB
|
mapreduce.map.memory.mb
|
=
2GB
|
mapreduce.reduce.memory.mb
|
= 2 *
2 = 4GB
|
mapreduce.map.java.opts
|
= 0.8 * 2 = 1.6GB
|
mapreduce.reduce.java.opts
|
= 0.8 * 2 *
2 = 3.2GB
|
yarn.app.mapreduce.am.resource.mb
|
= 2 *
2 = 4GB
|
yarn.app.mapreduce.am.command-opts
|
= 0.8 * 2 *
2 = 3.2GB
|
需要说明的几点:
1、yarn.nodemanager.resource.memory-mb,表示当前节点上最大可以使用的内存。
2、yarn.scheduler.minimum-allocation-mb ,表示当前节点上可以分配的container 最小内存。
3、yarn.scheduler.maximum-allocation-mb,表示当前节点上可以分配的container 最大内存。
4、map 和 reduce的job是运行在yarn上的,利用container 来运行tasks。
5、map 和 reduce 的task是运行在互相独立的container中,相互不影响。
6、map 和 reduce 运行的task需要的内存是等于或者大于 container 最小内存,即yarn.scheduler.minimum-allocation-mb的值。
7、map 和 reduce运行task的时候会单独启动一个jvm,jvm的内存大小一般为物理内存的80%,即0.8