-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-1103] [WIP] Automatic garbage collection of RDD, shuffle and broadcast data #126
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
Changes from 1 commit
1e752f1
80dd977
e427a9e
8512612
a24fefc
cb0a5a6
ae9da88
e61daa0
a7260d3
892b952
e1fba5f
f2881fd
620eca3
a007307
d2f8b97
6c9dcf6
c7ccef1
ba52e00
d0edef3
544ac86
e95479c
f201a8d
c92e4d9
0d17060
34f436f
fbfeec8
88904a3
e442246
8557c12
7edbc98
634a097
7ed72fb
5016375
f0aabb1
762a4d8
a6460d4
c5b1d98
a2cc8bc
ada45f0
cd72d19
b27f8e8
a430f06
104a89a
6222697
41c9ece
2b95b5e
4d05314
cff023c
d25a86e
f489fdc
61b8d6e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…h blocks are told about to the driver. Also, fixed Broadcast API to hide destroy functionality.
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,7 +28,8 @@ import org.apache.spark.SparkException | |
| * attempts to distribute broadcast variables using efficient broadcast algorithms to reduce | ||
| * communication cost. | ||
| * | ||
| * Broadcast variables are created from a variable `v` by calling [[SparkContext#broadcast]]. | ||
| * Broadcast variables are created from a variable `v` by calling | ||
| * [[org.apache.spark.SparkContext#broadcast]]. | ||
| * The broadcast variable is a wrapper around `v`, and its value can be accessed by calling the | ||
| * `value` method. The interpreter session below shows this: | ||
| * | ||
|
|
@@ -51,15 +52,17 @@ import org.apache.spark.SparkException | |
| */ | ||
| abstract class Broadcast[T](val id: Long) extends Serializable { | ||
|
|
||
| protected var _isValid: Boolean = true | ||
|
|
||
| /** | ||
| * Whether this Broadcast is actually usable. This should be false once persisted state is | ||
| * removed from the driver. | ||
| * Flag signifying whether the broadcast variable is valid | ||
| * (that is, not already destroyed) or not. | ||
| */ | ||
| def isValid: Boolean = _isValid | ||
| @volatile private var _isValid = true | ||
|
|
||
| def value: T | ||
| /** Get the broadcasted value. */ | ||
| def value: T = { | ||
| assertValid() | ||
| getValue() | ||
| } | ||
|
|
||
| /** | ||
| * Asynchronously delete cached copies of this broadcast on the executors. | ||
|
|
@@ -74,23 +77,50 @@ abstract class Broadcast[T](val id: Long) extends Serializable { | |
| * this is called, it will need to be re-sent to each executor. | ||
| * @param blocking Whether to block until unpersisting has completed | ||
| */ | ||
| def unpersist(blocking: Boolean) | ||
| def unpersist(blocking: Boolean) { | ||
| assertValid() | ||
| doUnpersist(blocking) | ||
| } | ||
|
|
||
| /** | ||
| * Remove all persisted state associated with this broadcast on both the executors and | ||
| * the driver. | ||
| * Destroy all data and metadata related to this broadcast variable. Use this with caution; | ||
| * once a broadcast variable has been destroyed, it cannot be used again. | ||
| */ | ||
| private[spark] def destroy(blocking: Boolean) { | ||
| assertValid() | ||
| _isValid = false | ||
| onDestroy(blocking) | ||
| doDestroy(blocking) | ||
| } | ||
|
|
||
| protected def onDestroy(blocking: Boolean) | ||
| /** | ||
| * Whether this Broadcast is actually usable. This should be false once persisted state is | ||
| * removed from the driver. | ||
| */ | ||
| private[spark] def isValid: Boolean = { | ||
| _isValid | ||
| } | ||
|
|
||
| /** | ||
| * Actually get the broadcasted value. Concrete implementations of Broadcast class must | ||
|
Contributor
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. What if we removed the word "Actually" from this and the following two docs? It's not super clear to mean what it means to "Actually" do it... especially since the below two have a "blocking" parameter which already seems to dictate whether or not it does the thing right away.
Contributor
Author
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. If we say "get the broadcast value", its same as the method |
||
| * define their own way to get the value. | ||
| */ | ||
| private[spark] def getValue(): T | ||
|
|
||
| /** | ||
| * If this broadcast is no longer valid, throw an exception. | ||
| * Actually unpersist the broadcasted value on the executors. Concrete implementations of | ||
| * Broadcast class must define their own logic to unpersist their own data. | ||
| */ | ||
| protected def assertValid() { | ||
| private[spark] def doUnpersist(blocking: Boolean) | ||
|
|
||
| /** | ||
| * Actually destroy all data and metadata related to this broadcast variable. | ||
| * Implementation of Broadcast class must define their own logic to destroy their own | ||
| * state. | ||
| */ | ||
| private[spark] def doDestroy(blocking: Boolean) | ||
|
|
||
| /** Check if this broadcast is valid. If not valid, exception is thrown. */ | ||
| private[spark] def assertValid() { | ||
| if (!_isValid) { | ||
| throw new SparkException("Attempted to use %s after it has been destroyed!".format(toString)) | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,16 +28,26 @@ import org.apache.spark.io.CompressionCodec | |
| import org.apache.spark.storage.{BroadcastBlockId, StorageLevel} | ||
| import org.apache.spark.util.{MetadataCleaner, MetadataCleanerType, TimeStampedHashSet, Utils} | ||
|
|
||
| /** | ||
| * A [[org.apache.spark.broadcast.Broadcast]] implementation that uses HTTP server | ||
| * as a broadcast mechanism. The first time a HTTP broadcast variable (sent as part of a | ||
| * task) is deserialized in the executor, the broadcasted data is fetched from the driver | ||
| * (through a HTTP server running at the driver) and stored in the BlockManager of the | ||
| * executor to speed up future accesses. | ||
| */ | ||
| private[spark] class HttpBroadcast[T](@transient var value_ : T, isLocal: Boolean, id: Long) | ||
| extends Broadcast[T](id) with Logging with Serializable { | ||
|
|
||
| def value: T = { | ||
| assertValid() | ||
| value_ | ||
| } | ||
| def getValue = value_ | ||
|
|
||
| val blockId = BroadcastBlockId(id) | ||
|
|
||
| /* | ||
| * Broadcasted data is also stored in the BlockManager of the driver. | ||
| * The BlockManagerMaster | ||
| * does not need to be told about this block as not only | ||
| * need to know about this data block. | ||
| */ | ||
| HttpBroadcast.synchronized { | ||
| SparkEnv.get.blockManager.putSingle( | ||
| blockId, value_, StorageLevel.MEMORY_AND_DISK, tellMaster = false) | ||
|
|
@@ -50,21 +60,24 @@ private[spark] class HttpBroadcast[T](@transient var value_ : T, isLocal: Boolea | |
| /** | ||
| * Remove all persisted state associated with this HTTP broadcast on the executors. | ||
| */ | ||
| def unpersist(blocking: Boolean) { | ||
| def doUnpersist(blocking: Boolean) { | ||
|
Contributor
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. should these be
Contributor
Author
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. No, it doesnt apply when function is not concrete in trait. If it was necessary, it would not have compiled ;) |
||
| HttpBroadcast.unpersist(id, removeFromDriver = false, blocking) | ||
| } | ||
|
|
||
| protected def onDestroy(blocking: Boolean) { | ||
| /** | ||
| * Remove all persisted state associated with this HTTP broadcast on the executors and driver. | ||
| */ | ||
| def doDestroy(blocking: Boolean) { | ||
| HttpBroadcast.unpersist(id, removeFromDriver = true, blocking) | ||
| } | ||
|
|
||
| // Used by the JVM when serializing this object | ||
| /** Used by the JVM when serializing this object. */ | ||
| private def writeObject(out: ObjectOutputStream) { | ||
| assertValid() | ||
| out.defaultWriteObject() | ||
| } | ||
|
|
||
| // Used by the JVM when deserializing this object | ||
| /** Used by the JVM when deserializing this object. */ | ||
| private def readObject(in: ObjectInputStream) { | ||
| in.defaultReadObject() | ||
| HttpBroadcast.synchronized { | ||
|
|
@@ -74,6 +87,13 @@ private[spark] class HttpBroadcast[T](@transient var value_ : T, isLocal: Boolea | |
| logInfo("Started reading broadcast variable " + id) | ||
| val start = System.nanoTime | ||
| value_ = HttpBroadcast.read[T](id) | ||
| /* | ||
| * Storing the broadcast data in BlockManager so that all | ||
|
Contributor
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. This comment has many typos, repeated words, etc.
Contributor
Author
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. Fixed. Will push with all updates.
Contributor
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. |
||
| * so that all subsequent tasks using the broadcast variable | ||
| * does not need to fetch it again. The BlockManagerMaster | ||
| * does not need to be told about this block as no one | ||
| * needs to know about this data block. | ||
| */ | ||
| SparkEnv.get.blockManager.putSingle( | ||
| blockId, value_, StorageLevel.MEMORY_AND_DISK, tellMaster = false) | ||
| val time = (System.nanoTime - start) / 1e9 | ||
|
|
||
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.
would be good to set the name of the thread, so that stack dumps are easier to understand.
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.
Yes, I am working on an updated patch based on all the feedback and I have already put that in.