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

feat(stats): introduce block efficiency metrics #14654

Merged
merged 12 commits into from
Jan 23, 2024
Merged

feat(stats): introduce block efficiency metrics #14654

merged 12 commits into from
Jan 23, 2024

Conversation

MrCroxx
Copy link
Contributor

@MrCroxx MrCroxx commented Jan 18, 2024

I hereby agree to the terms of the RisingWave Labs, Inc. Contributor License Agreement.

What's changed and what's your intention?

Introduce block efficiency metrics to track the ratio of how much a block is read from between loading and eviction from the block cache by table id.

image

Checklist

  • I have written necessary rustdoc comments
  • I have added necessary unit tests and integration tests
  • I have added test labels as necessary. See details.
  • I have added fuzzing tests or opened an issue to track them. (Optional, recommended for new SQL features Sqlsmith: Sql feature generation #7934).
  • My PR contains breaking changes. (If it deprecates some features, please create a tracking issue to remove them in the future).
  • All checks passed in ./risedev check (or alias, ./risedev c)
  • My PR changes performance-critical code. (Please run macro/micro-benchmarks and show the results.)
  • My PR contains critical fixes that are necessary to be merged into the latest release. (Please check out the details)

Documentation

  • My PR needs documentation updates. (Please use the Release note section below to summarize the impact on users)

Release note

If this PR includes changes that directly affect users or other significant modifications relevant to the community, kindly draft a release note to provide a concise summary of these changes. Please prioritize highlighting the impact these changes will have on users.

@MrCroxx MrCroxx self-assigned this Jan 19, 2024
@MrCroxx MrCroxx marked this pull request as ready for review January 19, 2024 07:47
@MrCroxx MrCroxx requested a review from wenym1 January 19, 2024 08:28
src/storage/src/hummock/sstable/block.rs Outdated Show resolved Hide resolved
src/storage/src/hummock/sstable/block.rs Outdated Show resolved Hide resolved
src/storage/src/hummock/sstable/block.rs Outdated Show resolved Hide resolved
src/common/src/range.rs Outdated Show resolved Hide resolved
src/storage/src/hummock/sstable/block.rs Outdated Show resolved Hide resolved
- local hitmap is updated when iter
- global hitmap is updated when local hitmap drops
- metrics is updated when block is evicted from block cache

Signed-off-by: MrCroxx <[email protected]>
Signed-off-by: MrCroxx <[email protected]>
Copy link
Contributor

@wenym1 wenym1 left a comment

Choose a reason for hiding this comment

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

Rest LGTM.

}
}

pub fn fill(&mut self, start_bit: usize, end_bit: usize) {
Copy link
Contributor

Choose a reason for hiding this comment

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

fill of LocalHitmap and Hitmap is basically the same. Is it possible to unify their code in a macro or generic method?

Or do you have any usage of fill of Hitmap? If you only use the fill of LocalHitmap, we may only keep the fill of LocalHitmap.

src/storage/src/monitor/hitmap.rs Outdated Show resolved Hide resolved
pub fn slice(&self, range: impl RangeBounds<usize>) -> &[u8] {
let start = range.start().unwrap_or_default();
let end = range.end().unwrap_or(self.data_len);
&self.data[start..end]
Copy link
Contributor

Choose a reason for hiding this comment

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

Shall we forward the idx range to slice directly just like how we originally use the range?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't found any function of slice that receives a impl RangeBounds<usize> to forward it directly. I'll restore the function to fn data(&self) -> &[u8] as it does include any other operations any more.


self.value_range = prefix.value_range();
self.offset = offset;
self.entry_len = prefix.entry_len();

self.hitmap.fill_with_ratio(
Copy link
Contributor

Choose a reason for hiding this comment

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

May use fraction instead of f64, or we pass (start, end, len) of usize. May increase unnecessary cost on floating point computation for each key.

@MrCroxx MrCroxx requested a review from wenym1 January 23, 2024 08:57
Copy link
Contributor

@wenym1 wenym1 left a comment

Choose a reason for hiding this comment

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

Rest LGTM!

pub fn fill(&mut self, start_bit: usize, end_bit: usize) {
const MASK: usize = (1 << 6) - 1;

let end_bit = std::cmp::min(end_bit, Self::bits());
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we compare end_bit with Self::bits()-1 if end_bit is inclusive?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

end_bit is exclusive.

let head_elem = start_bit >> 6;
let tail_elem = end_bit >> 6;

for i in head_elem..=std::cmp::min(tail_elem, N - 1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this cmp necessary if we have compared end_bit and Self::bits?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For end_bit is exclusive, the comparison is needed here.

@MrCroxx MrCroxx added this pull request to the merge queue Jan 23, 2024
Copy link
Collaborator

@hzxa21 hzxa21 left a comment

Choose a reason for hiding this comment

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

LSTM

Merged via the queue into main with commit 2e16c26 Jan 23, 2024
30 of 31 checks passed
@MrCroxx MrCroxx deleted the xx/statistics branch January 23, 2024 10:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants