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

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ aqpbm-datagen = { path = "aqpbm-datagen" }
aqpbm-core = { path = "aqpbm-core", default-features = false }
sketch-bench = { path = "sketch-bench" }
aqpbm-usecase = { path = "aqpbm-usecase" }
system-bench = { path = "system-bench" }
# sketch-runtime = { path = "sketch-runtime" } # parked;

[profile.release]
Expand Down
2 changes: 2 additions & 0 deletions aqpbm-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ heap-jemalloc = ["sketch-bench/heap-jemalloc", "dep:tikv-jemallocator"]
# `TrackingAllocator` now lives in aqpbm-core (the CLI installs it
# as `#[global_allocator]` directly), so enable it there too.
heap-track = ["sketch-bench/heap-track", "aqpbm-core/heap-track"]
planeval = ["system-bench/planeval"]

[dependencies]
aqpbm-datagen = { workspace = true, features = ["import"] }
aqpbm-core.workspace = true
sketch-bench.workspace = true
system-bench.workspace = true
clap.workspace = true
serde.workspace = true
serde_json.workspace = true
Expand Down
63 changes: 60 additions & 3 deletions aqpbm-cli/src/benchmark_external_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@ use std::path::PathBuf;

use anyhow::{bail, Context, Result};
use aqpbm_core::harness::benchmark_external::{report, run_engine, write_report, EngineRunSetup};
use aqpbm_core::harness::cgroup::CgroupSource;
use aqpbm_core::harness::engine::EngineUnderTest;
use aqpbm_core::harness::fake::FakeEngine;
use aqpbm_core::harness::protocol::{
load_probe_for, MeasurementClocks, OsCpuClock, ProcessCpuFiles, Protocol,
};
use aqpbm_core::harness::run_directory::RunDirectory;
use clap::{Parser, Subcommand};
use system_bench::engines_external::clickhouse_server::{ClickHouseEngine, ClickHouseServer};

/// The engines this binary can run.
pub const ENGINES: [&str; 1] = ["fake"];
pub const ENGINES: [&str; 2] = ["fake", "clickhouse"];

#[derive(Parser, Debug)]
pub struct BenchmarkExternalArgs {
Expand All @@ -38,9 +40,30 @@ 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).
/// The engine: `fake` (the harness's own fake engine) or `clickhouse`.
#[arg(long)]
pub engine: String,
/// The ClickHouse server's HTTP interface, e.g. `http://10.0.0.1:8123`
/// (engine `clickhouse`).
#[arg(long)]
pub clickhouse_url: Option<String>,
/// The server's cgroup v2 directory, e.g.
/// `/sys/fs/cgroup/system.slice/docker-<id>.scope` (engine `clickhouse`).
#[arg(long)]
pub server_cgroup_directory: Option<PathBuf>,
/// The SSH destination of the server host, e.g. `bench@10.0.0.2`; the
/// cgroup directory is read over SSH. Omitted: it is read on this host.
#[arg(long)]
pub server_ssh_host: Option<String>,
/// The SSH client used with `--server-ssh-host`.
#[arg(long, default_value = "ssh")]
pub ssh_program: String,
/// `max_threads` of every ClickHouse statement; 1 for the main figures.
#[arg(long, default_value_t = 1)]
pub clickhouse_max_threads: u32,
/// How long one ClickHouse statement may run, in seconds.
#[arg(long, default_value_t = 600)]
pub clickhouse_statement_timeout_seconds: u64,
/// Only these variants (repeatable); every variant under plans/ by default.
#[arg(long = "variant")]
pub variants: Vec<String>,
Expand Down Expand Up @@ -76,7 +99,41 @@ pub fn run(args: BenchmarkExternalArgs) -> Result<()> {

fn run_engine_cmd(args: RunArgs) -> Result<()> {
let engine: Box<dyn EngineUnderTest> = match args.engine.as_str() {
"fake" => Box::new(FakeEngine::default()),
"fake" => {
if args.clickhouse_url.is_some()
|| args.server_cgroup_directory.is_some()
|| args.server_ssh_host.is_some()
{
bail!(
"--clickhouse-url, --server-cgroup-directory and --server-ssh-host are for engine clickhouse only"
);
}
Box::new(FakeEngine::default())
}
"clickhouse" => {
let (Some(url), Some(cgroup_directory)) = (
args.clickhouse_url.clone(),
args.server_cgroup_directory.clone(),
) else {
bail!("engine clickhouse needs --clickhouse-url and --server-cgroup-directory");
};
let cgroup = match args.server_ssh_host.clone() {
Some(host) => CgroupSource::Remote {
ssh_program: args.ssh_program.clone(),
host,
cgroup_directory,
},
None => CgroupSource::Local(cgroup_directory),
};
Box::new(ClickHouseEngine::new(ClickHouseServer {
url,
cgroup,
max_threads: args.clickhouse_max_threads,
statement_timeout: std::time::Duration::from_secs(
args.clickhouse_statement_timeout_seconds,
),
})?)
}
other => bail!(
"unknown engine '{other}'; known engines: {}",
ENGINES.join(", ")
Expand Down
25 changes: 24 additions & 1 deletion aqpbm-cli/tests/benchmark_external_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ fn an_unknown_engine_names_the_known_engines() {
"--run-directory",
run.to_str().unwrap(),
"--engine",
"clickhouse",
"no-such-engine",
]);
assert!(!out.status.success());
let stderr = String::from_utf8_lossy(&out.stderr);
Expand All @@ -162,3 +162,26 @@ fn an_unknown_engine_names_the_known_engines() {
);
let _ = std::fs::remove_dir_all(run.parent().unwrap());
}

/// X3: the clickhouse engine needs the server and its cgroup directory.
#[test]
fn the_clickhouse_engine_needs_its_server() {
let run = fixture("x3");
let out = approxbench(&[
"benchmark-external",
"run",
"--run-directory",
run.to_str().unwrap(),
"--engine",
"clickhouse",
"--clickhouse-url",
"http://10.0.0.2:8123",
]);
assert!(!out.status.success());
let stderr = String::from_utf8_lossy(&out.stderr);
assert!(
stderr.contains("--clickhouse-url") && stderr.contains("--server-cgroup-directory"),
"{stderr}"
);
let _ = std::fs::remove_dir_all(run.parent().unwrap());
}
114 changes: 114 additions & 0 deletions scripts/extbench-up.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#!/usr/bin/env bash
# Start (or stop) one measured server for `approxbench benchmark-external` on
# this host: a docker container pinned to given cores. The harness reads its
# cgroup over SSH (`--server-ssh-host`, `--server-cgroup-directory`).
#
# scripts/extbench-up.sh clickhouse up <data-dir> <cores> <numa-node> <http-port> [<name>]
# scripts/extbench-up.sh clickhouse down <data-dir> [<name>]
# scripts/extbench-up.sh check-listen-host <address>
#
# Example: LISTEN_HOST=10.0.0.2 scripts/extbench-up.sh clickhouse up /data/run-1/clickhouse 2,22 0 18123
#
# Environment:
# LISTEN_HOST address the server listens on (required):
# a private (10/8, 172.16/12, 192.168/16) or loopback
# address, never 0.0.0.0 or a public one: the server
# has no password
# CLICKHOUSE_BINARY path of the ClickHouse binary to bind-mount (required)
# CLICKHOUSE_SHA256 its expected sha256 (required); a mismatch refuses
# BASE_IMAGE the image the binary runs in, pinned by digest (required)
#
# The harness reads the group from outside the container, so its reads are
# never charged to the server's group.
#
# Every start begins from an empty data dir. The script only deletes a data
# dir it created (it holds the marker file .extbench-data-dir). The
# container runs as the invoking user, with no CPU quota (--cpus unset) and
# no memory limit. ClickHouse runs on its embedded configuration: without a
# main config file it reads no config.d, so the few settings changed here
# are `--key=value` overrides. The embedded configuration also defines the
# native, MySQL, PostgreSQL and interserver ports (a port of 0 binds a random
# one), so they get the four ports after the HTTP port, on LISTEN_HOST too.
set -euo pipefail

marker=.extbench-data-dir

# Exit 0 when $1 is a private or loopback IPv4 address.
private_address() {
local a b c d
IFS=. read -r a b c d <<<"$1" || return 1
for octet in "$a" "$b" "$c" "$d"; do
[[ "$octet" =~ ^[0-9]+$ ]] && [ "$octet" -le 255 ] || return 1
done
[ "$a" = 10 ] && return 0
[ "$a" = 127 ] && return 0
[ "$a" = 172 ] && [ "$b" -ge 16 ] && [ "$b" -le 31 ] && return 0
[ "$a" = 192 ] && [ "$b" = 168 ] && return 0
return 1
}

if [ "${1:-}" = check-listen-host ]; then
private_address "${2:?address}" || { echo "refused: ${2} is not a private address" >&2; exit 1; }
exit 0
fi

engine=${1:?engine}; action=${2:?up|down}; data_dir=$(realpath -m "${3:?data dir}")

[ "$engine" = clickhouse ] || { echo "unknown engine $engine" >&2; exit 2; }

if [ "$action" = down ]; then
name=${4:-extbench-clickhouse}
docker rm -f "$name" >/dev/null 2>&1 || true
exit 0
fi

cores=${4:?cores}; numa=${5:?numa node}; http_port=${6:?http port}
name=${7:-extbench-clickhouse}
: "${LISTEN_HOST:?set LISTEN_HOST to a private address}" "${CLICKHOUSE_BINARY:?}" \
"${CLICKHOUSE_SHA256:?}" "${BASE_IMAGE:?}"
private_address "$LISTEN_HOST" || { echo "refused: LISTEN_HOST $LISTEN_HOST is not a private address" >&2; exit 1; }
CLICKHOUSE_BINARY=$(realpath "$CLICKHOUSE_BINARY")
actual=$(sha256sum "$CLICKHOUSE_BINARY" | cut -d' ' -f1)
[ "$actual" = "$CLICKHOUSE_SHA256" ] || { echo "binary sha256 $actual != $CLICKHOUSE_SHA256" >&2; exit 1; }

if [ -e "$data_dir" ]; then
[ -f "$data_dir/$marker" ] || { echo "refused: $data_dir exists and was not made by this script" >&2; exit 1; }
docker rm -f "$name" >/dev/null 2>&1 || true
rm -rf "$data_dir"
fi
mkdir -p "$data_dir/db"; touch "$data_dir/$marker"

docker rm -f "$name" >/dev/null 2>&1 || true
docker run -d --name "$name" --network host \
--cpuset-cpus "$cores" --cpuset-mems "$numa" --user "$(id -u):$(id -g)" \
-v "$CLICKHOUSE_BINARY:/usr/bin/clickhouse:ro" -v "$data_dir/db:/var/lib/clickhouse" \
-w /var/lib/clickhouse \
"$BASE_IMAGE" /usr/bin/clickhouse server -- --path=/var/lib/clickhouse/ \
--http_port="$http_port" --tcp_port=$((http_port + 1)) --mysql_port=$((http_port + 2)) \
--postgresql_port=$((http_port + 3)) --interserver_http_port=$((http_port + 4)) \
--listen_host="$LISTEN_HOST" --logger.level=warning --display_name="$name" >/dev/null
for _ in $(seq 1 60); do
curl -sf "http://$LISTEN_HOST:$http_port/ping" >/dev/null && break; sleep 1
done
curl -sf "http://$LISTEN_HOST:$http_port/ping" >/dev/null || { echo "the server did not start" >&2; docker logs "$name" >&2; exit 1; }

id=$(docker inspect -f '{{.Id}}' "$name")
group="/sys/fs/cgroup/system.slice/docker-$id.scope"
[ -d "$group" ] || { echo "no cgroup at $group (is docker on the systemd cgroup driver?)" >&2; exit 1; }

query() { curl -sf "http://$LISTEN_HOST:$http_port/" --data-binary "$1"; }
siblings() {
for core in ${cores//,/ }; do
printf '%s:%s ' "$core" "$(cat "/sys/devices/system/cpu/cpu$core/topology/thread_siblings_list")"
done
}
{ echo "binary_sha256 $actual"
echo "version $(query "SELECT version()")"
echo "git_hash $(query "SELECT value FROM system.build_options WHERE name = 'VERSION_GITHASH'")"
echo "base_image $BASE_IMAGE"
echo "cpuset $cores mems $numa"
echo "thread_siblings $(siblings)"
echo "cpu_model $(lscpu | sed -n 's/^Model name: *//p')"
echo "cgroup $group"
echo "kernel $(uname -r)"; } > "$data_dir/versions.txt"
cat "$data_dir/versions.txt"
1 change: 1 addition & 0 deletions system-bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ asap-frontend-promql = { git = "https://github.com/ProjectASAP/ASAPPlanner", rev
asap_sketchlib = { workspace = true, optional = true }
futures = { version = "0.3", optional = true }
tokio = { version = "1", features = ["rt", "macros"], optional = true }
aqpbm-core.workspace = true
aqpbm-usecase.workspace = true
anyhow.workspace = true
clap.workspace = true
Expand Down
Loading
Loading