Skip to content
Draft
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
2 changes: 1 addition & 1 deletion .github/workflows/mvp-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:

- name: Check workspace formatting
working-directory: ASAPQuery-backend
run: cargo fmt -p control_plane -p data_plane -- --check
run: cargo fmt --all -- --check

- name: Check workspace
env:
Expand Down
31 changes: 28 additions & 3 deletions Cargo.lock

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

9 changes: 8 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
[workspace]
resolver = "2"
members = ["crates/control-plane", "crates/data-plane"]
members = [
"crates/control-plane",
"crates/data-plane",
"crates/internal-metrics",
"crates/storage",
]

[workspace.package]
edition = "2021"
Expand Down Expand Up @@ -30,6 +35,8 @@ tokio = { version = "1.0", features = ["full"] }
axum = "0.7"
reqwest = { version = "0.12", default-features = false, features = ["json", "rustls-tls"] }
control_plane = { path = "crates/control-plane" }
internal_metrics = { path = "crates/internal-metrics" }
storage = { path = "crates/storage" }

# asap_sketchlib#271's head, ahead of the Planner's pin (389530c): DDSketch
# view merges in place, with width-specialized loops (a 1 h quantile over
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ not stored) with a Prometheus `execution` error (422,
|---|---|
| `crates/control-plane/` | package `control_plane`: workload → `asap-planner` → plan file |
| `crates/data-plane/` | package `data_plane`: the data plane and its binary |
| `crates/storage/` | package `storage`: raw samples and views in memory, the view cache, segments and persistence |
| `crates/internal-metrics/` | package `internal_metrics`: the backend's measurements of itself, exported on `/metrics` |
| `benchmarks/` | the backend alone: `micro/` benchmarks (examples of `data_plane`) and `scripts/` |
| `eval/` | comparisons with other systems and the live demo; see [eval/README.md](eval/README.md) |
| `deployment/monitoring/` | Prometheus, exporters and Grafana for the demo and the comparisons |
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/micro/ingest_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ use axum::http::{Request, StatusCode};
use control_plane::{plan_workload, DeploymentInputs};
use data_plane::engine::{EngineOptions, PrecomputeMode};
use data_plane::ingestion::IngestionOptions;
use data_plane::metrics::thread_cpu_seconds;
use data_plane::remote_write::{encode, Label, Sample, TimeSeries, WriteRequest};
use data_plane::{router, DataPlane};
use internal_metrics::thread_cpu_seconds;
use tower::ServiceExt;

#[tokio::main(flavor = "multi_thread")]
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/micro/range_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ use axum::Router;
use control_plane::{plan_workload, DeploymentInputs};
use data_plane::engine::EngineOptions;
use data_plane::ingestion::IngestionOptions;
use data_plane::metrics::thread_cpu_seconds;
use data_plane::remote_write::{encode, Label, Sample, TimeSeries, WriteRequest};
use data_plane::{router, DataPlane, EXECUTION_HEADER};
use http_body_util::BodyExt;
use internal_metrics::thread_cpu_seconds;
use tower::ServiceExt;

const STEP_MS: i64 = 15_000;
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/micro/rw_corpus_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ static ALLOCATOR: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
use std::sync::mpsc;
use std::time::Instant;

use data_plane::metrics::thread_cpu_ns;
use data_plane::remote_write::{decode_samples, Limits};
use data_plane::store::RawSample;
use internal_metrics::thread_cpu_ns;
use storage::store::RawSample;

fn main() {
let args: Vec<String> = std::env::args().collect();
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/micro/tier_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ use axum::Router;
use control_plane::{plan_workload, DeploymentInputs};
use data_plane::engine::EngineOptions;
use data_plane::ingestion::IngestionOptions;
use data_plane::persist::ViewRead;
use data_plane::remote_write::{encode, Label, Sample, TimeSeries, WriteRequest};
use data_plane::{router, DataPlane};
use http_body_util::BodyExt;
use storage::persist::ViewRead;
use tower::ServiceExt;

const WINDOW_MS: i64 = 15_000;
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/micro/view_read_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ 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};
use storage::persist::{ViewFiles, ViewRead};

fn main() {
let args: Vec<String> = std::env::args().collect();
Expand Down
11 changes: 5 additions & 6 deletions crates/data-plane/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@ edition.workspace = true
[dependencies]
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"
internal_metrics.workspace = true
storage.workspace = true
ahash = "0.8"
# The per-thread series cache of the Remote Write decoder (a table of
# indices hashed by the keys they point to).
hashbrown = "0.15"
# Shortest round-trip float digits for range responses (prometheus.rs).
ryu = "1"
libc = "0.2"
# The data plane's allocator (main.rs): many small per-request allocations.
tikv-jemallocator = "0.6"
serde.workspace = true
Expand All @@ -30,15 +27,17 @@ tokio.workspace = true
axum.workspace = true
reqwest.workspace = true
prost = "0.13"
rmp-serde = "1"
snap = "1.1"
futures = "0.3"
form_urlencoded = "1"

[dev-dependencies]
control_plane.workspace = true
asap_sketchlib.workspace = true
tower = { version = "0.5", features = ["util"] }
http-body-util = "0.1"
# posix_fadvise in the tier and view-read benchmarks (cold reads).
libc = "0.2"

# The micro benchmarks live in benchmarks/micro/ and build as examples of this
# crate (`cargo run --release -p data_plane --example <name>`).
Expand Down
72 changes: 26 additions & 46 deletions crates/data-plane/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,28 @@ use std::sync::mpsc::{channel, sync_channel, Receiver, Sender, SyncSender};
use std::sync::{Arc, Condvar, Mutex, MutexGuard, RwLock};
use std::time::Instant;

use asap_executor::planner::plan::physical_asap_dag::PhysicalASAPNodeId;
use asap_executor::runtime::Limits;
use asap_executor::values::Batch;
use asap_planner::InstallablePlan;

use internal_metrics::{Metrics, PushMetrics, Timer};
use storage::memory_budget::serve_view_cache;
use storage::persist::{plan_hash, ViewFiles, ViewRead};
use storage::store::{
PublishedStore, QueryTimeResults, RawData, RawSample, RawShards, RunStore, SeriesPartition,
ViewStore, ViewTier, WindowSlot,
};
use storage::window_cache::WindowCache;
use tokio::sync::oneshot;

use crate::ingestion::{
ClosedWindow, Computed, Ingestion, IngestionOptions, IngestionStats, Precompute,
RefreshTaskGraph, Refreshed, Routing,
};
use crate::metrics::{Gauges, Metrics, PushMetrics, Timer};
use crate::persist::{plan_hash, ViewFiles, ViewRead};
use crate::metrics_endpoint::Gauges;
use crate::push::{Partial, PushGroup, PushShard};
use crate::query::{QueryEngine, Snapshot, Unanswered};
use crate::result_cache::{Answer, ResultCache};
use crate::store::SeriesPartition;
use crate::store::{
PublishedStore, QueryTimeResults, RawData, RawSample, RawShards, RunStore, ViewStore, ViewTier,
WindowSlot,
};
use crate::window_cache::WindowCache;
use asap_executor::planner::plan::physical_asap_dag::PhysicalASAPNodeId;
use asap_executor::values::Batch;

/// How the views of a closed refresh window are built
/// (docs/design/parallel-precompute.md). The `data_plane` binary defaults
Expand Down Expand Up @@ -145,7 +145,7 @@ pub struct EngineOptions {
/// recently used are dropped first.
pub result_cache_max_bytes: usize,
/// Where the materialized views are persisted and loaded from at
/// startup ([`crate::persist`]); `None`: kept in memory only.
/// startup ([`storage::persist`]); `None`: kept in memory only.
pub view_dir: Option<std::path::PathBuf>,
/// How often the view files are synced to disk: a refreshed window is
/// durable within this long. 0 syncs after every window.
Expand Down Expand Up @@ -223,7 +223,7 @@ impl Default for EngineOptions {
view_sync_interval_ms: 5_000,
view_cache_max_bytes: None,
view_cache_idle_ms: None,
view_segment_ms: crate::persist::DEFAULT_SEGMENT_MS,
view_segment_ms: storage::persist::DEFAULT_SEGMENT_MS,
view_read: ViewRead::Mmap,
cold_decode_delay_ms: 0,
unpersistable_views: Vec::new(),
Expand Down Expand Up @@ -385,6 +385,8 @@ struct Shared {
/// keep a refresh from finishing.
precompute_gate: Mutex<()>,
metrics: Metrics,
/// The views' cold tier, when they are persisted.
view_tier: Option<Arc<ViewTier>>,
}

/// Marks the engine stopped when its thread exits, panics included.
Expand Down Expand Up @@ -466,9 +468,6 @@ impl EngineHandle {
.map(|(width_ms, views)| (width_ms, views.iter().map(ToString::to_string).collect()))
.collect();
let mut metrics = Metrics::new(&groups, &query_texts);
if let Some(tier) = &tier {
let _ = metrics.view_tier.set(tier.clone());
}
if options.precompute_mode == PrecomputeMode::Push {
metrics.push = Some(PushMetrics::new(groups.len(), shard_count));
}
Expand Down Expand Up @@ -504,6 +503,7 @@ impl EngineHandle {
published: PublishedStore::new(Arc::new(raw_shards.clone())),
precompute_gate: Mutex::new(()),
metrics,
view_tier: tier.clone(),
});
let (commands, command_receiver) = channel();
let (jobs, job_receiver) = sync_channel(options.max_precompute_backlog.max(1));
Expand Down Expand Up @@ -771,7 +771,7 @@ impl EngineHandle {
}

/// The query-time partition of the view store.
pub fn query_time_results(&self) -> &QueryTimeResults {
pub fn query_time_results(&self) -> &QueryTimeResults<Unanswered> {
self.query.query_time_results()
}

Expand All @@ -783,7 +783,7 @@ impl EngineHandle {
/// The engine's measurements and counters in the Prometheus text
/// format.
pub fn render_metrics(&self) -> String {
crate::metrics::render(
crate::metrics_endpoint::render(
&self.shared.metrics,
&Gauges {
stats: self.stats(),
Expand All @@ -798,6 +798,7 @@ impl EngineHandle {
now_ms: crate::ingestion::wall_clock_ms(),
query_time_results: self.query.query_time_results(),
result_cache: self.query.result_cache(),
view_tier: self.shared.view_tier.as_deref(),
},
)
}
Expand Down Expand Up @@ -1002,7 +1003,7 @@ fn install(
"materialized views"
);
let results = QueryTimeResults::new(
crate::ingestion::millis(options.query_time_results_retention_ms),
storage::store::millis(options.query_time_results_retention_ms),
options.query_time_results_max_bytes,
);
let query = QueryEngine::new(
Expand Down Expand Up @@ -2440,15 +2441,15 @@ fn serve_persist(
/// with its budget (the option, else from the cgroup's `memory.max`, else
/// none) and idle time.
fn view_tier(options: &EngineOptions) -> ViewTier {
let cgroup = crate::memory_budget::own_cgroup()
.and_then(|dir| crate::memory_budget::read_cgroup(&dir).ok());
let cgroup = storage::memory_budget::own_cgroup()
.and_then(|dir| storage::memory_budget::read_cgroup(&dir).ok());
let other_pools = (options.result_cache_max_bytes + options.query_time_results_max_bytes)
as u64
+ options.max_persist_backlog_bytes;
let budget = options.view_cache_max_bytes.or_else(|| {
cgroup
.as_ref()
.and_then(|cgroup| crate::memory_budget::default_view_cache_budget(cgroup, other_pools))
cgroup.as_ref().and_then(|cgroup| {
storage::memory_budget::default_view_cache_budget(cgroup, other_pools)
})
});
let idle_ms = options
.view_cache_idle_ms
Expand All @@ -2464,27 +2465,6 @@ fn view_tier(options: &EngineOptions) -> ViewTier {
)
}

/// The view cache's monitor: once a second, drops idle windows and, under
/// a cgroup memory limit, lowers the cache's target while anonymous memory
/// runs higher than its budget assumed.
fn serve_view_cache(tier: Arc<ViewTier>, budget: Option<u64>, running: Arc<AtomicBool>) {
let cgroup = crate::memory_budget::own_cgroup();
while running.load(Ordering::SeqCst) {
std::thread::sleep(std::time::Duration::from_secs(1));
tier.cache.evict_idle(std::time::Instant::now());
if let Some(memory) = cgroup
.as_ref()
.and_then(|dir| crate::memory_budget::read_cgroup(dir).ok())
{
let cached = tier.cache.stats().bytes;
tier.cache
.set_target_bytes(crate::memory_budget::monitored_target(
budget, &memory, cached,
));
}
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down Expand Up @@ -2697,7 +2677,7 @@ mod tests {
let widths: Vec<i64> = ingestion.group_windows().iter().map(|w| w.0).collect();
assert_eq!(widths, [60_000, 10_000]);
ingestion.set_push_groups(vec![true, false]);
let series = crate::series_ids::intern_pairs(&[("__name__", "m_engine_push_late")]);
let series = storage::series_ids::intern_pairs(&[("__name__", "m_engine_push_late")]);
ingestion.observe(&[(series.metric.clone(), 1_000)]);
ingestion.advance_newest_sample(Some(25_000));
ingestion.advance_clock(25_000);
Expand Down
Loading