tgravescs commented on a change in pull request #25299: [SPARK-27651][Core] 
Avoid the network when shuffle blocks are fetched from the same host
URL: https://github.com/apache/spark/pull/25299#discussion_r318151785
 
 

 ##########
 File path: 
core/src/main/scala/org/apache/spark/storage/ShuffleBlockFetcherIterator.scala
 ##########
 @@ -358,12 +382,65 @@ final class ShuffleBlockFetcherIterator(
     }
   }
 
+
+  /**
+   * Fetch the host-local blocks while we are fetching remote blocks. This is 
ok because
+   * `ManagedBuffer`'s memory is allocated lazily when we create the input 
stream, so all we
+   * track in-memory are the ManagedBuffer references themselves.
+   */
+  private[this] def fetchHostLocalBlocks() {
+    logDebug(s"Start fetching host-local blocks: ${hostLocalBlocks.mkString(", 
")}")
+    val hostLocalExecutorIds = 
hostLocalBlocksByExecutor.keySet.map(_.executorId)
+    val readsWithoutLocalDir = LinkedHashMap[BlockManagerId, Seq[(BlockId, 
Long)]]()
+    val localDirsByExec = 
blockManager.getHostLocalDirs(hostLocalExecutorIds.toArray)
+    hostLocalBlocksByExecutor.foreach { case (bmId, blockInfos) =>
+      val localDirs = localDirsByExec.get(bmId.executorId)
+      if (localDirs.isDefined) {
+        blockInfos.foreach {  case (blockId, _) =>
+          try {
+            val buf = blockManager
+              .getHostLocalShuffleData(blockId.asInstanceOf[ShuffleBlockId], 
localDirs.get)
+            shuffleMetrics.incLocalBlocksFetched(1)
+            shuffleMetrics.incLocalBytesRead(buf.size)
+            buf.retain()
+            results.put(SuccessFetchResult(blockId, 
blockManager.blockManagerId,
+              buf.size(), buf, isNetworkReqDone = false))
+          } catch {
+            case e: Exception =>
+              // If we see an exception, stop immediately.
+              logError(s"Error occurred while fetching local blocks", e)
+              results.put(FailureFetchResult(blockId, 
blockManager.blockManagerId, e))
+              return
+          }
+        }
+      } else {
+        readsWithoutLocalDir += bmId -> blockInfos
+      }
+    }
+
+    if (readsWithoutLocalDir.nonEmpty) {
 
 Review comment:
   so the downside to this is its going to wait to fetch all local blocks 
before starting these remote block fetches which would happen in parallel and 
could be going on at the same time.
   I'm guessing most of the time we are hoping they are cached and thus won't 
hit here and one would think the local blocks are less then remote blocks on 
huge jobs anyway so it might not matter.  Just thought I would bring up in case 
others had opinion.    

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to