feat: add cost and memory tables, passports and sampler limits to track 1 outputs

plots.py summary gains per-request CPU by component, PostgreSQL waits and
pool, H1b throttling and memory peaks; compare.py and plots.py headers
name the spec, change and host; errors logs match 5xx by status field and
keep the exception tail; series labels record sampler limits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-11 07:26:36 +03:00
co-authored by Claude Opus 5.5
parent 68edc66742
commit dcea85942a
4 changed files with 332 additions and 20 deletions
+42 -14
View File
@@ -65,6 +65,16 @@ SAMPLER = "mtusi-bench-sampler"
SAMPLER_SCRIPT = ROOT / "bench" / "sampler.sh"
# один прогон стенда любого профиля: flock держится до выхода процесса
LOCK_FILE = ROOT / "bench" / ".bench.lock"
# строки журналов окна с 5xx и отказами (`raw/<ступень>-errors.log`):
# PostgreSQL — отказ и FATAL; API — ответ 5xx или запись error; HAProxy —
# поле статуса 5xx или ответ без сервера. Подстроки «53300» и « 5»
# ловили метки времени и request_id (verify S4)
ERRORS_PG_RE = re.compile(r"too many clients|FATAL")
ERRORS_API_RE = re.compile(r'"status": 5\d\d\b|"level": "error"')
ERRORS_LB_RE = re.compile(r"\s5\d\d\s|<NOSRV>")
# длинная строка журнала: начало и конец (класс исключения — в конце)
ERRORS_HEAD = 300
ERRORS_TAIL = 300
# второе хранилище этапа восстановления: контейнер, volume и имя в сети
# стенда (по нему API переключается на восстановленную базу)
RESTORE_DB = "mtusi-bench-postgres-restore"
@@ -2235,6 +2245,13 @@ class Measured:
return self.cores("db_usec")
def shorten(line: str) -> str:
"""Строка журнала в файл ошибок: длинная — начало, «…» и конец."""
if len(line) <= ERRORS_HEAD + ERRORS_TAIL:
return line
return f"{line[:ERRORS_HEAD]} … {line[-ERRORS_TAIL:]}"
def k6_failure(script: str, proc: subprocess.CompletedProcess[str]) -> str:
tail = (proc.stdout + proc.stderr)[-3000:]
return f"k6 {script} failed ({proc.returncode}):\n{tail}"
@@ -3879,12 +3896,18 @@ class Bench:
# max_connections — в лимитах конфигурации, не в паспорте
known = self.results.meta.setdefault("limits", {})
config = self.cell["config"]
if config in known and known[config] != limits:
# лимиты сэмплера добавляет run_cell после его запуска
earlier = known.get(config, {})
sampler = earlier.get("sampler")
stand_only = {k: v for k, v in earlier.items() if k != "sampler"}
if config in known and stand_only != limits:
raise BenchError(
f"{config}: limits differ from the earlier repeat: "
f"{limits}",
)
known[config] = limits
known[config] = (
limits if sampler is None else {**limits, "sampler": sampler}
)
if "stand" not in self.results.meta:
passport = stand.passport()
passport["postgres"]["settings"].pop("max_connections", None)
@@ -4545,6 +4568,15 @@ class Bench:
size = p.sizes[0]
stand.start_sampler()
self.say(f"{tag}: sampler started")
# лимиты сэмплера — тоже у запущенного контейнера, в лимитах
# конфигурации (спек «Лимиты конфигурации серии», verify S11)
sampler = stand.container_limits(SAMPLER)
known = self.results.meta["limits"][cell["config"]]
if known.setdefault("sampler", sampler) != sampler:
raise BenchError(
f"{cell['config']}: sampler limits differ from the earlier "
f"repeat: {sampler}",
)
replicas = stand.replicas()
instances = [stand.full_id(name)[:12] for name in replicas]
addresses = {
@@ -4952,14 +4984,14 @@ class Bench:
) -> None:
"""Доказательства 5xx и отказов «too many clients» ступени (H3):
строки PostgreSQL, API и LB окна, без секретов — строки со словом
`password` отбрасываются, длина строки ограничена."""
`password` отбрасываются. Длинная строка (traceback) сокращается
до начала и конца: класс исключения — в конце (verify S4)."""
def pick(text: str, needles: tuple[str, ...], limit: int) -> list[str]:
def pick(text: str, pattern: re.Pattern[str], limit: int) -> list[str]:
lines = [
line[:600]
shorten(line)
for line in text.splitlines()
if any(n in line for n in needles)
and "password" not in line.lower()
if pattern.search(line) and "password" not in line.lower()
]
return lines[:limit]
@@ -4967,20 +4999,16 @@ class Bench:
f"# {name}: коды ошибок окна k6 — {codes or 'нет'}",
"",
"## PostgreSQL",
*pick(pg_log, (scaling.TOO_MANY_CLIENTS, "FATAL"), 10),
*pick(pg_log, ERRORS_PG_RE, 10),
"",
"## API",
]
for replica in self.stand.replicas():
out += pick(
self.window_log(replica, w0, w1),
('"status": 5', '"level": "error"', "53300", "too many"),
10,
)
out += pick(self.window_log(replica, w0, w1), ERRORS_API_RE, 10)
out += [
"",
"## HAProxy",
*pick(self.window_log(LB, w0, w1), (" 5", "<NOSRV>", "sD"), 10),
*pick(self.window_log(LB, w0, w1), ERRORS_LB_RE, 10),
]
path = self.results.dir / "raw" / f"{name}-errors.log"
path.write_text("\n".join(out) + "\n", encoding="utf-8")