Github user witgo commented on a diff in the pull request:
https://github.com/apache/spark/pull/12113#discussion_r58711271
--- Diff: core/src/main/scala/org/apache/spark/MapOutputTracker.scala ---
@@ -492,16 +624,51 @@ private[spark] object MapOutputTracker extends
Logging {
} {
objOut.close()
}
- out.toByteArray
+ val arr = out.toByteArray
+ if (minBroadcastSize >= 0 && arr.length >= minBroadcastSize) {
+ // Use broadcast instead.
+ // Important arr(0) is the tag == DIRECT, ignore that while
deserializing !
+ val bcast = broadcastManager.newBroadcast(arr, isLocal)
+ // toByteArray creates copy, so we can reuse out
+ out.reset()
+ out.write(BROADCAST)
+ val oos = new ObjectOutputStream(new GZIPOutputStream(out))
+ oos.writeObject(bcast)
+ oos.close()
+ val outArr = out.toByteArray
+ logInfo("Broadcast mapstatuses size = " + outArr.length + ", actual
size = " + arr.length)
+ (outArr, bcast)
+ } else {
+ (arr, null)
+ }
}
// Opposite of serializeMapStatuses.
def deserializeMapStatuses(bytes: Array[Byte]): Array[MapStatus] = {
- val objIn = new ObjectInputStream(new GZIPInputStream(new
ByteArrayInputStream(bytes)))
- Utils.tryWithSafeFinally {
- objIn.readObject().asInstanceOf[Array[MapStatus]]
- } {
- objIn.close()
+ assert (bytes.length > 0)
+
+ def deserializeObject(arr: Array[Byte], off: Int, len: Int): AnyRef = {
+ val objIn = new ObjectInputStream(new GZIPInputStream(
+ new ByteArrayInputStream(arr, off, len)))
+ Utils.tryWithSafeFinally {
+ objIn.readObject()
+ } {
+ objIn.close()
+ }
+ }
+
+ bytes(0) match {
+ case DIRECT =>
+ deserializeObject(bytes, 1, bytes.length -
1).asInstanceOf[Array[MapStatus]]
+ case BROADCAST =>
+ // deserialize the Broadcast, pull .value array out of it, and
then deserialize that
+ val bcast = deserializeObject(bytes, 1, bytes.length - 1).
+ asInstanceOf[Broadcast[Array[Byte]]]
+ logInfo("Broadcast mapstatuses size = " + bytes.length +
+ ", actual size = " + bcast.value.length)
+ // Important - ignore the DIRECT tag ! Start from offset 1
+ deserializeObject(bcast.value, 1, bcast.value.length -
1).asInstanceOf[Array[MapStatus]]
--- End diff --
Sorry, My English is poor. Judging from the code of
`TorrentBroadcast.readBlocks` and `Dispatcher.MessageLoop`, it is possible that
most of the GetLocations messages are processed in the front of the
UpdateBlockInfo messages.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]