You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/01/04 15:13:17 UTC
[GitHub] [arrow-datafusion] ic4y opened a new pull request #1520: use bumpalo for GroupState
ic4y opened a new pull request #1520:
URL: https://github.com/apache/arrow-datafusion/pull/1520
# Which issue does this PR close?
Closes #1504
<!--
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.
-->
# Rationale for this change
Using bumpalo to allocate GroupState to a chunk of memory as much as possible
<!--
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.
-->
# Are there any user-facing changes?
Nothing
<!--
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] hntd187 commented on a change in pull request #1520: use bumpalo for GroupState
Posted by GitBox <gi...@apache.org>.
hntd187 commented on a change in pull request #1520:
URL: https://github.com/apache/arrow-datafusion/pull/1520#discussion_r778340393
##########
File path: datafusion/src/physical_plan/hash_aggregate.rs
##########
@@ -610,10 +615,14 @@ struct Accumulators {
map: RawTable<(u64, usize)>,
/// State for each group
- group_states: Vec<GroupState>,
+ //group_states: Vec<GroupState>,
+ group_states: BumpVec<'a, GroupState>,
}
-impl std::fmt::Debug for Accumulators {
+// will not be used multiple async, so Accumulators is Send
+unsafe impl Send for Accumulators<'_> {}
Review comment:
If it's not used why does it need to be `Send`? I personally prefer no unsafe, does this work without it?
--
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] ic4y commented on a change in pull request #1520: use bumpalo for GroupState
Posted by GitBox <gi...@apache.org>.
ic4y commented on a change in pull request #1520:
URL: https://github.com/apache/arrow-datafusion/pull/1520#discussion_r778516821
##########
File path: datafusion/src/physical_plan/hash_aggregate.rs
##########
@@ -610,10 +615,14 @@ struct Accumulators {
map: RawTable<(u64, usize)>,
/// State for each group
- group_states: Vec<GroupState>,
+ //group_states: Vec<GroupState>,
+ group_states: BumpVec<'a, GroupState>,
}
-impl std::fmt::Debug for Accumulators {
+// will not be used multiple async, so Accumulators is Send
+unsafe impl Send for Accumulators<'_> {}
Review comment:
This doesn't work. because accumulators holds `bump` for use in async func. async func requires `send`, but bump is `ref` not `send`.
--
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] ic4y closed pull request #1520: use bumpalo for GroupState
Posted by GitBox <gi...@apache.org>.
ic4y closed pull request #1520:
URL: https://github.com/apache/arrow-datafusion/pull/1520
--
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] ic4y commented on pull request #1520: use bumpalo for GroupState
Posted by GitBox <gi...@apache.org>.
ic4y commented on pull request #1520:
URL: https://github.com/apache/arrow-datafusion/pull/1520#issuecomment-1004941980
From
```rust
struct Accumulators {
map: RawTable<(u64, usize)>,
group_states: Vec<GroupState>,
}
```
To
```rust
struct Accumulators {
map: RawTable<(u64, usize)>,
group_states:BumpVec<GroupState>,
}
```
By using bumpalo to allocate memory for group_states, the time to destruct group_states can be greatly reduced in the case of high cardinality, and the time consumption of destructuring group_states is almost not counted in pprf
The total test data is 350 million, and the deduplication number of user_id is 50 million。
`sql : select count(1) from (select user_id from event group by user_id)a`
**master:**
drop_in_place<GroupState> takes 6s(50%) ,total 14s

**bumpalo:**
drop_in_place<GroupState> takes 0s(not counted) ,total 8s(40% increase)

Under the TPC-H benchmark test, there is almost no difference. I think the reason is that the grouping base is not high enough.

--
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] ic4y commented on pull request #1520: use bumpalo for GroupState
Posted by GitBox <gi...@apache.org>.
ic4y commented on pull request #1520:
URL: https://github.com/apache/arrow-datafusion/pull/1520#issuecomment-1005596623
@alamb Sorry, there are three problems now
1. 3.8.0 version of BumpVec does not implement the Drop trait, so the GroupState is not really freed and there will be a memory leak problem. So the above test results are not accurate.
2. The direct use of BumpVec does not assign the GroupState to bump arena, the allocation is only the GroupState reference
3. On MacOs, there is the problem that drop_in_place takes up a lot of time.However, I tested on linux and didn't find this problem.
I’m not familiar with bumpalo yet, but I’m trying to solve these problems.
--
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 pull request #1520: use bumpalo for GroupState
Posted by GitBox <gi...@apache.org>.
alamb commented on pull request #1520:
URL: https://github.com/apache/arrow-datafusion/pull/1520#issuecomment-1005634682
It is fascinating that calling the `Drop` function for `GroupState` consumes so much time in your profile.
```rust
/// The state that is built for each output group.
#[derive(Debug)]
struct GroupState {
/// The actual group by values, one for each group column
group_by_values: Box<[ScalarValue]>,
// Accumulator state, one for each aggregate
accumulator_set: Vec<AccumulatorItem>,
/// scratch space used to collect indices for input rows in a
/// bach that have values to aggregate. Reset on each batch
indices: Vec<u32>,
}
```
One way you could confirm it is the actual time required to call `Drop` is using code like this to temporarily skip the drops and see if it goes faster:
```rust
impl Drop for GroupState {
fn drop(&mut self) {
// Test out skipping running `drop` on the different fields
// to confirm calling their `Drop` is taking a long time
// Note this LEAKS memory!
let t = std::mem::replace(&mut self.group_by_values, Box::new([]));
std::mem::forget(t);
let t = std::mem::replace(&mut self.accumulator_set, vec![]);
std::mem::forget(t);
let t = std::mem::replace(&mut self.indices, vec![]);
std::mem::forget(t);
}
}
```
--
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] ic4y commented on pull request #1520: use bumpalo for GroupState
Posted by GitBox <gi...@apache.org>.
ic4y commented on pull request #1520:
URL: https://github.com/apache/arrow-datafusion/pull/1520#issuecomment-1006702019
@alamb Thank you, I tried your method, and the `Drop` does consumes so much time.
But I added the following to the code (this is mentioned in the [user guide](https://github.com/apache/arrow-datafusion/blob/ecb09d9e37a4ea8f06d145c4fdcbdb3b8bb64ab7/docs/source/user-guide/library.md))
```rust
#[global_allocator]
static ALLOC: snmalloc_rs::SnMalloc = snmalloc_rs::SnMalloc;
```
It seems that using SnMalloc memory allocator solved this problem, and the time of `Drop` almost disappears.
So use bumpalo for GroupState is currently meaningless, this problem can be solved by SnMalloc.
Thanks again @alamb for helping me,then I will close this pr
--
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