Skip to content
Snippets Groups Projects
Commit 82577339 authored by Reynold Xin's avatar Reynold Xin
Browse files

[SPARK-3116] Remove the excessive lockings in TorrentBroadcast

Author: Reynold Xin <rxin@apache.org>

Closes #2028 from rxin/torrentBroadcast and squashes the following commits:

92c62a5 [Reynold Xin] Revert the MEMORY_AND_DISK_SER changes.
03a5221 [Reynold Xin] [SPARK-3116] Remove the excessive lockings in TorrentBroadcast
parent 1f1819b2
No related branches found
No related tags found
No related merge requests found
...@@ -17,8 +17,7 @@ ...@@ -17,8 +17,7 @@
package org.apache.spark.broadcast package org.apache.spark.broadcast
import java.io.{ByteArrayOutputStream, ByteArrayInputStream, InputStream, import java.io._
ObjectInputStream, ObjectOutputStream, OutputStream}
import scala.reflect.ClassTag import scala.reflect.ClassTag
import scala.util.Random import scala.util.Random
...@@ -53,10 +52,8 @@ private[spark] class TorrentBroadcast[T: ClassTag]( ...@@ -53,10 +52,8 @@ private[spark] class TorrentBroadcast[T: ClassTag](
private val broadcastId = BroadcastBlockId(id) private val broadcastId = BroadcastBlockId(id)
TorrentBroadcast.synchronized { SparkEnv.get.blockManager.putSingle(
SparkEnv.get.blockManager.putSingle( broadcastId, value_, StorageLevel.MEMORY_AND_DISK, tellMaster = false)
broadcastId, value_, StorageLevel.MEMORY_AND_DISK, tellMaster = false)
}
@transient private var arrayOfBlocks: Array[TorrentBlock] = null @transient private var arrayOfBlocks: Array[TorrentBlock] = null
@transient private var totalBlocks = -1 @transient private var totalBlocks = -1
...@@ -91,18 +88,14 @@ private[spark] class TorrentBroadcast[T: ClassTag]( ...@@ -91,18 +88,14 @@ private[spark] class TorrentBroadcast[T: ClassTag](
// Store meta-info // Store meta-info
val metaId = BroadcastBlockId(id, "meta") val metaId = BroadcastBlockId(id, "meta")
val metaInfo = TorrentInfo(null, totalBlocks, totalBytes) val metaInfo = TorrentInfo(null, totalBlocks, totalBytes)
TorrentBroadcast.synchronized { SparkEnv.get.blockManager.putSingle(
SparkEnv.get.blockManager.putSingle( metaId, metaInfo, StorageLevel.MEMORY_AND_DISK, tellMaster = true)
metaId, metaInfo, StorageLevel.MEMORY_AND_DISK, tellMaster = true)
}
// Store individual pieces // Store individual pieces
for (i <- 0 until totalBlocks) { for (i <- 0 until totalBlocks) {
val pieceId = BroadcastBlockId(id, "piece" + i) val pieceId = BroadcastBlockId(id, "piece" + i)
TorrentBroadcast.synchronized { SparkEnv.get.blockManager.putSingle(
SparkEnv.get.blockManager.putSingle( pieceId, tInfo.arrayOfBlocks(i), StorageLevel.MEMORY_AND_DISK, tellMaster = true)
pieceId, tInfo.arrayOfBlocks(i), StorageLevel.MEMORY_AND_DISK, tellMaster = true)
}
} }
} }
...@@ -165,21 +158,20 @@ private[spark] class TorrentBroadcast[T: ClassTag]( ...@@ -165,21 +158,20 @@ private[spark] class TorrentBroadcast[T: ClassTag](
val metaId = BroadcastBlockId(id, "meta") val metaId = BroadcastBlockId(id, "meta")
var attemptId = 10 var attemptId = 10
while (attemptId > 0 && totalBlocks == -1) { while (attemptId > 0 && totalBlocks == -1) {
TorrentBroadcast.synchronized { SparkEnv.get.blockManager.getSingle(metaId) match {
SparkEnv.get.blockManager.getSingle(metaId) match { case Some(x) =>
case Some(x) => val tInfo = x.asInstanceOf[TorrentInfo]
val tInfo = x.asInstanceOf[TorrentInfo] totalBlocks = tInfo.totalBlocks
totalBlocks = tInfo.totalBlocks totalBytes = tInfo.totalBytes
totalBytes = tInfo.totalBytes arrayOfBlocks = new Array[TorrentBlock](totalBlocks)
arrayOfBlocks = new Array[TorrentBlock](totalBlocks) hasBlocks = 0
hasBlocks = 0
case None =>
case None => Thread.sleep(500)
Thread.sleep(500)
}
} }
attemptId -= 1 attemptId -= 1
} }
if (totalBlocks == -1) { if (totalBlocks == -1) {
return false return false
} }
...@@ -192,17 +184,15 @@ private[spark] class TorrentBroadcast[T: ClassTag]( ...@@ -192,17 +184,15 @@ private[spark] class TorrentBroadcast[T: ClassTag](
val recvOrder = new Random().shuffle(Array.iterate(0, totalBlocks)(_ + 1).toList) val recvOrder = new Random().shuffle(Array.iterate(0, totalBlocks)(_ + 1).toList)
for (pid <- recvOrder) { for (pid <- recvOrder) {
val pieceId = BroadcastBlockId(id, "piece" + pid) val pieceId = BroadcastBlockId(id, "piece" + pid)
TorrentBroadcast.synchronized { SparkEnv.get.blockManager.getSingle(pieceId) match {
SparkEnv.get.blockManager.getSingle(pieceId) match { case Some(x) =>
case Some(x) => arrayOfBlocks(pid) = x.asInstanceOf[TorrentBlock]
arrayOfBlocks(pid) = x.asInstanceOf[TorrentBlock] hasBlocks += 1
hasBlocks += 1 SparkEnv.get.blockManager.putSingle(
SparkEnv.get.blockManager.putSingle( pieceId, arrayOfBlocks(pid), StorageLevel.MEMORY_AND_DISK, tellMaster = true)
pieceId, arrayOfBlocks(pid), StorageLevel.MEMORY_AND_DISK, tellMaster = true)
case None => case None =>
throw new SparkException("Failed to get " + pieceId + " of " + broadcastId) throw new SparkException("Failed to get " + pieceId + " of " + broadcastId)
}
} }
} }
...@@ -291,9 +281,7 @@ private[broadcast] object TorrentBroadcast extends Logging { ...@@ -291,9 +281,7 @@ private[broadcast] object TorrentBroadcast extends Logging {
* If removeFromDriver is true, also remove these persisted blocks on the driver. * If removeFromDriver is true, also remove these persisted blocks on the driver.
*/ */
def unpersist(id: Long, removeFromDriver: Boolean, blocking: Boolean) = { def unpersist(id: Long, removeFromDriver: Boolean, blocking: Boolean) = {
synchronized { SparkEnv.get.blockManager.master.removeBroadcast(id, removeFromDriver, blocking)
SparkEnv.get.blockManager.master.removeBroadcast(id, removeFromDriver, blocking)
}
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment