Skip to content

Conversation

@viirya
Copy link
Member

@viirya viirya commented Sep 30, 2024

Which issue does this PR close?

Closes #887.

Rationale for this change

What changes are included in this PR?

How are these changes tested?

@viirya viirya force-pushed the revise_shuffle_memory branch from 18be135 to d063f15 Compare September 30, 2024 20:38
@Kontinuation
Copy link
Member

I've copied the tests on my branch to this PR and the test hangs:

running 6 tests
test execution::datafusion::shuffle_writer::test::test_slot_size ... ok
test execution::datafusion::shuffle_writer::test::test_pmod ... ok
test execution::datafusion::shuffle_writer::test::test_insert_larger_batch ... ok
test execution::datafusion::shuffle_writer::test::test_insert_smaller_batch ... ok
test execution::datafusion::shuffle_writer::test::test_large_number_of_partitions has been running for over 60 seconds
test execution::datafusion::shuffle_writer::test::test_large_number_of_partitions_spilling has been running for over 60 seconds
^C

It is possibly caused by deadlocking on buffered_partitions.lock() when spilling is triggered.

@viirya
Copy link
Member Author

viirya commented Oct 1, 2024

Thanks. I knew the cause of the deadlocks. I'm going to revamp some codes.

@viirya viirya force-pushed the revise_shuffle_memory branch 2 times, most recently from 64c7c0d to d25837a Compare October 9, 2024 15:47
@viirya viirya force-pushed the revise_shuffle_memory branch from d25837a to da8d679 Compare October 9, 2024 16:07
@viirya viirya force-pushed the revise_shuffle_memory branch from 718c15c to 8172a7c Compare October 9, 2024 17:12
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 33.97%. Comparing base (c3023c5) to head (e678cb0).
Report is 25 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main     #988      +/-   ##
============================================
- Coverage     34.03%   33.97%   -0.07%     
+ Complexity      875      857      -18     
============================================
  Files           112      112              
  Lines         43289    43426     +137     
  Branches       9572     9622      +50     
============================================
+ Hits          14734    14752      +18     
- Misses        25521    25630     +109     
- Partials       3034     3044      +10     
Flag Coverage Δ
?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@viirya
Copy link
Member Author

viirya commented Oct 9, 2024

Hmm, these tests for large partition number shuffle fail on MacOS runners only. And no stack trace...But I cannot reproduce it locally.

@viirya
Copy link
Member Author

viirya commented Oct 9, 2024

Okay, it is the error I expected before:

ret: Err(ArrowError(ExternalError(IoError(Custom { kind: Uncategorized, error: PathError { path: "/var/folders/t_/mmhnh941511_hp2lwh383bp00000gn/T/.tmpQv8o2b/.tmpioYozN", err: Os { code: 24, kind: Uncategorized, message: "Too many open files" } } })), None))

But I had increase it by ulimit. It doesn't help.

@viirya viirya force-pushed the revise_shuffle_memory branch from 5e50f98 to ebf4663 Compare October 9, 2024 22:02
@viirya viirya force-pushed the revise_shuffle_memory branch from ebf4663 to e121814 Compare October 9, 2024 22:03

#[test]
#[cfg_attr(miri, ignore)] // miri can't call foreign function `ZSTD_createCCtx`
#[cfg(not(target_os = "macos"))] // Github MacOS runner fails with "Too many open files".
Copy link
Member Author

Choose a reason for hiding this comment

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

These tests fail on MacOS runners with "Too many open files" error. ulimit cannot help too.

I skip them on MacOS runners. We have ubuntu runners to test them.

Copy link
Member

Choose a reason for hiding this comment

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

The test shuffle_write_test(10000, 10, 200, Some(10 * 1024 * 1024)) spilled 1700 times, it spills too frequently for data of this size. Seems that the excessive spilling problem is inevitable if we reserve full batch capacity for the arrow builder.

Copy link
Member

Choose a reason for hiding this comment

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

This PR seems like an important improvement because it now uses the memory pool features. Perhaps we can follow up with optimizations to reduce spilling. wdyt @Kontinuation?

Copy link
Member

Choose a reason for hiding this comment

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

Sure. Let's merge this.

I'm also considering adding a native sort-based shuffle writer that works better with constraint resources.

Copy link
Member Author

@viirya viirya Oct 12, 2024

Choose a reason for hiding this comment

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

We've discussed to support sort-based shuffle in the native shuffle writer, similar to Spark shuffle, in the early development. So I think it is on our roadmap though it is not urgent at that moment.

@viirya viirya requested a review from andygrove October 9, 2024 23:50
@andygrove
Copy link
Member

I'm testing this PR out now, in conjunction with some other PRs because I currently have a reproducible deadlock caused by memory pool issues, as far as I can tell.

@viirya viirya force-pushed the revise_shuffle_memory branch from cc9e531 to 6763b1e Compare October 12, 2024 16:50
Copy link
Member

@andygrove andygrove left a comment

Choose a reason for hiding this comment

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

Thanks @viirya

@andygrove andygrove merged commit e146cfa into apache:main Oct 14, 2024
@viirya
Copy link
Member Author

viirya commented Oct 14, 2024

Thanks @andygrove @Kontinuation

@viirya viirya deleted the revise_shuffle_memory branch October 14, 2024 15:27
andygrove added a commit to andygrove/datafusion-comet that referenced this pull request Oct 15, 2024
viirya added a commit to viirya/arrow-datafusion-comet that referenced this pull request Oct 15, 2024
viirya added a commit that referenced this pull request Oct 15, 2024
viirya added a commit to viirya/arrow-datafusion-comet that referenced this pull request Oct 16, 2024
viirya added a commit to viirya/arrow-datafusion-comet that referenced this pull request Oct 16, 2024
viirya added a commit to viirya/arrow-datafusion-comet that referenced this pull request Oct 16, 2024
viirya added a commit to viirya/arrow-datafusion-comet that referenced this pull request Oct 16, 2024
viirya added a commit to viirya/arrow-datafusion-comet that referenced this pull request Oct 16, 2024
andygrove pushed a commit that referenced this pull request Oct 19, 2024
* Revert "chore: Revert "chore: Reserve memory for native shuffle writer per partition (#988)" (#1020)"

This reverts commit 8d097d5.

* fix

* fix

* fix

* fix
andygrove added a commit that referenced this pull request Oct 21, 2024
…HashJoin (#1007)

* experiment

* fix and add credit

* disable by default and make internal

* remove sort

* minor optimization

* minor optimization

* remove unused import

* disable feature by default

* fix dockerfile

* Add section to tuning guide

* update benchmarking guide

* Revert "chore: Reserve memory for native shuffle writer per partition (#988)"

This reverts commit e146cfa.

* mark feature as experimental and explain risks

* workaround for TPC-DS q14 hanging on a RightSemi join

* revert a change

* remove debug logging:

* format

* add link to tuning guide
kazuyukitanimura pushed a commit to kazuyukitanimura/datafusion-comet that referenced this pull request Nov 5, 2024
…#988)

* chore: Reserve memory for native shuffle writer per partition

* Revise

* skip large partition number shuffle on macos runners

* For review
coderfender pushed a commit to coderfender/datafusion-comet that referenced this pull request Dec 13, 2025
## Which issue does this PR close?

<!--
We generally require a GitHub issue to be filed for all bug fixes and
enhancements and this helps us generate change logs for our releases.
You can link an issue to this PR using the GitHub syntax. For example
`Closes apache#123` indicates that this PR will close issue apache#123.
-->

Closes #.

## Rationale for this change

<!--
Why are you proposing this change? If this is already explained clearly
in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand
your changes and offer better suggestions for fixes.
-->

## What changes are included in this PR?

<!--
There is no need to duplicate the description in the issue here but it
is sometimes worth providing a summary of the individual changes in this
PR.
-->

```
cb3e977 perf: Add experimental feature to replace SortMergeJoin with ShuffledHashJoin (apache#1007)
3df9d5c fix: Make comet-git-info.properties optional (apache#1027)
4033687 chore: Reserve memory for native shuffle writer per partition (apache#1022)
bd541d6 (public/main) remove hard-coded version number from Dockerfile (apache#1025)
e3ac6cf feat: Implement bloom_filter_agg (apache#987)
8d097d5 (origin/main) chore: Revert "chore: Reserve memory for native shuffle writer per partition (apache#988)" (apache#1020)
591f45a chore: Bump arrow-rs to 53.1.0 and datafusion (apache#1001)
e146cfa chore: Reserve memory for native shuffle writer per partition (apache#988)
abd9f85 fix: Fallback to Spark if named_struct contains duplicate field names (apache#1016)
22613e9 remove legacy comet-spark-shell (apache#1013)
d40c802 clarify that Maven central only has jars for Linux (apache#1009)
837c256 docs: Various documentation improvements (apache#1005)
0667c60 chore: Make parquet reader options Comet options instead of Hadoop options (apache#968)
0028f1e fix: Fallback to Spark if scan has meta columns (apache#997)
b131cc3 feat: Support `GetArrayStructFields` expression (apache#993)
3413397 docs: Update tuning guide (apache#995)
afd28b9 Quality of life fixes for easier hacking (apache#982)
18150fb chore: Don't transform the HashAggregate to CometHashAggregate if Comet shuffle is disabled (apache#991)
a1599e2 chore: Update for 0.3.0 release, prepare for 0.4.0 development (apache#970)
```

## How are these changes tested?

<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code

If tests are not included in your PR, please explain why (for example,
are they covered by existing tests)?
-->
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.

Memory over-reservation when running native shuffle write

4 participants