-
Notifications
You must be signed in to change notification settings - Fork 28.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SPARK-2565. Update ShuffleReadMetrics as blocks are fetched #1507
Closed
+85
−65
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ import scala.util.{Failure, Success} | |
import io.netty.buffer.ByteBuf | ||
|
||
import org.apache.spark.{Logging, SparkException} | ||
import org.apache.spark.executor.ShuffleReadMetrics | ||
import org.apache.spark.network.BufferMessage | ||
import org.apache.spark.network.ConnectionManagerId | ||
import org.apache.spark.network.netty.ShuffleCopier | ||
|
@@ -47,10 +48,6 @@ import org.apache.spark.util.Utils | |
private[storage] | ||
trait BlockFetcherIterator extends Iterator[(BlockId, Option[Iterator[Any]])] with Logging { | ||
def initialize() | ||
def numLocalBlocks: Int | ||
def numRemoteBlocks: Int | ||
def fetchWaitTime: Long | ||
def remoteBytesRead: Long | ||
} | ||
|
||
|
||
|
@@ -72,14 +69,12 @@ object BlockFetcherIterator { | |
class BasicBlockFetcherIterator( | ||
private val blockManager: BlockManager, | ||
val blocksByAddress: Seq[(BlockManagerId, Seq[(BlockId, Long)])], | ||
serializer: Serializer) | ||
serializer: Serializer, | ||
readMetrics: ShuffleReadMetrics) | ||
extends BlockFetcherIterator { | ||
|
||
import blockManager._ | ||
|
||
private var _remoteBytesRead = 0L | ||
private var _fetchWaitTime = 0L | ||
|
||
if (blocksByAddress == null) { | ||
throw new IllegalArgumentException("BlocksByAddress is null") | ||
} | ||
|
@@ -89,13 +84,9 @@ object BlockFetcherIterator { | |
|
||
protected var startTime = System.currentTimeMillis | ||
|
||
// This represents the number of local blocks, also counting zero-sized blocks | ||
private var numLocal = 0 | ||
// BlockIds for local blocks that need to be fetched. Excludes zero-sized blocks | ||
protected val localBlocksToFetch = new ArrayBuffer[BlockId]() | ||
|
||
// This represents the number of remote blocks, also counting zero-sized blocks | ||
private var numRemote = 0 | ||
// BlockIds for remote blocks that need to be fetched. Excludes zero-sized blocks | ||
protected val remoteBlocksToFetch = new HashSet[BlockId]() | ||
|
||
|
@@ -132,7 +123,10 @@ object BlockFetcherIterator { | |
val networkSize = blockMessage.getData.limit() | ||
results.put(new FetchResult(blockId, sizeMap(blockId), | ||
() => dataDeserialize(blockId, blockMessage.getData, serializer))) | ||
_remoteBytesRead += networkSize | ||
// TODO: NettyBlockFetcherIterator has some race conditions where multiple threads can | ||
// be incrementing bytes read at the same time (SPARK-2625). | ||
readMetrics.remoteBytesRead += networkSize | ||
readMetrics.remoteBlocksFetched += 1 | ||
logDebug("Got remote block " + blockId + " after " + Utils.getUsedTimeMs(startTime)) | ||
} | ||
} | ||
|
@@ -155,14 +149,14 @@ object BlockFetcherIterator { | |
// Split local and remote blocks. Remote blocks are further split into FetchRequests of size | ||
// at most maxBytesInFlight in order to limit the amount of data in flight. | ||
val remoteRequests = new ArrayBuffer[FetchRequest] | ||
var totalBlocks = 0 | ||
for ((address, blockInfos) <- blocksByAddress) { | ||
totalBlocks += blockInfos.size | ||
if (address == blockManagerId) { | ||
numLocal = blockInfos.size | ||
// Filter out zero-sized blocks | ||
localBlocksToFetch ++= blockInfos.filter(_._2 != 0).map(_._1) | ||
_numBlocksToFetch += localBlocksToFetch.size | ||
} else { | ||
numRemote += blockInfos.size | ||
val iterator = blockInfos.iterator | ||
var curRequestSize = 0L | ||
var curBlocks = new ArrayBuffer[(BlockId, Long)] | ||
|
@@ -192,7 +186,7 @@ object BlockFetcherIterator { | |
} | ||
} | ||
logInfo("Getting " + _numBlocksToFetch + " non-empty blocks out of " + | ||
(numLocal + numRemote) + " blocks") | ||
totalBlocks + " blocks") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this ever used other than for logging? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Naw |
||
remoteRequests | ||
} | ||
|
||
|
@@ -205,6 +199,7 @@ object BlockFetcherIterator { | |
// getLocalFromDisk never return None but throws BlockException | ||
val iter = getLocalFromDisk(id, serializer).get | ||
// Pass 0 as size since it's not in flight | ||
readMetrics.localBlocksFetched += 1 | ||
results.put(new FetchResult(id, 0, () => iter)) | ||
logDebug("Got local block " + id) | ||
} catch { | ||
|
@@ -238,12 +233,6 @@ object BlockFetcherIterator { | |
logDebug("Got local blocks in " + Utils.getUsedTimeMs(startTime) + " ms") | ||
} | ||
|
||
override def numLocalBlocks: Int = numLocal | ||
override def numRemoteBlocks: Int = numRemote | ||
override def fetchWaitTime: Long = _fetchWaitTime | ||
override def remoteBytesRead: Long = _remoteBytesRead | ||
|
||
|
||
// Implementing the Iterator methods with an iterator that reads fetched blocks off the queue | ||
// as they arrive. | ||
@volatile protected var resultsGotten = 0 | ||
|
@@ -255,7 +244,7 @@ object BlockFetcherIterator { | |
val startFetchWait = System.currentTimeMillis() | ||
val result = results.take() | ||
val stopFetchWait = System.currentTimeMillis() | ||
_fetchWaitTime += (stopFetchWait - startFetchWait) | ||
readMetrics.fetchWaitTime += (stopFetchWait - startFetchWait) | ||
if (! result.failed) bytesInFlight -= result.size | ||
while (!fetchRequests.isEmpty && | ||
(bytesInFlight == 0 || bytesInFlight + fetchRequests.front.size <= maxBytesInFlight)) { | ||
|
@@ -269,8 +258,9 @@ object BlockFetcherIterator { | |
class NettyBlockFetcherIterator( | ||
blockManager: BlockManager, | ||
blocksByAddress: Seq[(BlockManagerId, Seq[(BlockId, Long)])], | ||
serializer: Serializer) | ||
extends BasicBlockFetcherIterator(blockManager, blocksByAddress, serializer) { | ||
serializer: Serializer, | ||
readMetrics: ShuffleReadMetrics) | ||
extends BasicBlockFetcherIterator(blockManager, blocksByAddress, serializer, readMetrics) { | ||
|
||
import blockManager._ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: since this doesn't mutate internal state the original lack of parentheses is correct style.