This is an automated email from the ASF dual-hosted git repository.

angerszhuuuu pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-celeborn.git


The following commit(s) were added to refs/heads/main by this push:
     new 16d193071 [CELEBORN-541][PERF] handleGetReducerFileGroup occupy too 
much RPC thread cause other RPC can't been handled (#1444)
16d193071 is described below

commit 16d193071f8460bc16b40f4fa24c1e55cc16ce6a
Author: Angerszhuuuu <[email protected]>
AuthorDate: Fri Apr 21 17:04:52 2023 +0800

    [CELEBORN-541][PERF] handleGetReducerFileGroup occupy too much RPC thread 
cause other RPC can't been handled (#1444)
    
    * [CELEBORN-541][PERF] handleGetReducerFileGroup occupy too much RPC thread 
cause other RPC can't been handled
---
 .../commit/ReducePartitionCommitHandler.scala      | 91 +++++++++++++---------
 1 file changed, 54 insertions(+), 37 deletions(-)

diff --git 
a/client/src/main/scala/org/apache/celeborn/client/commit/ReducePartitionCommitHandler.scala
 
b/client/src/main/scala/org/apache/celeborn/client/commit/ReducePartitionCommitHandler.scala
index eda572f78..e0f7ee81d 100644
--- 
a/client/src/main/scala/org/apache/celeborn/client/commit/ReducePartitionCommitHandler.scala
+++ 
b/client/src/main/scala/org/apache/celeborn/client/commit/ReducePartitionCommitHandler.scala
@@ -54,6 +54,8 @@ class ReducePartitionCommitHandler(
   extends CommitHandler(appId, conf, committedPartitionInfo)
   with Logging {
 
+  private val getReducerFileGroupRequest =
+    JavaUtils.newConcurrentHashMap[Int, util.Set[RpcCallContext]]()
   private val dataLostShuffleSet = ConcurrentHashMap.newKeySet[Int]()
   private val stageEndShuffleSet = ConcurrentHashMap.newKeySet[Int]()
   private val inProcessStageEndShuffleSet = ConcurrentHashMap.newKeySet[Int]()
@@ -93,7 +95,11 @@ class ReducePartitionCommitHandler(
   }
 
   override def setStageEnd(shuffleId: Int): Unit = {
-    stageEndShuffleSet.add(shuffleId)
+    getReducerFileGroupRequest synchronized {
+      stageEndShuffleSet.add(shuffleId)
+      getReducerFileGroupRequest.remove(shuffleId)
+        .asScala.foreach(replyGetReducerFileGroup(_, shuffleId))
+    }
   }
 
   override def removeExpiredShuffle(shuffleId: Int): Unit = {
@@ -129,12 +135,12 @@ class ReducePartitionCommitHandler(
     if (!dataLost) {
       logInfo(s"Succeed to handle stageEnd for $shuffleId.")
       // record in stageEndShuffleSet
-      stageEndShuffleSet.add(shuffleId)
+      setStageEnd(shuffleId)
     } else {
       logError(s"Failed to handle stageEnd for $shuffleId, lost file!")
       dataLostShuffleSet.add(shuffleId)
       // record in stageEndShuffleSet
-      stageEndShuffleSet.add(shuffleId)
+      setStageEnd(shuffleId)
     }
     inProcessStageEndShuffleSet.remove(shuffleId)
     true
@@ -249,43 +255,54 @@ class ReducePartitionCommitHandler(
     }
   }
 
-  override def handleGetReducerFileGroup(context: RpcCallContext, shuffleId: 
Int): Unit = {
-    val (isTimeout, cost) = waitStageEnd(shuffleId)
-    if (isTimeout) {
-      logError(s"[handleGetReducerFileGroup] Wait for handleStageEnd Timeout! 
$shuffleId.")
-      context.reply(GetReducerFileGroupResponse(
-        StatusCode.STAGE_END_TIME_OUT,
-        JavaUtils.newConcurrentHashMap(),
-        Array.empty))
+  private def replyGetReducerFileGroup(context: RpcCallContext, shuffleId: 
Int): Unit = {
+    if (isStageDataLost(shuffleId)) {
+      context.reply(
+        GetReducerFileGroupResponse(
+          StatusCode.SHUFFLE_DATA_LOST,
+          JavaUtils.newConcurrentHashMap(),
+          Array.empty))
     } else {
-      logDebug("[handleGetReducerFileGroup] Wait for handleStageEnd complete 
cost" +
-        s" ${cost}ms")
-      if (isStageDataLost(shuffleId)) {
-        context.reply(
-          GetReducerFileGroupResponse(
-            StatusCode.SHUFFLE_DATA_LOST,
-            JavaUtils.newConcurrentHashMap(),
-            Array.empty))
+      // LocalNettyRpcCallContext is for the UTs
+      if (context.isInstanceOf[LocalNettyRpcCallContext]) {
+        context.reply(GetReducerFileGroupResponse(
+          StatusCode.SUCCESS,
+          reducerFileGroupsMap.getOrDefault(shuffleId, 
JavaUtils.newConcurrentHashMap()),
+          getMapperAttempts(shuffleId)))
       } else {
-        // LocalNettyRpcCallContext is for the UTs
-        if (context.isInstanceOf[LocalNettyRpcCallContext]) {
-          context.reply(GetReducerFileGroupResponse(
-            StatusCode.SUCCESS,
-            reducerFileGroupsMap.getOrDefault(shuffleId, 
JavaUtils.newConcurrentHashMap()),
-            getMapperAttempts(shuffleId)))
+        val cachedMsg = getReducerFileGroupRpcCache.get(
+          shuffleId,
+          new Callable[ByteBuffer]() {
+            override def call(): ByteBuffer = {
+              val returnedMsg = GetReducerFileGroupResponse(
+                StatusCode.SUCCESS,
+                reducerFileGroupsMap.getOrDefault(shuffleId, 
JavaUtils.newConcurrentHashMap()),
+                getMapperAttempts(shuffleId))
+              
context.asInstanceOf[RemoteNettyRpcCallContext].nettyEnv.serialize(returnedMsg)
+            }
+          })
+        
context.asInstanceOf[RemoteNettyRpcCallContext].callback.onSuccess(cachedMsg)
+      }
+    }
+  }
+
+  override def handleGetReducerFileGroup(context: RpcCallContext, shuffleId: 
Int): Unit = {
+    // Quick return for ended stage, avoid occupy sync lock.
+    if (isStageEnd(shuffleId)) {
+      replyGetReducerFileGroup(context, shuffleId)
+    } else {
+      getReducerFileGroupRequest.synchronized {
+        // If setStageEnd() called after isStageEnd and before got lock, 
should reply here.
+        if (isStageEnd(shuffleId)) {
+          replyGetReducerFileGroup(context, shuffleId)
         } else {
-          val cachedMsg = getReducerFileGroupRpcCache.get(
-            shuffleId,
-            new Callable[ByteBuffer]() {
-              override def call(): ByteBuffer = {
-                val returnedMsg = GetReducerFileGroupResponse(
-                  StatusCode.SUCCESS,
-                  reducerFileGroupsMap.getOrDefault(shuffleId, 
JavaUtils.newConcurrentHashMap()),
-                  getMapperAttempts(shuffleId))
-                
context.asInstanceOf[RemoteNettyRpcCallContext].nettyEnv.serialize(returnedMsg)
-              }
-            })
-          
context.asInstanceOf[RemoteNettyRpcCallContext].callback.onSuccess(cachedMsg)
+          if (getReducerFileGroupRequest.contains(shuffleId)) {
+            getReducerFileGroupRequest.get(shuffleId).add(context)
+          } else {
+            val set = new util.HashSet[RpcCallContext]()
+            set.add(context)
+            getReducerFileGroupRequest.put(shuffleId, set)
+          }
         }
       }
     }

Reply via email to