[SPARK-14560] Spillables can be forced to spill after inserting all data, to avoid OOM #12369
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.
What changes were proposed in this pull request?
This adds a new configuration,
spark.shuffle.spillAfterRead, which can be used to forceSpillables to spill their contents after all records have been inserted. The default is false, to keep previous behavior and avoid a performance penalty when unnecessary. However this needed in cases to prevent an OOM when oneSpillableacquires all of the execution memory available for a task, thus leaving no memory available for any other operations in the same task.This also required some small refactoring of
Spillableto support a forced spill from an external request (as opposed to not having enough memory as records are added).I was initially hoping to limit the places where we needed to spill -- I thought that it would only be in a
ShuffleMapTaskwhich also does a shuffle-read. In that case there is clearly aSpillableon both the shuffle-read and shuffle-write side. However, I realized this wasn't sufficient -- there are other cases when you can have multipleSpillables, eg if you use a common partitioner across several aggregations, which will get pipelined into one stage.This also makes
Spillables register themselves asMemoryConsumers with theTaskMemoryManager. Note that this does not lead to cooperative memory management forSpillables -- the only reason for this is to improve the logging around memory usage. Before this change, there would be messages like:instead, with this change the logs report the memory as being associated with the corresponing
SpillableHow was this patch tested?