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.

49 changes: 35 additions & 14 deletions aqpbm-cli/src/benchmark_external_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@ use aqpbm_core::harness::protocol::{
};
use aqpbm_core::harness::run_directory::RunDirectory;
use clap::{Parser, Subcommand};
use system_bench::engines_external::asapquery_backend_server::{
AsapqueryBackendEngine, AsapqueryBackendServer,
};
use system_bench::engines_external::clickhouse_server::{ClickHouseEngine, ClickHouseServer};
use system_bench::engines_external::victoriametrics_server::{
VictoriaMetricsEngine, VictoriaMetricsServer,
};

/// The engines this binary can run.
pub const ENGINES: [&str; 3] = ["fake", "clickhouse", "victoriametrics"];
pub const ENGINES: [&str; 4] = ["fake", "clickhouse", "victoriametrics", "asapquery-backend"];

#[derive(Parser, Debug)]
pub struct BenchmarkExternalArgs {
Expand All @@ -45,8 +48,8 @@ pub struct RunArgs {
/// The run directory: workloads/, plans/<variant>/, results/.
#[arg(long)]
pub run_directory: PathBuf,
/// The engine: `fake` (the harness's own fake engine), `clickhouse` or
/// `victoriametrics`.
/// The engine: `fake` (the harness's own fake engine), `clickhouse`,
/// `victoriametrics` or `asapquery-backend`.
#[arg(long)]
pub engine: String,
/// The ClickHouse server's HTTP interface, e.g. `http://10.0.0.1:8123`
Expand Down Expand Up @@ -76,9 +79,13 @@ pub struct RunArgs {
#[arg(long)]
pub victoriametrics_url: Option<String>,
/// The server's `-streamAggr.config` file on the server host, replaced
/// for each arm (engine `victoriametrics`).
/// for each arm with a plan file (engine `victoriametrics`).
#[arg(long)]
pub victoriametrics_stream_aggregation_config: Option<PathBuf>,
/// The ASAPQuery-backend server's HTTP interface, e.g.
/// `http://10.0.0.1:8080` (engine `asapquery-backend`).
#[arg(long)]
pub asapquery_backend_url: Option<String>,
/// Only these variants (repeatable); every variant under plans/ by default.
#[arg(long = "variant")]
pub variants: Vec<String>,
Expand Down Expand Up @@ -118,13 +125,14 @@ fn run_engine_cmd(args: RunArgs) -> Result<()> {
let engine: Box<dyn EngineUnderTest> = match args.engine.as_str() {
"fake" => {
if args.clickhouse_url.is_some()
|| args.asapquery_backend_url.is_some()
|| args.victoriametrics_url.is_some()
|| args.victoriametrics_stream_aggregation_config.is_some()
|| args.server_cgroup_directory.is_some()
|| args.server_ssh_host.is_some()
{
bail!(
"--clickhouse-url, --victoriametrics-url, --victoriametrics-stream-aggregation-config, --server-cgroup-directory and --server-ssh-host are for engines clickhouse and victoriametrics only"
"--clickhouse-url, --victoriametrics-url, --victoriametrics-stream-aggregation-config, --asapquery-backend-url, --server-cgroup-directory and --server-ssh-host are for the server engines only"
);
}
Box::new(FakeEngine::default())
Expand All @@ -144,14 +152,10 @@ fn run_engine_cmd(args: RunArgs) -> Result<()> {
})?)
}
"victoriametrics" => {
let (Some(url), Some(cgroup), Some(stream_aggregation_config)) = (
args.victoriametrics_url.clone(),
server_cgroup(&args),
args.victoriametrics_stream_aggregation_config.clone(),
) else {
bail!(
"engine victoriametrics needs --victoriametrics-url, --server-cgroup-directory and --victoriametrics-stream-aggregation-config"
);
let (Some(url), Some(cgroup)) =
(args.victoriametrics_url.clone(), server_cgroup(&args))
else {
bail!("engine victoriametrics needs --victoriametrics-url and --server-cgroup-directory");
};
// Wall-clock data runs one arm at a time.
if args.warmup != 0 || args.runs != 1 {
Expand All @@ -160,7 +164,24 @@ fn run_engine_cmd(args: RunArgs) -> Result<()> {
Box::new(VictoriaMetricsEngine::new(VictoriaMetricsServer {
url,
cgroup,
stream_aggregation_config,
stream_aggregation_config: args.victoriametrics_stream_aggregation_config.clone(),
request_timeout: std::time::Duration::from_secs(600),
})?)
}
"asapquery-backend" => {
let (Some(url), Some(cgroup)) =
(args.asapquery_backend_url.clone(), server_cgroup(&args))
else {
bail!(
"engine asapquery-backend needs --asapquery-backend-url and --server-cgroup-directory"
);
};
if args.warmup != 0 || args.runs != 1 {
bail!("engine asapquery-backend runs one arm per server start: pass --warmup 0 --runs 1");
}
Box::new(AsapqueryBackendEngine::new(AsapqueryBackendServer {
url,
cgroup,
request_timeout: std::time::Duration::from_secs(600),
})?)
}
Expand Down
48 changes: 48 additions & 0 deletions aqpbm-cli/tests/benchmark_external_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,51 @@ fn the_victoriametrics_engine_needs_its_server_and_one_run() {
assert!(stderr.contains("--warmup 0 --runs 1"), "{stderr}");
let _ = std::fs::remove_dir_all(run.parent().unwrap());
}

#[test]
fn the_asapquery_backend_engine_needs_its_server_and_one_run() {
let run = fixture("x5");
let base = [
"benchmark-external",
"run",
"--run-directory",
run.to_str().unwrap(),
"--engine",
"asapquery-backend",
];
let out = approxbench(&base);
assert!(!out.status.success());
let stderr = String::from_utf8_lossy(&out.stderr);
assert!(stderr.contains("--asapquery-backend-url"), "{stderr}");
let mut with_server = base.to_vec();
with_server.extend([
"--asapquery-backend-url",
"http://127.0.0.1:1",
"--server-cgroup-directory",
"/sys/fs/cgroup/system.slice/docker-1.scope",
]);
let out = approxbench(&with_server);
assert!(!out.status.success());
let stderr = String::from_utf8_lossy(&out.stderr);
assert!(stderr.contains("--warmup 0 --runs 1"), "{stderr}");
let _ = std::fs::remove_dir_all(run.parent().unwrap());
}

#[test]
fn the_fake_engine_refuses_server_flags() {
let run = fixture("x6");
let out = approxbench(&[
"benchmark-external",
"run",
"--run-directory",
run.to_str().unwrap(),
"--engine",
"fake",
"--asapquery-backend-url",
"http://127.0.0.1:1",
]);
assert!(!out.status.success());
let stderr = String::from_utf8_lossy(&out.stderr);
assert!(stderr.contains("--asapquery-backend-url"), "{stderr}");
let _ = std::fs::remove_dir_all(run.parent().unwrap());
}
3 changes: 3 additions & 0 deletions system-bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,6 @@ thiserror.workspace = true
prost = "0.13"
snap = "1.1"
ureq = { version = "2", default-features = false }

[dev-dependencies]
aqpbm-datagen.workspace = true
3 changes: 2 additions & 1 deletion system-bench/src/bin/systemeval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ use aqpbm_usecase::spec::Spec;
use clap::builder::PossibleValuesParser;
use clap::Parser;

use system_bench::systemeval::query::{ask, Collected};
use system_bench::prometheus_api::query::ask;
use system_bench::systemeval::query::Collected;
use system_bench::systemeval::system;
use system_bench::systemeval::write::{Options, Writer};

Expand Down
179 changes: 179 additions & 0 deletions system-bench/src/engines_external/asapquery_backend_server.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
use std::sync::atomic::{AtomicBool, Ordering};
use std::time::Duration;

use aqpbm_core::harness::cgroup::CgroupSource;
use aqpbm_core::harness::data::SampleChunk;
use aqpbm_core::harness::engine::{
Answers, ArmSpec, CpuAccounting, EngineDescription, EngineError, EngineUnderTest, Footprint,
InstalledArm, PlanSummary, QueryLanguage, StepReport, WorkloadSpec,
};

use crate::prometheus_api::query_text_arm::{
ask_every_query, queries_to_ask, write_chunk, QueryToAsk,
};

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct AsapqueryBackendServer {
pub url: String,
pub cgroup: CgroupSource,
pub request_timeout: Duration,
}

pub struct AsapqueryBackendEngine {
server: AsapqueryBackendServer,
connection: AsapqueryBackendConnection,
installed_once: AtomicBool,
}

#[derive(Clone)]
pub struct AsapqueryBackendConnection {
pub agent: ureq::Agent,
pub base: String,
}

impl AsapqueryBackendConnection {
pub fn new(url: &str, request_timeout: Duration) -> AsapqueryBackendConnection {
AsapqueryBackendConnection {
agent: ureq::AgentBuilder::new()
.timeout_connect(Duration::from_secs(5))
.timeout(request_timeout)
.build(),
base: url.trim_end_matches('/').to_string(),
}
}

pub fn make_visible(&self, through_ms: i64) -> anyhow::Result<()> {
use anyhow::Context;
self.agent
.post(&format!(
"{}/api/v1/precompute/watermark?time_ms={through_ms}",
self.base
))
.call()
.with_context(|| format!("closing panes through {through_ms}"))?;
Ok(())
}

pub fn status(&self) -> anyhow::Result<serde_json::Value> {
Ok(serde_json::from_str(
&self
.agent
.get(&format!("{}/api/v1/status/asap", self.base))
.call()?
.into_string()?,
)?)
}

pub fn held_bytes(&self) -> anyhow::Result<Footprint> {
let text = self
.agent
.get(&format!("{}/metrics", self.base))
.call()?
.into_string()?;
let gauge = |name: &str| -> anyhow::Result<u64> {
text.lines()
.find_map(|line| {
let (metric, value) = line.split_once(' ')?;
(metric == name).then(|| value.trim().parse::<f64>().ok())?
})
.map(|value| value as u64)
.ok_or_else(|| anyhow::anyhow!("the server's /metrics has no {name}"))
};
Ok(Footprint {
view_bytes: gauge("asap_view_bytes")?,
raw_retained_bytes: gauge("asap_raw_data_bytes")?,
peak_bytes: None,
})
}
}

impl AsapqueryBackendEngine {
pub fn new(server: AsapqueryBackendServer) -> Result<AsapqueryBackendEngine, EngineError> {
let connection = AsapqueryBackendConnection::new(&server.url, server.request_timeout);
connection.status().map_err(|error| {
EngineError(format!("ASAPQuery-backend at {}: {error:#}", server.url))
})?;
Ok(AsapqueryBackendEngine {
server,
connection,
installed_once: AtomicBool::new(false),
})
}
}

impl EngineUnderTest for AsapqueryBackendEngine {
fn description(&self) -> EngineDescription {
EngineDescription {
id: "asapquery-backend".into(),
version: "unreported".into(),
version_dirty: false,
build_profile: "server".into(),
}
}

fn cpu_accounting(&self) -> CpuAccounting {
CpuAccounting::Cgroup(self.server.cgroup.clone())
}

fn install(
&self,
workload: &WorkloadSpec,
arm: &ArmSpec,
) -> Result<Box<dyn InstalledArm>, EngineError> {
if arm.engine_options.get("plan_file").is_some() {
return Err(EngineError(
"ASAPQuery-backend runs the plan it was started with; this adapter installs no \
plan file, so give it a variant with plans: false"
.into(),
));
}
let queries = queries_to_ask(workload, &[QueryLanguage::PromQl])?;
if self.installed_once.swap(true, Ordering::SeqCst) {
return Err(EngineError(
"ASAPQuery-backend keeps every sample written to it: restart the server before \
the next arm, and run this engine with --warmup 0 --runs 1"
.into(),
));
}
Ok(Box::new(AsapqueryBackendArm {
connection: self.connection.clone(),
queries,
}))
}
}

struct AsapqueryBackendArm {
connection: AsapqueryBackendConnection,
queries: Vec<QueryToAsk>,
}

impl InstalledArm for AsapqueryBackendArm {
fn plan_summary(&self) -> PlanSummary {
PlanSummary::default()
}

fn ingest(&mut self, chunk: &SampleChunk) -> Result<StepReport, EngineError> {
write_chunk(&self.connection.agent, &self.connection.base, chunk)?;
self.connection
.make_visible(chunk.end_ms)
.map_err(|error| EngineError(format!("{error:#}")))?;
Ok(StepReport::default())
}

fn evaluate(&mut self, at_ms: i64) -> Result<(Answers, StepReport), EngineError> {
let answers = ask_every_query(
&self.connection.agent,
&self.connection.base,
&self.queries,
at_ms,
&[],
)?;
Ok((answers, StepReport::default()))
}

fn footprint(&self) -> Result<Footprint, EngineError> {
self.connection
.held_bytes()
.map_err(|error| EngineError(format!("{error:#}")))
}
}
1 change: 1 addition & 0 deletions system-bench/src/engines_external/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
//! The deployment-capabilities files under `capabilities/` tell the planner
//! what each engine can run; their README gives the evidence per entry.

pub mod asapquery_backend_server;
pub mod clickhouse;
pub mod clickhouse_server;
pub mod plan_file;
Expand Down
Loading
Loading