<p>Node label is a way to group nodes with similar characteristics and applications can specify where to run.</p>
<p>Now we only support node partition, which is:</p>
<ul>
<li>One node can have only one node partition, so a cluster is partitioned to several disjoint sub-clusters by node partitions. By default, nodes belong to DEFAULT partition (partition="")</li>
<li>User need to configure how much resources of each partition can be used by different queues. For more detail, please refer next section.</li>
<li>There are two kinds of node partitions:
<ul>
<li>Exclusive: containers will be allocated to nodes with exactly match node partition. (e.g. asking partition=“x” will be allocated to node with partition=“x”, asking DEFAULT partition will be allocated to DEFAULT partition nodes).</li>
<li>Non-exclusive: if a partition is non-exclusive, it shares idle resource to container requesting DEFAULT partition.</li>
</ul>
</li>
</ul>
<p>User can specify set of node labels which can be accessed by each queue, one application can only use subset of node labels that can be accessed by the queue which contains the application.</p></section><section>
<h2><aname="Features"></a>Features</h2>
<p>The <code>Node Labels</code> supports the following features for now:</p>
<ul>
<li>Partition cluster - each node can be assigned one label, so the cluster will be divided to several smaller disjoint partitions.</li>
<li>ACL of node-labels on queues - user can set accessible node labels on each queue so only some nodes can only be accessed by specific queues.</li>
<li>Specify percentage of resource of a partition which can be accessed by a queue - user can set percentage like: queue A can access 30% of resources on nodes with label=hbase. Such percentage setting will be consistent with existing resource manager</li>
<li>Specify required node label in resource request, it will only be allocated when node has the same label. If no node label requirement specified, such Resource Request will only be allocated on nodes belong to DEFAULT partition.</li>
<li>Operability
<ul>
<li>Node labels and node labels mapping can be recovered across RM restart</li>
<li>Update node labels - admin can update labels on nodes and labels on queues when RM is running</li>
</ul>
</li>
<li>Mapping of NM to node labels can be done in three ways, but in all of the approaches Partition Label should be one among the valid node labels list configured in the RM.
<ul>
<li><b>Centralized :</b> Node to labels mapping can be done through RM exposed CLI, REST or RPC.</li>
<li><b>Distributed :</b> Node to labels mapping will be set by a configured Node Labels Provider in NM. We have two different providers in YARN: <i>Script</i> based provider and <i>Configuration</i> based provider. In case of script, NM can be configured with a script path and the script can emit the labels of the node. In case of config, node Labels can be directly configured in the NM’s yarn-site.xml. In both of these options dynamic refresh of the label mapping is supported.</li>
<li><b>Delegated-Centralized :</b> Node to labels mapping will be set by a configured Node Labels Provider in RM. This would be helpful when label mapping cannot be provided by each node due to security concerns and to avoid interaction through RM Interfaces for each node in a large cluster. Labels will be fetched from this interface during NM registration and periodical refresh is also supported.</li>
<td> Set configuration type for node labels. Administrators can specify “centralized”, “delegated-centralized” or “distributed”. Default value is “centralized”.</td></tr>
</tbody>
</table>
<p>Notes:</p>
<ul>
<li>Make sure <code>yarn.node-labels.fs-store.root-dir</code> is created and <code>ResourceManager</code> has permission to access it. (Typically from “yarn” user)</li>
<li>If user want to store node label to local file system of RM (instead of HDFS), paths like <code>file:///home/yarn/node-label</code> can be used</li>
</ul></section><section>
<h3><aname="Add.2Fmodify_node_labels_list_to_YARN"></a>Add/modify node labels list to YARN</h3>
<ul>
<li>Add cluster node labels list:
<ul>
<li>Executing <code>yarn rmadmin -addToClusterNodeLabels "label_1(exclusive=true/false),label_2(exclusive=true/false)"</code> to add node label.</li>
<li>If user don’t specify “(exclusive=…)”, exclusive will be <code>true</code> by default.</li>
<li>Run <code>yarn cluster --list-node-labels</code> to check added node labels are visible in the cluster.</li>
</ul>
</li>
</ul></section><section>
<h3><aname="Remove_node_labels_from_YARN"></a>Remove node labels from YARN</h3>
<ul>
<li>Remove cluster node labels:
<ul>
<li>To remove one or more node labels, execute the following command: <code>yarn rmadmin -removeFromClusterNodeLabels "<label>[,<label>,...]"</code>. The command argument should be a comma-separated list of node labels to remove.</li>
<li>It is not allowed to remove a label which has been associated with queues, i.e., one or more queues have access to this label.</li>
<li>To verify if specified node labels have been successfully removed, run <code>yarn cluster --list-node-labels</code>.</li>
</ul>
</li>
</ul></section><section>
<h3><aname="Add.2Fmodify_node-to-labels_mapping_to_YARN"></a>Add/modify node-to-labels mapping to YARN</h3>
<ul>
<li>
<p>Configuring nodes to labels mapping in <b>Centralized</b> NodeLabel setup</p>
<ul>
<li>Executing <code>yarn rmadmin -replaceLabelsOnNode "node1[:port]=label1 node2=label2" [-failOnUnknownNodes]</code> adds label1 to node1, label2 to node2. If user doesn’t specify port, it adds the label to all <code>NodeManagers</code> running on the node. If option <code>-failOnUnknownNodes</code> is set, this command will fail if specified nodes are unknown.</li>
<li>To remove mapping from a node, use <code>-replaceLabelsOnNode</code> but do not specify any labels. For example, <code>yarn rmadmin -replaceLabelsOnNode "node1"</code> removes label1 from node1.</li>
</ul>
</li>
<li>
<p>Configuring nodes to labels mapping in <b>Distributed</b> NodeLabel setup</p>
</li>
</ul>
<tableborder="0"class="bodyTable">
<thead>
<trclass="a">
<th>Property </th>
<th> Value</th></tr>
</thead><tbody>
<trclass="b">
<td>yarn.node-labels.configuration-type </td>
<td> Needs to be set as <i>“distributed”</i> in RM, to fetch node to labels mapping from a configured Node Labels Provider in NM.</td></tr>
<trclass="a">
<td>yarn.nodemanager.node-labels.provider </td>
<td> When <i>“yarn.node-labels.configuration-type”</i> is configured with <i>“distributed”</i> in RM, Administrators can configure the provider for the node labels by configuring this parameter in NM. Administrators can configure <i>“config”</i>, <i>“script”</i> or the <i>class name</i> of the provider. Configured class needs to extend <i>org.apache.hadoop.yarn.server.nodemanager.nodelabels.NodeLabelsProvider</i>. If <i>“config”</i> is configured, then <i>“ConfigurationNodeLabelsProvider”</i> and if <i>“script”</i> is configured, then <i>“ScriptNodeLabelsProvider”</i> will be used.</td></tr>
<td> Interval at which NM syncs its node labels with RM. NM will send its loaded labels every x intervals configured, along with heartbeat to RM. This resync is required even when the labels are not modified because admin might have removed the cluster label which was provided by NM. Default is 2 mins.</td></tr>
<td> When <i>“yarn.nodemanager.node-labels.provider”</i> is configured with <i>“config”</i>, <i>“script”</i> or the <i>configured class</i> extends AbstractNodeLabelsProvider, then periodically node labels are retrieved from the node labels provider. This configuration is to define the interval period. If -1 is configured, then node labels are retrieved from provider only during initialization. Defaults to 10 mins.</td></tr>
<td> When <i>“yarn.nodemanager.node-labels.provider”</i> is configured with <i>“script”</i>, then this configuration provides the timeout period after which it will interrupt the script which queries the node labels. Defaults to 20 mins.</td></tr>
<td> The node label script to run. Script output Line starting with <i>“NODE_PARTITION:”</i> will be considered as node label Partition. In case multiple lines of script output have this pattern, then the last one will be considered.</td></tr>
<td> When <i>“yarn.nodemanager.node-labels.provider”</i> is configured with <i>“config”</i>, then ConfigurationNodeLabelsProvider fetches the partition label from this parameter.</td></tr>
</tbody>
</table>
<ul>
<li>Configuring nodes to labels mapping in <b>Delegated-Centralized</b> NodeLabel setup</li>
</ul>
<tableborder="0"class="bodyTable">
<thead>
<trclass="a">
<th>Property </th>
<th> Value</th></tr>
</thead><tbody>
<trclass="b">
<td>yarn.node-labels.configuration-type </td>
<td> Needs to be set as <i>“delegated-centralized”</i> to fetch node to labels mapping from a configured Node Labels Provider in RM.</td></tr>
<td> When <i>“yarn.node-labels.configuration-type”</i> is configured with <i>“delegated-centralized”</i>, then administrators should configure the class for fetching node labels by ResourceManager. Configured class needs to extend <i>org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsMappingProvider</i>.</td></tr>
<td> When <i>“yarn.node-labels.configuration-type”</i> is configured with <i>“delegated-centralized”</i>, then periodically node labels are retrieved from the node labels provider. This configuration is to define the interval. If -1 is configured, then node labels are retrieved from provider only once for each node after it registers. Defaults to 30 mins.</td></tr>
</tbody>
</table></section><section>
<h3><aname="Configuration_of_Schedulers_for_node_labels"></a>Configuration of Schedulers for node labels</h3>
<td> Set the percentage of the queue can access to nodes belong to DEFAULT partition. The sum of DEFAULT capacities for direct children under each parent, must be equal to 100.</td></tr>
<td> Admin need specify labels can be accessible by each queue, split by comma, like “hbase,storm” means queue can access label hbase and storm. All queues can access to nodes without label, user don’t have to specify that. If user don’t specify this field, it will inherit from its parent. If user want to explicitly specify a queue can only access nodes without labels, just put a space as the value.</td></tr>
<td> Set the percentage of the queue can access to nodes belong to <code><label></code> partition . The sum of <code><label></code> capacities for direct children under each parent, must be equal to 100. By default, it’s 0.</td></tr>
<td> Similar to yarn.scheduler.capacity.<code><queue-path></code>.maximum-capacity, it is for maximum-capacity for labels of each queue. By default, it’s 100.</td></tr>
<td> Value like “hbase”, which means: if applications submitted to the queue without specifying node label in their resource requests, it will use “hbase” as default-node-label-expression. By default, this is empty, so application will get containers from nodes without label.</td></tr>
</tbody>
</table>
<p><b>An example of node label configuration</b>:</p>
<p>Assume we have a queue structure</p>
<divclass="source">
<divclass="source">
<pre> root
/ | \
engineer sales marketing
</pre></div></div>
<p>We have 5 nodes (hostname=h1..h5) in the cluster, each of them has 24G memory, 24 vcores. 1 among the 5 nodes has GPU (assume it’s h5). So admin added GPU label to h5.</p>
<p>Assume user have a Capacity Scheduler configuration like: (key=value is used here for readability)</p>
<p>You can see root.engineering/marketing/sales.capacity=33, so each of them has guaranteed resource equals to 1/3 of resource <b>without partition</b>. So each of them can use 1/3 resource of h1..h4, which is 24 * 4 * (1/3) = (32G mem, 32 v-cores).</p>
<p>And only engineering/marketing queue has permission to access GPU partition (see root.<code><queue-name></code>.accessible-node-labels).</p>
<p>Each of engineering/marketing queue has guaranteed resource equals to 1/2 of resource <b>with partition=GPU</b>. So each of them can use 1/2 resource of h5, which is 24 * 0.5 = (12G mem, 12 v-cores).</p>
<p>Notes:</p>
<ul>
<li>After finishing configuration of CapacityScheduler, execute <code>yarn rmadmin -refreshQueues</code> to apply changes</li>
<li>Go to scheduler page of RM Web UI to check if you have successfully set configuration.</li>
</ul></section></section><section>
<h2><aname="Specifying_node_label_for_application"></a>Specifying node label for application</h2>
<p>Applications can use following Java APIs to specify node label to request</p>
<ul>
<li><code>ApplicationSubmissionContext.setNodeLabelExpression(..)</code> to set node label expression for all containers of the application.</li>
<li><code>ResourceRequest.setNodeLabelExpression(..)</code> to set node label expression for individual resource requests. This can overwrite node label expression set in ApplicationSubmissionContext</li>
<li>Specify <code>setAMContainerResourceRequest.setNodeLabelExpression</code> in <code>ApplicationSubmissionContext</code> to indicate expected node label for application master container.</li>
<h3><aname="Monitoring_through_web_UI"></a>Monitoring through web UI</h3>
<p>Following label-related fields can be seen on web UI:</p>
<ul>
<li>Nodes page: <aclass="externalLink"href="http://RM-Address:port/cluster/nodes">http://RM-Address:port/cluster/nodes</a>, you can get labels on each node</li>
<li>Node labels page: <aclass="externalLink"href="http://RM-Address:port/cluster/nodelabels">http://RM-Address:port/cluster/nodelabels</a>, you can get type (exclusive/non-exclusive), number of active node managers, total resource of each partition</li>
<li>Scheduler page: <aclass="externalLink"href="http://RM-Address:port/cluster/scheduler">http://RM-Address:port/cluster/scheduler</a>, you can get label-related settings of each queue, and resource usage of queue partitions.</li>
</ul></section><section>
<h3><aname="Monitoring_through_commandline"></a>Monitoring through commandline</h3>
<ul>
<li>Use <code>yarn cluster --list-node-labels</code> to get labels in the cluster</li>
<li>Use <code>yarn node -status <NodeId></code> to get node status including labels on a given node</li>
</ul></section></section><section>
<h2><aname="Useful_links"></a>Useful links</h2>
<ul>
<li><ahref="./CapacityScheduler.html">YARN Capacity Scheduler</a>, if you need more understanding about how to configure Capacity Scheduler</li>
<li>Write YARN application using node labels, you can see following two links as examples: <aclass="externalLink"href="https://issues.apache.org/jira/browse/YARN-2502">YARN distributed shell</a>, <aclass="externalLink"href="https://issues.apache.org/jira/browse/MAPREDUCE-6304">Hadoop MapReduce</a></li>