feat: sample CPU and memory in failover and rollout profiles

Run bench/sampler.sh in a new scan mode (cgroup walk, no network, no
psql or LB polling) for the whole load of the failover and rollout
profiles. bench/resources.py turns the samples into per-window CPU,
throttling and memory of every component and the VM, with
samples.csv, resources.csv and summary sections; CPU per successful
request only in steady windows. Check the peak CPU budget before the
stand starts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-12 17:42:04 +03:00
co-authored by Claude Opus 5.5
parent 417fdd2f22
commit 6505b5e929
8 changed files with 1752 additions and 67 deletions
+58 -23
View File
@@ -1,22 +1,37 @@
#!/usr/bin/env bash
# Сэмплер стенда трека 1 (решение 7 design change scaling-bench). Работает
# только внутри контейнера mtusi-bench-sampler (образ PostgreSQL стенда,
# --cgroupns host, сеть mtusi-bench), не на хосте: его запускает
# bench/run.py (Stand.start_sampler). Раз в интервал пишет в
# /work/samples.log строки с отметкой часов ВМ в наносекундах:
# Сэмплер стенда (решение 7 design change scaling-bench, решение 1 design
# change profile-resources). Работает только внутри контейнера
# mtusi-bench-sampler (образ PostgreSQL стенда, --cgroupns host), не на
# хосте: его запускает bench/run.py (Stand.start_sampler). Раз в интервал
# пишет в /work/samples.log строки с отметкой часов ВМ в наносекундах
# (одна отметка на весь тик):
# cg <нс> <роль> <id12> <usage_usec> <nr_periods> <nr_throttled>
# <throttled_usec> <memory.current> <cpu.pressure some total>
# cg <нс> <роль> <id12> missing — нет каталога cgroup
# vm <нс> <занято jiffies> <всего jiffies> <PSI CPU some total, мкс>
# lb <нс> # <заголовок CSV статистики HAProxy> / lb <нс> api,<строка>
# lb <нс> missing — статистика недоступна
# В фоне psql с \watch пишет /work/pg-samples.log (одно соединение на всю
# ячейку): act, db, wal, io — разбор в bench/scaling.py (parse_samples).
# Аргументы: <интервал, с> <роль>=<полный id контейнера>…
# Режимы — по второму аргументу:
# list (серии трека 1): <интервал, с> <роль>=<полный id контейнера>…
# Сеть mtusi-bench. Строки cg заданных контейнеров, vm и lb; в фоне
# psql с \watch пишет /work/pg-samples.log (одно соединение на всю
# ячейку): act, db, wal, io — разбор в bench/scaling.py
# (parse_samples).
# scan (профили failover и rollout): <интервал, с> scan
# Контейнер без сети. На каждом тике — обход /sys/fs/cgroup/docker/*/
# (только каталоги с именем из 64 hex — контейнеры), строка
# `cg <нс> - <id12> …` на каждый; роли назначает оркестратор. Строки
# vm — как в list. Ни psql, ни опроса LB: наблюдатель не обращается к
# стенду.
set -u
interval=$1
shift
mode=list
if [[ ${1:-} == scan ]]; then
mode=scan
shift
fi
roles=()
ids=()
for arg in "$@"; do
@@ -24,6 +39,7 @@ for arg in "$@"; do
ids+=("${arg#*=}")
done
if [[ $mode == list ]]; then
export PGPASSWORD="$POSTGRES_PASSWORD"
psql "host=postgres user=$POSTGRES_USER dbname=$POSTGRES_DB \
application_name=bench-sampler" -XAtq -F '|' >/work/pg-samples.log 2>&1 <<SQL &
@@ -50,26 +66,35 @@ SELECT 'io', (SELECT ts FROM t), coalesce(sum(writes), 0)::text,
FROM pg_stat_io WHERE object = 'wal'
\watch $interval
SQL
fi
exec 4>>/work/samples.log
cg_line() {
local role=$1 id=$2 dir=/sys/fs/cgroup/docker/$2
local key val usage=0 periods=0 throttled=0 thr_usec=0 mem=0 psi=0 rest
local key val usage= periods=0 throttled=0 thr_usec=0 mem= psi=0 rest=
if [[ ! -r $dir/cpu.stat ]]; then
printf 'cg %s %s %s missing\n' "$ns" "$role" "${id:0:12}" >&4
return
fi
while read -r key val; do
case $key in
usage_usec) usage=$val ;;
nr_periods) periods=$val ;;
nr_throttled) throttled=$val ;;
throttled_usec) thr_usec=$val ;;
esac
done <"$dir/cpu.stat"
read -r mem <"$dir/memory.current"
read -r _ _ _ _ rest <"$dir/cpu.pressure"
# каталог может пропасть между проверкой и чтением (контейнер
# остановлен посреди тика): тогда тоже missing, а не строка нулей
{
while read -r key val; do
case $key in
usage_usec) usage=$val ;;
nr_periods) periods=$val ;;
nr_throttled) throttled=$val ;;
throttled_usec) thr_usec=$val ;;
esac
done <"$dir/cpu.stat"
read -r mem <"$dir/memory.current"
read -r _ _ _ _ rest <"$dir/cpu.pressure"
} 2>/dev/null
if [[ -z $usage || -z $mem ]]; then
printf 'cg %s %s %s missing\n' "$ns" "$role" "${id:0:12}" >&4
return
fi
psi=${rest#total=}
printf 'cg %s %s %s %s %s %s %s %s %s\n' "$ns" "$role" "${id:0:12}" \
"$usage" "$periods" "$throttled" "$thr_usec" "$mem" "$psi" >&4
@@ -100,13 +125,23 @@ lb_lines() {
exec 3<&-
}
hex64='^[0-9a-f]{64}$'
while :; do
# EPOCHREALTIME bash 5 — часы ВМ без запуска date
ns=${EPOCHREALTIME/./}000
for i in "${!ids[@]}"; do
cg_line "${roles[$i]}" "${ids[$i]}"
done
if [[ $mode == scan ]]; then
for dir in /sys/fs/cgroup/docker/*/; do
dir=${dir%/}
id=${dir##*/}
[[ $id =~ $hex64 ]] && cg_line - "$id"
done
else
for i in "${!ids[@]}"; do
cg_line "${roles[$i]}" "${ids[$i]}"
done
fi
vm_line
lb_lines
[[ $mode == list ]] && lb_lines
sleep "$interval"
done