feat: add track 1 series db with a tight PostgreSQL CPU limit

Configs may carry a fifth element, the PostgreSQL CPU limit, which goes
into the config key (-pg<CPU>), the budget and the cell stand. Series db:
1, 2, 4 replicas at the tight limit and a 4 x 1 control at 2 CPU; label
summaries show PostgreSQL CPU at R* against its limit and throttling.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-11 11:27:30 +03:00
co-authored by Claude Opus 5.5
parent a3279374f7
commit 95539a1883
4 changed files with 152 additions and 37 deletions
+79 -21
View File
@@ -227,16 +227,39 @@ def spread(values: Iterable[float | None], digits: int = 0) -> str:
# ----------------------------------------------------- конфигурации
def config_key(replicas: int, cpus: str, _memory: str, max_conn: int) -> str:
"""Имя конфигурации: `4x1`, у предела соединений не 100 — `4x1-c50`.
def config_key(
replicas: int,
cpus: str,
_memory: str,
max_conn: int,
db_cpus: str = "",
) -> str:
"""Имя конфигурации: `4x1`, у предела соединений не 100 — `4x1-c50`,
у своего лимита CPU PostgreSQL (серия `db`) — `4x1-pg0.5`.
Память реплики в имя не входит: в сериях она задана числом CPU."""
key = f"{replicas}x{cpus}"
return key if max_conn == 100 else f"{key}-c{max_conn}"
if max_conn != 100:
key = f"{key}-c{max_conn}"
return f"{key}-pg{db_cpus}" if db_cpus else key
def unpack_config(config: Any) -> tuple[int, str, str, int, str]:
"""Конфигурация серии: (реплик, CPU и память реплики, max_connections
[, CPU PostgreSQL]). Пятый элемент — только у серии `db`; без него
лимит PostgreSQL — профиля."""
replicas, cpus, memory, max_conn, *rest = config
return (
int(replicas),
str(cpus),
str(memory),
int(max_conn),
str(rest[0]) if rest else "",
)
def plan_cells(
configs: list[tuple[int, str, str, int]],
configs: list[tuple[Any, ...]],
repeats: int,
seed: int,
) -> list[dict[str, Any]]:
@@ -252,21 +275,24 @@ def plan_cells(
if len(order) > 1 and order[0] == previous:
order[0], order[1] = order[1], order[0]
for index in order:
replicas, cpus, memory, max_conn = configs[index]
key = config_key(replicas, cpus, memory, max_conn)
plan.append(
{
"cell": f"{key}-r{round_no}",
"config": key,
"replicas": replicas,
"replica_cpus": cpus,
"replica_memory": memory,
"db_max_connections": max_conn,
"repeat": round_no,
"round": round_no,
"order": len(plan) + 1,
},
replicas, cpus, memory, max_conn, db_cpus = unpack_config(
configs[index],
)
key = config_key(replicas, cpus, memory, max_conn, db_cpus)
cell = {
"cell": f"{key}-r{round_no}",
"config": key,
"replicas": replicas,
"replica_cpus": cpus,
"replica_memory": memory,
"db_max_connections": max_conn,
"repeat": round_no,
"round": round_no,
"order": len(plan) + 1,
}
if db_cpus:
cell["db_cpus"] = db_cpus
plan.append(cell)
previous = order[-1]
return plan
@@ -1141,9 +1167,13 @@ def config_stats(
profile = meta["profile"]
fixed = profile.get("fixed_rps") or []
order = [
config_key(int(r), str(c), str(m), int(mc))
for r, c, m, mc in profile.get("configs", [])
config_key(*unpack_config(config))
for config in profile.get("configs", [])
]
db_limits = {
config_key(*parts): parts[4] or str(profile.get("db_cpus", ""))
for parts in map(unpack_config, profile.get("configs", []))
}
result = []
for key in order:
cells = [s for s in searches if s["config"] == key]
@@ -1155,6 +1185,7 @@ def config_stats(
at_f: list[list[str]] = []
reasons = []
db_at_r = []
db_thr_at_r: list[float | None] = []
app_at_r = []
app_sec = []
marginals: list[float | None] = []
@@ -1183,6 +1214,7 @@ def config_stats(
if r_row is not None:
at_r.append((r_row.get("signs") or "").split())
db_at_r.append(num(r_row.get("db_cpu_cores")))
db_thr_at_r.append(num(r_row.get("db_throttled_ratio")))
app_at_r.append(num(r_row.get("app_cpu_cores")))
if f_row is not None:
at_f.append((f_row.get("signs") or "").split())
@@ -1235,6 +1267,8 @@ def config_stats(
"signs_r": majority(at_r),
"signs_f": majority(at_f),
"db_cpu_r": median(db_at_r),
"db_throttled_r": median(db_thr_at_r),
"db_cpus": db_limits.get(key, ""),
"app_cpu_r": median(app_at_r),
"app_cpu_second_max": max(
(v for v in app_sec if v is not None),
@@ -1375,7 +1409,8 @@ def render_summary(
f"{profile['repeats']}, порядок кругами (зерно "
f"{profile['order_seed']})",
f"- Лимиты без swap: PostgreSQL {profile['db_cpus']} CPU / "
f"{profile['db_memory']}, HAProxy {profile['lb_cpus']} / "
f"{profile['db_memory']} (у конфигураций `-pg<CPU>` — свой лимит "
f"CPU), HAProxy {profile['lb_cpus']} / "
f"{profile['lb_memory']}, Valkey {profile['cache_cpus']} / "
f"{profile['cache_memory']}, k6 {profile['generator_cpus']} / "
f"{profile['generator_memory']}, сэмплер {profile['sampler_cpus']} "
@@ -1420,6 +1455,29 @@ def render_summary(
f"{fmt(c['app_us_marginal'], 0)} | {fmt(c['host_cost'], 2)} |",
)
lines.append("")
if any("-pg" in c["config"] for c in stats):
# серия db: насыщение PostgreSQL — CPU у лимита и троттлинг CFS
lines += [
"## PostgreSQL на R*",
"",
"| Конфигурация | Лимит CPU PostgreSQL | CPU PostgreSQL на R*, "
"ядер | Доля лимита | Троттлинг PostgreSQL на R*, доля "
"периодов |",
"|---|---|---|---|---|",
]
for c in stats:
limit = num(c.get("db_cpus"))
share = (
c["db_cpu_r"] / limit
if limit and c["db_cpu_r"] is not None
else None
)
lines.append(
f"| {c['config']} | {c.get('db_cpus') or '—'} | "
f"{fmt(c['db_cpu_r'], 2)} | {fmt(share, 2)} | "
f"{fmt(c.get('db_throttled_r'), 3)} |",
)
lines.append("")
for lvl in fixed:
lines += [
f"## Фиксированный уровень {lvl} запросов/с",