Skip to content

Commit 61c87d7

Browse files
committed
YARN-2393. FairScheduler: Add the notion of steady fair share. (Wei Yan via kasha)
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1619845 13f79535-47bb-0310-9956-ffa450edef68
1 parent fd200dc commit 61c87d7

File tree

16 files changed

+328
-47
lines changed

16 files changed

+328
-47
lines changed

hadoop-yarn-project/CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ Release 2.6.0 - UNRELEASED
5555
YARN-2174. Enable HTTPs for the writer REST API of TimelineServer.
5656
(Zhijie Shen via jianhe)
5757

58+
YARN-2393. FairScheduler: Add the notion of steady fair share.
59+
(Wei Yan via kasha)
60+
5861
IMPROVEMENTS
5962

6063
YARN-2197. Add a link to YARN CHANGES.txt in the left side of doc

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/FSAppAttempt.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -717,12 +717,6 @@ public void setFairShare(Resource fairShare) {
717717
this.fairShare = fairShare;
718718
}
719719

720-
@Override
721-
public boolean isActive() {
722-
return true;
723-
}
724-
725-
726720
@Override
727721
public void updateDemand() {
728722
demand = Resources.createResource(0);

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/FSParentQueue.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import org.apache.hadoop.yarn.api.records.Resource;
3636
import org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainer;
3737
import org.apache.hadoop.yarn.util.resource.Resources;
38-
import org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainer;
3938
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ActiveUsersManager;
4039
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.SchedulerApplicationAttempt;
4140

@@ -68,6 +67,16 @@ public void recomputeShares() {
6867
}
6968
}
7069

70+
public void recomputeSteadyShares() {
71+
policy.computeSteadyShares(childQueues, getSteadyFairShare());
72+
for (FSQueue childQueue : childQueues) {
73+
childQueue.getMetrics().setSteadyFairShare(childQueue.getSteadyFairShare());
74+
if (childQueue instanceof FSParentQueue) {
75+
((FSParentQueue) childQueue).recomputeSteadyShares();
76+
}
77+
}
78+
}
79+
7180
@Override
7281
public Resource getDemand() {
7382
return demand;

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/FSQueue.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
@Unstable
4242
public abstract class FSQueue implements Queue, Schedulable {
4343
private Resource fairShare = Resources.createResource(0, 0);
44+
private Resource steadyFairShare = Resources.createResource(0, 0);
4445
private final String name;
4546
protected final FairScheduler scheduler;
4647
private final FSQueueMetrics metrics;
@@ -151,7 +152,17 @@ public void setFairShare(Resource fairShare) {
151152
this.fairShare = fairShare;
152153
metrics.setFairShare(fairShare);
153154
}
154-
155+
156+
/** Get the steady fair share assigned to this Schedulable. */
157+
public Resource getSteadyFairShare() {
158+
return steadyFairShare;
159+
}
160+
161+
public void setSteadyFairShare(Resource steadyFairShare) {
162+
this.steadyFairShare = steadyFairShare;
163+
metrics.setSteadyFairShare(steadyFairShare);
164+
}
165+
155166
public boolean hasAccess(QueueACL acl, UserGroupInformation user) {
156167
return scheduler.getAllocationConfiguration().hasAccess(name, acl, user);
157168
}
@@ -161,7 +172,7 @@ public boolean hasAccess(QueueACL acl, UserGroupInformation user) {
161172
* queue's current share
162173
*/
163174
public abstract void recomputeShares();
164-
175+
165176
/**
166177
* Gets the children of this queue, if any.
167178
*/
@@ -194,7 +205,9 @@ protected boolean assignContainerPreCheck(FSSchedulerNode node) {
194205
return true;
195206
}
196207

197-
@Override
208+
/**
209+
* Returns true if queue has at least one app running.
210+
*/
198211
public boolean isActive() {
199212
return getNumRunnableApps() > 0;
200213
}

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/FSQueueMetrics.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public class FSQueueMetrics extends QueueMetrics {
3333

3434
@Metric("Fair share of memory in MB") MutableGaugeInt fairShareMB;
3535
@Metric("Fair share of CPU in vcores") MutableGaugeInt fairShareVCores;
36+
@Metric("Steady fair share of memory in MB") MutableGaugeInt steadyFairShareMB;
37+
@Metric("Steady fair share of CPU in vcores") MutableGaugeInt steadyFairShareVCores;
3638
@Metric("Minimum share of memory in MB") MutableGaugeInt minShareMB;
3739
@Metric("Minimum share of CPU in vcores") MutableGaugeInt minShareVCores;
3840
@Metric("Maximum share of memory in MB") MutableGaugeInt maxShareMB;
@@ -55,7 +57,20 @@ public int getFairShareMB() {
5557
public int getFairShareVirtualCores() {
5658
return fairShareVCores.value();
5759
}
58-
60+
61+
public void setSteadyFairShare(Resource resource) {
62+
steadyFairShareMB.set(resource.getMemory());
63+
steadyFairShareVCores.set(resource.getVirtualCores());
64+
}
65+
66+
public int getSteadyFairShareMB() {
67+
return steadyFairShareMB.value();
68+
}
69+
70+
public int getSteadyFairShareVCores() {
71+
return steadyFairShareVCores.value();
72+
}
73+
5974
public void setMinShare(Resource resource) {
6075
minShareMB.set(resource.getMemory());
6176
minShareVCores.set(resource.getVirtualCores());

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/FairScheduler.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,8 @@ private synchronized void addNode(RMNode node) {
851851
Resources.addTo(clusterResource, node.getTotalCapability());
852852
updateRootQueueMetrics();
853853

854+
queueMgr.getRootQueue().setSteadyFairShare(clusterResource);
855+
queueMgr.getRootQueue().recomputeSteadyShares();
854856
LOG.info("Added node " + node.getNodeAddress() +
855857
" cluster capacity: " + clusterResource);
856858
}
@@ -885,6 +887,8 @@ private synchronized void removeNode(RMNode rmNode) {
885887
}
886888

887889
nodes.remove(rmNode.getNodeID());
890+
queueMgr.getRootQueue().setSteadyFairShare(clusterResource);
891+
queueMgr.getRootQueue().recomputeSteadyShares();
888892
LOG.info("Removed node " + rmNode.getNodeAddress() +
889893
" cluster capacity: " + clusterResource);
890894
}

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/QueueManager.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ private FSQueue getQueue(String name, boolean create, FSQueueType queueType) {
118118
if (queue == null && create) {
119119
// if the queue doesn't exist,create it and return
120120
queue = createQueue(name, queueType);
121+
122+
// Update steady fair share for all queues
123+
if (queue != null) {
124+
rootQueue.recomputeSteadyShares();
125+
}
121126
}
122127
return queue;
123128
}
@@ -190,7 +195,7 @@ private FSQueue createQueue(String name, FSQueueType queueType) {
190195
parent = newParent;
191196
}
192197
}
193-
198+
194199
return parent;
195200
}
196201

@@ -376,5 +381,8 @@ public void updateAllocationConfiguration(AllocationConfiguration queueConf) {
376381
+ queue.getName(), ex);
377382
}
378383
}
384+
385+
// Update steady fair shares for all queues
386+
rootQueue.recomputeSteadyShares();
379387
}
380388
}

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/Schedulable.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import org.apache.hadoop.yarn.api.records.Resource;
2525
import org.apache.hadoop.yarn.server.resourcemanager.resource.ResourceWeights;
2626
import org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainer;
27-
import org.apache.hadoop.yarn.util.resource.Resources;
2827

2928
/**
3029
* A Schedulable represents an entity that can be scheduled such as an
@@ -102,10 +101,4 @@ public interface Schedulable {
102101

103102
/** Assign a fair share to this Schedulable. */
104103
public void setFairShare(Resource fairShare);
105-
106-
/**
107-
* Returns true if queue has atleast one app running. Always returns true for
108-
* AppSchedulables.
109-
*/
110-
public boolean isActive();
111104
}

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/SchedulingPolicy.java

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@
1717
*/
1818
package org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair;
1919

20-
import java.util.Collection;
21-
import java.util.Comparator;
22-
import java.util.concurrent.ConcurrentHashMap;
23-
2420
import org.apache.hadoop.classification.InterfaceAudience.Public;
2521
import org.apache.hadoop.classification.InterfaceStability.Evolving;
2622
import org.apache.hadoop.util.ReflectionUtils;
@@ -29,6 +25,10 @@
2925
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.policies.FairSharePolicy;
3026
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.policies.FifoPolicy;
3127

28+
import java.util.Collection;
29+
import java.util.Comparator;
30+
import java.util.concurrent.ConcurrentHashMap;
31+
3232
@Public
3333
@Evolving
3434
public abstract class SchedulingPolicy {
@@ -131,15 +131,30 @@ public static boolean isApplicableTo(SchedulingPolicy policy, byte depth) {
131131
public abstract Comparator<Schedulable> getComparator();
132132

133133
/**
134-
* Computes and updates the shares of {@link Schedulable}s as per the
135-
* {@link SchedulingPolicy}, to be used later at schedule time.
134+
* Computes and updates the shares of {@link Schedulable}s as per
135+
* the {@link SchedulingPolicy}, to be used later for scheduling decisions.
136+
* The shares computed are instantaneous and only consider queues with
137+
* running applications.
136138
*
137139
* @param schedulables {@link Schedulable}s whose shares are to be updated
138140
* @param totalResources Total {@link Resource}s in the cluster
139141
*/
140142
public abstract void computeShares(
141143
Collection<? extends Schedulable> schedulables, Resource totalResources);
142144

145+
/**
146+
* Computes and updates the steady shares of {@link FSQueue}s as per the
147+
* {@link SchedulingPolicy}. The steady share does not differentiate
148+
* between queues with and without running applications under them. The
149+
* steady share is not used for scheduling, it is displayed on the Web UI
150+
* for better visibility.
151+
*
152+
* @param queues {@link FSQueue}s whose shares are to be updated
153+
* @param totalResources Total {@link Resource}s in the cluster
154+
*/
155+
public abstract void computeSteadyShares(
156+
Collection<? extends FSQueue> queues, Resource totalResources);
157+
143158
/**
144159
* Check if the resource usage is over the fair share under this policy
145160
*

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/policies/ComputeFairShares.java

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import org.apache.hadoop.yarn.api.records.Resource;
2424
import org.apache.hadoop.yarn.server.resourcemanager.resource.ResourceType;
25+
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FSQueue;
2526
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.Schedulable;
2627

2728
/**
@@ -49,14 +50,29 @@ public static void computeShares(
4950
ResourceType type) {
5051
Collection<Schedulable> activeSchedulables = new ArrayList<Schedulable>();
5152
for (Schedulable sched : schedulables) {
52-
if (sched.isActive()) {
53-
activeSchedulables.add(sched);
54-
} else {
53+
if ((sched instanceof FSQueue) && !((FSQueue) sched).isActive()) {
5554
setResourceValue(0, sched.getFairShare(), type);
55+
} else {
56+
activeSchedulables.add(sched);
5657
}
5758
}
5859

59-
computeSharesInternal(activeSchedulables, totalResources, type);
60+
computeSharesInternal(activeSchedulables, totalResources, type, false);
61+
}
62+
63+
/**
64+
* Compute the steady fair share of the given queues. The steady fair
65+
* share is an allocation of shares considering all queues, i.e.,
66+
* active and inactive.
67+
*
68+
* @param queues
69+
* @param totalResources
70+
* @param type
71+
*/
72+
public static void computeSteadyShares(
73+
Collection<? extends FSQueue> queues, Resource totalResources,
74+
ResourceType type) {
75+
computeSharesInternal(queues, totalResources, type, true);
6076
}
6177

6278
/**
@@ -102,7 +118,7 @@ public static void computeShares(
102118
*/
103119
private static void computeSharesInternal(
104120
Collection<? extends Schedulable> schedulables, Resource totalResources,
105-
ResourceType type) {
121+
ResourceType type, boolean isSteadyShare) {
106122
if (schedulables.isEmpty()) {
107123
return;
108124
}
@@ -145,7 +161,13 @@ private static void computeSharesInternal(
145161
}
146162
// Set the fair shares based on the value of R we've converged to
147163
for (Schedulable sched : schedulables) {
148-
setResourceValue(computeShare(sched, right, type), sched.getFairShare(), type);
164+
if (isSteadyShare) {
165+
setResourceValue(computeShare(sched, right, type),
166+
((FSQueue) sched).getSteadyFairShare(), type);
167+
} else {
168+
setResourceValue(
169+
computeShare(sched, right, type), sched.getFairShare(), type);
170+
}
149171
}
150172
}
151173

0 commit comments

Comments
 (0)