Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly record the rawBytesRead_ metric in TableScan #8147

Closed
wants to merge 2 commits into from

Conversation

JkSelf
Copy link
Collaborator

@JkSelf JkSelf commented Dec 21, 2023

Based on @oerling design:
rawBytesRead is the quantized size of data read by a query. Read is the volume copied from storage. The second is 0 if data comes from caches. With DirectBufferedInput these are close but then read has unused coalesced columns counted where raw read does not. A column can be coalesced into IO but never hit by the query due to filtering.

Currently, DirectBufferInput only tracks rawBytesRead in the loadSync method. It does not track rawBytesRead in the asynchronous loadData method. This PR adds the rawBytesRead metric to the loadData method.

Copy link

netlify bot commented Dec 21, 2023

Deploy Preview for meta-velox canceled.

Name Link
🔨 Latest commit c4b4e78
🔍 Latest deploy log https://app.netlify.com/sites/meta-velox/deploys/65b1f9afe9924f0008aac693

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Dec 21, 2023
@@ -274,6 +274,7 @@ std::vector<cache::CachePin> DirectCoalescedLoad::loadData(bool isPrefetch) {
}
input_->read(buffers, requests_[0].region.offset, LogType::FILE);
ioStats_->read().increment(size);
ioStats_->incRawBytesRead(size);

Choose a reason for hiding this comment

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

Looks it's a duplicated metric. Can we use ioStats_->Read instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@FelixYBW Yes, the duplicated metric has been removed. Additionally, the getCompletedBytes method in HiveDataSource has been updated to retrieve the ioStats_->read() metric instead of the rawBytesRead_ metric. Here is a detailed explanation of the changes #8147 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

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

@JkSelf do we want to increment incRawBytesRead here? From my discussion with @oerling, rawBytesRead counts the number of bytes read by query which shall only be incremented in loadSync? Thanks!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@xiaoxmeng Got it. Updated. Please help to review again. Thanks.

@JkSelf JkSelf changed the title Add the raw bytes read metric in scan Correctly record the rawInputBytes metric in TableScan Jan 4, 2024
@JkSelf JkSelf changed the title Correctly record the rawInputBytes metric in TableScan Correctly record the rawBytesRead_ metric in TableScan Jan 4, 2024
@JkSelf
Copy link
Collaborator Author

JkSelf commented Jan 4, 2024

@mbasmanova Can you help to review? Thanks.

@mbasmanova mbasmanova requested review from Yuhta and xiaoxmeng January 4, 2024 01:09
Copy link
Contributor

@mbasmanova mbasmanova left a comment

Choose a reason for hiding this comment

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

@Yuhta Jimmy, would you help review this PR?

CC: @oerling @xiaoxmeng

@FelixYBW
Copy link

FelixYBW commented Jan 4, 2024

Looks we still have two metrics used, like here. Should we unified to one metric? Or the two metrics count different thing?

ioStats_->incRawBytesRead(loadedRegion_.length);
auto ranges = makeRanges(loadedRegion_.length, data_, tinyData_);
uint64_t usecs = 0;
{
MicrosecondTimer timer(&usecs);
input_->read(ranges, loadedRegion_.offset, LogType::FILE);
}
ioStats_->read().increment(loadedRegion_.length);

@JkSelf
Copy link
Collaborator Author

JkSelf commented Jan 5, 2024

Looks we still have two metrics used, like here. Should we unified to one metric? Or the two metrics count different thing?

ioStats_->incRawBytesRead(loadedRegion_.length);
auto ranges = makeRanges(loadedRegion_.length, data_, tinyData_);
uint64_t usecs = 0;
{
MicrosecondTimer timer(&usecs);
input_->read(ranges, loadedRegion_.offset, LogType::FILE);
}
ioStats_->read().increment(loadedRegion_.length);

@FelixYBW It seems the value ioStats_->incRawBytesRead(loadedRegion_.length) and ioStats_->read().increment(loadedRegion_.length) are same. But i don't know why adding two metrics. @xiaoxmeng Do you have any input? Thanks.

Copy link
Contributor

@xiaoxmeng xiaoxmeng left a comment

Choose a reason for hiding this comment

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

@JkSelf LGTM. Thanks!

@JkSelf
Copy link
Collaborator Author

JkSelf commented Jan 9, 2024

@oerling You added the read_ metric to the IoStats class https://github.com/facebookincubator/velox/blob/main/velox/common/io/IoStatistics.h#L152. I noticed that there is also an incRawBytesRead_ metric. It appears that both metrics count the same value when collecting the metric data

ioStats_->incRawBytesRead(loadedRegion_.length);
auto ranges = makeRanges(loadedRegion_.length, data_, tinyData_);
uint64_t usecs = 0;
{
MicrosecondTimer timer(&usecs);
input_->read(ranges, loadedRegion_.offset, LogType::FILE);
}
ioStats_->read().increment(loadedRegion_.length);
. Could you provide some insight into the purpose or usage of these metrics? I would appreciate any input you have. Thank you

@JkSelf
Copy link
Collaborator Author

JkSelf commented Jan 9, 2024

@xiaoxmeng @mbasmanova Can you help to merge if no further comment? Thanks for your help

@facebook-github-bot
Copy link
Contributor

@xiaoxmeng has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@JkSelf
Copy link
Collaborator Author

JkSelf commented Jan 10, 2024

@xiaoxmeng @mbasmanova Can you help to merge? Thanks.

@xiaoxmeng
Copy link
Contributor

@oerling You added the read_ metric to the IoStats class https://github.com/facebookincubator/velox/blob/main/velox/common/io/IoStatistics.h#L152. I noticed that there is also an incRawBytesRead_ metric. It appears that both metrics count the same value when collecting the metric data

ioStats_->incRawBytesRead(loadedRegion_.length);
auto ranges = makeRanges(loadedRegion_.length, data_, tinyData_);
uint64_t usecs = 0;
{
MicrosecondTimer timer(&usecs);
input_->read(ranges, loadedRegion_.offset, LogType::FILE);
}
ioStats_->read().increment(loadedRegion_.length);

. Could you provide some insight into the purpose or usage of these metrics? I would appreciate any input you have. Thank you

@JkSelf I synced with @oerling offline and we might need to first make a refactor on our side about these different counters as these are also used by Meta internal projects. The meaning of these read counters are a bit different with and without cache and we will update with better documentation on these to avoid the confusion. Thanks!

@FelixYBW
Copy link

@oerling You added the read_ metric to the IoStats class https://github.com/facebookincubator/velox/blob/main/velox/common/io/IoStatistics.h#L152. I noticed that there is also an incRawBytesRead_ metric. It appears that both metrics count the same value when collecting the metric data

ioStats_->incRawBytesRead(loadedRegion_.length);
auto ranges = makeRanges(loadedRegion_.length, data_, tinyData_);
uint64_t usecs = 0;
{
MicrosecondTimer timer(&usecs);
input_->read(ranges, loadedRegion_.offset, LogType::FILE);
}
ioStats_->read().increment(loadedRegion_.length);

. Could you provide some insight into the purpose or usage of these metrics? I would appreciate any input you have. Thank you

@JkSelf I synced with @oerling offline and we might need to first make a refactor on our side about these different counters as these are also used by Meta internal projects. The meaning of these read counters are a bit different with and without cache and we will update with better documentation on these to avoid the confusion. Thanks!

From @oerling :
"rawBytesRead is the quantized size of data read by a query. Read is the volume copied from storage. The second is 0 if data comes from caches. With DirectBufferedInput these are close but then read has unused coalesced columns counted where raw read does not. A column can be coalesced into IO but never hit by the query due to filtering."

@JkSelf
Copy link
Collaborator Author

JkSelf commented Jan 10, 2024

@xiaoxmeng @FelixYBW Thank you for providing the crucial information. As said by @oerling, i think it is more accurate to use rawBytesRead instead of read() to represent the actual number of bytes read. What are your thoughts on this? I have made the change to rawBytesRead in the latest commit. Can you help to review? Thank you.

@JkSelf
Copy link
Collaborator Author

JkSelf commented Jan 11, 2024

@xiaoxmeng Do you have any further comment? Thanks.

@JkSelf
Copy link
Collaborator Author

JkSelf commented Jan 12, 2024

@xiaoxmeng Can you help to review again? Thanks.

@@ -274,6 +274,7 @@ std::vector<cache::CachePin> DirectCoalescedLoad::loadData(bool isPrefetch) {
}
input_->read(buffers, requests_[0].region.offset, LogType::FILE);
ioStats_->read().increment(size);
ioStats_->incRawBytesRead(size - overread);
Copy link
Contributor

Choose a reason for hiding this comment

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

@JkSelf Can you also fix this in DwioCoalescedLoadBase::updateStats? Thanks

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@Yuhta The rawBytesRead already updated in loadSync and loadData. It seems no need updated in DwioCoalescedLoadBase::updateStats.

Copy link
Contributor

Choose a reason for hiding this comment

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

Where is it updated in DwioCoalescedLoad::loadData and SsdLoad::loadData? I cannot find it

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have reviewed the code and found that the update of rawBytesRead for CachedInputBuffer is done in the loadSync function. loadSync is executed unconditionally after loadOrFuture here. However, in the case of DirectInputBuffer, the execution of loadSync is conditional here, so we need to update rawBytesRead in the loadData function instead.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@Yuhta Do you have any further comment? Thanks.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the explanation. Can you add comment to those 2 places saying the counter is increased in loadSync unconditionally so we don't need to do it in loadData?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@Yuhta Added the comments. Please help to review again. Thanks.

@facebook-github-bot
Copy link
Contributor

@xiaoxmeng has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@xiaoxmeng has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@xiaoxmeng merged this pull request in 6d2f0d4.

Copy link

Conbench analyzed the 1 benchmark run on commit 6d2f0d40.

There weren't enough matching historic benchmark results to make a call on whether there were regressions.

The full Conbench report has more details.

@facebook-github-bot
Copy link
Contributor

This pull request has been reverted by 0f96c1c.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged Reverted
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants