spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From witgo <...@git.apache.org>
Subject [GitHub] spark pull request: [SPARK-1239] Improve fetching of map output st...
Date Wed, 06 Apr 2016 02:24:19 GMT
Github user witgo commented on a diff in the pull request:

    https://github.com/apache/spark/pull/12113#discussion_r58643596
  
    --- 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 --
    
    What happens if this happens at the same time on different executors?


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Mime
View raw message