From 561bb33ca9fd5724ef5b236b24b810aa8eca0a7f Mon Sep 17 00:00:00 2001 From: Matej Kocourek Date: Fri, 20 Nov 2026 00:42:33 +0100 Subject: [PATCH 01/10] Pin r-benchmarks to main (86c5182, PRL-PRG/r-benchmarks#4 merged) Co-Authored-By: Claude Opus 5.5 --- pyproject.toml | 5 +---- uv.lock | 4 ++-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index a414490..056e14b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,11 +10,8 @@ dependencies = ["jsonschema>=4.22", "rbench"] # The benchmark suite, its harnesses and drivers, pinned to one commit. bench, # the benchmarking library underneath, comes with it: rbench pins its commit, # and uv.lock records both. -# -# 65ca9a3 is the head of r-benchmarks' `modularize` branch -# (PRL-PRG/r-benchmarks#4); move to the merge commit on main once it is merged. [tool.uv.sources] -rbench = { git = "https://github.com/PRL-PRG/r-benchmarks.git", rev = "65ca9a3dda1e35b6d550d97c71c086b479c8cfde" } +rbench = { git = "https://github.com/PRL-PRG/r-benchmarks.git", rev = "86c5182ce98e9380734d4557283c73e1984e061e" } # bench with Thermal (PRL-PRG/bench#3, from the fork) until r-benchmarks pins a # bench that has it diff --git a/uv.lock b/uv.lock index c51772a..4553d44 100644 --- a/uv.lock +++ b/uv.lock @@ -194,7 +194,7 @@ wheels = [ [[package]] name = "rbench" version = "0.1.0" -source = { git = "https://github.com/PRL-PRG/r-benchmarks.git?rev=65ca9a3dda1e35b6d550d97c71c086b479c8cfde#65ca9a3dda1e35b6d550d97c71c086b479c8cfde" } +source = { git = "https://github.com/PRL-PRG/r-benchmarks.git?rev=86c5182ce98e9380734d4557283c73e1984e061e#86c5182ce98e9380734d4557283c73e1984e061e" } dependencies = [ { name = "bench" }, ] @@ -378,7 +378,7 @@ dev = [ [package.metadata] requires-dist = [ { name = "jsonschema", specifier = ">=4.22" }, - { name = "rbench", git = "https://github.com/PRL-PRG/r-benchmarks.git?rev=65ca9a3dda1e35b6d550d97c71c086b479c8cfde" }, + { name = "rbench", git = "https://github.com/PRL-PRG/r-benchmarks.git?rev=86c5182ce98e9380734d4557283c73e1984e061e" }, ] [package.metadata.requires-dev] From 793002ba98191d8860882b3764055e959d01e185 Mon Sep 17 00:00:00 2001 From: Matej Kocourek Date: Fri, 20 Nov 2026 01:07:50 +0100 Subject: [PATCH 02/10] WIP: sentinel, ingest, results per methodology (squashed later) --- machines/kabylake.toml | 17 +++ machines/prl-bench-x64-1.toml | 15 -- node/speedr-node | 85 ++++++++--- node/speedr-publish | 19 +++ site/R/prerender.R | 4 +- site/R/stats.R | 2 +- site/render.sh | 13 ++ speedr/cli.py | 55 ++++++- speedr/ingest.py | 261 +++++++++++++++++++++++++++++++++ speedr/machines.py | 33 ++--- speedr/results.py | 47 +++--- speedr/schema/meta.schema.json | 99 ++++++++++--- speedr/sentinel.py | 50 +++++++ tests/data/meta-example.json | 5 +- tests/test_ingest.py | 103 +++++++++++++ tests/test_registry.py | 8 +- tests/test_results.py | 22 +-- 17 files changed, 718 insertions(+), 120 deletions(-) create mode 100644 machines/kabylake.toml delete mode 100644 machines/prl-bench-x64-1.toml create mode 100755 node/speedr-publish create mode 100644 speedr/ingest.py create mode 100644 speedr/sentinel.py create mode 100644 tests/test_ingest.py diff --git a/machines/kabylake.toml b/machines/kabylake.toml new file mode 100644 index 0000000..be594d1 --- /dev/null +++ b/machines/kabylake.toml @@ -0,0 +1,17 @@ +# The Intel Core i7-7700K boxes: Slurm partition `kabylake` of the prlprg-bench +# cluster (MSI Z270M Mortar, BIOS 1.60, 32 GB). Their results are one series; +# the sentinel checks each run's box against the reference below. +name = "kabylake" +os = "linux" +arch = "x86_64" +cpu = "Intel Core i7-7700K at a fixed 4.2 GHz (turbo and SMT off), 32 GB" +cores = "3" # isolated core the benchmarks are pinned to +runtime = "docker" +profiler = "perf" +profiles = "validated" # perf on x86-64 is the method VMIL'26 validated +track_devel = true +wake = "wol" + +# Reference times (ms) of the sentinel benchmarks under R 4.5.2: medians of +# its calibration runs. Empty: not calibrated, every run passes. +[sentinel] diff --git a/machines/prl-bench-x64-1.toml b/machines/prl-bench-x64-1.toml deleted file mode 100644 index 1254605..0000000 --- a/machines/prl-bench-x64-1.toml +++ /dev/null @@ -1,15 +0,0 @@ -# The reference machine: dedicated Linux x86-64 box (see docs/machines.md for -# its host setup). Values marked TBD are filled in when the box is installed. -name = "prl-bench-x64-1" -os = "linux" -arch = "x86_64" -cpu = "TBD" -cores = "TBD" # isolated cores the benchmarks are pinned to -runtime = "docker" -profiler = "perf" -profiles = "validated" # perf on x86-64 is the method VMIL'26 validated -track_devel = true -# wol until we know whether the scheduler shares its L2 segment; switch to -# ipmi if the board has a BMC, or relay via a host on its subnet. -wake = "wol" -wake_secret = "WAKE_PRL_BENCH_X64_1" diff --git a/node/speedr-node b/node/speedr-node index 25f88cf..3733629 100755 --- a/node/speedr-node +++ b/node/speedr-node @@ -7,10 +7,12 @@ # speedr-node env|id SOURCE the build settings | the build id # speedr-node configure SOURCE configure only; print config.h # speedr-node build SOURCE build R (cached by build id) in $work/r/ -# speedr-node run SOURCE [timing.py args] timing pass -> $work/results/LABEL/RUN_ID/, -# copied to the controller's spool +# speedr-node run SOURCE [timing.py args] sentinel, then the timing pass -> +# $work/results/LABEL/RUN_ID/, copied to +# the controller's spool # -# SOURCE is a release (4.6.2), `devel` or `patched` (today's snapshot, kept as +# A run is recorded for machine $SPEEDR_MACHINE, by default the Slurm partition +# (machines/.toml). SOURCE is a release (4.6.2), `devel` or `patched` (today's snapshot, kept as # devel-r), such a label (devel-r90937), or a source tarball. How a # version is built: build/settings.toml. Data (sources, logs, results) goes to # $SPEEDR_WORK (~/speedr-work); this checkout needs `uv sync` once. @@ -27,6 +29,8 @@ cran=https://cloud.r-project.org/src/contrib extra_pkg=clusterGeneration # results go to the controller's spool (speedr's key can only write there) spool=speedr@prl-prg-bench-master: +# the node's probe result, written by the cluster's Slurm prolog before each job +probe=/run/prlprg-bench/probe.json mkdir -p "$work/src" "$work/results" "$work/r" # the speedr account is in the docker group; others go through sudo @@ -145,28 +149,73 @@ build) ;; run) l=$(resolve "$1"); shift + machine=${SPEEDR_MACHINE:-${SLURM_JOB_PARTITION:-}} + [ -n "$machine" ] || { echo "no machine: set SPEEDR_MACHINE (machines/.toml)"; exit 2; } id=$(build_id "$l") [ -x "$work/r/$id/bin/R" ] || { echo "R $l: no build $id; run '$0 build $l' first"; exit 1; } + eval "$("$repo/.venv/bin/speedr" sentinel --plan)" # version include runs iterations warmups + sentinel_id=$(build_id "$(resolve "$version")") + [ -x "$work/r/$sentinel_id/bin/R" ] || "$0" build "$version" run_id=$(date -u +%Y%m%dT%H%M%SZ)-$(openssl rand -hex 3) out=$work/results/$l/$run_id; mkdir -p "$out" cp "$work/r/$id/speedr-build.env" "$out/" - # setup() caches inputs in the benchmarks' data/ folders, some per R - # version (Matrix objects): start every run without them - find "$repo/.venv" -path '*/rbench/benchmarks/*/data' -prune -exec rm -rf {} + - echo "R $l (build $id): run $run_id on CPU $bench_cpus, kernel $(uname -r)" + [ -r "$probe" ] && cp "$probe" "$out/" + started=$(date -u +%Y-%m-%dT%H:%M:%SZ) + echo "R $l (build $id) on $machine: run $run_id on CPU $bench_cpus, kernel $(uname -r)" + # the container runs under dockerd, not this process: when Slurm cancels # the job (SIGTERM), stop it too - name=speedr-run-$run_id - trap 'docker kill "$name" >/dev/null 2>&1; exit 143' TERM INT - # seccomp=unconfined: docker's default profile refuses the personality - # call `setarch -R` makes to switch ASLR off for R - docker run --rm --name "$name" --user "$(id -u):$(id -g)" -e HOME=/tmp --network none \ - --cpuset-cpus "$bench_cpus" --cpuset-mems 0 --security-opt seccomp=unconfined \ - -v "$repo:$repo" -v "$work:$work" -w "$repo" "$image" \ - .venv/bin/python drivers/timing.py --R "$work/r/$id/bin/R" \ - --json "$out/timing.json" --csv "$out/timing.csv" --dir "$out/exec" --no-progress "$@" & - rc=0; wait $! || rc=$? # in the background, so the trap runs as soon as the signal arrives - rsync -aR "$work/results/./$l/$run_id" "$spool" && echo "results: $out, copied to the controller's spool" + name="" + trap '[ -n "$name" ] && docker kill "$name" >/dev/null 2>&1; exit 143' TERM INT + bench() { # NAME R-BUILD-ID TIMING-ARGS... -> drivers/timing.py in the image, on the bench CPU + name=speedr-$1-$run_id; local r=$2; shift 2 + # setup() caches inputs in the benchmarks' data/ folders, some per R + # version (Matrix objects): start every pass without them + find "$repo/.venv" -path '*/rbench/benchmarks/*/data' -prune -exec rm -rf {} + + # seccomp=unconfined: docker's default profile refuses the personality + # call `setarch -R` makes to switch ASLR off for R + docker run --rm --name "$name" --user "$(id -u):$(id -g)" -e HOME=/tmp --network none \ + --cpuset-cpus "$bench_cpus" --cpuset-mems 0 --security-opt seccomp=unconfined \ + -v "$repo:$repo" -v "$work:$work" -w "$repo" "$image" \ + .venv/bin/python drivers/timing.py --R "$work/r/$r/bin/R" --no-progress "$@" & + local rc=0; wait $! || rc=$? # in the background, so the trap runs as soon as the signal arrives + return $rc + } + + # the sentinel: is this box performing as its machine should? + bench sentinel "$sentinel_id" --include "$include" --runs "$runs" --iterations "$iterations" \ + --warmups "$warmups" --json "$out/sentinel-timing.json" --dir "$out/sentinel-exec" >/dev/null || true + rc=0; "$repo/.venv/bin/speedr" sentinel "$out/sentinel-timing.json" "$machine" > "$out/sentinel.json" || rc=$? + echo "sentinel: $(tr -d '\n ' < "$out/sentinel.json" | grep -o '"deviation":[^,]*,"status":"[a-z]*"')" + if [ "$rc" = 3 ]; then + echo "sentinel failed: not running the timing pass on $(hostname -s)" + if [ -n "${SLURM_JOB_ID:-}" ]; then # keep the job, held, for when the box is fixed + scontrol update jobid="$SLURM_JOB_ID" comment="sentinel failed on $(hostname -s)" + scontrol requeuehold "$SLURM_JOB_ID" + fi + exit 1 + fi + [ "$rc" = 0 ] || exit "$rc" + + rc=0; bench run "$id" --json "$out/timing.json" --csv "$out/timing.csv" --dir "$out/exec" "$@" || rc=$? + { + echo "run_id=$run_id"; echo "label=$l"; echo "machine=$machine"; echo "node=$(hostname -s)" + echo "job=${SLURM_JOB_ID:-}"; echo "config=default" + echo "methodology=$("$repo/.venv/bin/speedr" methodology --current)" + echo "started=$started"; echo "finished=$(date -u +%Y-%m-%dT%H:%M:%SZ)"; echo "exit=$rc" + echo "kernel=$(uname -r)"; echo "cmdline=$(cat /proc/cmdline)" + echo "os_release=$(. /etc/os-release && echo "$PRETTY_NAME")" + echo "boot_id=$(cat /proc/sys/kernel/random/boot_id)"; echo "uptime_s=$(cut -d' ' -f1 /proc/uptime)" + echo "cpuset=$bench_cpus" + echo "source_sha256=$(sha256sum "$work/src/R-$l.tar.gz" | cut -d' ' -f1)" + echo "speedr=$(git -C "$repo" rev-parse HEAD)" + "$repo/.venv/bin/speedr" suite | awk '{ print $1 "=" $2 }' + } > "$out/run.env.new" + # run.env last: the controller ingests a run once it has arrived + rsync -aR --exclude run.env.new "$work/results/./$l/$run_id" "$spool" && + mv "$out/run.env.new" "$out/run.env" && + rsync -aR "$work/results/./$l/$run_id/run.env" "$spool" && + echo "results: $out, copied to the controller's spool" exit $rc ;; *) echo "usage: $0 image | env|id|configure|build SOURCE | run SOURCE [timing args]" >&2; exit 2 ;; diff --git a/node/speedr-publish b/node/speedr-publish new file mode 100755 index 0000000..9ed2c91 --- /dev/null +++ b/node/speedr-publish @@ -0,0 +1,19 @@ +#!/bin/bash +# On the controller, as speedr (cron, every few minutes): ingest the runs the +# nodes copied into the spool into a speedR-results checkout, commit and push +# them. Pushing to its `results` branch renders the dashboard (GitHub Pages). +# +# speedr-publish [SPOOL [RESULTS]] default /srv/speedr/spool, ~/speedR-results +set -euo pipefail +repo=$(cd "$(dirname "$0")/.." && pwd) +spool=${1:-/srv/speedr/spool} +results=${2:-$HOME/speedR-results} +exec 9>"$results/.git/speedr-publish.lock" +flock -n 9 || exit 0 # the previous one is still at it +cd "$results" +git pull -q --ff-only +new=$("$repo/.venv/bin/speedr" ingest "$spool" "$results") +[ -n "$new" ] || exit 0 +git add -A +git commit -q -m "Ingest $(echo "$new" | wc -l) run(s)" -m "$(echo "$new" | sed "s|^$results/||")" +git push -q diff --git a/site/R/prerender.R b/site/R/prerender.R index 5c290ac..9f4cb28 100644 --- a/site/R/prerender.R +++ b/site/R/prerender.R @@ -45,7 +45,9 @@ banner <- if (d$mock) { # others: render.sh puts each version in _site//, so the script swaps # that path segment (a plain `quarto render` has none, and shows no links) m <- d$methodology -others <- setdiff(d$methodology_versions$version, m$version) +all_versions <- paste(d$methodology_versions$version, collapse = " ") +rendered <- strsplit(Sys.getenv("SPEEDR_RENDERED", all_versions), " ")[[1]] +others <- setdiff(intersect(d$methodology_versions$version, rendered), m$version) links <- if (length(others)) paste0( " · other versions: ", paste0(sprintf('%s', others, others), collapse = ", ") diff --git a/site/R/stats.R b/site/R/stats.R index 69d98cf..7f95d64 100644 --- a/site/R/stats.R +++ b/site/R/stats.R @@ -25,7 +25,7 @@ estimate_runs <- function(samples) { rss <- tapply(ok$max_rss_mb, key, stats::median) parts <- do.call(rbind, strsplit(names(m), "\r", fixed = TRUE)) data.frame( - run = as.integer(parts[, 1]), benchmark = parts[, 2], + run = type.convert(parts[, 1], as.is = TRUE), benchmark = parts[, 2], log_mean = unname(m), log_se = unname(s / sqrt(n)), n = unname(n), est_ms = unname(exp(m)), gc_ms = unname(gc), max_rss_mb = unname(rss), stringsAsFactors = FALSE diff --git a/site/render.sh b/site/render.sh index db9f971..c7766c7 100755 --- a/site/render.sh +++ b/site/render.sh @@ -2,12 +2,25 @@ # Render the dashboard once per methodology version (../methodology/versions.csv) # into _site//, each showing only the runs measured under it, and # point _site/index.html at the newest. Extra arguments go to `quarto render`. +# +# SPEEDR_RESULTS_ROOT= renders its results: a version +# with an index there (//index), and only those. Unset, every +# version renders the synthetic mock. set -eu cd "$(dirname "$0")" versions=$(Rscript -e 'source("R/load.R"); cat(methodology_versions()$version)') +if [ -n "${SPEEDR_RESULTS_ROOT:-}" ]; then + root=$(cd "$SPEEDR_RESULTS_ROOT" && pwd) + with="" + for v in $versions; do [ -d "$root/$v/index" ] && with="$with $v"; done + versions=${with# } + [ -n "$versions" ] || { echo "render.sh: no results in $root" >&2; exit 1; } +fi +export SPEEDR_RENDERED="$versions" # the other versions the version bar links to rm -rf _site for v in $versions; do echo "render.sh: methodology $v" + if [ -n "${SPEEDR_RESULTS_ROOT:-}" ]; then export SPEEDR_RESULTS="$root/$v/index"; fi SPEEDR_METHODOLOGY=$v quarto render --output-dir "_site/$v" "$@" done newest=${versions##* } diff --git a/speedr/cli.py b/speedr/cli.py index e0ea492..cc5f603 100644 --- a/speedr/cli.py +++ b/speedr/cli.py @@ -1,19 +1,30 @@ -"""`speedr` command line. Grows a subcommand per pipeline stage (build, run, -profile, ingest, ...); for now it covers the registry, the metadata schema, the -suite pin and the profile manifest.""" +"""`speedr` command line: the registry, the metadata schema, the suite pin, +build settings, the sentinel, the profile manifest and the ingest.""" import argparse import json import sys from pathlib import Path -from . import __version__, build, configs, machines, meta, methodology, profile, results, upstream +from . import ( + __version__, + build, + configs, + ingest, + machines, + meta, + methodology, + profile, + results, + sentinel, + upstream, +) def cmd_machines(args: argparse.Namespace) -> int: for m in machines.load_all(): print(f"{m.name:24} {m.os}/{m.arch:8} wake={m.wake:9} profiler={m.profiler:7} " - f"labels={','.join(m.runner_labels)}") + f"sentinel={'calibrated' if m.sentinel else 'uncalibrated'}") return 0 @@ -24,6 +35,9 @@ def cmd_configs(args: argparse.Namespace) -> int: def cmd_methodology(args: argparse.Namespace) -> int: + if args.current: + print(methodology.current().version) + return 0 for m in methodology.load_all(): print(f"{m.version:6} {m.status:7} {m.date} {m.summary}") return 0 @@ -54,6 +68,21 @@ def cmd_check_results(args: argparse.Namespace) -> int: return 1 if problems else 0 +def cmd_sentinel(args: argparse.Namespace) -> int: + if args.plan: + print(sentinel.plan()) + return 0 + r = sentinel.check(json.loads(Path(args.report).read_text()), args.machine) + print(json.dumps(r, indent=1)) + return 3 if r["status"] == "failed" else 0 + + +def cmd_ingest(args: argparse.Namespace) -> int: + for run in ingest.ingest(Path(args.spool), Path(args.root)): + print(run) + return 0 + + def cmd_suite(args: argparse.Namespace) -> int: for name, commit in upstream.commits().items(): print(f"{name:7} {commit}") @@ -77,8 +106,9 @@ def parser() -> argparse.ArgumentParser: func=cmd_machines) sub.add_parser("configs", help="list and validate configs.toml").set_defaults( func=cmd_configs) - sub.add_parser("methodology", help="list the methodology versions").set_defaults( - func=cmd_methodology) + mv = sub.add_parser("methodology", help="list the methodology versions") + mv.add_argument("--current", action="store_true", help="print only the one new runs use") + mv.set_defaults(func=cmd_methodology) b = sub.add_parser("build-env", help="the compilers and configure answers to build an R " "version with (build/settings.toml)") b.add_argument("version", @@ -90,6 +120,17 @@ def parser() -> argparse.ArgumentParser: r = sub.add_parser("check-results", help="check a speedR-results checkout's layout") r.add_argument("root", metavar="DIR") r.set_defaults(func=cmd_check_results) + s = sub.add_parser("sentinel", help="check a sentinel run against the machine's reference " + "(exit 3: failed)") + s.add_argument("report", nargs="?", metavar="REPORT.json", help="the sentinel's --json report") + s.add_argument("machine", nargs="?", help="machines/.toml") + s.add_argument("--plan", action="store_true", + help="print the R version, benchmarks and run design as shell assignments") + s.set_defaults(func=cmd_sentinel) + i = sub.add_parser("ingest", help="add the spool's new runs to a speedR-results checkout") + i.add_argument("spool", metavar="SPOOL") + i.add_argument("root", metavar="RESULTS") + i.set_defaults(func=cmd_ingest) sub.add_parser("suite", help="show the rbench and bench commits, checked against the " "environment").set_defaults(func=cmd_suite) pm = sub.add_parser("profile-manifest", diff --git a/speedr/ingest.py b/speedr/ingest.py new file mode 100644 index 0000000..18e047b --- /dev/null +++ b/speedr/ingest.py @@ -0,0 +1,261 @@ +"""Ingest: turn the runs the nodes copy into the controller's spool into +speedR-results (layout: results.py). + + /