節點屬性是一種描述節點屬性的方式,不提供資源保證。應用程式可以使用此方式根據這些屬性的多重表達式,選取適合其容器放置的正確節點。
節點屬性
的顯著功能如下
與標籤不同,屬性可以同時從集中式和分散式模式映射到節點。由於屬性在不同的模式中使用不同的前綴來識別,因此不會有衝突。在集中式的情況下,屬性由前綴“rm.yarn.io”識別,而在分散式的情況下,屬性由前綴“nm.yarn.io”識別。這表示屬性由前綴和名稱唯一識別。
與節點標籤不同,節點屬性不需要明確啟用,因為它將始終存在,即使不使用該功能,也不會對效能或相容性產生影響。
在 yarn-site.xml
中設定下列屬性
屬性 | 值 | 預設值 |
---|---|---|
yarn.node-attribute.fs-store.root-dir | 集中式屬性對應儲存的路徑 | file:///tmp/hadoop-yarn-${user}/node-attribute/ |
yarn.node-attribute.fs-store.impl.class | 設定的類別需要延伸 org.apache.hadoop.yarn.nodelabels.NodeAttributeStore | FileSystemNodeAttributeStore |
備註
yarn.node-attribute.fs-store.root-dir
是由資源管理員處理程序使用者建立,且 ResourceManager
有權限存取它。(通常來自「yarn」使用者)file:///home/yarn/node-attributes
等路徑,否則如果在 hdfs 中可以使用 hdfs://namenode:port/path/to/store/node-attributes/
等路徑。在 集中式 方法中,支援三種選項來對應節點的屬性
新增 執行 yarn nodeattributes -add “node1:attribute[(type)][=value],attribute2 node2:attribute2[=value],attribute3
會將屬性新增到節點,而不會影響節點上已存在的對應。
移除 執行 yarn nodeattributes -remove “node1:attribute,attribute1 node2:attribute2"
會將屬性從節點中移除,而不會影響節點上已存在的對應。
取代 執行 yarn nodeattributes -replace “node1:attribute[(type)][=value],attribute1[=value],attribute2 node2:attribute2[=value],attribute3""
會將節點的現有屬性取代為此命令中設定的屬性。
備註
在 分散式 模式中設定節點的屬性
屬性 | 值 |
---|---|
yarn.nodemanager.node-attributes.provider | 管理員可以在 NM 中設定此參數來設定節點屬性的提供者。管理員可以設定提供者的「config」、「script」或類別名稱。設定的類別需要延伸 org.apache.hadoop.yarn.server.nodemanager.nodelabels.NodeAttributesProvider。如果設定「config」,則會使用 「ConfigurationNodeAttributesProvider」,如果設定「script」,則會使用 「ScriptBasedNodeAttributesProvider」。 |
yarn.nodemanager.node-attributes.provider.fetch-interval-ms | 當 “yarn.nodemanager.node-attributes.provider” 設定為 “config”、“script” 或設定的類別延伸 NodeAttributesProvider 時,會定期從節點屬性提供者擷取節點屬性。此設定用於定義間隔時間。如果設定為 -1,則僅會在初始化期間從提供者擷取節點屬性。預設為 10 分鐘。 |
yarn.nodemanager.node-attributes.provider.fetch-timeout-ms | 當 “yarn.nodemanager.node-attributes.provider” 設定為 “script” 時,此設定會提供逾時時間,逾時後將中斷查詢節點屬性的指令碼。預設為 20 分鐘。 |
yarn.nodemanager.node-attributes.provider.script.path | NM 執行的節點屬性指令碼用於收集節點屬性。指令碼輸出中以「NODE_ATTRIBUTE:」開頭的行會視為節點屬性記錄,屬性名稱、類型和值應以逗號分隔。每一個這樣的行都會解析成一個節點屬性。 |
yarn.nodemanager.node-attributes.provider.script.opts | 傳遞給節點屬性指令碼的引數。 |
yarn.nodemanager.node-attributes.provider.configured-node-attributes | 當「yarn.nodemanager.node-attributes.provider」設定為「config」時,ConfigurationNodeAttributesProvider 會從此參數擷取節點屬性。 |
應用程式可以使用配置限制 API 指定節點屬性要求,如 配置限制文件 中所述。
以下是使用節點屬性運算式建立排程要求物件的範例
//expression : AND(python!=3:java=1.8) SchedulingRequest schedulingRequest = SchedulingRequest.newBuilder().executionType( ExecutionTypeRequest.newInstance(ExecutionType.GUARANTEED)) .allocationRequestId(10L).priority(Priority.newInstance(1)) .placementConstraintExpression( PlacementConstraints.and( PlacementConstraints .targetNodeAttribute(PlacementConstraints.NODE, NodeAttributeOpCode.NE, PlacementConstraints.PlacementTargets .nodeAttribute("python", "3")), PlacementConstraints .targetNodeAttribute(PlacementConstraints.NODE, NodeAttributeOpCode.EQ, PlacementConstraints.PlacementTargets .nodeAttribute("java", "1.8"))) .build()).resourceSizing( ResourceSizing.newInstance(1, Resource.newInstance(1024, 1))) .build();
上述 SchedulingRequest 要求 1 個容器,而該容器必須符合下列限制
節點屬性 rm.yarn.io/python
不存在於節點上,或存在但其值不等於 3
節點屬性 rm.yarn.io/java
必須存在於節點上,且其值等於 1.8
作為 http://rm-http-address:port/ws/v1/cluster/nodes/{nodeid}
REST 輸出的屬性一部分,以及對應至指定節點的值可以取得。
尚未支援
yarn cluster --list-node-attributes
取得叢集中的所有屬性yarn nodeattributes -list
取得叢集中的屬性yarn nodeattributes -attributestonodes -attributes <Attributes>
列出每個屬性,所有已對應的節點和為每個節點設定的屬性值。選擇性地,我們可以使用 -attributes 指定特定屬性。yarn nodeattributes -nodestoattributes -nodes <主機名稱>
列出所有屬性及其對應至節點的值。選擇性地,我們可以使用 -nodes 指定特定節點。yarn node -status
取得的節點狀態/詳細資料將列出所有屬性和其與節點相關聯的值。