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

In-memory engine: add metrics for range count #16971

Merged
merged 6 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions Cargo.lock

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

23 changes: 21 additions & 2 deletions components/region_cache_memory_engine/src/background.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use crate::{
keys::{decode_key, encode_key, encoding_for_filter, InternalBytes, InternalKey, ValueType},
memory_controller::{MemoryController, MemoryUsage},
metrics::{
GC_FILTERED_STATIC, RANGE_CACHE_MEMORY_USAGE, RANGE_GC_TIME_HISTOGRAM,
GC_FILTERED_STATIC, RANGE_CACHE_COUNT, RANGE_CACHE_MEMORY_USAGE, RANGE_GC_TIME_HISTOGRAM,
RANGE_LOAD_TIME_HISTOGRAM,
},
range_manager::LoadFailedReason,
Expand Down Expand Up @@ -679,10 +679,29 @@ impl RunnableWithTimer for BackgroundRunner {
fn on_timeout(&mut self) {
let mem_usage = self.core.memory_controller.mem_usage();
RANGE_CACHE_MEMORY_USAGE.set(mem_usage as i64);

let core = self.core.engine.read();
let pending = core.range_manager.pending_ranges.len();
let cached = core.range_manager.ranges().len();
let loading = core.range_manager.pending_ranges_loading_data.len();
let evictions = core.range_manager.get_and_reset_range_evictions();
drop(core);
RANGE_CACHE_COUNT
.with_label_values(&["pending_range"])
.set(pending as i64);
RANGE_CACHE_COUNT
.with_label_values(&["cached_range"])
.set(cached as i64);
RANGE_CACHE_COUNT
.with_label_values(&["loading_range"])
.set(loading as i64);
RANGE_CACHE_COUNT
.with_label_values(&["range_evictions"])
.set(evictions as i64);
}

fn get_interval(&self) -> Duration {
Duration::from_secs(10)
Duration::from_secs(1)
}
}

Expand Down
6 changes: 6 additions & 0 deletions components/region_cache_memory_engine/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ lazy_static! {
exponential_buckets(0.00001, 2.0, 20).unwrap()
)
.unwrap();
pub static ref RANGE_CACHE_COUNT: IntGaugeVec = register_int_gauge_vec!(
"tikv_range_cache_count",
"The count of each type on range cache.",
&["type"]
)
.unwrap();
pub static ref IN_MEMORY_ENGINE_FLOW: IntCounterVec = register_int_counter_vec!(
"tikv_range_cache_memory_engine_flow",
"Bytes and keys of read/written of range cache memory engine",
Expand Down
12 changes: 10 additions & 2 deletions components/region_cache_memory_engine/src/range_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
use std::{
collections::{BTreeMap, BTreeSet, VecDeque},
result,
sync::Arc,
sync::{
atomic::{AtomicU64, Ordering},
Arc,
},
};

use engine_rocks::RocksSnapshot;
Expand Down Expand Up @@ -144,6 +147,7 @@ pub struct RangeManager {
pub(crate) pending_ranges_loading_data: VecDeque<(CacheRange, Arc<RocksSnapshot>, bool)>,

ranges_in_gc: BTreeSet<CacheRange>,
range_evictions: AtomicU64,
}

impl RangeManager {
Expand Down Expand Up @@ -314,7 +318,7 @@ impl RangeManager {
"range_start" => log_wrappers::Value(&evict_range.start),
"range_end" => log_wrappers::Value(&evict_range.end),
);

self.range_evictions.fetch_add(1, Ordering::Relaxed);
let meta = self.ranges.remove(&range_key).unwrap();
let (left_range, right_range) = range_key.split_off(evict_range);
assert!((left_range.is_some() || right_range.is_some()) || &range_key == evict_range);
Expand Down Expand Up @@ -377,6 +381,10 @@ impl RangeManager {
self.pending_ranges.push(cache_range);
Ok(())
}

pub fn get_and_reset_range_evictions(&self) -> u64 {
self.range_evictions.swap(0, Ordering::Relaxed)
}
}

#[derive(Debug, PartialEq)]
Expand Down
13 changes: 13 additions & 0 deletions metrics/grafana/tikv_details.dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -4116,6 +4116,19 @@ def RangeCacheMemoryEngine() -> RowPanel:
),
],
),
graph_panel(
title="Range Count",
description="The count of different types of range",
targets=[
target(
expr=expr_avg(
"tikv_range_cache_count",
by_labels=["instance", "type"],
),
legend_format="{{instance}}--{{type}}",
),
],
),
]
)
layout.row(
Expand Down
Loading