vanzin 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_r315854332
##########
File path:
core/src/test/scala/org/apache/spark/storage/ShuffleBlockFetcherIteratorSuite.scala
##########
@@ -120,32 +160,65 @@ class ShuffleBlockFetcherIteratorSuite extends
SparkFunSuite with PrivateMethodT
metrics)
// 3 local blocks fetched in initialization
- verify(blockManager, times(3)).getBlockData(any())
-
- for (i <- 0 until 5) {
- assert(iterator.hasNext, s"iterator should have 5 elements but actually
has $i elements")
+ verify(blockManager, times(3)).getLocalBlockData(any())
+ // 4 host-local locks fetched in initialization
+ verify(blockManager, times(4))
+ .getHostLocalShuffleData(any(), isA(classOf[Array[String]]))
+
+ val allBlocks = localBlocks ++ remoteBlocks ++ remoteBlocksAsFallback ++
hostLocalBlocks
+ for (i <- 0 until allBlocks.size) {
+ assert(iterator.hasNext,
+ s"iterator should have ${allBlocks.size} elements but actually has $i
elements")
val (blockId, inputStream) = iterator.next()
// Make sure we release buffers when a wrapped input stream is closed.
- val mockBuf = localBlocks.getOrElse(blockId, remoteBlocks(blockId))
- // Note: ShuffleBlockFetcherIterator wraps input streams in a
BufferReleasingInputStream
- val wrappedInputStream =
inputStream.asInstanceOf[BufferReleasingInputStream]
- verify(mockBuf, times(0)).release()
- val delegateAccess = PrivateMethod[InputStream]('delegate)
-
- verify(wrappedInputStream.invokePrivate(delegateAccess()),
times(0)).close()
- wrappedInputStream.close()
- verify(mockBuf, times(1)).release()
- verify(wrappedInputStream.invokePrivate(delegateAccess()),
times(1)).close()
- wrappedInputStream.close() // close should be idempotent
- verify(mockBuf, times(1)).release()
- verify(wrappedInputStream.invokePrivate(delegateAccess()),
times(1)).close()
+ val mockBuf = allBlocks(blockId)
+ verifyBufferRelease(mockBuf, inputStream)
}
- // 3 local blocks, and 2 remote blocks
- // (but from the same block manager so one call to fetchBlocks)
- verify(blockManager, times(3)).getBlockData(any())
- verify(transfer, times(1)).fetchBlocks(any(), any(), any(), any(), any(),
any())
+ // 2 remote blocks are read from the same block manager and 1 host-local
is fall back on to
+ // a remote read so there are 2 calls to fetchBlock
+ verify(transfer, times(2)).fetchBlocks(any(), any(), any(), any(), any(),
any())
+ }
+
+ test("only 1 host local without local dir which falls back to remote fetch")
{
+ val blockManager = mock(classOf[BlockManager])
+ val localBmId = BlockManagerId("test-local-client", "test-local-host", 1)
+ doReturn(localBmId).when(blockManager).blockManagerId
+
+ val blockId1 = ShuffleBlockId(0, 5, 0)
+ val mockBuf = createMockManagedBuffer()
+ val remoteBlocksAsFallback = Map[BlockId, ManagedBuffer](blockId1 ->
mockBuf)
+ val transfer = createMockTransfer(remoteBlocksAsFallback)
+ val hostLocalBmIdNoLocDir = BlockManagerId("test-host-local-client-2",
"test-local-host", 4)
+
+ doReturn(Map("test-host-local-client-1" -> Array("local-dir")))
+ .when(blockManager).getHostLocalDirs(any())
+
+ val blocksByAddress = Seq[(BlockManagerId, Seq[(BlockId, Long)])](
+ (hostLocalBmIdNoLocDir, remoteBlocksAsFallback.keys.map(blockId =>
(blockId, 1L)).toSeq)
+ ).toIterator
+
+ val taskContext = TaskContext.empty()
+ val metrics = taskContext.taskMetrics.createTempShuffleReadMetrics()
+ val iterator = new ShuffleBlockFetcherIterator(
+ taskContext,
+ transfer,
+ blockManager,
+ blocksByAddress,
+ (_, in) => in,
+ 48 * 1024 * 1024,
+ Int.MaxValue,
+ Int.MaxValue,
+ Int.MaxValue,
+ true,
+ false,
+ metrics)
+
+ assert(iterator.hasNext, s"iterator should have 1 element")
+ val (_, inputStream) = iterator.next()
Review comment:
Is there a way to check that the remote path was really taken? That
currently assumed to have happened from the test setup, but it would be good to
check it explicitly.
Probably just:
verify(transfer, times(1)).fetchBlocks(any(), any(), any(), any(),
any(), any())
----------------------------------------------------------------
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]