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:
+30
-6
@@ -14,6 +14,7 @@ from dataclasses import dataclass
|
||||
from typing import Any
|
||||
|
||||
import failover
|
||||
import resources as res
|
||||
|
||||
ROLLOUT_FIELDS = [
|
||||
"label",
|
||||
@@ -274,6 +275,29 @@ def start_time(events: list[ContainerEvent]) -> float | None:
|
||||
return create.time if create else None
|
||||
|
||||
|
||||
def script_start(
|
||||
events: list[ContainerEvent],
|
||||
since: float,
|
||||
ignore: frozenset[str] | set[str] = frozenset(),
|
||||
) -> float | None:
|
||||
"""Начало подготовки замены (решение 4 design change
|
||||
`profile-resources`): первое `exec_start` в контейнер проекта не
|
||||
раньше `since` (первого запроса) — первое обращение скрипта к LB.
|
||||
Оркестратор во время нагрузки `docker exec` не делает, k6 — вне
|
||||
проекта; `exec_start` проверок здоровья (`ignore` — их действия)
|
||||
отбрасываются (найдено в apply: они тоже приходят каждые 5 с)."""
|
||||
return next(
|
||||
(
|
||||
e.time
|
||||
for e in events
|
||||
if e.action.startswith("exec_start")
|
||||
and e.action not in ignore
|
||||
and e.time >= since
|
||||
),
|
||||
None,
|
||||
)
|
||||
|
||||
|
||||
def diff(later: Any, earlier: Any) -> float | None:
|
||||
if later is None or earlier is None:
|
||||
return None
|
||||
@@ -515,9 +539,11 @@ def render_summary(
|
||||
row: dict[str, Any] | None,
|
||||
replicas: 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"]
|
||||
info = meta.get("rollout", {})
|
||||
lines = [
|
||||
@@ -537,11 +563,7 @@ def render_summary(
|
||||
f"замены {profile['rollout_budget_s']} с, ещё "
|
||||
f"{profile['rollout_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']}",
|
||||
failover.limits_line(profile),
|
||||
"- Посторонние контейнеры в VM во время замера: "
|
||||
+ (", ".join(meta.get("other_containers") or []) or "нет"),
|
||||
"",
|
||||
@@ -604,6 +626,8 @@ def render_summary(
|
||||
f"{r['errors']} | {r['after_drain']} |",
|
||||
)
|
||||
lines.append("")
|
||||
if resources:
|
||||
lines += res.render_rollout(resources)
|
||||
for title, key in (
|
||||
("до", "containers_before"),
|
||||
("после", "containers_after"),
|
||||
|
||||
Reference in New Issue
Block a user