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
36 changes: 18 additions & 18 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ version = "0.1.0"
# The backend depends on two Planner crates, at one immutable revision:
# `asap-planner` to plan and `asap-executor` to execute. Planner IR types
# are reached through `asap_executor::planner`.
asap-planner = { git = "https://github.com/ProjectASAP/ASAPPlanner", rev = "39a25ee3f5d3029ed13bd725d730be1f4ca58cb7" }
asap-executor = { git = "https://github.com/ProjectASAP/ASAPPlanner", rev = "39a25ee3f5d3029ed13bd725d730be1f4ca58cb7" }
asap-planner = { git = "https://github.com/ProjectASAP/ASAPPlanner", rev = "3f95d9eebbb43c4e0205af4b5b5e8af9d4f517e2" }
asap-executor = { git = "https://github.com/ProjectASAP/ASAPPlanner", rev = "3f95d9eebbb43c4e0205af4b5b5e8af9d4f517e2" }
# The sketch library the Planner's executor pins, for the byte encodings of
# the sketch states the data plane persists; keep it at the Planner's rev
# (draft: ASAPPlanner#1553 head, for SIL intents).
Expand Down
2 changes: 1 addition & 1 deletion data_plane/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ form_urlencoded = "1"

[dev-dependencies]
# Parses SIL intents for the intent round loop's end-to-end test.
asap-frontend-sil = { git = "https://github.com/ProjectASAP/ASAPPlanner", rev = "39a25ee3f5d3029ed13bd725d730be1f4ca58cb7" }
asap-frontend-sil = { git = "https://github.com/ProjectASAP/ASAPPlanner", rev = "3f95d9eebbb43c4e0205af4b5b5e8af9d4f517e2" }
# Paused time for the intent loop's latency and overrun tests.
tokio = { workspace = true, features = ["test-util"] }
control_plane.workspace = true
Expand Down
23 changes: 22 additions & 1 deletion data_plane/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ pub struct EngineOptions {
/// reads too; 1: every run on its query worker alone. The answers are
/// the same for any value.
pub query_parallelism: usize,
/// Parts each precompute window run's grouped builds split into on the
/// query worker pool (built when `query_parallelism` is above 1);
/// default 1: each window runs on its precompute thread. Above 1 a
/// window commits sooner for more CPU (the pool's split overhead).
pub precompute_parallelism: usize,
/// Threads of the query worker pool (rayon's global pool, sized once per
/// process) that runs those parts. Ingest, precompute and persist
/// threads share the same cores; leave them room on a busy server.
Expand Down Expand Up @@ -238,6 +243,7 @@ impl Default for EngineOptions {
run_memory_limit_bytes: 4 << 30,
query_threads: std::thread::available_parallelism().map_or(1, usize::from),
query_parallelism: std::thread::available_parallelism().map_or(1, usize::from),
precompute_parallelism: 1,
query_pool_threads: std::thread::available_parallelism().map_or(1, usize::from),
query_min_split_rows: None,
share_one_evaluation_results: true,
Expand Down Expand Up @@ -435,7 +441,9 @@ impl EngineHandle {
// the query runs', counted apart.
let ingestion_raw_reads = Arc::new(crate::store::RawReadCounts::default());
let precompute = Arc::new(
precompute.with_raw_reads(options.label_pushdown, ingestion_raw_reads.clone()),
precompute
.with_raw_reads(options.label_pushdown, ingestion_raw_reads.clone())
.with_parallelism(options.precompute_parallelism),
);
// Push mode: the groups the shards build by push.
let push_groups: Vec<Option<PushGroup>> = match options.precompute_mode {
Expand Down Expand Up @@ -1222,6 +1230,19 @@ fn serve_shard(
continue;
}
ShardMessage::Flush => {
let routing = shared
.routing
.read()
.unwrap_or_else(|e| e.into_inner())
.clone();
// Compacting is append work; a flush with nothing to compact
// is not counted as a run.
if let Some(through) = routing.flush_seal_through(newest_ms) {
let timer = Timer::start();
if Arc::make_mut(&mut raw_data).seal_through(through) {
shared.metrics.append.record(timer);
}
}
// The raw data travels only with a flush, which a window
// closing reads; the coordinator lets it go after its pass,
// so appending rarely copies the pane lists it shares.
Expand Down
38 changes: 35 additions & 3 deletions data_plane/src/ingestion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ impl Ingestion {
limits,
label_pushdown: true,
raw_read_counts: None,
parallelism: 1,
},
))
}
Expand Down Expand Up @@ -500,6 +501,7 @@ impl Ingestion {
Routing {
scanned_metrics: self.scanned_metrics.clone(),
max_future_ms: millis(self.options.max_future_ms),
allowed_lateness_ms: millis(self.options.allowed_lateness_ms),
cutoffs,
late_through,
groups_waiting: self.groups.iter().any(|g| g.refreshed_through.is_none()),
Expand Down Expand Up @@ -720,6 +722,10 @@ pub struct Routing {
/// Each scanned metric's samples at or before this are in a window
/// every group scanning it has closed (`None`: no group closed one).
views_closed_through: HashMap<String, Option<i64>>,
/// The allowed lateness: a shard whose newest sample is at `t`
/// compacts the panes ending at or before `t` minus it when it flushes
/// ([`Self::flush_seal_through`]).
allowed_lateness_ms: i64,
}

/// One batch of samples routed by a shard.
Expand Down Expand Up @@ -805,6 +811,16 @@ impl Routing {
routed
}

/// Where a shard whose newest sample is at `newest_ms` compacts its
/// panes when it flushes: through the watermark its own samples allow
/// (at most the watermark the flush's pass sets, which takes the
/// newest sample over every shard). The windows that pass closes then
/// read one chunk per pane instead of one per request; a sample that
/// arrives later for a compacted pane adds a chunk, as after any seal.
pub fn flush_seal_through(&self, newest_ms: Option<i64>) -> Option<i64> {
newest_ms.map(|newest| newest.saturating_sub(self.allowed_lateness_ms))
}

/// Seals and evicts `raw_data` as the ingestion stands: compacts the
/// panes the watermark has passed and drops the panes at or before
/// each metric's cutoff.
Expand Down Expand Up @@ -932,9 +948,21 @@ pub struct Precompute {
label_pushdown: bool,
/// Where the runs count their raw reads' rows; `None`: not counted.
raw_read_counts: Option<Arc<RawReadCounts>>,
/// Parts a run's grouped summary builds split into on the query
/// worker pool ([`RunContext::with_parallelism`]: the same states for
/// any value); 1 (the default) runs each window on its own thread.
parallelism: usize,
}

impl Precompute {
/// Splits each window run's grouped builds into `parallelism` parts on
/// the worker pool (which must exist when it is above 1), so a large
/// window commits sooner; the pool's CPU counts as the run's.
pub fn with_parallelism(mut self, parallelism: usize) -> Self {
self.parallelism = parallelism.max(1);
self
}

/// The runs' raw reads select series by the `Scan`'s label predicates
/// when `label_pushdown`, and count their rows in `counts`.
pub fn with_raw_reads(mut self, label_pushdown: bool, counts: Arc<RawReadCounts>) -> Self {
Expand Down Expand Up @@ -1004,9 +1032,13 @@ impl Precompute {
window_end_ms: end,
},
self.limits.clone(),
)?;
let outputs = block_on(instance.execute_ingestion(group.compiled.roots(), context)?)?;
outputs
)?
.with_parallelism(self.parallelism);
let outputs =
block_on(instance.execute_ingestion(group.compiled.roots(), context.clone())?);
// The pool's work on this run counts as this thread's phase CPU.
crate::metrics::add_offloaded_cpu_ns(context.parallel_cpu_ns());
outputs?
};
Ok(self.computed(window.group, missing, outputs))
}
Expand Down
6 changes: 6 additions & 0 deletions data_plane/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ struct Args {
/// per run. Answers are the same for any value. Default: the cores.
#[arg(long, default_value_t = EngineOptions::default().query_parallelism)]
query_parallelism: usize,
/// Parts each precompute window run's grouped summary builds split
/// into on the query worker pool (the stored states are the same for
/// any value): above 1, windows commit sooner for more CPU. Default 1.
#[arg(long, default_value_t = EngineOptions::default().precompute_parallelism)]
precompute_parallelism: usize,
/// Threads of the query worker pool those parts run on. Ingest,
/// precompute and persist threads share the cores. Default: the cores.
#[arg(long, default_value_t = EngineOptions::default().query_pool_threads)]
Expand Down Expand Up @@ -260,6 +265,7 @@ async fn main() -> anyhow::Result<()> {
run_memory_limit_bytes: args.run_memory_limit_bytes,
query_threads: args.query_threads,
query_parallelism: args.query_parallelism,
precompute_parallelism: args.precompute_parallelism,
query_pool_threads: args.query_pool_threads,
share_one_evaluation_results: !args.no_shared_results,
label_pushdown: !args.no_label_pushdown,
Expand Down
Loading