3333import org .apache .hadoop .util .Time ;
3434import org .apache .hadoop .yarn .api .records .Container ;
3535import org .apache .hadoop .yarn .api .records .ExecutionType ;
36+ import org .apache .hadoop .yarn .api .records .ExecutionTypeRequest ;
3637import org .apache .hadoop .yarn .api .records .ResourceRequest ;
3738import org .apache .hadoop .yarn .server .resourcemanager .ClusterMetrics ;
3839import 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