Skip to content
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
1 change: 1 addition & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions data_plane/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ asap-planner.workspace = true
asap-executor.workspace = true
asap_sketchlib.workspace = true
serde_bytes = "0.11"
# Each view fragment is compressed (segment.rs).
zstd = "0.13"
ahash = "0.8"
# The per-thread series cache of the Remote Write decoder (a table of
# indices hashed by the keys they point to).
Expand Down
67 changes: 50 additions & 17 deletions data_plane/examples/view_read_bench.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
//! Cold view reads, `mmap` versus `pread` (docs/design/tiered-view-storage.md,
//! B3): writes `WINDOWS` windows of `SERIES` rows of one view (KLL states of
//! `SAMPLES` samples each, a series identity and a value) to a segment,
//! seals it, then decodes every window both ways, with the page cache warm
//! and after dropping it, and prints ns per window and per row, and the
//! process's `RssAnon`/`RssFile`.
//! B3): writes `WINDOWS` windows of `SERIES` rows of one view (states of
//! `SAMPLES` samples each of `FAMILY`, `kll` (default), `ddsketch` (alpha
//! 0.02) or `counter` (exact); a series identity and a value) to a
//! segment, timing the writes, seals it, then decodes every window both
//! ways, with the page cache warm and after dropping it, and prints ns per
//! window and per row, and the process's `RssAnon`/`RssFile`.
//!
//! `cargo run --release -p data_plane --example view_read_bench -- [SERIES] [WINDOWS] [SAMPLES] [DIR]`
//! `cargo run --release -p data_plane --example view_read_bench -- [SERIES] [WINDOWS] [SAMPLES] [DIR] [FAMILY]`

#[global_allocator]
static ALLOCATOR: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
Expand All @@ -17,8 +18,9 @@ use std::time::{Duration, Instant};
use asap_executor::planner::ir::schema::{
DataType, Field, FieldDataType, Schema, PROMQL_SERIES_IDENTITY,
};
use asap_executor::planner::summary_type::SketchAlgorithm;
use asap_executor::summary_kernels::DatasketchesKLLAccumulator;
use asap_executor::planner::summary_type::{ExactKind, ExactParams, SketchAlgorithm};
use asap_executor::summary_kernels::exact::ExactAccumulator;
use asap_executor::summary_kernels::{DDSketchAccumulator, DatasketchesKLLAccumulator};
use asap_executor::values::{Batch, Value};
use asap_executor::AggregateCore;
use data_plane::persist::{ViewFiles, ViewRead};
Expand All @@ -29,9 +31,15 @@ fn main() {
let windows: i64 = args.get(2).map_or(40, |a| a.parse().unwrap());
let samples: usize = args.get(3).map_or(15, |a| a.parse().unwrap());
let dir = PathBuf::from(args.get(4).map_or("view-read-bench", String::as_str));
let family_name = args.get(5).map_or("kll", String::as_str);
let _ = std::fs::remove_dir_all(&dir);

let family = FieldDataType::Sketch(SketchAlgorithm::Kll);
let family = match family_name {
"kll" => FieldDataType::Sketch(SketchAlgorithm::Kll),
"ddsketch" => FieldDataType::Sketch(SketchAlgorithm::DDSketch),
"counter" => FieldDataType::ExactAggregate(ExactKind::Counter, ExactParams::Counter),
other => panic!("unknown family {other}: kll, ddsketch or counter"),
};
let schema = Arc::new(Schema::with_time_index(
vec![
Field::plain("ts", DataType::Timestamp, false),
Expand All @@ -44,14 +52,35 @@ fn main() {
));
let mut files = ViewFiles::open(&dir, 1, Duration::from_secs(5)).unwrap();
let mut locations = Vec::new();
let mut write = Duration::ZERO;
for window in 0..windows {
let end = (window + 1) * 15_000;
let rows = (0..series)
.map(|s| {
let mut kll = DatasketchesKLLAccumulator::new(132);
for i in 0..samples {
kll.update(((s * 31 + i * 7 + window as usize) % 1000) as f64);
}
let sample = |i: usize| ((s * 31 + i * 7 + window as usize) % 1000) as f64;
let state: Arc<dyn AggregateCore> = match family_name {
"kll" => {
let mut kll = DatasketchesKLLAccumulator::new(132);
(0..samples).for_each(|i| kll.update(sample(i)));
Arc::new(kll)
}
"ddsketch" => {
let mut dd = asap_sketchlib::DdSketch::new(0.02);
(0..samples).for_each(|i| dd.add(&sample(i)));
Arc::new(DDSketchAccumulator::restore_from_disk(dd).unwrap())
}
_ => {
let mut counter = ExactAccumulator::new(family.clone(), false).unwrap();
(0..samples).for_each(|i| {
counter.update(
None,
(window as usize * samples + i) as f64,
end - 15_000 + i as i64 * 100,
)
});
Arc::new(counter)
}
};
vec![
Value::Timestamp(end),
Value::Utf8(
Expand All @@ -64,15 +93,17 @@ fn main() {
Value::Float64(s as f64),
Value::Summary {
family: family.clone(),
state: Arc::new(kll) as Arc<dyn AggregateCore>,
state,
},
]
})
.collect();
let batch = Batch::try_new(schema.clone(), rows).unwrap();
let started = Instant::now();
let written = files
.append(0, (end - 15_000, end), &[(1, std::slice::from_ref(&batch))])
.unwrap();
write += started.elapsed();
let location = written
.locations
.into_iter()
Expand All @@ -84,8 +115,10 @@ fn main() {
files.seal(0).unwrap();
let bytes: u64 = locations.iter().map(|l| u64::from(l.len())).sum();
println!(
"{windows} windows x {series} rows, {samples} samples per KLL: {:.1} MiB of fragments",
bytes as f64 / 1048576.0
"{windows} windows x {series} rows, {samples} samples per {family_name} state: {:.1} MiB of fragments, {:.1} B per row; write {:.0} ns per row",
bytes as f64 / 1048576.0,
bytes as f64 / (windows as f64 * series as f64),
write.as_nanos() as f64 / (windows as f64 * series as f64)
);
// pread first: a mapped page cannot be dropped from the page cache.
for how in [ViewRead::Pread, ViewRead::Mmap] {
Expand All @@ -95,7 +128,7 @@ fn main() {
}
let started = Instant::now();
for location in &locations {
std::hint::black_box(location.read(&schema, how).unwrap());
std::hint::black_box(location.read(&schema, how).unwrap().0);
}
let ns = started.elapsed().as_nanos() as f64;
println!(
Expand Down
7 changes: 5 additions & 2 deletions data_plane/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub mod remote_write;
pub mod result_cache;
pub mod segment;
pub mod series_ids;
mod state_codec;
pub mod store;
pub mod window_cache;

Expand Down Expand Up @@ -266,7 +267,9 @@ async fn query(
let instant = match InstantQuery::parse(query.0.as_deref(), &body) {
Ok(Some(instant)) => instant,
Ok(None) if state.no_forward => {
return not_answered("the request has no query parameter");
return not_answered(
"the request has no query parameter, or names Prometheus' min or max time",
);
}
Ok(None) => return forward(state, "query", method, query, headers, body).await,
Err(bad) => {
Expand Down Expand Up @@ -322,7 +325,7 @@ async fn query_range(
Ok(Some(range)) => range,
Ok(None) if state.no_forward => {
return not_answered(
"the request lacks query, start, end or step, or names a time that is not in Unix seconds",
"the request lacks query, start, end or step, or names Prometheus' min or max time",
);
}
Ok(None) => return forward(state, "query_range", method, query, headers, body).await,
Expand Down
Loading
Loading