Skip to content

minor: SortExec measure elapsed_compute time when sorting#12099

Merged
alamb merged 2 commits intoapache:mainfrom
mhilton:sort-exec-elapsed-compute
Aug 22, 2024
Merged

minor: SortExec measure elapsed_compute time when sorting#12099
alamb merged 2 commits intoapache:mainfrom
mhilton:sort-exec-elapsed-compute

Conversation

@mhilton
Copy link
Copy Markdown
Contributor

@mhilton mhilton commented Aug 21, 2024

Whilst investigating query execution performance I noticed that some SortExec nodes were reporting suspiciously short elapsed_compute times. It appears that the SortExec node wasn't running the elapsed_compute timer when it doing the actual sorting operation.

Which issue does this PR close?

Closes #.

Rationale for this change

What changes are included in this PR?

Are these changes tested?

Are there any user-facing changes?

Whilst investigating query execution performance I noticed that
some SortExec nodes were reporting suspiciously short elapsed_compute
times. It appears that the SortExec node wasn't running the
elapsed_compute timer when it doing the actual sorting operation.
@github-actions github-actions Bot added the physical-expr Changes to the physical-expr crates label Aug 21, 2024
Copy link
Copy Markdown
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 @mhilton -- I think this PR is good and an improvement over the current state of affairs and could be merged as is

However I think there are other potential places that the CPU is not accounted for either that we may want to investigate

let fetch = self.fetch;
let expressions = Arc::clone(&self.expr);
let stream = futures::stream::once(futures::future::lazy(move |_| {
let timer = metrics.elapsed_compute().timer();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I looked at the rest of this code, and I think there are other non trivial consumers of compute (e.g. the call to concat_batches above)

What I would recommend is moving this timer up into the SortExec::in_mem_sort and add one in SortExec::in_mem_sort_stream

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I did double check and the streaming_merge code does seem to track elapsed compute reasonably:

// NB timer records time taken on drop, so there are no
// calls to `timer.done()` below.
let elapsed_compute = self.metrics.elapsed_compute().clone();
let _timer = elapsed_compute.timer();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Where I have put the timer is part of the stream, so would not execute until the stream is polled, that means it wouldn't be tracked if the timer was moved to in_mem_sort_stream. I agree there should probably be another one there too though. in_mem_sort looks to be reasonably trivial to me, but I could add timers in the non-async blocks too if you think it's worthwhile.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah, I think I missed the fact the timer is in the future 👍

Copy link
Copy Markdown
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 again @mhilton

let fetch = self.fetch;
let expressions = Arc::clone(&self.expr);
let stream = futures::stream::once(futures::future::lazy(move |_| {
let timer = metrics.elapsed_compute().timer();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah, I think I missed the fact the timer is in the future 👍

@alamb alamb merged commit 41e7378 into apache:main Aug 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

physical-expr Changes to the physical-expr crates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants