yarn組件依賴關係
yarn主要由兩部分組成,ResourceManager和NodeManger。NodeManager裏面包含多個Container,每個Container裏可以運行多個task,比如MapTask和ReduceTask等。ApplicationMaster也是在Container中運行。
在YARN中,資源管理由ResourceManager和NodeManager共同完成,其中,ResourceManager中的調度器負責資源的分配,而NodeManager則負責資源的供給和隔離。ResourceManager將某個NodeManager上資源分配給任務(這就是所謂的“資源調度”)後,NodeManager需按照要求爲任務提供相應的資源,甚至保證這些資源應具有獨佔性,爲任務運行提供基礎的保證,這就是所謂的資源隔離。
關於yarn的詳細介紹可參考:yarn的架構及作業調度
內存相關參數
配置文件 | 配置設置 | 默認值 |
---|---|---|
yarn-site.xml | yarn.nodemanager.resource.memory-mb | -1 |
yarn-site.xml | yarn.nodemanager.vmem-pmem-ratio | 2.1 |
yarn-site.xml | yarn.nodemanager.vmem-check-enabled | true |
yarn-site.xml | yarn.nodemanager.pmem-check-enabled | true |
yarn-site.xml | yarn.scheduler.minimum-allocation-mb | 1024MB |
yarn-site.xml | yarn.scheduler.maximum-allocation-mb | 8192 MB |
yarn-site.xml | yarn.nodemanager.resource.cpu-vcores | 8 |
yarn-site.xml | yarn.scheduler.minimum-allocation-vcores | 1 |
yarn-site.xml | yarn.scheduler.maximum-allocation-vcores | 32 |
mapred-site.xml | yarn.app.mapreduce.am.resource.mb | 1536 MB |
mapred-site.xml | yarn.app.mapreduce.am.command-opts | -Xmx1024m |
mapred-site.xml | mapreduce.map.memory.mb | 1024 MB |
mapred-site.xml | mapreduce.reduce.memory.mb | 1024 MB |
mapred-site.xml | mapreduce.map.java.opts | 最新版已經去掉 |
mapred-site.xml | mapreduce.reduce.java.opts | 最新版已經去掉 |
參數解釋
NodeManager
yarn.nodemanager.resource.memory-mb
:節點最大可用內存,如果值爲-1且yarn.nodemanager.resource.detect-hardware-capabilities
值爲true
,則根據系統內存自動計算,否則默認值爲8192Myarn.nodemanager.vmem-pmem-ratio
:虛擬內存率,Container 的虛擬內存大小的限制,每使用1MB物理內存,最多可用的虛擬內存數yarn.nodemanager.pmem-check-enabled
:是否啓動一個線程檢查每個任務正使用的物理內存量,如果任務超出分配值,則直接將其殺掉,默認是true;yarn.nodemanager.vmem-check-enabled
:是否啓動一個線程檢查每個任務正使用的虛擬內存量,如果任務超出分配值,則直接將其殺掉,默認是true
ResourceManager
yarn.scheduler.minimum-allocation-mb
:單個任務可申請的最少物理內存量,默認是1024(MB),如果一個任務申請的物理內存量少於該值,則該對應的值改爲這個數yarn.scheduler.maximum-allocation-mb
:單個任務可申請的最多物理內存量,默認是8192(MB)。
ApplicationMaster
mapreduce.map.memory.mb
:分配給 Map Container的內存大小,默認爲1024。如果Map Task實際使用的資源量超過該值,則會被強制殺死。mapreduce.reduce.memory.mb
:分配給 Reduce Container的內存大小,默認爲1024。如果Reduce Task實際使用的資源量超過該值,則會被強制殺死。mapreduce.map.java.opts
:運行 Map 任務的 jvm 參數,如 -Xmx,-Xms 等選項mapreduce.reduce.java.opts
:運行 Reduce 任務的 jvm 參數,如-Xmx,-Xms等選項
CPU 資源
yarn.nodemanager.resource.cpu-vcores
:該節點上 YARN 可使用的虛擬 CPU 個數,如果值是-1且yarn.nodemanager.resource.detect-hardware-capabilities
值爲·true`,則其cpu數目根據系統而定,否則默認值爲8yarn.scheduler.minimum-allocation-vcores
:單個任務可申請的最小虛擬CPU個數, 默認是1yarn.scheduler.maximum-allocation-vcores
:單個任務可申請的最多虛擬CPU個數,默認是4
Killing Container
在本地虛擬機上跑task時報錯如下
Application application_1537990303043_0001 failed 2 times due to AM Container for appattempt_1537990303043_0001_000002 exited with exitCode: -103
Diagnostics:
Container [pid=2344,containerID=container_1537990303043_0001_02_000001] is running beyond virtual memory limits.
Current usage: 74.0 MB of 1 GB physical memory used;
2.2 GB of 2.1 GB virtual memory used. Killing container.
虛擬機物理內存設置的是1G,則對應虛擬內存最大爲1*2.1=2.1GB,實際使用了2.2[此處疑問:爲什麼就使用了2.2,單個任務默認分配1024M,加上一個任務的Container默認1024M導致嗎?],所以需要擴大虛擬內存的比例,或者限制container和task的大小,或者關閉掉對虛擬內存的檢測。
yarn-site.xml
<!--
<property>
<name>yarn.scheduler.minimum-allocation-mb</name>
<value>256</value>
<description>每個container可申請最小內存</description>
</property>
<property>
<name>yarn.scheduler.maximum-allocation-mb</name>
<value>512</value>
<description>每個container可申請最大內存</description>
</property>
-->
<property>
<name>yarn.nodemanager.vmem-pmem-ratio</name>
<value>3</value>
<description>虛擬內存和物理內存比率,默認爲2.1</description>
</property>
<property>
<name>yarn.nodemanager.vmem-check-enabled</name>
<value>false</value>
<description>不檢查虛擬內存,默認爲true</description>
</property>
混淆點
yarn.scheduler.minimum-allocation-mb
和yarn.scheduler.maximum-allocation-mb
這兩個參數不能限制任務的真正大小???
這兩個參數是管理員用來設置用戶能夠設置的每個任務可申請的最小和最大內存資源。具體每個任務到底申請多少,由各個應用程序單獨設置,如果是mapreduce程序,可以map task申請的資源可通過mapreduce.map.memory.mb指定,reduce task的資源可通過mapreduce.reduce.memory.mb指定,這兩個參數最大不能超過yarn.scheduler.maximum-allocation-mb
更多內容請移駕:https://sustcoder.github.io