You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@celeborn.apache.org by "waitinfuture (via GitHub)" <gi...@apache.org> on 2023/09/04 09:17:42 UTC

[GitHub] [incubator-celeborn] waitinfuture opened a new pull request, #1876: [CELEBORN-943][PERF] Pre-create CelebornInputStreams in CelebornShuffleReader

waitinfuture opened a new pull request, #1876:
URL: https://github.com/apache/incubator-celeborn/pull/1876

   <!--
   Thanks for sending a pull request!  Here are some tips for you:
     - Make sure the PR title start w/ a JIRA ticket, e.g. '[CELEBORN-XXXX] Your PR title ...'.
     - Be sure to keep the PR description updated to reflect all changes.
     - Please write your PR title to summarize what this PR proposes.
     - If possible, provide a concise example to reproduce the issue for a faster review.
   -->
   
   ### What changes were proposed in this pull request?
   This PR fixes performance degradation when Spark's coalescePartitions takes effect caused
   by RPC latency. 
   
   
   ### Why are the changes needed?
   I encountered a performance degradation when testing  tpcds 10T q10:
   ||Time|
   |---|---|
   |ESS|14s|
   |Celeborn| 24s|
   After digging into it I found out that q10 triggers partition coalescence:
   
   As I configured `spark.sql.adaptive.coalescePartitions.minPartitionNum` to 1000, `CelebornShuffleReader`
   will call `shuffleClient.readPartition` sequentially 1000 times, causing the delay.
   
   This PR optimizes by calling `shuffleClient.readPartition` in parallel.
   
   ### Does this PR introduce _any_ user-facing change?
   No, but introduced a new client side configuration `celeborn.client.streamCreatorPool.threads`
   which defaults to 32.
   
   
   ### How was this patch tested?
   TPCDS 1T and passes GA.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-celeborn] waitinfuture commented on a diff in pull request #1876: [CELEBORN-943][PERF] Pre-create CelebornInputStreams in CelebornShuffleReader

Posted by "waitinfuture (via GitHub)" <gi...@apache.org>.
waitinfuture commented on code in PR #1876:
URL: https://github.com/apache/incubator-celeborn/pull/1876#discussion_r1314857630


##########
client-spark/spark-3/src/main/scala/org/apache/spark/shuffle/celeborn/CelebornShuffleReader.scala:
##########
@@ -62,15 +70,51 @@ class CelebornShuffleReader[K, C](
         metrics.incFetchWaitTime(time)
     }
 
+    if (streamCreatorPool == null) {
+      CelebornShuffleReader.synchronized {
+        if (streamCreatorPool == null) {
+          streamCreatorPool = ThreadUtils.newDaemonCachedThreadPool(
+            "create-stream-thread",
+            conf.readStreamCreatorPoolThreads,
+            60);
+        }
+      }
+    }
+
+    val streams = new ConcurrentHashMap[Integer, CelebornInputStream]()
+    (startPartition until endPartition).map(partitionId => {
+      streamCreatorPool.submit(new Runnable {
+        override def run(): Unit = {
+          if (exceptionRef.get() == null) {
+            try {
+              val inputStream = shuffleClient.readPartition(
+                handle.shuffleId,
+                partitionId,
+                context.attemptNumber(),
+                startMapIndex,
+                endMapIndex)
+              streams.put(partitionId, inputStream)
+            } catch {
+              case e: IOException =>
+                logInfo("Exception caught when readPartition!")
+                exceptionRef.compareAndSet(null, e)
+            }
+          }
+        }
+      })
+    })
+
     val recordIter = (startPartition until endPartition).iterator.map(partitionId => {
       if (handle.numMappers > 0) {
         val start = System.currentTimeMillis()
-        val inputStream = shuffleClient.readPartition(
-          handle.shuffleId,
-          partitionId,
-          context.attemptNumber(),
-          startMapIndex,
-          endMapIndex)
+        var inputStream: CelebornInputStream = streams.get(partitionId)
+        while (inputStream == null) {
+          if (exceptionRef.get() != null) {

Review Comment:
   > the method `shuffleClient.readPartition` explicitly declares the throwing of an IOException.
   > 
   > https://github.com/apache/incubator-celeborn/blob/b66eaff880e91864a21c96dbac94fa5f8cd84f4c/client/src/main/java/org/apache/celeborn/client/ShuffleClient.java#L191-L193
   
   Right. Do we have to consider RuntimeException here?



##########
client-spark/spark-3/src/main/scala/org/apache/spark/shuffle/celeborn/CelebornShuffleReader.scala:
##########
@@ -62,15 +70,51 @@ class CelebornShuffleReader[K, C](
         metrics.incFetchWaitTime(time)
     }
 
+    if (streamCreatorPool == null) {
+      CelebornShuffleReader.synchronized {
+        if (streamCreatorPool == null) {
+          streamCreatorPool = ThreadUtils.newDaemonCachedThreadPool(
+            "create-stream-thread",
+            conf.readStreamCreatorPoolThreads,
+            60);
+        }
+      }
+    }
+
+    val streams = new ConcurrentHashMap[Integer, CelebornInputStream]()
+    (startPartition until endPartition).map(partitionId => {
+      streamCreatorPool.submit(new Runnable {
+        override def run(): Unit = {
+          if (exceptionRef.get() == null) {
+            try {
+              val inputStream = shuffleClient.readPartition(
+                handle.shuffleId,
+                partitionId,
+                context.attemptNumber(),
+                startMapIndex,
+                endMapIndex)
+              streams.put(partitionId, inputStream)
+            } catch {
+              case e: IOException =>
+                logInfo("Exception caught when readPartition!")
+                exceptionRef.compareAndSet(null, e)
+            }
+          }
+        }
+      })
+    })
+
     val recordIter = (startPartition until endPartition).iterator.map(partitionId => {
       if (handle.numMappers > 0) {
         val start = System.currentTimeMillis()
-        val inputStream = shuffleClient.readPartition(
-          handle.shuffleId,
-          partitionId,
-          context.attemptNumber(),
-          startMapIndex,
-          endMapIndex)
+        var inputStream: CelebornInputStream = streams.get(partitionId)
+        while (inputStream == null) {
+          if (exceptionRef.get() != null) {

Review Comment:
   > the method `shuffleClient.readPartition` explicitly declares the throwing of an IOException.
   > 
   > https://github.com/apache/incubator-celeborn/blob/b66eaff880e91864a21c96dbac94fa5f8cd84f4c/client/src/main/java/org/apache/celeborn/client/ShuffleClient.java#L191-L193
   
   Right. Do we need to consider RuntimeException here?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-celeborn] pan3793 commented on a diff in pull request #1876: [CELEBORN-943][PERF] Pre-create CelebornInputStreams in CelebornShuffleReader

Posted by "pan3793 (via GitHub)" <gi...@apache.org>.
pan3793 commented on code in PR #1876:
URL: https://github.com/apache/incubator-celeborn/pull/1876#discussion_r1314872782


##########
common/src/main/scala/org/apache/celeborn/common/CelebornConf.scala:
##########
@@ -3818,6 +3819,14 @@ object CelebornConf extends Logging {
       .intConf
       .createWithDefault(4)
 
+  val READ_STREAM_CREATOR_POOL_THREADS: ConfigEntry[Int] =
+    buildConf("celeborn.client.streamCreatorPool.threads")

Review Comment:
   ```suggestion
       buildConf("celeborn.client.eagerlyCreateInputStream.threads")
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-celeborn] codecov[bot] commented on pull request #1876: [CELEBORN-943][PERF] Pre-create CelebornInputStreams in CelebornShuffleReader

Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #1876:
URL: https://github.com/apache/incubator-celeborn/pull/1876#issuecomment-1704931363

   ## [Codecov](https://app.codecov.io/gh/apache/incubator-celeborn/pull/1876?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   > Merging [#1876](https://app.codecov.io/gh/apache/incubator-celeborn/pull/1876?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) (85b8ed3) into [main](https://app.codecov.io/gh/apache/incubator-celeborn/commit/b66eaff880e91864a21c96dbac94fa5f8cd84f4c?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) (b66eaff) will **increase** coverage by `0.03%`.
   > The diff coverage is `85.72%`.
   
   ```diff
   @@            Coverage Diff             @@
   ##             main    #1876      +/-   ##
   ==========================================
   + Coverage   46.52%   46.55%   +0.03%     
   ==========================================
     Files         164      164              
     Lines       10205    10212       +7     
     Branches      936      936              
   ==========================================
   + Hits         4747     4753       +6     
   - Misses       5145     5146       +1     
     Partials      313      313              
   ```
   
   
   | [Files Changed](https://app.codecov.io/gh/apache/incubator-celeborn/pull/1876?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
   |---|---|---|
   | [...cala/org/apache/celeborn/common/CelebornConf.scala](https://app.codecov.io/gh/apache/incubator-celeborn/pull/1876?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-Y29tbW9uL3NyYy9tYWluL3NjYWxhL29yZy9hcGFjaGUvY2VsZWJvcm4vY29tbW9uL0NlbGVib3JuQ29uZi5zY2FsYQ==) | `87.46% <85.72%> (-<0.01%)` | :arrow_down: |
   
   :mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-celeborn] pan3793 commented on a diff in pull request #1876: [CELEBORN-943][PERF] Pre-create CelebornInputStreams in CelebornShuffleReader

Posted by "pan3793 (via GitHub)" <gi...@apache.org>.
pan3793 commented on code in PR #1876:
URL: https://github.com/apache/incubator-celeborn/pull/1876#discussion_r1314822328


##########
client-spark/spark-3/src/main/scala/org/apache/spark/shuffle/celeborn/CelebornShuffleReader.scala:
##########
@@ -62,15 +70,51 @@ class CelebornShuffleReader[K, C](
         metrics.incFetchWaitTime(time)
     }
 
+    if (streamCreatorPool == null) {
+      CelebornShuffleReader.synchronized {
+        if (streamCreatorPool == null) {
+          streamCreatorPool = ThreadUtils.newDaemonCachedThreadPool(
+            "create-stream-thread",
+            conf.readStreamCreatorPoolThreads,
+            60);
+        }
+      }
+    }
+
+    val streams = new ConcurrentHashMap[Integer, CelebornInputStream]()
+    (startPartition until endPartition).map(partitionId => {
+      streamCreatorPool.submit(new Runnable {
+        override def run(): Unit = {
+          if (exceptionRef.get() == null) {
+            try {
+              val inputStream = shuffleClient.readPartition(
+                handle.shuffleId,
+                partitionId,
+                context.attemptNumber(),
+                startMapIndex,
+                endMapIndex)
+              streams.put(partitionId, inputStream)
+            } catch {
+              case e: IOException =>
+                logInfo("Exception caught when readPartition!")
+                exceptionRef.compareAndSet(null, e)
+            }
+          }
+        }
+      })
+    })
+
     val recordIter = (startPartition until endPartition).iterator.map(partitionId => {
       if (handle.numMappers > 0) {
         val start = System.currentTimeMillis()
-        val inputStream = shuffleClient.readPartition(
-          handle.shuffleId,
-          partitionId,
-          context.attemptNumber(),
-          startMapIndex,
-          endMapIndex)
+        var inputStream: CelebornInputStream = streams.get(partitionId)
+        while (inputStream == null) {
+          if (exceptionRef.get() != null) {

Review Comment:
   there is a chance that shuffleClient.readPartition throws a non-IOException, then it goes dead lock



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-celeborn] cfmcgrady commented on a diff in pull request #1876: [CELEBORN-943][PERF] Pre-create CelebornInputStreams in CelebornShuffleReader

Posted by "cfmcgrady (via GitHub)" <gi...@apache.org>.
cfmcgrady commented on code in PR #1876:
URL: https://github.com/apache/incubator-celeborn/pull/1876#discussion_r1314791055


##########
client-spark/spark-3/src/main/scala/org/apache/spark/shuffle/celeborn/CelebornShuffleReader.scala:
##########
@@ -62,15 +70,51 @@ class CelebornShuffleReader[K, C](
         metrics.incFetchWaitTime(time)
     }
 
+    if (streamCreatorPool == null) {
+      CelebornShuffleReader.synchronized {
+        if (streamCreatorPool == null) {
+          streamCreatorPool = ThreadUtils.newDaemonCachedThreadPool(
+            "create-stream-thread",
+            conf.readStreamCreatorPoolThreads,
+            60);
+        }
+      }
+    }
+
+    val streams = new ConcurrentHashMap[Integer, CelebornInputStream]()
+    (startPartition until endPartition).map(partitionId => {
+      streamCreatorPool.submit(new Runnable {
+        override def run(): Unit = {
+          if (exceptionRef.get() == null) {
+            try {
+              val inputStream = shuffleClient.readPartition(
+                handle.shuffleId,
+                partitionId,
+                context.attemptNumber(),
+                startMapIndex,
+                endMapIndex)
+              streams.put(partitionId, inputStream)
+            } catch {
+              case e: IOException =>
+                logInfo("Exception caught when readPartition!")
+                exceptionRef.compareAndSet(null, e)
+            }
+          }
+        }
+      })
+    })
+
     val recordIter = (startPartition until endPartition).iterator.map(partitionId => {
       if (handle.numMappers > 0) {
         val start = System.currentTimeMillis()
-        val inputStream = shuffleClient.readPartition(
-          handle.shuffleId,
-          partitionId,
-          context.attemptNumber(),
-          startMapIndex,
-          endMapIndex)
+        var inputStream: CelebornInputStream = streams.get(partitionId)
+        while (inputStream == null) {
+          if (exceptionRef.get() != null) {
+            throw exceptionRef.get()
+          }
+          Thread.sleep(50)
+          inputStream = streams.get(partitionId)
+        }
         metricsCallback.incReadTime(System.currentTimeMillis() - start)
         inputStream.setCallback(metricsCallback)
         // ensure inputStream is closed when task completes

Review Comment:
   ~~we need to close all `streams`.~~



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-celeborn] waitinfuture closed pull request #1876: [CELEBORN-943][PERF] Pre-create CelebornInputStreams in CelebornShuffleReader

Posted by "waitinfuture (via GitHub)" <gi...@apache.org>.
waitinfuture closed pull request #1876: [CELEBORN-943][PERF] Pre-create CelebornInputStreams in CelebornShuffleReader
URL: https://github.com/apache/incubator-celeborn/pull/1876


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-celeborn] waitinfuture commented on pull request #1876: [CELEBORN-943][PERF] Pre-create CelebornInputStreams in CelebornShuffleReader

Posted by "waitinfuture (via GitHub)" <gi...@apache.org>.
waitinfuture commented on PR #1876:
URL: https://github.com/apache/incubator-celeborn/pull/1876#issuecomment-1704937825

   @pan3793 I prefer to merge this PR into 0.3.1


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-celeborn] pan3793 commented on a diff in pull request #1876: [CELEBORN-943][PERF] Pre-create CelebornInputStreams in CelebornShuffleReader

Posted by "pan3793 (via GitHub)" <gi...@apache.org>.
pan3793 commented on code in PR #1876:
URL: https://github.com/apache/incubator-celeborn/pull/1876#discussion_r1314890311


##########
client-spark/spark-3/src/main/scala/org/apache/spark/shuffle/celeborn/CelebornShuffleReader.scala:
##########
@@ -62,15 +71,54 @@ class CelebornShuffleReader[K, C](
         metrics.incFetchWaitTime(time)
     }
 
+    if (streamCreatorPool == null) {
+      CelebornShuffleReader.synchronized {
+        if (streamCreatorPool == null) {
+          streamCreatorPool = ThreadUtils.newDaemonCachedThreadPool(
+            "celeborn-create-stream-thread",
+            conf.readStreamCreatorPoolThreads,
+            60);
+        }
+      }
+    }
+
+    val streams = new ConcurrentHashMap[Integer, CelebornInputStream]()
+    (startPartition until endPartition).map(partitionId => {
+      streamCreatorPool.submit(new Runnable {
+        override def run(): Unit = {
+          if (exceptionRef.get() == null) {
+            try {
+              val inputStream = shuffleClient.readPartition(
+                handle.shuffleId,
+                partitionId,
+                context.attemptNumber(),
+                startMapIndex,
+                endMapIndex)
+              streams.put(partitionId, inputStream)
+            } catch {
+              case e: IOException =>
+                logInfo("Exception caught when readPartition!", e)
+                exceptionRef.compareAndSet(null, e)
+              case e: Exception =>

Review Comment:
   ```suggestion
                 case e: Throwable =>
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-celeborn] pan3793 commented on a diff in pull request #1876: [CELEBORN-943][PERF] Pre-create CelebornInputStreams in CelebornShuffleReader

Posted by "pan3793 (via GitHub)" <gi...@apache.org>.
pan3793 commented on code in PR #1876:
URL: https://github.com/apache/incubator-celeborn/pull/1876#discussion_r1314818956


##########
client-spark/spark-3/src/main/scala/org/apache/spark/shuffle/celeborn/CelebornShuffleReader.scala:
##########
@@ -62,15 +70,51 @@ class CelebornShuffleReader[K, C](
         metrics.incFetchWaitTime(time)
     }
 
+    if (streamCreatorPool == null) {
+      CelebornShuffleReader.synchronized {
+        if (streamCreatorPool == null) {
+          streamCreatorPool = ThreadUtils.newDaemonCachedThreadPool(
+            "create-stream-thread",
+            conf.readStreamCreatorPoolThreads,
+            60);
+        }
+      }
+    }
+
+    val streams = new ConcurrentHashMap[Integer, CelebornInputStream]()
+    (startPartition until endPartition).map(partitionId => {
+      streamCreatorPool.submit(new Runnable {
+        override def run(): Unit = {
+          if (exceptionRef.get() == null) {
+            try {
+              val inputStream = shuffleClient.readPartition(
+                handle.shuffleId,
+                partitionId,
+                context.attemptNumber(),
+                startMapIndex,
+                endMapIndex)
+              streams.put(partitionId, inputStream)
+            } catch {
+              case e: IOException =>
+                logInfo("Exception caught when readPartition!")
+                exceptionRef.compareAndSet(null, e)
+            }
+          }
+        }
+      })
+    })
+
     val recordIter = (startPartition until endPartition).iterator.map(partitionId => {
       if (handle.numMappers > 0) {
         val start = System.currentTimeMillis()
-        val inputStream = shuffleClient.readPartition(
-          handle.shuffleId,
-          partitionId,
-          context.attemptNumber(),
-          startMapIndex,
-          endMapIndex)
+        var inputStream: CelebornInputStream = streams.get(partitionId)
+        while (inputStream == null) {
+          if (exceptionRef.get() != null) {
+            throw exceptionRef.get()
+          }
+          Thread.sleep(50)

Review Comment:
   why sleep is required



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-celeborn] cfmcgrady commented on a diff in pull request #1876: [CELEBORN-943][PERF] Pre-create CelebornInputStreams in CelebornShuffleReader

Posted by "cfmcgrady (via GitHub)" <gi...@apache.org>.
cfmcgrady commented on code in PR #1876:
URL: https://github.com/apache/incubator-celeborn/pull/1876#discussion_r1314840795


##########
client-spark/spark-3/src/main/scala/org/apache/spark/shuffle/celeborn/CelebornShuffleReader.scala:
##########
@@ -62,15 +70,51 @@ class CelebornShuffleReader[K, C](
         metrics.incFetchWaitTime(time)
     }
 
+    if (streamCreatorPool == null) {
+      CelebornShuffleReader.synchronized {
+        if (streamCreatorPool == null) {
+          streamCreatorPool = ThreadUtils.newDaemonCachedThreadPool(
+            "create-stream-thread",
+            conf.readStreamCreatorPoolThreads,
+            60);
+        }
+      }
+    }
+
+    val streams = new ConcurrentHashMap[Integer, CelebornInputStream]()
+    (startPartition until endPartition).map(partitionId => {
+      streamCreatorPool.submit(new Runnable {
+        override def run(): Unit = {
+          if (exceptionRef.get() == null) {
+            try {
+              val inputStream = shuffleClient.readPartition(
+                handle.shuffleId,
+                partitionId,
+                context.attemptNumber(),
+                startMapIndex,
+                endMapIndex)
+              streams.put(partitionId, inputStream)
+            } catch {
+              case e: IOException =>
+                logInfo("Exception caught when readPartition!")
+                exceptionRef.compareAndSet(null, e)
+            }
+          }
+        }
+      })
+    })
+
     val recordIter = (startPartition until endPartition).iterator.map(partitionId => {
       if (handle.numMappers > 0) {
         val start = System.currentTimeMillis()
-        val inputStream = shuffleClient.readPartition(
-          handle.shuffleId,
-          partitionId,
-          context.attemptNumber(),
-          startMapIndex,
-          endMapIndex)
+        var inputStream: CelebornInputStream = streams.get(partitionId)
+        while (inputStream == null) {
+          if (exceptionRef.get() != null) {

Review Comment:
   the method `shuffleClient.readPartition` explicitly declares the throwing of an IOException.
   
   https://github.com/apache/incubator-celeborn/blob/b66eaff880e91864a21c96dbac94fa5f8cd84f4c/client/src/main/java/org/apache/celeborn/client/ShuffleClient.java#L191-L193



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-celeborn] cfmcgrady commented on a diff in pull request #1876: [CELEBORN-943][PERF] Pre-create CelebornInputStreams in CelebornShuffleReader

Posted by "cfmcgrady (via GitHub)" <gi...@apache.org>.
cfmcgrady commented on code in PR #1876:
URL: https://github.com/apache/incubator-celeborn/pull/1876#discussion_r1314791055


##########
client-spark/spark-3/src/main/scala/org/apache/spark/shuffle/celeborn/CelebornShuffleReader.scala:
##########
@@ -62,15 +70,51 @@ class CelebornShuffleReader[K, C](
         metrics.incFetchWaitTime(time)
     }
 
+    if (streamCreatorPool == null) {
+      CelebornShuffleReader.synchronized {
+        if (streamCreatorPool == null) {
+          streamCreatorPool = ThreadUtils.newDaemonCachedThreadPool(
+            "create-stream-thread",
+            conf.readStreamCreatorPoolThreads,
+            60);
+        }
+      }
+    }
+
+    val streams = new ConcurrentHashMap[Integer, CelebornInputStream]()
+    (startPartition until endPartition).map(partitionId => {
+      streamCreatorPool.submit(new Runnable {
+        override def run(): Unit = {
+          if (exceptionRef.get() == null) {
+            try {
+              val inputStream = shuffleClient.readPartition(
+                handle.shuffleId,
+                partitionId,
+                context.attemptNumber(),
+                startMapIndex,
+                endMapIndex)
+              streams.put(partitionId, inputStream)
+            } catch {
+              case e: IOException =>
+                logInfo("Exception caught when readPartition!")
+                exceptionRef.compareAndSet(null, e)
+            }
+          }
+        }
+      })
+    })
+
     val recordIter = (startPartition until endPartition).iterator.map(partitionId => {
       if (handle.numMappers > 0) {
         val start = System.currentTimeMillis()
-        val inputStream = shuffleClient.readPartition(
-          handle.shuffleId,
-          partitionId,
-          context.attemptNumber(),
-          startMapIndex,
-          endMapIndex)
+        var inputStream: CelebornInputStream = streams.get(partitionId)
+        while (inputStream == null) {
+          if (exceptionRef.get() != null) {
+            throw exceptionRef.get()
+          }
+          Thread.sleep(50)
+          inputStream = streams.get(partitionId)
+        }
         metricsCallback.incReadTime(System.currentTimeMillis() - start)
         inputStream.setCallback(metricsCallback)
         // ensure inputStream is closed when task completes

Review Comment:
   we need to close all `streams`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-celeborn] waitinfuture commented on pull request #1876: [CELEBORN-943][PERF] Pre-create CelebornInputStreams in CelebornShuffleReader

Posted by "waitinfuture (via GitHub)" <gi...@apache.org>.
waitinfuture commented on PR #1876:
URL: https://github.com/apache/incubator-celeborn/pull/1876#issuecomment-1705300315

   Thanks, merging to main/0.3


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-celeborn] cfmcgrady commented on a diff in pull request #1876: [CELEBORN-943][PERF] Pre-create CelebornInputStreams in CelebornShuffleReader

Posted by "cfmcgrady (via GitHub)" <gi...@apache.org>.
cfmcgrady commented on code in PR #1876:
URL: https://github.com/apache/incubator-celeborn/pull/1876#discussion_r1314791055


##########
client-spark/spark-3/src/main/scala/org/apache/spark/shuffle/celeborn/CelebornShuffleReader.scala:
##########
@@ -62,15 +70,51 @@ class CelebornShuffleReader[K, C](
         metrics.incFetchWaitTime(time)
     }
 
+    if (streamCreatorPool == null) {
+      CelebornShuffleReader.synchronized {
+        if (streamCreatorPool == null) {
+          streamCreatorPool = ThreadUtils.newDaemonCachedThreadPool(
+            "create-stream-thread",
+            conf.readStreamCreatorPoolThreads,
+            60);
+        }
+      }
+    }
+
+    val streams = new ConcurrentHashMap[Integer, CelebornInputStream]()
+    (startPartition until endPartition).map(partitionId => {
+      streamCreatorPool.submit(new Runnable {
+        override def run(): Unit = {
+          if (exceptionRef.get() == null) {
+            try {
+              val inputStream = shuffleClient.readPartition(
+                handle.shuffleId,
+                partitionId,
+                context.attemptNumber(),
+                startMapIndex,
+                endMapIndex)
+              streams.put(partitionId, inputStream)
+            } catch {
+              case e: IOException =>
+                logInfo("Exception caught when readPartition!")
+                exceptionRef.compareAndSet(null, e)
+            }
+          }
+        }
+      })
+    })
+
     val recordIter = (startPartition until endPartition).iterator.map(partitionId => {
       if (handle.numMappers > 0) {
         val start = System.currentTimeMillis()
-        val inputStream = shuffleClient.readPartition(
-          handle.shuffleId,
-          partitionId,
-          context.attemptNumber(),
-          startMapIndex,
-          endMapIndex)
+        var inputStream: CelebornInputStream = streams.get(partitionId)
+        while (inputStream == null) {
+          if (exceptionRef.get() != null) {
+            throw exceptionRef.get()
+          }
+          Thread.sleep(50)
+          inputStream = streams.get(partitionId)
+        }
         metricsCallback.incReadTime(System.currentTimeMillis() - start)
         inputStream.setCallback(metricsCallback)
         // ensure inputStream is closed when task completes

Review Comment:
   ~~we need to close all `streams`.~~



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-celeborn] waitinfuture commented on pull request #1876: [CELEBORN-943][PERF] Pre-create CelebornInputStreams in CelebornShuffleReader

Posted by "waitinfuture (via GitHub)" <gi...@apache.org>.
waitinfuture commented on PR #1876:
URL: https://github.com/apache/incubator-celeborn/pull/1876#issuecomment-1705157287

   > I'm not sure that pre-create the connection is always a good idea, for a busy cluster, this may cause the worker to keep a longer time for each connection and thus increase the opened socket numbers of workers.
   
   IMO it's fine because usually the executor is reused, and after many tasks finish, it's probably that the executor already creates connections with many workers.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-celeborn] cfmcgrady commented on a diff in pull request #1876: [CELEBORN-943][PERF] Pre-create CelebornInputStreams in CelebornShuffleReader

Posted by "cfmcgrady (via GitHub)" <gi...@apache.org>.
cfmcgrady commented on code in PR #1876:
URL: https://github.com/apache/incubator-celeborn/pull/1876#discussion_r1314801032


##########
client/src/main/java/org/apache/celeborn/client/read/LocalPartitionReader.java:
##########
@@ -111,10 +113,8 @@ public LocalPartitionReader(
 
     chunkOffsets = new ArrayList<>(streamHandle.getChunkOffsetsList());
     numChunks = streamHandle.getNumChunks();
-    shuffleChannel = FileChannelUtils.openReadableFileChannel(streamHandle.getFullPath());
-    if (endMapIndex != Integer.MAX_VALUE) {
-      shuffleChannel.position(chunkOffsets.get(0));
-    }
+    fullPath = streamHandle.getFullPath();
+    mapRangeRead = (endMapIndex != Integer.MAX_VALUE);

Review Comment:
   ```suggestion
       mapRangeRead = endMapIndex != Integer.MAX_VALUE;
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-celeborn] RexXiong commented on a diff in pull request #1876: [CELEBORN-943][PERF] Pre-create CelebornInputStreams in CelebornShuffleReader

Posted by "RexXiong (via GitHub)" <gi...@apache.org>.
RexXiong commented on code in PR #1876:
URL: https://github.com/apache/incubator-celeborn/pull/1876#discussion_r1314824712


##########
client-spark/spark-3/src/main/scala/org/apache/spark/shuffle/celeborn/CelebornShuffleReader.scala:
##########
@@ -62,15 +70,51 @@ class CelebornShuffleReader[K, C](
         metrics.incFetchWaitTime(time)
     }
 
+    if (streamCreatorPool == null) {
+      CelebornShuffleReader.synchronized {
+        if (streamCreatorPool == null) {
+          streamCreatorPool = ThreadUtils.newDaemonCachedThreadPool(
+            "create-stream-thread",

Review Comment:
   Naming pool with `celeborn` prefix



##########
client-spark/spark-3/src/main/scala/org/apache/spark/shuffle/celeborn/CelebornShuffleReader.scala:
##########
@@ -62,15 +70,51 @@ class CelebornShuffleReader[K, C](
         metrics.incFetchWaitTime(time)
     }
 
+    if (streamCreatorPool == null) {
+      CelebornShuffleReader.synchronized {
+        if (streamCreatorPool == null) {
+          streamCreatorPool = ThreadUtils.newDaemonCachedThreadPool(
+            "create-stream-thread",
+            conf.readStreamCreatorPoolThreads,
+            60);
+        }
+      }
+    }
+
+    val streams = new ConcurrentHashMap[Integer, CelebornInputStream]()
+    (startPartition until endPartition).map(partitionId => {
+      streamCreatorPool.submit(new Runnable {
+        override def run(): Unit = {
+          if (exceptionRef.get() == null) {
+            try {
+              val inputStream = shuffleClient.readPartition(
+                handle.shuffleId,
+                partitionId,
+                context.attemptNumber(),
+                startMapIndex,
+                endMapIndex)
+              streams.put(partitionId, inputStream)
+            } catch {
+              case e: IOException =>
+                logInfo("Exception caught when readPartition!")
+                exceptionRef.compareAndSet(null, e)
+            }
+          }
+        }
+      })
+    })
+
     val recordIter = (startPartition until endPartition).iterator.map(partitionId => {
       if (handle.numMappers > 0) {
         val start = System.currentTimeMillis()
-        val inputStream = shuffleClient.readPartition(
-          handle.shuffleId,
-          partitionId,
-          context.attemptNumber(),
-          startMapIndex,
-          endMapIndex)
+        var inputStream: CelebornInputStream = streams.get(partitionId)
+        while (inputStream == null) {
+          if (exceptionRef.get() != null) {

Review Comment:
   +1



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-celeborn] pan3793 commented on a diff in pull request #1876: [CELEBORN-943][PERF] Pre-create CelebornInputStreams in CelebornShuffleReader

Posted by "pan3793 (via GitHub)" <gi...@apache.org>.
pan3793 commented on code in PR #1876:
URL: https://github.com/apache/incubator-celeborn/pull/1876#discussion_r1314818956


##########
client-spark/spark-3/src/main/scala/org/apache/spark/shuffle/celeborn/CelebornShuffleReader.scala:
##########
@@ -62,15 +70,51 @@ class CelebornShuffleReader[K, C](
         metrics.incFetchWaitTime(time)
     }
 
+    if (streamCreatorPool == null) {
+      CelebornShuffleReader.synchronized {
+        if (streamCreatorPool == null) {
+          streamCreatorPool = ThreadUtils.newDaemonCachedThreadPool(
+            "create-stream-thread",
+            conf.readStreamCreatorPoolThreads,
+            60);
+        }
+      }
+    }
+
+    val streams = new ConcurrentHashMap[Integer, CelebornInputStream]()
+    (startPartition until endPartition).map(partitionId => {
+      streamCreatorPool.submit(new Runnable {
+        override def run(): Unit = {
+          if (exceptionRef.get() == null) {
+            try {
+              val inputStream = shuffleClient.readPartition(
+                handle.shuffleId,
+                partitionId,
+                context.attemptNumber(),
+                startMapIndex,
+                endMapIndex)
+              streams.put(partitionId, inputStream)
+            } catch {
+              case e: IOException =>
+                logInfo("Exception caught when readPartition!")
+                exceptionRef.compareAndSet(null, e)
+            }
+          }
+        }
+      })
+    })
+
     val recordIter = (startPartition until endPartition).iterator.map(partitionId => {
       if (handle.numMappers > 0) {
         val start = System.currentTimeMillis()
-        val inputStream = shuffleClient.readPartition(
-          handle.shuffleId,
-          partitionId,
-          context.attemptNumber(),
-          startMapIndex,
-          endMapIndex)
+        var inputStream: CelebornInputStream = streams.get(partitionId)
+        while (inputStream == null) {
+          if (exceptionRef.get() != null) {
+            throw exceptionRef.get()
+          }
+          Thread.sleep(50)

Review Comment:
   why sleep is required



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-celeborn] pan3793 commented on pull request #1876: [CELEBORN-943][PERF] Pre-create CelebornInputStreams in CelebornShuffleReader

Posted by "pan3793 (via GitHub)" <gi...@apache.org>.
pan3793 commented on PR #1876:
URL: https://github.com/apache/incubator-celeborn/pull/1876#issuecomment-1705108156

   I'm not sure that pre-create the connection is always a good idea, for a busy cluster, this may cause the worker to keep a longer time for each connection and thus increase the opened socket numbers of workers.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-celeborn] pan3793 commented on a diff in pull request #1876: [CELEBORN-943][PERF] Pre-create CelebornInputStreams in CelebornShuffleReader

Posted by "pan3793 (via GitHub)" <gi...@apache.org>.
pan3793 commented on code in PR #1876:
URL: https://github.com/apache/incubator-celeborn/pull/1876#discussion_r1314934518


##########
client-spark/spark-3/src/main/scala/org/apache/spark/shuffle/celeborn/CelebornShuffleReader.scala:
##########
@@ -62,15 +70,51 @@ class CelebornShuffleReader[K, C](
         metrics.incFetchWaitTime(time)
     }
 
+    if (streamCreatorPool == null) {
+      CelebornShuffleReader.synchronized {
+        if (streamCreatorPool == null) {
+          streamCreatorPool = ThreadUtils.newDaemonCachedThreadPool(
+            "create-stream-thread",
+            conf.readStreamCreatorPoolThreads,
+            60);
+        }
+      }
+    }
+
+    val streams = new ConcurrentHashMap[Integer, CelebornInputStream]()
+    (startPartition until endPartition).map(partitionId => {
+      streamCreatorPool.submit(new Runnable {
+        override def run(): Unit = {
+          if (exceptionRef.get() == null) {
+            try {
+              val inputStream = shuffleClient.readPartition(
+                handle.shuffleId,
+                partitionId,
+                context.attemptNumber(),
+                startMapIndex,
+                endMapIndex)
+              streams.put(partitionId, inputStream)
+            } catch {
+              case e: IOException =>
+                logInfo("Exception caught when readPartition!")
+                exceptionRef.compareAndSet(null, e)
+            }
+          }
+        }
+      })
+    })
+
     val recordIter = (startPartition until endPartition).iterator.map(partitionId => {
       if (handle.numMappers > 0) {
         val start = System.currentTimeMillis()
-        val inputStream = shuffleClient.readPartition(
-          handle.shuffleId,
-          partitionId,
-          context.attemptNumber(),
-          startMapIndex,
-          endMapIndex)
+        var inputStream: CelebornInputStream = streams.get(partitionId)
+        while (inputStream == null) {
+          if (exceptionRef.get() != null) {

Review Comment:
   should catch Throwable for safe



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-celeborn] waitinfuture commented on pull request #1876: [CELEBORN-943][PERF] Pre-create CelebornInputStreams in CelebornShuffleReader

Posted by "waitinfuture (via GitHub)" <gi...@apache.org>.
waitinfuture commented on PR #1876:
URL: https://github.com/apache/incubator-celeborn/pull/1876#issuecomment-1704916886

   ping @FMX @RexXiong cc @pan3793 @cfmcgrady 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-celeborn] pan3793 commented on a diff in pull request #1876: [CELEBORN-943][PERF] Pre-create CelebornInputStreams in CelebornShuffleReader

Posted by "pan3793 (via GitHub)" <gi...@apache.org>.
pan3793 commented on code in PR #1876:
URL: https://github.com/apache/incubator-celeborn/pull/1876#discussion_r1314856891


##########
client-spark/spark-3/src/main/scala/org/apache/spark/shuffle/celeborn/CelebornShuffleReader.scala:
##########
@@ -62,15 +70,51 @@ class CelebornShuffleReader[K, C](
         metrics.incFetchWaitTime(time)
     }
 
+    if (streamCreatorPool == null) {
+      CelebornShuffleReader.synchronized {
+        if (streamCreatorPool == null) {
+          streamCreatorPool = ThreadUtils.newDaemonCachedThreadPool(
+            "create-stream-thread",
+            conf.readStreamCreatorPoolThreads,
+            60);
+        }
+      }
+    }
+
+    val streams = new ConcurrentHashMap[Integer, CelebornInputStream]()
+    (startPartition until endPartition).map(partitionId => {
+      streamCreatorPool.submit(new Runnable {
+        override def run(): Unit = {
+          if (exceptionRef.get() == null) {
+            try {
+              val inputStream = shuffleClient.readPartition(
+                handle.shuffleId,
+                partitionId,
+                context.attemptNumber(),
+                startMapIndex,
+                endMapIndex)
+              streams.put(partitionId, inputStream)
+            } catch {
+              case e: IOException =>
+                logInfo("Exception caught when readPartition!")
+                exceptionRef.compareAndSet(null, e)
+            }
+          }
+        }
+      })
+    })
+
     val recordIter = (startPartition until endPartition).iterator.map(partitionId => {
       if (handle.numMappers > 0) {
         val start = System.currentTimeMillis()
-        val inputStream = shuffleClient.readPartition(
-          handle.shuffleId,
-          partitionId,
-          context.attemptNumber(),
-          startMapIndex,
-          endMapIndex)
+        var inputStream: CelebornInputStream = streams.get(partitionId)
+        while (inputStream == null) {
+          if (exceptionRef.get() != null) {

Review Comment:
   It's not guaranteed that this method won't throw other unchecked exceptions.
   
   The `javac` only checks checked exceptions must be listed in the method signature, for Scala compiler, no checks.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-celeborn] waitinfuture commented on pull request #1876: [CELEBORN-943][PERF] Pre-create CelebornInputStreams in CelebornShuffleReader

Posted by "waitinfuture (via GitHub)" <gi...@apache.org>.
waitinfuture commented on PR #1876:
URL: https://github.com/apache/incubator-celeborn/pull/1876#issuecomment-1705188905

   comments addressed, PTAL @pan3793 @RexXiong @cfmcgrady 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org