Skip to content

Conversation

crepererum
Copy link
Contributor

Which issue does this PR close?

Fixes #5278.

Rationale for this change

This prevents endless spinning and locked up tokio tasks if the inputs never yield pending.

What changes are included in this PR?

One yield point.

Are these changes tested?

Regression test taken from #5278 (with some clean-ups to make it a real test).

Are there any user-facing changes?

Probably a more stable DF execution.

@github-actions github-actions bot added the core Core DataFusion crate label Feb 16, 2023
This prevents endless spinning and locked up tokio tasks if the inputs
never yield `pending`.

Fixes apache#5278.
Copy link
Contributor

@metesynnada metesynnada left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution. LGTM, However, this test has many duplicates with UnboundedExec in datafusion/core/src/test/exec.rs. Maybe we can reduce code size by refactoring UnboundedExec to be used here.

@crepererum
Copy link
Contributor Author

Maybe we can reduce code size by refactoring UnboundedExec to be used her

done.

Copy link
Contributor

@metesynnada metesynnada left a comment

Choose a reason for hiding this comment

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

LGTM. Have you resolved the thread::sleep issue related to the CoalescePartitionsExec usage? The test does not seem to suggest that.

Alternatively, do you think we should be cautious when using thread::sleep? I would like to hear your opinion on the matter.


/// See <https://github.com/apache/arrow-datafusion/issues/5278>
#[tokio::test]
async fn unbounded_repartition_sa() -> Result<()> {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can insert a timeout here in case of an error. You can check unbounded_file_with_swapped_join for an example.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I cannot get that timeout macro to work reliably. It only seems to work w/ multi-thread tokio executors that have more than 1 thread. However than the test itself is a bit of a lucky shot either, because the main test method will no longer block just because the repartition task spins forever. So I guess we have to live w/o a timeout.

@crepererum
Copy link
Contributor Author

crepererum commented Feb 16, 2023

LGTM. Have you resolved the thread::sleep issue related to the CoalescePartitionsExec usage? The test does not seem to suggest that.

Not sure what "the thread::sleep issue" is, but the sleep is not required to trigger the bug. If you perform a thread::sleep in tokio, you for sure block the entire executor thread during the sleep. This is expected behavior. You should never do that (expect when you use spawn_blocking, but that comes w/ I a performance penalty).

The test blocks forever without the yield point, so IMHO this fixes the original issue.

@metesynnada
Copy link
Contributor

LGTM. Have you resolved the thread::sleep issue related to the CoalescePartitionsExec usage? The test does not seem to suggest that.

Not sure what "the thread::sleep issue" is, but the sleep is not required to trigger the bug. If you perform a thread::sleep in tokio, you for sure block the entire executor thread during the sleep. This is expected behavior. You should never do that (expect when you use spawn_blocking, but that comes w/ I a performance penalty).

The test blocks forever without the yield point, so IMHO this fixes the original issue.

I see. Thanks for the contribution!

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thank you @crepererum and @metesynnada

I verified that the test covers this code

I removed the yield, and the new test blocks:

cargo test --test repartition_exec_blocks
...
running 1 test
test unbounded_repartition_sa has been running for over 60 seconds
(killed)

And with the yield it completes quickly:

running 1 test
test unbounded_repartition_sa ... ok�(B

test result: ok�(B. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

timer.done();
}

// If the input stream is endless, we may spin forever and never yield back to tokio. Hence let us yield.
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

@ozankabak ozankabak left a comment

Choose a reason for hiding this comment

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

LGTM too, thank you!

@alamb alamb merged commit ded897e into apache:main Feb 17, 2023
@alamb
Copy link
Contributor

alamb commented Feb 17, 2023

Thanks everyone!

@ursabot
Copy link

ursabot commented Feb 17, 2023

Benchmark runs are scheduled for baseline = 22b974f and contender = ded897e. ded897e is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
Conbench compare runs links:
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ec2-t3-xlarge-us-east-2] ec2-t3-xlarge-us-east-2
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on test-mac-arm] test-mac-arm
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ursa-i9-9960x] ursa-i9-9960x
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ursa-thinkcentre-m75q] ursa-thinkcentre-m75q
Buildkite builds:
Supported benchmarks:
ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
test-mac-arm: Supported benchmark langs: C++, Python, R
ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java

jiangzhx pushed a commit to jiangzhx/arrow-datafusion that referenced this pull request Feb 24, 2023
* fix: add yield point to `RepartitionExec`

This prevents endless spinning and locked up tokio tasks if the inputs
never yield `pending`.

Fixes apache#5278.

* refactor: use a single `UnboundedExec` for testing

* refactor: rename test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Core DataFusion crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Strange Behaviour on RepartitionExec with CoalescePartitionsExec.
5 participants