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:
+29
-6
@@ -16,6 +16,8 @@ from dataclasses import dataclass
|
||||
from datetime import UTC, datetime
|
||||
from typing import Any
|
||||
|
||||
import resources as res
|
||||
|
||||
# худшее время обнаружения по проверкам LB, с (infra/haproxy/haproxy.cfg:
|
||||
# inter 1s, fastinter 500ms, fall 2, timeout check 2500ms, timeout connect
|
||||
# 500ms): адрес пропал — inter + 0,5 + fastinter + 0,5; зависшая —
|
||||
@@ -474,13 +476,33 @@ def fmt(value: Any) -> str:
|
||||
return str(value)
|
||||
|
||||
|
||||
def limits_line(profile: dict[str, Any]) -> str:
|
||||
"""Строка лимитов шапки сводки; с сэмплером — и его лимит, и k6 без
|
||||
лимита (design change `profile-resources`, решение 7)."""
|
||||
line = (
|
||||
f"- Лимиты без swap: API {profile['cpus']} CPU / "
|
||||
f"{profile['memory']} на реплику, HAProxy {profile['lb_cpus']} CPU / "
|
||||
f"{profile['lb_memory']}, PostgreSQL {profile['db_cpus']} CPU / "
|
||||
f"{profile['db_memory']}, Valkey {profile['cache_cpus']} CPU / "
|
||||
f"{profile['cache_memory']}"
|
||||
)
|
||||
if profile.get("sample_resources"):
|
||||
line += (
|
||||
f", сэмплер {profile['sampler_cpus']} CPU / "
|
||||
f"{profile['sampler_memory']}, k6 без лимита"
|
||||
)
|
||||
return line
|
||||
|
||||
|
||||
def render_summary(
|
||||
meta: dict[str, Any],
|
||||
phases: list[dict[str, Any]],
|
||||
timeline: list[dict[str, Any]],
|
||||
resources: list[dict[str, Any]] | None = None,
|
||||
) -> str:
|
||||
"""`summary.md` профиля отказа: условия, таблица фаз, шкалы вокруг
|
||||
действия и возврата."""
|
||||
действия и возврата; с `resources` (строки `resources.csv`) — ещё
|
||||
ресурсы по фазам и окнам."""
|
||||
profile = meta["profile"]
|
||||
lines = [
|
||||
f"# Отказ реплик под нагрузкой: метка `{meta['label']}`",
|
||||
@@ -498,11 +520,7 @@ def render_summary(
|
||||
f"{profile['failover_down_s']} с до возврата, "
|
||||
f"{profile['failover_after_s']} с после; порог восстановления "
|
||||
f"{profile['failover_success']:.0%}",
|
||||
f"- Лимиты без swap: API {profile['cpus']} CPU / "
|
||||
f"{profile['memory']} на реплику, HAProxy {profile['lb_cpus']} CPU / "
|
||||
f"{profile['lb_memory']}, PostgreSQL {profile['db_cpus']} CPU / "
|
||||
f"{profile['db_memory']}, Valkey {profile['cache_cpus']} CPU / "
|
||||
f"{profile['cache_memory']}",
|
||||
limits_line(profile),
|
||||
"- Посторонние контейнеры в VM во время замера: "
|
||||
+ (", ".join(meta.get("other_containers") or []) or "нет"),
|
||||
"",
|
||||
@@ -538,6 +556,9 @@ def render_summary(
|
||||
f"{fmt(row['pg_idle_tx_terminated'])} | {fmt(row['flags'])} |",
|
||||
)
|
||||
lines.append("")
|
||||
if resources:
|
||||
order = list(dict.fromkeys(r["phase"] for r in resources))
|
||||
lines += res.render_failover(resources, order)
|
||||
for row in phases:
|
||||
rows = [r for r in timeline if r["phase"] == row["phase"]]
|
||||
reach = max(
|
||||
@@ -576,6 +597,8 @@ def render_summary(
|
||||
f"{fmt(r['p95_ms'])} | {fmt(r['instances'])} |",
|
||||
)
|
||||
lines.append("")
|
||||
if resources:
|
||||
lines += res.render_failover_phase(resources, row["phase"])
|
||||
if meta.get("host_warnings"):
|
||||
lines += ["## Предупреждения о хосте", ""]
|
||||
lines += [f"- {w}" for w in meta["host_warnings"]]
|
||||
|
||||
Reference in New Issue
Block a user