Skip to content

Commit c915a65

Browse files
committed
YARN-4418. AM Resource Limit per partition can be updated to ResourceUsage as well. (Sunil G via wangda)
(cherry picked from commit 07b0fb9)
1 parent e02ad5a commit c915a65

File tree

6 files changed

+88
-12
lines changed

6 files changed

+88
-12
lines changed

hadoop-yarn-project/CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,9 @@ Release 2.8.0 - UNRELEASED
564564
YARN-4309. Add container launch related debug information to container logs
565565
when a container fails. (Varun Vasudev via wangda)
566566

567+
YARN-4418. AM Resource Limit per partition can be updated to ResourceUsage as well.
568+
(Sunil G via wangda)
569+
567570
OPTIMIZATIONS
568571

569572
YARN-3339. TestDockerContainerExecutor should pull a single image and not

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

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ private enum ResourceType {
6161
//CACHED_USED and CACHED_PENDING may be read by anyone, but must only
6262
//be written by ordering policies
6363
USED(0), PENDING(1), AMUSED(2), RESERVED(3), CACHED_USED(4),
64-
CACHED_PENDING(5);
64+
CACHED_PENDING(5), AMLIMIT(6);
6565

6666
private int idx;
6767

@@ -92,6 +92,7 @@ public String toString() {
9292
sb.append("pending=" + resArr[1] + "%, ");
9393
sb.append("am_used=" + resArr[2] + "%, ");
9494
sb.append("reserved=" + resArr[3] + "%}");
95+
sb.append("am_limit=" + resArr[6] + "%, ");
9596
return sb.toString();
9697
}
9798
}
@@ -106,11 +107,19 @@ public Resource getUsed() {
106107
public Resource getUsed(String label) {
107108
return _get(label, ResourceType.USED);
108109
}
109-
110+
111+
public Resource getCachedUsed() {
112+
return _get(NL, ResourceType.CACHED_USED);
113+
}
114+
110115
public Resource getCachedUsed(String label) {
111116
return _get(label, ResourceType.CACHED_USED);
112117
}
113-
118+
119+
public Resource getCachedPending() {
120+
return _get(NL, ResourceType.CACHED_PENDING);
121+
}
122+
114123
public Resource getCachedPending(String label) {
115124
return _get(label, ResourceType.CACHED_PENDING);
116125
}
@@ -149,15 +158,23 @@ public void copyAllUsed(ResourceUsage other) {
149158
public void setUsed(String label, Resource res) {
150159
_set(label, ResourceType.USED, res);
151160
}
152-
161+
153162
public void setCachedUsed(String label, Resource res) {
154163
_set(label, ResourceType.CACHED_USED, res);
155164
}
156-
165+
166+
public void setCachedUsed(Resource res) {
167+
_set(NL, ResourceType.CACHED_USED, res);
168+
}
169+
157170
public void setCachedPending(String label, Resource res) {
158171
_set(label, ResourceType.CACHED_PENDING, res);
159172
}
160173

174+
public void setCachedPending(Resource res) {
175+
_set(NL, ResourceType.CACHED_PENDING, res);
176+
}
177+
161178
/*
162179
* Pending
163180
*/
@@ -263,6 +280,41 @@ public void setAMUsed(String label, Resource res) {
263280
_set(label, ResourceType.AMUSED, res);
264281
}
265282

283+
/*
284+
* AM-Resource Limit
285+
*/
286+
public Resource getAMLimit() {
287+
return getAMLimit(NL);
288+
}
289+
290+
public Resource getAMLimit(String label) {
291+
return _get(label, ResourceType.AMLIMIT);
292+
}
293+
294+
public void incAMLimit(String label, Resource res) {
295+
_inc(label, ResourceType.AMLIMIT, res);
296+
}
297+
298+
public void incAMLimit(Resource res) {
299+
incAMLimit(NL, res);
300+
}
301+
302+
public void decAMLimit(Resource res) {
303+
decAMLimit(NL, res);
304+
}
305+
306+
public void decAMLimit(String label, Resource res) {
307+
_dec(label, ResourceType.AMLIMIT, res);
308+
}
309+
310+
public void setAMLimit(Resource res) {
311+
setAMLimit(NL, res);
312+
}
313+
314+
public void setAMLimit(String label, Resource res) {
315+
_set(label, ResourceType.AMLIMIT, res);
316+
}
317+
266318
private static Resource normalize(Resource res) {
267319
if (res == null) {
268320
return Resources.none();

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,7 @@ public synchronized Resource getAMResourceLimitPerPartition(
606606
minimumAllocation);
607607

608608
metrics.setAMResouceLimit(amResouceLimit);
609+
queueUsage.setAMLimit(nodePartition, amResouceLimit);
609610
return amResouceLimit;
610611
}
611612

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/QueueCapacities.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,11 @@ public void setAbsoluteMaximumCapacity(String label, float value) {
217217
}
218218

219219
/* Absolute Maximum AM resource percentage Getter and Setter */
220+
221+
public float getMaxAMResourcePercentage() {
222+
return _get(NL, CapacityType.MAX_AM_PERC);
223+
}
224+
220225
public float getMaxAMResourcePercentage(String label) {
221226
return _get(label, CapacityType.MAX_AM_PERC);
222227
}
@@ -225,6 +230,10 @@ public void setMaxAMResourcePercentage(String label, float value) {
225230
_set(label, CapacityType.MAX_AM_PERC, value);
226231
}
227232

233+
public void setMaxAMResourcePercentage(float value) {
234+
_set(NL, CapacityType.MAX_AM_PERC, value);
235+
}
236+
228237
/**
229238
* Clear configurable fields, like
230239
* (absolute)capacity/(absolute)maximum-capacity, this will be used by queue

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/TestResourceUsage.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ public class TestResourceUsage {
3737

3838
@Parameterized.Parameters
3939
public static Collection<String[]> getParameters() {
40-
return Arrays.asList(new String[][] { { "Pending" }, { "Used" },
41-
{ "Reserved" }, { "AMUsed" } });
40+
return Arrays.asList(new String[][]{{"Pending"}, {"Used"}, {"Reserved"},
41+
{"AMUsed"}, {"AMLimit"}, {"CachedUsed"}, {"CachedPending"}});
4242
}
4343

4444
public TestResourceUsage(String suffix) {
@@ -112,16 +112,26 @@ private void internalTestModifyAndRead(String label) throws Exception {
112112
check(0, 0, res);
113113

114114
// Add 1,1 should returns 1,1
115-
inc(usage, suffix, Resource.newInstance(1, 1), label);
116-
check(1, 1, get(usage, suffix, label));
115+
try {
116+
inc(usage, suffix, Resource.newInstance(1, 1), label);
117+
check(1, 1, get(usage, suffix, label));
118+
} catch (NoSuchMethodException e) {
119+
// Few operations need not have to be verified as some resources doesn't
120+
// inc/dec apis exposed (For Eg: CachedUsed and CachedPending).
121+
}
117122

118123
// Set 2,2
119124
set(usage, suffix, Resource.newInstance(2, 2), label);
120125
check(2, 2, get(usage, suffix, label));
121126

122127
// dec 2,2
123-
dec(usage, suffix, Resource.newInstance(2, 2), label);
124-
check(0, 0, get(usage, suffix, label));
128+
try {
129+
dec(usage, suffix, Resource.newInstance(2, 2), label);
130+
check(0, 0, get(usage, suffix, label));
131+
} catch (NoSuchMethodException e) {
132+
// Few operations need not have to be verified, as some resources doesn't
133+
// inc/dec apis exposed (For Eg: CachedUsed and CachedPending).
134+
}
125135
}
126136

127137
void check(int mem, int cpu, Resource res) {

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestQueueCapacities.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ public static Collection<String[]> getParameters() {
4343
{ "UsedCapacity" },
4444
{ "AbsoluteUsedCapacity" },
4545
{ "MaximumCapacity" },
46-
{ "AbsoluteMaximumCapacity" } });
46+
{ "AbsoluteMaximumCapacity" },
47+
{ "MaxAMResourcePercentage" } });
4748
}
4849

4950
public TestQueueCapacities(String suffix) {

0 commit comments

Comments
 (0)