Skip to content

Commit 6421ca4

Browse files
author
Minni Mittal
committed
Addressed comments
1 parent 138b7fc commit 6421ca4

File tree

3 files changed

+68
-73
lines changed

3 files changed

+68
-73
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,13 @@ public AllocateResponse allocate(AllocateRequest request)
398398
amrmTokenIdentifier.getApplicationAttemptId();
399399
RMAppAttemptMetrics rmMetrics = getAppAttemptMetrics(appAttemptId);
400400
// we do this here to prevent the internal lock in allocate()
401-
rmMetrics.setAllocateLatenciesTimestamps(request.getAskList());
401+
if (rmMetrics != null) {
402+
rmMetrics.setAllocateLatenciesTimestamps(request.getAskList());
403+
}
402404
AllocateResponse response = allocate(request, amrmTokenIdentifier);
403-
rmMetrics.updateAllocateLatencies(response.getAllocatedContainers());
405+
if (rmMetrics != null) {
406+
rmMetrics.updateAllocateLatencies(response.getAllocatedContainers());
407+
}
404408
return response;
405409
}
406410

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

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ public class ClusterMetrics {
7777
MutableGaugeInt rmDispatcherEventQueueSize;
7878
@Metric("# of scheduler dispatcher event queue size")
7979
MutableGaugeInt schedulerDispatcherEventQueueSize;
80-
@Metric("Allocation Latencies for Guarantee containers")
81-
MutableQuantiles allocateLatencyGuarQuantiles;
80+
@Metric("Allocation Latencies for Guaranteed containers")
81+
MutableQuantiles allocateLatencyGuarQuantiles;
8282
@Metric("Allocation Latencies for Opportunistic containers")
83-
MutableQuantiles allocateLatencyOppQuantiles;
83+
MutableQuantiles allocateLatencyOppQuantiles;
8484
private boolean rmEventProcMonitorEnable = false;
8585

8686
private static final MetricsInfo RECORD_INFO = info("ClusterMetrics",
@@ -130,14 +130,14 @@ public static ClusterMetrics getMetrics() {
130130
}
131131

132132
private void initialize() {
133-
allocateLatencyGuarQuantiles = registry
134-
.newQuantiles("AllocateLatencyGuaranteed",
135-
"Latency to fulfill an Allocate(Guaranteed) requests", "ops",
136-
"latency", 5);
137-
allocateLatencyOppQuantiles = registry
138-
.newQuantiles("AllocateLatencyOpportunistic",
139-
"Latency to fulfill an Allocate(Opportunistic) requests", "ops",
140-
"latency", 5);
133+
allocateLatencyGuarQuantiles = registry.newQuantiles(
134+
"AllocateLatencyGuaranteed",
135+
"Latency to fulfill an Allocate(Guaranteed) requests", "ops",
136+
"latency", 5);
137+
allocateLatencyOppQuantiles = registry.newQuantiles(
138+
"AllocateLatencyOpportunistic",
139+
"Latency to fulfill an Allocate(Opportunistic) requests", "ops",
140+
"latency", 5);
141141
}
142142

143143
private static void registerMetrics() {
@@ -400,4 +400,22 @@ public int getSchedulerEventQueueSize() {
400400
public void setSchedulerEventQueueSize(int schedulerEventQueueSize) {
401401
this.schedulerDispatcherEventQueueSize.set(schedulerEventQueueSize);
402402
}
403+
404+
public MutableQuantiles getAllocateLatencyGuarQuantiles() {
405+
return allocateLatencyGuarQuantiles;
406+
}
407+
408+
public void setAllocateLatencyGuarQuantiles(
409+
MutableQuantiles allocateLatencyGuarQuantiles) {
410+
this.allocateLatencyGuarQuantiles = allocateLatencyGuarQuantiles;
411+
}
412+
413+
public MutableQuantiles getAllocateLatencyOppQuantiles() {
414+
return allocateLatencyOppQuantiles;
415+
}
416+
417+
public void setAllocateLatencyOppQuantiles(
418+
MutableQuantiles allocateLatencyOppQuantiles) {
419+
this.allocateLatencyOppQuantiles = allocateLatencyOppQuantiles;
420+
}
403421
}

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/attempt/RMAppAttemptMetrics.java

Lines changed: 33 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.apache.hadoop.util.Time;
3434
import org.apache.hadoop.yarn.api.records.Container;
3535
import org.apache.hadoop.yarn.api.records.ExecutionType;
36+
import org.apache.hadoop.yarn.api.records.ExecutionTypeRequest;
3637
import org.apache.hadoop.yarn.api.records.ResourceRequest;
3738
import org.apache.hadoop.yarn.server.resourcemanager.ClusterMetrics;
3839
import org.slf4j.Logger;
@@ -69,8 +70,10 @@ public class RMAppAttemptMetrics {
6970
new int[NodeType.values().length][NodeType.values().length];
7071
private volatile int totalAllocatedContainers;
7172

72-
private ConcurrentHashMap<Long, Long> allocationGuaranteedLatencies = null;
73-
private ConcurrentHashMap<Long, Long> allocationOpportunisticLatencies = null;
73+
private ConcurrentHashMap<Long, Long> allocationGuaranteedLatencies =
74+
new ConcurrentHashMap<Long, Long>();
75+
private ConcurrentHashMap<Long, Long> allocationOpportunisticLatencies =
76+
new ConcurrentHashMap<Long, Long>();
7477

7578
public RMAppAttemptMetrics(ApplicationAttemptId attemptId,
7679
RMContext rmContext) {
@@ -79,8 +82,6 @@ public RMAppAttemptMetrics(ApplicationAttemptId attemptId,
7982
this.readLock = lock.readLock();
8083
this.writeLock = lock.writeLock();
8184
this.rmContext = rmContext;
82-
this.allocationGuaranteedLatencies = new ConcurrentHashMap<Long, Long>();
83-
this.allocationOpportunisticLatencies = new ConcurrentHashMap<Long, Long>();
8485
}
8586

8687
public void updatePreemptionInfo(Resource resource, RMContainer container) {
@@ -254,20 +255,9 @@ public void setApplicationAttemptHeadRoom(Resource headRoom) {
254255
this.applicationHeadroom = headRoom;
255256
}
256257

257-
/**
258-
* Add allocationID latency to the application ID with a timestap =
259-
* CurrentTime (guaranteed)
260-
*
261-
* @param allocId the allocation Id to add If the allocation ID is already
262-
* present (which shouldn't happen) it ignores the entry
263-
*/
264-
public void addAllocationGuarLatencyIfNotExists(long allocId) {
265-
addAllocationGuarLatencyIfNotExists(allocId, System.currentTimeMillis());
266-
}
267-
268258
/**
269259
* Add allocationID latency to the application ID with a specific timestamp
270-
* (guaranteed)
260+
* (guaranteed).
271261
*
272262
* @param allocId allocationId
273263
* @param timestamp the timestamp to associate
@@ -277,21 +267,9 @@ public void addAllocationGuarLatencyIfNotExists(long allocId,
277267
allocationGuaranteedLatencies.putIfAbsent(allocId, timestamp);
278268
}
279269

280-
/**
281-
* Add allocationID latency to the application ID with a timestap =
282-
* CurrentTime (opportunistic)
283-
*
284-
* @param allocId the allocation Id to add If the allocation ID is already
285-
* present (which shouldn't happen) it ignores the entry
286-
*/
287-
public void addAllocationOppLatencyIfNotExists(long allocId) {
288-
this.addAllocationOppLatencyIfNotExists(allocId,
289-
System.currentTimeMillis());
290-
}
291-
292270
/**
293271
* Add allocationID latency to the application ID with a specific timestamp
294-
* (opportunistic)
272+
* (opportunistic).
295273
*
296274
* @param allocId allocationId
297275
* @param timestamp the timestamp to associate
@@ -301,36 +279,35 @@ public void addAllocationOppLatencyIfNotExists(long allocId, long timestamp) {
301279
}
302280

303281
/**
304-
* Returns the time associated when the allocation Id was added This method
305-
* removes the allocation Id from the class (guaranteed)
282+
* Returns the time associated when the allocation Id was added. This method
283+
* removes the allocation Id from the class (guaranteed).
306284
*
307285
* @param allocId the allocation ID to get the associated time
308286
* @return the timestamp associated with that allocation id as well as stop
309287
* tracking it
310288
*/
311289
public long getAndRemoveGuaAllocationLatencies(long allocId) {
312-
Long ret = allocationGuaranteedLatencies.remove(new Long(allocId));
313-
return ret != null ? ret : 0l;
290+
Long ret = allocationGuaranteedLatencies.remove(allocId);
291+
return ret != null ? ret : 0L;
314292
}
315293

316294
/**
317-
* Returns the time associated when the allocation Id was added This method
318-
* removes the allocation Id from the class (opportunistic)
295+
* Returns the time associated when the allocation Id was added. This method
296+
* removes the allocation Id from the class (opportunistic).
319297
*
320298
* @param allocId the allocation ID to get the associated time
321299
* @return the timestamp associated with that allocation id as well as stop
322300
* tracking it
323301
*/
324302
public long getAndRemoveOppAllocationLatencies(long allocId) {
325-
Long ret = allocationOpportunisticLatencies.remove(new Long(allocId));
326-
return ret != null ? ret : 0l;
303+
Long ret = allocationOpportunisticLatencies.remove(allocId);
304+
return ret != null ? ret : 0L;
327305
}
328306

329307
/**
330308
* Set timestamp for the provided ResourceRequest. It will correctly identify
331309
* their ExecutionType, provided they have they have allocateId != 0 (DEFAULT)
332-
* This is used in conjunction with This is used in conjunction with
333-
* updatePromoteLatencies method method
310+
* This is used in conjunction with updatePromoteLatencies method.
334311
*
335312
* @param requests the ResourceRequests to add.
336313
*/
@@ -341,19 +318,18 @@ public void setAllocateLatenciesTimestamps(List<ResourceRequest> requests) {
341318
// we dont support tracking with negative or zero allocationIds
342319
long allocationRequestId = req.getAllocationRequestId();
343320
if (allocationRequestId > 0) {
344-
if (req.getExecutionTypeRequest() != null) {
345-
if (ExecutionType.GUARANTEED
346-
.equals(req.getExecutionTypeRequest().getExecutionType())) {
321+
ExecutionTypeRequest execReq = req.getExecutionTypeRequest();
322+
if (execReq != null) {
323+
if (ExecutionType.GUARANTEED.equals(execReq.getExecutionType())) {
347324
addAllocationGuarLatencyIfNotExists(allocationRequestId, now);
348325
} else {
349326
addAllocationOppLatencyIfNotExists(allocationRequestId, now);
350327
}
351328
}
352329
} else {
353-
LOG.warn(String.format(
354-
"Can't register allocate latency for %s container "
355-
+ "with negative or zero allocation IDs",
356-
req.getExecutionTypeRequest().getExecutionType()));
330+
LOG.warn("Can't register allocate latency for {} container with"
331+
+ "less than or equal to 0 allocation IDs",
332+
req.getExecutionTypeRequest().getExecutionType());
357333
}
358334
}
359335
}
@@ -362,39 +338,36 @@ public void setAllocateLatenciesTimestamps(List<ResourceRequest> requests) {
362338
/**
363339
* Updated the JMX metrics class (ClusterMetrics) with the delta time when
364340
* these containers where added. It will correctly identify their
365-
* ExecutionType, provided they have they have allocateId != 0 (DEFAULT)
341+
* ExecutionType, provided they have they have allocateId != 0 (DEFAULT).
366342
*
367343
* @param response the list of the containers to allocate.
368344
*/
369345
public void updateAllocateLatencies(List<Container> response) {
370-
371346
for (Container container : response) {
372347
long allocationRequestId = container.getAllocationRequestId();
348+
ExecutionType executionType = container.getExecutionType();
373349
// we dont support tracking with negative or zero allocationIds
374350
if (allocationRequestId > 0) {
375351
long now = System.currentTimeMillis();
376-
long allocIdTime =
377-
(container.getExecutionType() == ExecutionType.GUARANTEED) ?
378-
getAndRemoveGuaAllocationLatencies(allocationRequestId) :
379-
getAndRemoveOppAllocationLatencies(allocationRequestId);
352+
long allocIdTime = (executionType == ExecutionType.GUARANTEED) ?
353+
getAndRemoveGuaAllocationLatencies(allocationRequestId) :
354+
getAndRemoveOppAllocationLatencies(allocationRequestId);
380355
if (allocIdTime != 0) {
381-
if (container.getExecutionType() == ExecutionType.GUARANTEED) {
356+
if (executionType == ExecutionType.GUARANTEED) {
382357
ClusterMetrics.getMetrics()
383358
.addAllocateGuarLatencyEntry(now - allocIdTime);
384359
} else {
385360
ClusterMetrics.getMetrics()
386361
.addAllocateOppLatencyEntry(now - allocIdTime);
387362
}
388363
} else {
389-
LOG.error(String.format(
390-
"Can't register allocate latency for %s container %s; allotTime=%d ",
391-
container.getExecutionType(), container.getId(), allocIdTime));
364+
LOG.error("Can't register allocate latency for {} container {}; "
365+
+ "allotTime={}", executionType, container.getId(), allocIdTime);
392366
}
393367
} else {
394-
LOG.warn(String.format("Cant register promotion latency "
395-
+ "for container %s. Either allocationID is less than equal to 0 or "
396-
+ "lost the container ID", container.getExecutionType().name(),
397-
container.getId()));
368+
LOG.warn("Cant register promotion latency for {} container {}. Either "
369+
+ "allocationID is less than or equal to 0 or container is lost",
370+
executionType, container.getId());
398371
}
399372
}
400373
}

0 commit comments

Comments
 (0)