From f94a3d9ca5115a0ab9df90239b48def76cdb2bbd Mon Sep 17 00:00:00 2001 From: zeekling Date: Sun, 15 Dec 2024 16:24:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0Capacity=E8=B0=83=E5=BA=A6?= =?UTF-8?q?=E5=99=A8=E7=9A=84=E6=BA=90=E7=A0=81=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scheduler/capacity/LeafQueue.java | 12 ++++++++++++ .../scheduler/capacity/ParentQueue.java | 3 ++- .../allocator/RegularContainerAllocator.java | 8 ++++---- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/LeafQueue.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/LeafQueue.java index ccf33632ef..752a28ea5f 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/LeafQueue.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/LeafQueue.java @@ -1123,6 +1123,16 @@ private ConcurrentMap getUserLimitCache( } } + /** + * 分配资源到子队列的逻辑。 + * @param clusterResource the resource of the cluster. + * @param candidates {@link CandidateNodeSet} the nodes that are considered + * for the current placement. + * @param currentResourceLimits how much overall resource of this queue can use. + * @param schedulingMode Type of exclusive check when assign container on a + * NodeManager, see {@link SchedulingMode}. + * @return + */ @Override public CSAssignment assignContainers(Resource clusterResource, CandidateNodeSet candidates, @@ -1135,6 +1145,7 @@ public CSAssignment assignContainers(Resource clusterResource, + " #applications=" + orderingPolicy.getNumSchedulableEntities()); } + // 是否允许抢占。 setPreemptionAllowed(currentResourceLimits, candidates.getPartition()); // Check for reserved resources, try to allocate reserved container first. @@ -1228,6 +1239,7 @@ public CSAssignment assignContainers(Resource clusterResource, if (!cul.canAssign && Resources.fitsIn(appReserved, cul.reservation)) { userAssignable = false; } else { + // 资源分配到用户 userAssignable = canAssignToUser(clusterResource, application.getUser(), userLimit, application, candidates.getPartition(), currentResourceLimits); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/ParentQueue.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/ParentQueue.java index 401e60d126..9eb16367f3 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/ParentQueue.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/ParentQueue.java @@ -626,7 +626,7 @@ public CSAssignment assignContainers(Resource clusterResource, break; } - // Schedule + // Schedule , 开始给子队列分配资源。 CSAssignment assignedToChild = assignContainersToChildQueues( clusterResource, candidates, resourceLimits, schedulingMode); assignment.setType(assignedToChild.getType()); @@ -834,6 +834,7 @@ private CSAssignment assignContainersToChildQueues(Resource cluster, getResourceLimitsOfChild(childQueue, cluster, limits.getNetLimit(), candidates.getPartition()); + // 分配资源到队列 CSAssignment childAssignment = childQueue.assignContainers(cluster, candidates, childLimits, schedulingMode); if(LOG.isDebugEnabled()) { diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/allocator/RegularContainerAllocator.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/allocator/RegularContainerAllocator.java index cced238b60..704d135fbe 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/allocator/RegularContainerAllocator.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/allocator/RegularContainerAllocator.java @@ -423,7 +423,7 @@ private ContainerAllocation assignContainersOnNode(Resource clusterResource, ContainerAllocation allocation; NodeType requestLocalityType = null; - // Data-local + // Data-local 优先分配local。 PendingAsk nodeLocalAsk = application.getPendingAsk(schedulerKey, node.getNodeName()); if (nodeLocalAsk.getCount() > 0) { @@ -439,7 +439,7 @@ private ContainerAllocation assignContainersOnNode(Resource clusterResource, } } - // Rack-local + // Rack-local 在Rack-local 分配 PendingAsk rackLocalAsk = application.getPendingAsk(schedulerKey, node.getRackName()); if (rackLocalAsk.getCount() > 0) { @@ -466,7 +466,7 @@ private ContainerAllocation assignContainersOnNode(Resource clusterResource, } } - // Off-switch + // Off-switch 检查不限制 PendingAsk offSwitchAsk = application.getPendingAsk(schedulerKey, ResourceRequest.ANY); if (offSwitchAsk.getCount() > 0) { @@ -922,7 +922,7 @@ public CSAssignment assignContainers(Resource clusterResource, return CSAssignment.SKIP_ASSIGNMENT; } - // Schedule in priority order + // Schedule in priority order 按照优先级顺序分配资源 for (SchedulerRequestKey schedulerKey : application.getSchedulerKeys()) { ContainerAllocation result = allocate(clusterResource, candidates, schedulingMode, resourceLimits, schedulerKey, null);