Skip to content

Commit

Permalink
YARN-10965. Simplify logic in QueueHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
9uapaw committed Nov 15, 2021
1 parent 2bcb962 commit 83aabd0
Show file tree
Hide file tree
Showing 27 changed files with 1,348 additions and 722 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -829,6 +830,17 @@ public static Resource multiply(Resource lhs, float rhs) {
return newResource;
}

public static Resource multiplyRound(Resource lhs, float rhs) {
Resource newResource = Resource.newInstance(0, 0);

for (ResourceInformation resourceInformation : lhs.getResources()) {
newResource.setResourceValue(resourceInformation.getName(),
Math.round(resourceInformation.getValue() * rhs));
}

return newResource;
}

@InterfaceAudience.Private
@InterfaceStability.Unstable
public static Resource createResourceFromString(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,65 +1,55 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity;

import org.apache.hadoop.yarn.api.records.Resource;
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityVector.QueueCapacityType;
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityVector.ResourceUnitCapacityType;
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityVector.QueueCapacityVectorEntry;

public class AbsoluteResourceCapacityCalculator extends AbstractQueueCapacityCalculator {

@Override
protected float calculateMinimumResource(
QueueHierarchyUpdateContext updateContext, CSQueue childQueue, String label,
public float calculateMinimumResource(
QueueCapacityUpdateContext updateContext, CSQueue childQueue, String label,
QueueCapacityVectorEntry capacityVectorEntry) {
String resourceName = capacityVectorEntry.getResourceName();
ResourceVector ratio = updateContext.getNormalizedMinResourceRatio(
childQueue.getParent().getQueuePath(), label);
ResourceVector ratio = updateContext.getQueueBranchContext(childQueue.getParent().getQueuePath())
.getNormalizedResourceRatios().getOrDefault(label, ResourceVector.of(1));

return ratio.getValue(resourceName) * capacityVectorEntry.getResourceValue();
}

@Override
protected float calculateMaximumResource(
QueueHierarchyUpdateContext updateContext, CSQueue childQueue, String label,
public float calculateMaximumResource(
QueueCapacityUpdateContext updateContext, CSQueue childQueue, String label,
QueueCapacityVectorEntry capacityVectorEntry) {
return capacityVectorEntry.getResourceValue();
}

@Override
protected QueueCapacityType getCapacityType() {
return QueueCapacityType.ABSOLUTE;
}

@Override
public void setup(CSQueue queue, String label) {
Resource minResource = Resource.newInstance(0, 0);

for (String resourceName : getResourceNames(queue, label)) {
long resource = (long) queue.getConfiguredCapacityVector(
label).getResource(resourceName).getResourceValue();
minResource.setResourceValue(resourceName, minResource.getResourceValue(
resourceName) + resource);
}

queue.getQueueResourceQuotas().setConfiguredMinResource(label, minResource);
public void updateCapacitiesAfterCalculation(
QueueCapacityUpdateContext updateContext, CSQueue queue, String label) {
setQueueCapacities(updateContext.getUpdatedClusterResource(label), queue, label);
}

@Override
public void setMetrics(QueueHierarchyUpdateContext updateContext,
CSQueue queue, String label) {
float sumCapacity = 0f;
float sumAbsoluteCapacity = 0f;

for (String resourceName : getResourceNames(queue, label)) {
sumCapacity += queue.getConfiguredCapacityVector(label).getResource(
resourceName).getResourceValue() / queue.getParent()
.getQueueResourceQuotas().getEffectiveMinResource(label)
.getResourceValue(resourceName);
sumAbsoluteCapacity += updateContext.getAbsoluteMinCapacity(
queue.getQueuePath(), label).getValue(resourceName);
}

queue.getQueueCapacities().setCapacity(label, sumCapacity);
queue.getQueueCapacities().setAbsoluteCapacity(label, sumAbsoluteCapacity);
public ResourceUnitCapacityType getCapacityType() {
return ResourceUnitCapacityType.ABSOLUTE;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,20 @@ public float getAbsoluteCapacity() {
return queueCapacities.getAbsoluteCapacity();
}

@Override
public ResourceVector getOrCreateAbsoluteMinCapacityVector(String label) {
usageTracker.getAbsoluteMinCapacityVector().putIfAbsent(label, ResourceVector.newInstance());

return usageTracker.getAbsoluteMinCapacityVector().get(label);
}

@Override
public ResourceVector getOrCreateAbsoluteMaxCapacityVector(String label) {
usageTracker.getAbsoluteMaxCapacityVector().putIfAbsent(label, ResourceVector.newInstance());

return usageTracker.getAbsoluteMaxCapacityVector().get(label);
}

@Override
public float getAbsoluteMaximumCapacity() {
return queueCapacities.getAbsoluteMaximumCapacity();
Expand Down Expand Up @@ -368,11 +382,11 @@ protected void setupQueueConfigs(Resource clusterResource,
this.reservationsContinueLooking =
configuration.getReservationContinueLook();

this.configuredCapacityVectors = csContext.getConfiguration()
this.configuredCapacityVectors = configuration
.parseConfiguredResourceVector(queuePath.getFullPath(),
this.queueNodeLabelsSettings.getConfiguredNodeLabels());
this.configuredMaximumCapacityVectors = configuration
.parseConfiguredMaximumCapacityVector(queuePath.getFullPath(), this.queueNodeLabelsSettings.getConfiguredNodeLabels());
.parseConfiguredMaximumCapacityVector(queuePath.getFullPath(), this.queueNodeLabelsSettings.getConfiguredNodeLabels(), QueueCapacityVector.newInstance());
// Update metrics
CSQueueUtils.updateQueueStatistics(resourceCalculator, clusterResource,
this, labelManager, null);
Expand Down Expand Up @@ -567,7 +581,17 @@ public QueueCapacityVector getConfiguredCapacityVector(String label) {

@Override
public QueueCapacityVector getConfiguredMaximumCapacityVector(String label) {
return configuredCapacityVectors.get(label);
return configuredMaximumCapacityVectors.get(label);
}

@Override
public void setConfiguredMinCapacityVector(String label, QueueCapacityVector minCapacityVector) {
configuredCapacityVectors.put(label, minCapacityVector);
}

@Override
public void setConfiguredMaxCapacityVector(String label, QueueCapacityVector maxCapacityVector) {
configuredMaximumCapacityVectors.put(label, maxCapacityVector);
}

private void initializeQueueState(CapacitySchedulerConfiguration configuration) {
Expand Down
Loading

0 comments on commit 83aabd0

Please sign in to comment.