forked from mtusi2026/mtusi2026lab7
fix: record replica death and OOM in the login bench profile
The first baseline attempt on 13fdd18 lost CPU and peak memory of the
"before" variant: its replicas died inside the window and the profile
did not notice. Poll memory.peak during the window, inspect replicas
after it (OOMKilled, exit code, time of death), add oom / replica_died
marks and base H4 on them. The attempt is kept out of git and recorded
in QUESTIONS.md; the label is retaken as baseline2.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+65
-3
@@ -486,6 +486,9 @@ class Profile:
|
||||
login_light_rate: int = 50
|
||||
login_good_rate: int = 1
|
||||
login_users: int = 20
|
||||
# опрос `memory.peak` реплик в окне: последний пик до гибели реплики
|
||||
# (после OOM cgroup контейнера уже не прочитать)
|
||||
login_poll_s: int = 5
|
||||
login_budget_env: tuple[tuple[str, str], ...] = (
|
||||
("AUTH__LOGIN_MAX_FAILURES_PER_ACCOUNT", "0"),
|
||||
("AUTH__LOGIN_MAX_FAILURES_PER_ADDRESS", "0"),
|
||||
@@ -3865,6 +3868,39 @@ class Stand:
|
||||
"exit_code": state.get("ExitCode"),
|
||||
}
|
||||
|
||||
def replica_fate(self, name: str) -> dict[str, Any]:
|
||||
"""Судьба реплики за прогон профиля входа: состояние, OOM, код
|
||||
выхода, перезапуски и время завершения (часы ВМ, мс) — у
|
||||
неработающей; контейнера нет — `status` `missing`."""
|
||||
text = sh(
|
||||
"docker",
|
||||
"inspect",
|
||||
"-f",
|
||||
"{{json .State}}|{{.RestartCount}}",
|
||||
name,
|
||||
check=False,
|
||||
)
|
||||
state_json, _, restarts = text.rpartition("|")
|
||||
if not state_json:
|
||||
return {
|
||||
"status": "missing",
|
||||
"oom": False,
|
||||
"exit_code": None,
|
||||
"restarts": 0,
|
||||
"finished_ms": None,
|
||||
}
|
||||
state = json.loads(state_json)
|
||||
running = bool(state.get("Running"))
|
||||
return {
|
||||
"status": state.get("Status") or "",
|
||||
"oom": bool(state.get("OOMKilled")),
|
||||
"exit_code": None if running else state.get("ExitCode"),
|
||||
"restarts": int(restarts or 0),
|
||||
"finished_ms": (
|
||||
None if running else login.iso_ms(state.get("FinishedAt", ""))
|
||||
),
|
||||
}
|
||||
|
||||
def down_storages(self) -> list[str]:
|
||||
"""Хранилища, которые за прогон умирали, убивались или рестартовали."""
|
||||
down = []
|
||||
@@ -7494,7 +7530,10 @@ class Bench:
|
||||
"""Прогон: реплики варианта, сверка «Started API», генератор потока
|
||||
и лёгких запросов, затем верные входы со второго генератора; CPU — по
|
||||
`cpu.stat` контейнеров на границах окна, пик памяти реплик — их
|
||||
`memory.peak` (контейнеры нового прогона), хэши — по журналу."""
|
||||
`memory.peak` (контейнеры нового прогона; в окне — опрос раз в
|
||||
`login_poll_s`, последний пик до гибели), хэши — по журналу; после
|
||||
окна — `docker inspect` реплик (состояние, OOM, код выхода,
|
||||
перезапуски, время завершения): пометки `oom` и `replica_died`."""
|
||||
p = self.profile
|
||||
stand = self.stand
|
||||
name = run["run"]
|
||||
@@ -7555,7 +7594,18 @@ class Bench:
|
||||
key: stand.cgroup_value(c, "cpu.stat", "usage_usec")
|
||||
for key, c in containers.items()
|
||||
}
|
||||
time.sleep(max(0.0, end - time.time()))
|
||||
# последний прочитанный пик каждой реплики: после гибели
|
||||
# (OOM) её cgroup уже не прочитать
|
||||
last_peaks: dict[str, int] = {}
|
||||
while True:
|
||||
for replica in replicas:
|
||||
value = stand.cgroup_value(replica, "memory.peak")
|
||||
if value is not None:
|
||||
last_peaks[replica] = value
|
||||
left = end - time.time()
|
||||
if left <= 0:
|
||||
break
|
||||
time.sleep(min(p.login_poll_s, left))
|
||||
cpu_after = {
|
||||
key: stand.cgroup_value(c, "cpu.stat", "usage_usec")
|
||||
for key, c in containers.items()
|
||||
@@ -7589,6 +7639,10 @@ class Bench:
|
||||
peaks = [
|
||||
stand.cgroup_value(replica, "memory.peak") for replica in replicas
|
||||
]
|
||||
for replica, value in zip(replicas, peaks, strict=True):
|
||||
if value is not None:
|
||||
last_peaks[replica] = value
|
||||
fates = [stand.replica_fate(replica) for replica in replicas]
|
||||
usage = {
|
||||
"api_cpu_cores": (
|
||||
round(sum(c for c in api_cores if c is not None), 3)
|
||||
@@ -7603,6 +7657,13 @@ class Bench:
|
||||
"lb_cpu_cores": cores("lb"),
|
||||
"db_cpu_cores": cores("db"),
|
||||
"cache_cpu_cores": cores("cache"),
|
||||
"api_last_peak_mib": (
|
||||
round(max(last_peaks.values()) / 2**20, 1)
|
||||
if last_peaks
|
||||
else None
|
||||
),
|
||||
"fates": fates,
|
||||
"window_begin_ms": round(begin * 1000),
|
||||
}
|
||||
hashes = [
|
||||
login.count_hashes(
|
||||
@@ -7633,7 +7694,8 @@ class Bench:
|
||||
f"{row['light_p95_ms']} ms, flood 401 {row['flood_s401']} 429 "
|
||||
f"{row['flood_s429']}, good 201 {row['good_s201']}/"
|
||||
f"{row['good_count']}, hashes {row['hashes']}, api CPU "
|
||||
f"{row['api_cpu_cores']}, peak {row['api_peak_mib']} MiB",
|
||||
f"{row['api_cpu_cores']}, peak {row['api_peak_mib']} MiB"
|
||||
+ (f", replicas: {row['api_fate']}" if row["api_died"] else ""),
|
||||
)
|
||||
self.progress(last={"run": name, "flags": row["flags"]})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user