You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "tustvold (via GitHub)" <gi...@apache.org> on 2023/04/05 13:20:13 UTC
[GitHub] [arrow-datafusion] tustvold opened a new pull request, #5881: More realistic sort benchmarks
tustvold opened a new pull request, #5881:
URL: https://github.com/apache/arrow-datafusion/pull/5881
# 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 #123` indicates that this PR will close issue #123.
-->
Relates to #5879
# 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.
-->
This combines the merge and sort benchmarks together to avoid code duplication, it also makes a number of changes to make the benchmarks more realistic:
* Each partition / stream now contains multiple batches, an average of 13
* The sort_merge bench now performs a partitioned sort instead of sorting into a single partition and then running a SortPreservingMerge on the single partition (which is a no-op)
* Tuples are sliced and then collected into their output arrays, this ensures that DictionaryArray aren't all using the same identical dictionary values
* Merge benchmark is run on sorted data, with the other benchmarks run on unsorted data
*
# 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.
-->
# 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)?
-->
# Are there any user-facing changes?
<!--
If there are user-facing changes then we may require documentation to be updated before approving the PR.
-->
<!--
If there are any breaking changes to public APIs, please add the `api change` label.
-->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] tustvold commented on a diff in pull request #5881: More realistic sort benchmarks
Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold commented on code in PR #5881:
URL: https://github.com/apache/arrow-datafusion/pull/5881#discussion_r1158511665
##########
datafusion/core/benches/sort.rs:
##########
@@ -41,167 +94,80 @@ use rand::rngs::StdRng;
use rand::{Rng, SeedableRng};
use tokio::runtime::Runtime;
-use lazy_static::lazy_static;
+use datafusion::physical_plan::coalesce_partitions::CoalescePartitionsExec;
/// Total number of streams to divide each input into
/// models 8 partition plan (should it be 16??)
-const NUM_STREAMS: u64 = 8;
+const NUM_STREAMS: usize = 8;
+
+/// The size of each batch within each stream
+const BATCH_SIZE: usize = 1024;
/// Total number of input rows to generate
const INPUT_SIZE: u64 = 100000;
-// cases:
-
-// * physical sort expr (X, Y Z, NULLS FIRST, ASC) (not parameterized)
-//
-// streams of distinct values
-// streams with 10% duplicated values (within each stream, and across streams)
-// These cases are intended to model important usecases in TPCH
-// parameters:
-//
-// Input schemas
-lazy_static! {
Review Comment:
Lazy static seemed overkill for what this was doing, I opted to keep things simple
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] jaylmiller commented on pull request #5881: More realistic sort benchmarks
Posted by "jaylmiller (via GitHub)" <gi...@apache.org>.
jaylmiller commented on PR #5881:
URL: https://github.com/apache/arrow-datafusion/pull/5881#issuecomment-1498176105
> Thank you @tustvold -- I reviewed this and it makes sense to me. I also spot checked the inputs (by printing them out to standard out and it looked good)
>
> cc @jaylmiller
Looks good to me as well!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] tustvold merged pull request #5881: More realistic sort benchmarks
Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold merged PR #5881:
URL: https://github.com/apache/arrow-datafusion/pull/5881
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #5881: More realistic sort benchmarks
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #5881:
URL: https://github.com/apache/arrow-datafusion/pull/5881#discussion_r1158964935
##########
datafusion/core/benches/sort.rs:
##########
@@ -210,58 +178,61 @@ impl SortBenchCase {
}
}
- /// runs the specified plan to completion, draining all input and
- /// panic'ing on error
- fn run(&self) {
- let plan = Arc::clone(&self.plan);
- let task_ctx = Arc::clone(&self.task_ctx);
+ fn sort_merge(partitions: &[Vec<RecordBatch>]) -> Self {
+ let runtime = tokio::runtime::Builder::new_multi_thread().build().unwrap();
+ let session_ctx = SessionContext::new();
+ let task_ctx = session_ctx.task_ctx();
- assert_eq!(plan.output_partitioning().partition_count(), 1);
+ let schema = partitions[0][0].schema();
+ let sort = make_sort_exprs(schema.as_ref());
- self.runtime.block_on(async move {
- let mut stream = plan.execute(0, task_ctx).unwrap();
- while let Some(b) = stream.next().await {
- b.expect("unexpected execution error");
- }
- })
+ let exec = MemoryExec::try_new(partitions, schema, None).unwrap();
+ let exec =
+ SortExec::new_with_partitioning(sort.clone(), Arc::new(exec), true, None);
+ let plan = Arc::new(SortPreservingMergeExec::new(sort, Arc::new(exec)));
+
+ Self {
+ runtime,
+ task_ctx,
+ plan,
+ }
}
-}
-/// Encapsulates running a test case where input partitioning is not preserved.
-struct SortBenchCasePreservePartitioning {
- runtime: Runtime,
- task_ctx: Arc<TaskContext>,
- // The plan to run
- plan: Arc<dyn ExecutionPlan>,
- partition_count: usize,
-}
+ fn sort(partitions: &[Vec<RecordBatch>]) -> Self {
Review Comment:
```suggestion
/// Test SortExec in "non partitioned" mode which sorts the input streams
/// into a single sorted output stream
fn sort(partitions: &[Vec<RecordBatch>]) -> Self {
```
##########
datafusion/core/benches/sort.rs:
##########
@@ -210,58 +178,61 @@ impl SortBenchCase {
}
}
- /// runs the specified plan to completion, draining all input and
- /// panic'ing on error
- fn run(&self) {
- let plan = Arc::clone(&self.plan);
- let task_ctx = Arc::clone(&self.task_ctx);
+ fn sort_merge(partitions: &[Vec<RecordBatch>]) -> Self {
+ let runtime = tokio::runtime::Builder::new_multi_thread().build().unwrap();
+ let session_ctx = SessionContext::new();
+ let task_ctx = session_ctx.task_ctx();
- assert_eq!(plan.output_partitioning().partition_count(), 1);
+ let schema = partitions[0][0].schema();
+ let sort = make_sort_exprs(schema.as_ref());
- self.runtime.block_on(async move {
- let mut stream = plan.execute(0, task_ctx).unwrap();
- while let Some(b) = stream.next().await {
- b.expect("unexpected execution error");
- }
- })
+ let exec = MemoryExec::try_new(partitions, schema, None).unwrap();
+ let exec =
+ SortExec::new_with_partitioning(sort.clone(), Arc::new(exec), true, None);
+ let plan = Arc::new(SortPreservingMergeExec::new(sort, Arc::new(exec)));
Review Comment:
I would expect this to behave the same, performance wise, as `sort` -- is that your expectation too?
##########
datafusion/core/benches/sort.rs:
##########
@@ -210,58 +178,61 @@ impl SortBenchCase {
}
}
- /// runs the specified plan to completion, draining all input and
- /// panic'ing on error
- fn run(&self) {
- let plan = Arc::clone(&self.plan);
- let task_ctx = Arc::clone(&self.task_ctx);
+ fn sort_merge(partitions: &[Vec<RecordBatch>]) -> Self {
+ let runtime = tokio::runtime::Builder::new_multi_thread().build().unwrap();
+ let session_ctx = SessionContext::new();
+ let task_ctx = session_ctx.task_ctx();
- assert_eq!(plan.output_partitioning().partition_count(), 1);
+ let schema = partitions[0][0].schema();
+ let sort = make_sort_exprs(schema.as_ref());
- self.runtime.block_on(async move {
- let mut stream = plan.execute(0, task_ctx).unwrap();
- while let Some(b) = stream.next().await {
- b.expect("unexpected execution error");
- }
- })
+ let exec = MemoryExec::try_new(partitions, schema, None).unwrap();
+ let exec =
+ SortExec::new_with_partitioning(sort.clone(), Arc::new(exec), true, None);
+ let plan = Arc::new(SortPreservingMergeExec::new(sort, Arc::new(exec)));
+
+ Self {
+ runtime,
+ task_ctx,
+ plan,
+ }
}
-}
-/// Encapsulates running a test case where input partitioning is not preserved.
-struct SortBenchCasePreservePartitioning {
- runtime: Runtime,
- task_ctx: Arc<TaskContext>,
- // The plan to run
- plan: Arc<dyn ExecutionPlan>,
- partition_count: usize,
-}
+ fn sort(partitions: &[Vec<RecordBatch>]) -> Self {
+ let runtime = tokio::runtime::Builder::new_multi_thread().build().unwrap();
+ let session_ctx = SessionContext::new();
+ let task_ctx = session_ctx.task_ctx();
-impl SortBenchCasePreservePartitioning {
- /// Prepare to run a benchmark that merges the specified
- /// partitions (streams) together using all keyes
- fn new(partitions: &[Vec<RecordBatch>]) -> Self {
- let partition_count = partitions.len();
+ let schema = partitions[0][0].schema();
+ let sort = make_sort_exprs(schema.as_ref());
+
+ let exec = MemoryExec::try_new(partitions, schema, None).unwrap();
+ let exec = Arc::new(CoalescePartitionsExec::new(Arc::new(exec)));
+ let plan = Arc::new(SortExec::try_new(sort, exec, None).unwrap());
+
+ Self {
+ runtime,
+ task_ctx,
+ plan,
+ }
+ }
+
+ fn sort_partitioned(partitions: &[Vec<RecordBatch>]) -> Self {
Review Comment:
```suggestion
/// Test SortExec in "partitioned" mode which sorts the input streams
/// individually into some number of output streams
fn sort_partitioned(partitions: &[Vec<RecordBatch>]) -> Self {
```
##########
datafusion/core/benches/sort.rs:
##########
@@ -41,167 +94,82 @@ use rand::rngs::StdRng;
use rand::{Rng, SeedableRng};
use tokio::runtime::Runtime;
-use lazy_static::lazy_static;
+use datafusion::physical_plan::coalesce_partitions::CoalescePartitionsExec;
/// Total number of streams to divide each input into
/// models 8 partition plan (should it be 16??)
-const NUM_STREAMS: u64 = 8;
+const NUM_STREAMS: usize = 8;
+
+/// The size of each batch within each stream
+const BATCH_SIZE: usize = 1024;
/// Total number of input rows to generate
const INPUT_SIZE: u64 = 100000;
-// cases:
-// * physical sort expr (X, Y Z, NULLS FIRST, ASC) (not parameterized)
-//
-// streams of distinct values
-// streams with 10% duplicated values (within each stream, and across streams)
-// These cases are intended to model important usecases in TPCH
-// parameters:
-//
-// Input schemas
-lazy_static! {
- static ref I64_STREAMS: Vec<Vec<RecordBatch>> = i64_streams();
- static ref F64_STREAMS: Vec<Vec<RecordBatch>> = f64_streams();
-
- static ref UTF8_LOW_CARDINALITY_STREAMS: Vec<Vec<RecordBatch>> = utf8_low_cardinality_streams();
- static ref UTF8_HIGH_CARDINALITY_STREAMS: Vec<Vec<RecordBatch>> = utf8_high_cardinality_streams();
-
- static ref DICTIONARY_STREAMS: Vec<Vec<RecordBatch>> = dictionary_streams();
- static ref DICTIONARY_TUPLE_STREAMS: Vec<Vec<RecordBatch>> = dictionary_tuple_streams();
- static ref MIXED_DICTIONARY_TUPLE_STREAMS: Vec<Vec<RecordBatch>> = mixed_dictionary_tuple_streams();
- // * (string(low), string(low), string(high)) -- tpch q1 + iox
- static ref UTF8_TUPLE_STREAMS: Vec<Vec<RecordBatch>> = utf8_tuple_streams();
- // * (f64, string, string, int) -- tpch q2
- static ref MIXED_TUPLE_STREAMS: Vec<Vec<RecordBatch>> = mixed_tuple_streams();
-
-}
+type PartitionedBatches = Vec<Vec<RecordBatch>>;
fn criterion_benchmark(c: &mut Criterion) {
- c.bench_function("sort i64", |b| {
- let case = SortBenchCase::new(&I64_STREAMS);
-
- b.iter(move || case.run())
- });
- c.bench_function("sort i64 preserve partitioning", |b| {
- let case = SortBenchCasePreservePartitioning::new(&I64_STREAMS);
-
- b.iter(move || case.run())
- });
-
- c.bench_function("sort f64", |b| {
- let case = SortBenchCase::new(&F64_STREAMS);
-
- b.iter(move || case.run())
- });
- c.bench_function("sort f64 preserve partitioning", |b| {
- let case = SortBenchCasePreservePartitioning::new(&F64_STREAMS);
-
- b.iter(move || case.run())
- });
-
- c.bench_function("sort utf8 low cardinality", |b| {
- let case = SortBenchCase::new(&UTF8_LOW_CARDINALITY_STREAMS);
-
- b.iter(move || case.run())
- });
- c.bench_function("sort utf8 low cardinality preserve partitioning", |b| {
- let case = SortBenchCasePreservePartitioning::new(&UTF8_LOW_CARDINALITY_STREAMS);
-
- b.iter(move || case.run())
- });
-
- c.bench_function("sort utf8 high cardinality", |b| {
- let case = SortBenchCase::new(&UTF8_HIGH_CARDINALITY_STREAMS);
-
- b.iter(move || case.run())
- });
- c.bench_function("sort utf8 high cardinality preserve partitioning", |b| {
- let case = SortBenchCasePreservePartitioning::new(&UTF8_HIGH_CARDINALITY_STREAMS);
-
- b.iter(move || case.run())
- });
-
- c.bench_function("sort utf8 tuple", |b| {
- let case = SortBenchCase::new(&UTF8_TUPLE_STREAMS);
-
- b.iter(move || case.run())
- });
- c.bench_function("sort utf8 tuple preserve partitioning", |b| {
- let case = SortBenchCasePreservePartitioning::new(&UTF8_TUPLE_STREAMS);
-
- b.iter(move || case.run())
- });
-
- c.bench_function("sort utf8 dictionary", |b| {
- let case = SortBenchCase::new(&DICTIONARY_STREAMS);
-
- b.iter(move || case.run())
- });
- c.bench_function("sort utf8 dictionary preserve partitioning", |b| {
- let case = SortBenchCasePreservePartitioning::new(&DICTIONARY_STREAMS);
-
- b.iter(move || case.run())
- });
-
- c.bench_function("sort utf8 dictionary tuple", |b| {
- let case = SortBenchCase::new(&DICTIONARY_TUPLE_STREAMS);
- b.iter(move || case.run())
- });
- c.bench_function("sort utf8 dictionary tuple preserve partitioning", |b| {
- let case = SortBenchCasePreservePartitioning::new(&DICTIONARY_TUPLE_STREAMS);
- b.iter(move || case.run())
- });
-
- c.bench_function("sort mixed utf8 dictionary tuple", |b| {
- let case = SortBenchCase::new(&MIXED_DICTIONARY_TUPLE_STREAMS);
- b.iter(move || case.run())
- });
-
- c.bench_function(
- "sort mixed utf8 dictionary tuple preserve partitioning",
- |b| {
- let case =
- SortBenchCasePreservePartitioning::new(&MIXED_DICTIONARY_TUPLE_STREAMS);
+ let cases: Vec<(&str, &dyn Fn(bool) -> PartitionedBatches)> = vec![
+ ("i64", &i64_streams),
+ ("f64", &f64_streams),
+ ("utf8 low cardinality", &utf8_low_cardinality_streams),
+ ("utf8 high cardinality", &utf8_high_cardinality_streams),
+ ("utf8 tuple", &utf8_tuple_streams),
+ ("utf8 dictionary", &dictionary_streams),
+ ("utf8 dictionary tuple", &dictionary_tuple_streams),
+ ("mixed dictionary tuple", &mixed_dictionary_tuple_streams),
+ ("mixed tuple", &mixed_tuple_streams),
+ ];
+
+ for (name, f) in cases {
+ c.bench_function(&format!("merge sorted {name}"), |b| {
+ let data = f(true);
+ let case = BenchCase::merge_sorted(&data);
b.iter(move || case.run())
- },
- );
+ });
- c.bench_function("sort mixed tuple", |b| {
- let case = SortBenchCase::new(&MIXED_TUPLE_STREAMS);
+ c.bench_function(&format!("sort merge {name}"), |b| {
+ let data = f(false);
+ let case = BenchCase::sort_merge(&data);
+ b.iter(move || case.run())
+ });
- b.iter(move || case.run())
- });
- c.bench_function("sort mixed tuple preserve partitioning", |b| {
- let case = SortBenchCasePreservePartitioning::new(&MIXED_TUPLE_STREAMS);
+ c.bench_function(&format!("sort {name}"), |b| {
+ let data = f(false);
+ let case = BenchCase::sort(&data);
+ b.iter(move || case.run())
+ });
- b.iter(move || case.run())
- });
+ c.bench_function(&format!("sort partitioned {name}"), |b| {
+ let data = f(false);
+ let case = BenchCase::sort_partitioned(&data);
+ b.iter(move || case.run())
+ });
+ }
}
-/// Encapsulates running a test case where input partitioning is not preserved.
-struct SortBenchCase {
+/// Encapsulates running each test case
+struct BenchCase {
runtime: Runtime,
task_ctx: Arc<TaskContext>,
// The plan to run
plan: Arc<dyn ExecutionPlan>,
}
-impl SortBenchCase {
+impl BenchCase {
/// Prepare to run a benchmark that merges the specified
/// partitions (streams) together using all keyes
Review Comment:
```suggestion
/// pre-sorted partitions (streams) together using all keys
```
##########
datafusion/core/benches/sort.rs:
##########
@@ -210,58 +178,61 @@ impl SortBenchCase {
}
}
- /// runs the specified plan to completion, draining all input and
- /// panic'ing on error
- fn run(&self) {
- let plan = Arc::clone(&self.plan);
- let task_ctx = Arc::clone(&self.task_ctx);
+ fn sort_merge(partitions: &[Vec<RecordBatch>]) -> Self {
Review Comment:
```suggestion
/// Test SortExec in "partitioned" mode followed by a SortPreservingMerge
fn sort_merge(partitions: &[Vec<RecordBatch>]) -> Self {
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] tustvold commented on a diff in pull request #5881: More realistic sort benchmarks
Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold commented on code in PR #5881:
URL: https://github.com/apache/arrow-datafusion/pull/5881#discussion_r1159006238
##########
datafusion/core/benches/sort.rs:
##########
@@ -210,58 +178,61 @@ impl SortBenchCase {
}
}
- /// runs the specified plan to completion, draining all input and
- /// panic'ing on error
- fn run(&self) {
- let plan = Arc::clone(&self.plan);
- let task_ctx = Arc::clone(&self.task_ctx);
+ fn sort_merge(partitions: &[Vec<RecordBatch>]) -> Self {
+ let runtime = tokio::runtime::Builder::new_multi_thread().build().unwrap();
+ let session_ctx = SessionContext::new();
+ let task_ctx = session_ctx.task_ctx();
- assert_eq!(plan.output_partitioning().partition_count(), 1);
+ let schema = partitions[0][0].schema();
+ let sort = make_sort_exprs(schema.as_ref());
- self.runtime.block_on(async move {
- let mut stream = plan.execute(0, task_ctx).unwrap();
- while let Some(b) = stream.next().await {
- b.expect("unexpected execution error");
- }
- })
+ let exec = MemoryExec::try_new(partitions, schema, None).unwrap();
+ let exec =
+ SortExec::new_with_partitioning(sort.clone(), Arc::new(exec), true, None);
+ let plan = Arc::new(SortPreservingMergeExec::new(sort, Arc::new(exec)));
Review Comment:
Eventually yes, currently for single column cases it performs worse
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org