Skip to content

Conversation

@getChan
Copy link
Contributor

@getChan getChan commented Mar 23, 2025

Which issue does this PR close?

Rationale for this change

It is not certain, but it seems that plan creation and collect() should share the same runtime.. It is presumed that the issue occurred because RepartitionExec lazily polls within the runtime.

I will add more details if I find anything additional.

What changes are included in this PR?

  • Move the Runtime::new() intobench_function
  • Ensure that plan creation (ctx.sql()) and collect() share the same runtime.

Are these changes tested?

yes. below test are succeded

  • cargo bench -p datafusion --bench topk_aggregate
  • cargo bench -p datafusion --bench distinct_query_sql

Are there any user-facing changes?

No.

@github-actions github-actions bot added the core Core DataFusion crate label Mar 23, 2025
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.

Thanks for this @getChan

|b| b.iter(|| run(distinct_trace_id_100_partitions_100_000_samples_limit_100.0.clone(),
distinct_trace_id_100_partitions_100_000_samples_limit_100.1.clone())),
|b| b.iter(|| {
let rt = Runtime::new().unwrap();
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 this means that the benchmark will include the time to create each tokio runtime (with a bunch of threads, etc)

To avoid this I think you can create the runtime once, and then use it for each tieration:

            let rt = Runtime::new().unwrap();
    c.bench_function(
        format!("distinct query with {} partitions and {} samples per partition with limit {}", partitions, samples, limit).as_str(),
        |b| b.iter(|| {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it. Changed the runtime to be shared between loops.

However, it seems that other benchmark codes still have runtime creation within the iteration.

Copy link
Contributor

Choose a reason for hiding this comment

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

Filed as #15507

@github-actions github-actions bot added documentation Improvements or additions to documentation sql SQL Planner development-process Related to development process of DataFusion logical-expr Logical plan and expressions physical-expr Changes to the physical-expr crates optimizer Optimizer rules sqllogictest SQL Logic Tests (.slt) substrait Changes to the substrait crate catalog Related to the catalog crate common Related to common crate proto Related to proto crate functions Changes to functions implementation datasource Changes to the datasource crate labels Mar 26, 2025
@getChan getChan force-pushed the fix-repartition-bench-bug branch from c7414b2 to c36e781 Compare March 26, 2025 15:37
@github-actions github-actions bot removed documentation Improvements or additions to documentation sql SQL Planner development-process Related to development process of DataFusion logical-expr Logical plan and expressions physical-expr Changes to the physical-expr crates optimizer Optimizer rules sqllogictest SQL Logic Tests (.slt) substrait Changes to the substrait crate catalog Related to the catalog crate common Related to common crate proto Related to proto crate labels Mar 26, 2025
@github-actions github-actions bot removed functions Changes to functions implementation datasource Changes to the datasource crate labels Mar 26, 2025
@2010YOUY01
Copy link
Contributor

Thank you for the fix! I noticed there are two other tests panicked on the same line of source code, is this fix still applicable?

  1. Running sqllogictest with sqlite check: https://github.com/apache/datafusion/actions/runs/14152508679/job/39647603410
  2. custom_datasource example: https://github.com/apache/datafusion/actions/runs/14152369014/job/39647355093

@getChan
Copy link
Contributor Author

getChan commented Mar 30, 2025

Thank you for the fix! I noticed there are two other tests panicked on the same line of source code, is this fix still applicable?

  1. Running sqllogictest with sqlite check: https://github.com/apache/datafusion/actions/runs/14152508679/job/39647603410
  2. custom_datasource example: https://github.com/apache/datafusion/actions/runs/14152369014/job/39647355093

@2010YOUY01
This PR is to fix the bench test code. The partition not used yet error can occur depending on the execution environment of each test (it is not likely an error in repartitionExec). Therefore, this PR does not solve the issue you mentioned.

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 @getChan and @Omega359

@alamb alamb merged commit bde9803 into apache:main Mar 31, 2025
29 checks passed
@alamb
Copy link
Contributor

alamb commented Mar 31, 2025

Let's get this in and keep iterating on the benchmarks

nirnayroy pushed a commit to nirnayroy/datafusion that referenced this pull request May 2, 2025
* distinct_query_sql, topk_aggregate

* cargo clippy

* cargo fmt

* share runtime
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.

distinct_query_sql benchmark is failing

4 participants