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(storage): monitor avg_key_size and avg_epoch_count #8297

Merged
merged 8 commits into from
Mar 9, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions dashboard/proto/gen/hummock.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion grafana/risingwave-dashboard.dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ def section_compaction(outer_panels):
"Total bytes gotten from sstable_avg_key_size, for observing sstable_avg_key_size",
[
panels.target(
f"sum by(le, job, instance)(rate({metric('compactor_sstable_avg_key_size_sum')}[$__rate_interval])) / sum by(le, job, instance)(rate({metric('state_store_sstable_avg_key_size_count')}[$__rate_interval]))",
f"sum by(le, job, instance)(rate({metric('compactor_sstable_avg_key_size_sum')}[$__rate_interval])) / sum by(le, job, instance)(rate({metric('compactor_sstable_avg_key_size_count')}[$__rate_interval]))",
"avg_key_size - {{job}} @ {{instance}}",
),
panels.target(
Expand All @@ -778,6 +778,17 @@ def section_compaction(outer_panels):
],
),

panels.timeseries_count(
"Hummock Sstable Stat",
"Avg count gotten from sstable_avg_epoch_count, for observing sstable_avg_epoch_count",
[
panels.target(
f"sum by(le, job, instance)(rate({metric('compactor_sstable_avg_epoch_count_sum')}[$__rate_interval])) / sum by(le, job, instance)(rate({metric('compactor_sstable_avg_epoch_count_count')}[$__rate_interval]))",
"avg_epoch_count - {{job}} @ {{instance}}",
),
],
),

panels.timeseries_latency(
"Hummock Remote Read Duration",
"Total time of operations which read from remote storage when enable prefetch",
Expand Down
2 changes: 1 addition & 1 deletion grafana/risingwave-dashboard.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions proto/hummock.proto
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ message SstableInfo {
uint64 min_epoch = 9;
uint64 max_epoch = 10;
uint64 uncompressed_file_size = 11;

// Used to estimate the size of the newly generated sst key size
uint32 avg_key_size = 12;
}

enum LevelType {
Expand Down
2 changes: 2 additions & 0 deletions src/meta/src/hummock/compaction/level_selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,7 @@ pub mod tests {
uncompressed_file_size: (right - left + 1) as u64,
min_epoch: 0,
max_epoch: 0,
avg_key_size: 0,
}
}

Expand Down Expand Up @@ -628,6 +629,7 @@ pub mod tests {
uncompressed_file_size: (right - left + 1) as u64,
min_epoch,
max_epoch,
avg_key_size: 0,
}
}

Expand Down
1 change: 1 addition & 0 deletions src/meta/src/hummock/compaction_schedule_policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ mod tests {
uncompressed_file_size: input_file_size,
min_epoch: 0,
max_epoch: 0,
avg_key_size: 0,
}],
}],
splits: vec![],
Expand Down
1 change: 1 addition & 0 deletions src/meta/src/hummock/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ pub fn generate_test_tables(epoch: u64, sst_ids: Vec<HummockSstableId>) -> Vec<S
uncompressed_file_size: 2,
min_epoch: 0,
max_epoch: 0,
avg_key_size: 0,
});
}
sst_info
Expand Down
2 changes: 2 additions & 0 deletions src/storage/hummock_test/src/hummock_read_version_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ async fn test_read_version_basic() {
uncompressed_file_size: 1,
min_epoch: 0,
max_epoch: 0,
avg_key_size: 0,
}),
LocalSstableInfo::for_test(SstableInfo {
id: 2,
Expand All @@ -178,6 +179,7 @@ async fn test_read_version_basic() {
uncompressed_file_size: 1,
min_epoch: 0,
max_epoch: 0,
avg_key_size: 0,
}),
],
epoch_id_vec_for_clear,
Expand Down
1 change: 1 addition & 0 deletions src/storage/src/hummock/event_handler/uploader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,7 @@ mod tests {
uncompressed_file_size: 0,
min_epoch: 0,
max_epoch: 0,
avg_key_size: 0,
})]
}

Expand Down
85 changes: 56 additions & 29 deletions src/storage/src/hummock/sstable/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ pub struct SstableBuilderOutput<WO> {
pub writer_output: WO,
pub avg_key_size: usize,
pub avg_value_size: usize,
pub epoch_count: usize,
}

pub struct SstableBuilder<W: SstableWriter, F: FilterBuilder> {
Expand Down Expand Up @@ -119,8 +120,7 @@ pub struct SstableBuilder<W: SstableWriter, F: FilterBuilder> {

filter_builder: F,

min_epoch: u64,
max_epoch: u64,
epoch_set: BTreeSet<u64>,
}

impl<W: SstableWriter> SstableBuilder<W, XorFilterBuilder> {
Expand Down Expand Up @@ -168,8 +168,7 @@ impl<W: SstableWriter, F: FilterBuilder> SstableBuilder<W, F> {
total_key_count: 0,
table_stats: Default::default(),
last_table_stats: Default::default(),
min_epoch: u64::MAX,
max_epoch: u64::MIN,
epoch_set: BTreeSet::default(),
}
}

Expand Down Expand Up @@ -238,6 +237,8 @@ impl<W: SstableWriter, F: FilterBuilder> SstableBuilder<W, F> {
self.total_key_count += 1;
self.last_table_stats.total_key_count += 1;

self.epoch_set.insert(full_key.epoch);

if is_new_table && !self.block_builder.is_empty() {
self.build_block().await?;
}
Expand All @@ -263,9 +264,6 @@ impl<W: SstableWriter, F: FilterBuilder> SstableBuilder<W, F> {
self.raw_key.clear();
self.raw_value.clear();

self.min_epoch = cmp::min(self.min_epoch, full_key.epoch);
self.max_epoch = cmp::max(self.max_epoch, full_key.epoch);

if self.block_builder.approximate_len() >= self.options.block_capacity {
self.build_block().await?;
}
Expand Down Expand Up @@ -363,6 +361,48 @@ impl<W: SstableWriter, F: FilterBuilder> SstableBuilder<W, F> {
(tombstone_min_epoch, tombstone_max_epoch)
};

let (avg_key_size, avg_value_size) = if self.table_stats.is_empty() {
(0, 0)
} else {
let total_key_count: usize = self
.table_stats
.values()
.map(|s| s.total_key_count as usize)
.sum();

if total_key_count == 0 {
(0, 0)
} else {
let total_key_size: usize = self
.table_stats
.values()
.map(|s| s.total_key_size as usize)
.sum();

let total_value_size: usize = self
.table_stats
.values()
.map(|s| s.total_value_size as usize)
.sum();

(
total_key_size / total_key_count,
total_value_size / total_key_count,
)
}
};

let (min_epoch, max_epoch) = {
if self.epoch_set.is_empty() {
(u64::MAX, u64::MIN)
} else {
(
*self.epoch_set.first().unwrap(),
*self.epoch_set.last().unwrap(),
)
}
};

let sst_info = SstableInfo {
id: self.sstable_id,
key_range: Some(risingwave_pb::hummock::KeyRange {
Expand All @@ -377,43 +417,30 @@ impl<W: SstableWriter, F: FilterBuilder> SstableBuilder<W, F> {
total_key_count: self.total_key_count,
divide_version: 0,
uncompressed_file_size: uncompressed_file_size + meta.encoded_size() as u64,
min_epoch: cmp::min(self.min_epoch, tombstone_min_epoch),
max_epoch: cmp::max(self.max_epoch, tombstone_max_epoch),
min_epoch: cmp::min(min_epoch, tombstone_min_epoch),
max_epoch: cmp::max(max_epoch, tombstone_max_epoch),
avg_key_size: avg_key_size as u32,
};
tracing::trace!(
"meta_size {} bloom_filter_size {} add_key_counts {} stale_key_count {} min_epoch {} max_epoch {}",
"meta_size {} bloom_filter_size {} add_key_counts {} stale_key_count {} min_epoch {} max_epoch {} epoch_count {}",
meta.encoded_size(),
meta.bloom_filter.len(),
self.total_key_count,
self.stale_key_count,
self.min_epoch,
self.max_epoch,
min_epoch,
max_epoch,
self.epoch_set.len()
);
let bloom_filter_size = meta.bloom_filter.len();
let (avg_key_size, avg_value_size) = if self.table_stats.is_empty() {
(0, 0)
} else {
let avg_key_size = self
.table_stats
.values()
.map(|s| s.total_key_size as usize)
.sum::<usize>()
/ self.table_stats.len();
let avg_value_size = self
.table_stats
.values()
.map(|s| s.total_value_size as usize)
.sum::<usize>()
/ self.table_stats.len();
(avg_key_size, avg_value_size)
};

let writer_output = self.writer.finish(meta).await?;
Ok(SstableBuilderOutput::<W::Output> {
sst_info: LocalSstableInfo::with_stats(sst_info, self.table_stats),
bloom_filter_size,
writer_output,
avg_key_size,
avg_value_size,
epoch_count: self.epoch_set.len(),
})
}

Expand Down
1 change: 1 addition & 0 deletions src/storage/src/hummock/sstable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ impl Sstable {
uncompressed_file_size: self.meta.estimated_size as u64,
min_epoch: 0,
max_epoch: 0,
avg_key_size: 0,
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/storage/src/hummock/sstable/multi_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,12 @@ where
.sstable_avg_value_size
.observe(builder_output.avg_value_size as _);
}

if builder_output.epoch_count != 0 {
self.compactor_metrics
.sstable_avg_epoch_count
.observe(builder_output.epoch_count as _);
}
}
self.sst_outputs.push(SplitTableOutput {
upload_join_handle: builder_output.writer_output,
Expand Down
2 changes: 2 additions & 0 deletions src/storage/src/hummock/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ pub fn gen_dummy_sst_info(
uncompressed_file_size: file_size,
min_epoch: 0,
max_epoch: 0,
avg_key_size: 0,
}
}

Expand Down Expand Up @@ -188,6 +189,7 @@ pub async fn put_sst(
uncompressed_file_size: meta.estimated_size as u64,
min_epoch: 0,
max_epoch: 0,
avg_key_size: 0,
};
let writer_output = writer.finish(meta).await?;
writer_output.await.unwrap()?;
Expand Down
12 changes: 11 additions & 1 deletion src/storage/src/monitor/compactor_metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ pub struct CompactorMetrics {
pub sstable_avg_value_size: Histogram,
pub iter_scan_key_counts: GenericCounterVec<AtomicU64>,
pub write_build_l0_bytes: GenericCounter<AtomicU64>,
pub sstable_avg_epoch_count: Histogram,
}

impl CompactorMetrics {
Expand Down Expand Up @@ -171,7 +172,7 @@ impl CompactorMetrics {
let opts = histogram_opts!(
"compactor_sstable_avg_value_size",
"Total bytes gotten from sstable_avg_value_size, for observing sstable_avg_value_size",
exponential_buckets(1.0, 2.0, 25).unwrap() // max 16MB
exponential_buckets(1.0, 2.0, 26).unwrap() // max 32MB
);

let sstable_avg_value_size = register_histogram_with_registry!(opts, registry).unwrap();
Expand All @@ -198,6 +199,14 @@ impl CompactorMetrics {
registry
).unwrap();

let opts = histogram_opts!(
"compactor_sstable_avg_epoch_count",
"Total number gotten from sstable_avg_epoch_count, for observing sstable_avg_epoch_count",
exponential_buckets(1.0, 2.0, 17).unwrap()
);

let sstable_avg_epoch_count = register_histogram_with_registry!(opts, registry).unwrap();

Self {
compaction_upload_sst_counts,
compact_write_bytes,
Expand All @@ -219,6 +228,7 @@ impl CompactorMetrics {
sstable_avg_value_size,
iter_scan_key_counts,
write_build_l0_bytes,
sstable_avg_epoch_count,
}
}

Expand Down