Spark Streaming實(shí)時(shí)長(cháng)時(shí)服務(wù)與MapRedue、Spark、Hive等批處理應用共享YARN集群資源。在共享環(huán)境中,經(jīng)常因一個(gè)批處理應用占用大量網(wǎng)絡(luò )資源或者CPU資源導致Spark Streaming資源被搶占,服務(wù)不穩定。
該實(shí)驗在hadoop-2.7.1下操作
為了label的高可用(在ResourceManager重啟時(shí)候),我們需要為L(cháng)alel在HDFS上創(chuàng )建存儲目錄,用來(lái)存儲Label元信息。
sudo su hdfshadoop fs -mkdir -p /yarn/node-labelshadoop fs -chown -R yarn:yarn /yarnhadoop fs -chmod -R 700 /yarn我們需要將下列配置添加到yarn-site.xml
添加下列配置開(kāi)啟Label Scheduler
<property> <name>yarn.node-labels.enabled</name> <value>true</value></property>添加下列配置,label元數據在hdfs上的存儲路徑
<property> <name>yarn.node-labels.fs-store.root-dir</name> <value>hdfs://<host>:<port>/<absolute_path_to_node_label_directory></value></property>添加下列配置,為YARN配置capacity scheduler
label scheduler無(wú)法單獨使用,而且只能配合capacity scheduler策略使用
<property> <name>yarn.resourcemanager.scheduler.class</name> <value>org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler</value></property>由于我們對yarn-site.xml做了修改,所以我們需要重啟ResourceManager讓配置生效。
# stop rm$HADOOP_HOME/sbin/yarn-daemon.sh stop resourcemanager# start rm$HADOOP_HOME/sbin/yarn-daemon.sh start resourcemanagersudo su yarnyarn rmadmin -addToClusterNodeLabels "<label1>(exclusive=<true|false>),<label2>(exclusive=<true|false>)"NOTE:
exclusive并不是必須的參數,默認值為true
你可以通過(guò)下列命令來(lái)刪除集群的Label
yarn rmadmin -removeFromClusterNodeLabels "<label1>,<label2>"NOTE: 如果某個(gè)Label已經(jīng)關(guān)聯(lián)Queue,那么你無(wú)法從集群中將其移除
運行下列命令,將節點(diǎn)Label關(guān)聯(lián)到集群Label上。
yarn rmadmin -replaceLabelsOnNode "<node1>:<port>=<label1> <node2>:<port>=<label2>"NOTE: 節點(diǎn)的Label必須包含在集群的Label中。也就是說(shuō)我們在上一步中配置的集群Label為節點(diǎn)Label的全集。
如果想為節點(diǎn)刪除Label,我們也可以通過(guò)replaceLabelsOnNode命令來(lái)操作,我們只要將Label參數置為空即可。例如,我們可以通過(guò)下列命令來(lái)將node-1.example.com節點(diǎn)的Label置空。
sudo su yarnyarn rmadmin -replaceLabelsOnNode "node-1.example.com"<configuration> <!-- 父隊列root的相關(guān)配置 --> <property> <name>yarn.scheduler.capacity.root.queues</name> <value>x,y</value> </property> <property> <name>yarn.scheduler.capacity.root.accessible-node-labels.a.capacity</name> <value>100</value> <description>root隊列對a標簽節點(diǎn)可用的百分比</description> </property> <!-- 隊列x的相關(guān)配置 --> <property> <name>yarn.scheduler.capacity.root.x.capacity</name> <value>50</value> <description>x隊列可用root隊列資源的百分比</description> </property> <property> <name>yarn.scheduler.capacity.root.x.maximum-capacity</name> <value>100</value> <description>x隊列資源使用上限</description> </property> <property> <name>yarn.scheduler.capacity.root.x.accessible-node-labels</name> <value>a</value> <description>x隊列應用可用的節點(diǎn)標簽</description> </property> <property> <name>yarn.scheduler.capacity.root.x.default-node-label-expression</name> <value>a</value> <description>x隊列應用默認節點(diǎn)標簽</description> </property> <property> <name>yarn.scheduler.capacity.root.x.accessible-node-labels.a.capacity</name> <description>x隊列對a標簽節點(diǎn)可用的百分比</description> <value>100</value> </property> <!-- 隊列y的相關(guān)配置 --> <property> <name>yarn.scheduler.capacity.root.y.capacity</name> <value>50</value> </property></configuration>NOTE:
1.獲取更多配置
2.如果我們想讓某個(gè)隊列的使用沒(méi)有標簽的節點(diǎn),那么我們必須將yarn.scheduler.capacity.<queue-path>.accessible-node-labels設置為空格,例如:<property> <name>yarn.scheduler.capacity.root.y.accessible-nod-labels</name> <value> </value></property>3.擁有相同父隊列的隊列的
yarn.scheduler.capacity.<queue-path>.capacity之后必須等于100
在配置完capacity-scheduler.xml之后,我們需要刷新下隊列,讓配置生效。
sudo su yarnyarn rmadmin -refreshQueues我們可以啟動(dòng)個(gè)spark shell來(lái)驗證下yarn label scheduler是否正確開(kāi)啟。
bin/spark-shell --master yarn --deploy-mode client --driver-memory 2g --executor-memory 1g --executor-cores 1 --queue x --num-executors 2任務(wù)處于A(yíng)CCEPTED狀態(tài)說(shuō)明該任務(wù)所在的隊列沒(méi)有可用的資源。一開(kāi)始的時(shí)候我忘記配置
yarn.scheduler.capacity.root.accessible-node-labels.a.capacity,導致x隊列無(wú)可用資源。
capacity scheduler其實(shí)是多隊列的FIFO調度,所以存在任務(wù)餓死的可能性,又由于我們實(shí)驗環(huán)境采用2.7.1版本的hadoop,無(wú)法開(kāi)啟capacity scheduler的資源搶占功能,導致在有大任務(wù)運行時(shí),小任務(wù)提交無(wú)法分配到資源,最終餓死。
聯(lián)系客服