Skip to content

[SPARK-7698] Cache and reuse buffers in ExecutorMemoryAllocator when using heap allocation - #6227

Closed
JoshRosen wants to merge 2 commits into
apache:masterfrom
JoshRosen:SPARK-7698
Closed

JoshRosen wants to merge 2 commits into
apache:masterfrom
JoshRosen:SPARK-7698

Conversation

@JoshRosen

Copy link
Copy Markdown
Contributor

When on-heap memory allocation is used, ExecutorMemoryManager should maintain a cache / pool of buffers for re-use by tasks. This will significantly improve the performance of the new Tungsten's sort-shuffle for jobs with many short-lived tasks by eliminating a major source of GC.

This pull request is a minimum-viable-implementation of this idea. In its current form, this patch significantly improves performance on a stress test which launches huge numbers of short-lived shuffle map tasks back-to-back in the same JVM.

@AmplabJenkins

Copy link
Copy Markdown

Merged build triggered.

@AmplabJenkins

Copy link
Copy Markdown

Merged build started.

@SparkQA

SparkQA commented May 18, 2015

Copy link
Copy Markdown

Test build #32963 has started for PR 6227 at commit b154e86.

@JoshRosen

Copy link
Copy Markdown
Contributor Author

For https://gist.github.com/680ee530655941defcb2, this patch gives a roughly 3x speedup.

@SparkQA

SparkQA commented May 18, 2015

Copy link
Copy Markdown

Test build #32963 has finished for PR 6227 at commit b154e86.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@AmplabJenkins

Copy link
Copy Markdown

Merged build finished. Test PASSed.

@AmplabJenkins

Copy link
Copy Markdown

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/32963/
Test PASSed.

@JoshRosen

Copy link
Copy Markdown
Contributor Author

Leaving the [WIP] tag on for now while we discuss a few different design decisions.

@JoshRosen

Copy link
Copy Markdown
Contributor Author

@rxin @zsxwing In the long term, I think that we should consider a more complete design for buffer pooling in our allocator, including thinking through how / whether we want to support pooling for off-heap modes, how we want to match up allocation requests with things in the pages, whether we want to have more manual control over purging pages from the pool, etc. For the immediate 1.4 term, though, I think a super-simple approach like the one in this patch offers a nice improvement. Because the number of different allocation sizes is relatively small (one or two sizes, tops), I think the simple approach is fine for starters.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a minor question: I think you want to use LinkedList as Stack since you use pop. Right? If so, here you should use push. push calls addFirst, pop calls removeFirst, while add calls addLast.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Java's linked list is doubly-linked, so I don't think that this makes a perf. difference or anything, which is why I was a little sloppy here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought there was a special reason to use pop :)

@JoshRosen

Copy link
Copy Markdown
Contributor Author

On closer inspection, I'm thinking that we should probably prefer WeakReferences to SoftReferences, since it's probably better to allow this memory to be released sooner in response to memory demand rather than having the heap grow in order to try to keep empty pages in the pool.

@zsxwing

zsxwing commented May 20, 2015

Copy link
Copy Markdown
Member

@JoshRosen why not round up size to a power of 2? I think it's more possible to reuse the objects.

@zsxwing

zsxwing commented May 20, 2015

Copy link
Copy Markdown
Member

+1. WeakReferences is better for cache usage.

@JoshRosen

Copy link
Copy Markdown
Contributor Author

@zsxwing I think that all of our internal requests are already power-of-2 sized, so I don't think that's a concern yet. Right now, I think we'll only end up allocating pages whose sizes are drawn from a very small set (maybe 4 or fewer standard page sizes, tops). We might consider adding the rounding later, though.

@zsxwing

zsxwing commented May 20, 2015

Copy link
Copy Markdown
Member

I see. LGTM except the WeakReferences thing.

@JoshRosen JoshRosen changed the title [SPARK-7698] [WIP] Cache and reuse buffers in ExecutorMemoryAllocator when using heap allocation [SPARK-7698] Cache and reuse buffers in ExecutorMemoryAllocator when using heap allocation May 20, 2015
@JoshRosen

Copy link
Copy Markdown
Contributor Author

Just pushed a commit to fix the WeakReference thing :)

@AmplabJenkins

Copy link
Copy Markdown

Merged build triggered.

@AmplabJenkins

Copy link
Copy Markdown

Merged build started.

@SparkQA

SparkQA commented May 20, 2015

Copy link
Copy Markdown

Test build #33114 has started for PR 6227 at commit fd6cb55.

@zsxwing

zsxwing commented May 20, 2015

Copy link
Copy Markdown
Member

LGTM

@SparkQA

SparkQA commented May 20, 2015

Copy link
Copy Markdown

Test build #33114 has finished for PR 6227 at commit fd6cb55.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@AmplabJenkins

Copy link
Copy Markdown

Merged build finished. Test PASSed.

@AmplabJenkins

Copy link
Copy Markdown

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/33114/
Test PASSed.

@rxin

rxin commented May 20, 2015

Copy link
Copy Markdown
Contributor

LGTM

@JoshRosen

Copy link
Copy Markdown
Contributor Author

Thanks for the review. I'm going to merge this into master and branch-1.4 (1.4.0).

asfgit pushed a commit that referenced this pull request May 20, 2015
…using heap allocation

When on-heap memory allocation is used, ExecutorMemoryManager should maintain a cache / pool of buffers for re-use by tasks. This will significantly improve the performance of the new Tungsten's sort-shuffle for jobs with many short-lived tasks by eliminating a major source of GC.

This pull request is a minimum-viable-implementation of this idea.  In its current form, this patch significantly improves performance on a stress test which launches huge numbers of short-lived shuffle map tasks back-to-back in the same JVM.

Author: Josh Rosen <joshrosen@databricks.com>

Closes #6227 from JoshRosen/SPARK-7698 and squashes the following commits:

fd6cb55 [Josh Rosen] SoftReference -> WeakReference
b154e86 [Josh Rosen] WIP sketch of pooling in ExecutorMemoryManager

(cherry picked from commit 7956dd7)
Signed-off-by: Josh Rosen <joshrosen@databricks.com>
@asfgit asfgit closed this in 7956dd7 May 20, 2015
@JoshRosen
JoshRosen deleted the SPARK-7698 branch May 20, 2015 23:41
jeanlyn pushed a commit to jeanlyn/spark that referenced this pull request May 28, 2015
…using heap allocation

When on-heap memory allocation is used, ExecutorMemoryManager should maintain a cache / pool of buffers for re-use by tasks. This will significantly improve the performance of the new Tungsten's sort-shuffle for jobs with many short-lived tasks by eliminating a major source of GC.

This pull request is a minimum-viable-implementation of this idea.  In its current form, this patch significantly improves performance on a stress test which launches huge numbers of short-lived shuffle map tasks back-to-back in the same JVM.

Author: Josh Rosen <joshrosen@databricks.com>

Closes apache#6227 from JoshRosen/SPARK-7698 and squashes the following commits:

fd6cb55 [Josh Rosen] SoftReference -> WeakReference
b154e86 [Josh Rosen] WIP sketch of pooling in ExecutorMemoryManager
jeanlyn pushed a commit to jeanlyn/spark that referenced this pull request Jun 12, 2015
…using heap allocation

When on-heap memory allocation is used, ExecutorMemoryManager should maintain a cache / pool of buffers for re-use by tasks. This will significantly improve the performance of the new Tungsten's sort-shuffle for jobs with many short-lived tasks by eliminating a major source of GC.

This pull request is a minimum-viable-implementation of this idea.  In its current form, this patch significantly improves performance on a stress test which launches huge numbers of short-lived shuffle map tasks back-to-back in the same JVM.

Author: Josh Rosen <joshrosen@databricks.com>

Closes apache#6227 from JoshRosen/SPARK-7698 and squashes the following commits:

fd6cb55 [Josh Rosen] SoftReference -> WeakReference
b154e86 [Josh Rosen] WIP sketch of pooling in ExecutorMemoryManager
nemccarthy pushed a commit to nemccarthy/spark that referenced this pull request Jun 19, 2015
…using heap allocation

When on-heap memory allocation is used, ExecutorMemoryManager should maintain a cache / pool of buffers for re-use by tasks. This will significantly improve the performance of the new Tungsten's sort-shuffle for jobs with many short-lived tasks by eliminating a major source of GC.

This pull request is a minimum-viable-implementation of this idea.  In its current form, this patch significantly improves performance on a stress test which launches huge numbers of short-lived shuffle map tasks back-to-back in the same JVM.

Author: Josh Rosen <joshrosen@databricks.com>

Closes apache#6227 from JoshRosen/SPARK-7698 and squashes the following commits:

fd6cb55 [Josh Rosen] SoftReference -> WeakReference
b154e86 [Josh Rosen] WIP sketch of pooling in ExecutorMemoryManager
dongjoon-hyun added a commit that referenced this pull request Nov 2, 2026
### What changes were proposed in this pull request?

This PR aims to upgrade FasterXML Jackson to 2.22.4.

### Why are the changes needed?

Jackson 2.22.4 is the latest patch release on the 2.22 line.

- https://github.com/FasterXML/jackson/wiki/Jackson-Release-2.22.4 (2026-10-17)
  - Streaming
    - [#1683](FasterXML/jackson-core#1683) `ReaderBasedJsonParser` accepts lone surrogates in `\uXXXX` escapes in field names
    - [#1744](FasterXML/jackson-core#1744) `UTF8DataInputJsonParser` fails on JSON-escaped surrogate pairs in property names
    - [#1750](FasterXML/jackson-core#1750) `ALLOW_UNESCAPED_CONTROL_CHARS` is ignored for single-quoted string values in UTF-8 byte parsers
    - [#1742](FasterXML/jackson-core#1742), [#1746](FasterXML/jackson-core#1746), [#1756](FasterXML/jackson-core#1756) Non-blocking parser fixes for escaped surrogate pairs, leading decimal point numbers, and multi-byte UTF-8 characters after a backslash escape
    - [#1730](FasterXML/jackson-core#1730) `FilteringGeneratorDelegate` handles embedded objects, typed arrays, and raw/binary values consistently
  - Databind
    - CVE-2026-110879 [#6287](FasterXML/jackson-databind#6287) Validate type parameters and array element types of type ids
    - [#6206](FasterXML/jackson-databind#6206) Report a cycle through a `JsonValue` accessor as a `DatabindException`
    - [#6227](FasterXML/jackson-databind#6227) `BeanDescription.findProperties()` is not thread-safe on a shared, cached instance
    - [#6249](FasterXML/jackson-databind#6249) Avoid an NPE when the parser reports `VALUE_STRING` with null text
  - CBOR
    - CVE-2026-106554 [#821](FasterXML/jackson-dataformats-binary#821) Grow the `CBORParser.TagList` backing array geometrically

`jackson-annotations` stays at 2.22 as referenced by `jackson-bom` 2.22.4.

### Does this PR introduce _any_ user-facing change?

No.

### How was this patch tested?

Pass the CIs.

### Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Sonnet 5.5

Closes #60004 from dongjoon-hyun/SPARK-60799.

Authored-by: Dongjoon Hyun <dongjoon@apache.org>
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants