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:
+48
-7
@@ -318,7 +318,8 @@ class Profile:
|
||||
# как у образа; у ячейки серии — из конфигурации
|
||||
db_max_connections: int = 100
|
||||
series: str = ""
|
||||
configs: tuple[tuple[int, str, str, int], ...] = ()
|
||||
# у серии db — пятый элемент: CPU PostgreSQL конфигурации
|
||||
configs: tuple[tuple[Any, ...], ...] = ()
|
||||
write_chats: int = 1
|
||||
mix: tuple[tuple[str, float], ...] = ()
|
||||
fixed_rps: tuple[int, ...] = ()
|
||||
@@ -527,7 +528,7 @@ PROFILES = {
|
||||
def scaling_profile(
|
||||
name: str,
|
||||
series: str,
|
||||
configs: tuple[tuple[int, str, str, int], ...],
|
||||
configs: tuple[tuple[Any, ...], ...],
|
||||
**fields: Any,
|
||||
) -> Profile:
|
||||
"""Профиль серии трека 1: общие поля всех серий в одном месте, чтобы
|
||||
@@ -570,6 +571,14 @@ def scaling_profile(
|
||||
|
||||
|
||||
B_CONFIGS = tuple((k, "1", "512m", 100) for k in range(1, 7))
|
||||
# серия db: CPU PostgreSQL у 1, 2 и 4 реплик и контроль 4 × 1 при 2 CPU
|
||||
DB_CPUS_TIGHT = "0.5"
|
||||
DB_CONFIGS = (
|
||||
(1, "1", "512m", 100, DB_CPUS_TIGHT),
|
||||
(2, "1", "512m", 100, DB_CPUS_TIGHT),
|
||||
(4, "1", "512m", 100, DB_CPUS_TIGHT),
|
||||
(4, "1", "512m", 100, "2"),
|
||||
)
|
||||
PROFILES.update(
|
||||
{
|
||||
# фиксированный бюджет приложения 4 CPU / 2 ГиБ
|
||||
@@ -606,18 +615,45 @@ PROFILES.update(
|
||||
bisect_steps=1,
|
||||
max_steps=6,
|
||||
),
|
||||
# насыщение PostgreSQL управляемым опытом (verify S2, указание
|
||||
# пользователя 2026-10-11): 1, 2 и 4 реплики при узком лимите CPU
|
||||
# PostgreSQL и контроль — 4 реплики при прежних 2 CPU. Пятый
|
||||
# элемент конфигурации — CPU PostgreSQL; лимит — по калибровке
|
||||
# (design, «Найдено в verify»)
|
||||
"scaling_db": scaling_profile(
|
||||
"scaling_db",
|
||||
"db",
|
||||
DB_CONFIGS,
|
||||
),
|
||||
# самопроверка серии db и калибровка лимита: 2 и 4 реплики при
|
||||
# узком лимите, один повтор, короткие окна
|
||||
"scaling_db_quick": scaling_profile(
|
||||
"scaling_db_quick",
|
||||
"db_quick",
|
||||
DB_CONFIGS[1:3],
|
||||
sizes=(2_000,),
|
||||
repeats=1,
|
||||
fixed_rps=(250,),
|
||||
first_warmup_s=8,
|
||||
step_warmup_s=3,
|
||||
step_measure_s=8,
|
||||
bisect_steps=1,
|
||||
max_steps=6,
|
||||
),
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def cell_profile(profile: Profile, cell: dict[str, Any]) -> Profile:
|
||||
"""Профиль ячейки: реплики и max_connections из конфигурации."""
|
||||
"""Профиль ячейки: реплики, max_connections и (серия db) CPU
|
||||
PostgreSQL из конфигурации."""
|
||||
return replace(
|
||||
profile,
|
||||
replicas=cell["replicas"],
|
||||
cpus=cell["replica_cpus"],
|
||||
memory=cell["replica_memory"],
|
||||
db_max_connections=cell["db_max_connections"],
|
||||
db_cpus=cell.get("db_cpus") or profile.db_cpus,
|
||||
)
|
||||
|
||||
|
||||
@@ -625,12 +661,14 @@ def budget(profile: Profile, vm_cpus: int, vm_memory: int) -> dict[str, Any]:
|
||||
"""Сумма лимитов CPU и памяти стенда и генератора по конфигурациям
|
||||
серии (решение 1): реплики, PostgreSQL, LB, Valkey, k6, сэмплер."""
|
||||
result = {}
|
||||
for replicas, cpus, memory, max_conn in profile.configs:
|
||||
key = scaling.config_key(replicas, cpus, memory, max_conn)
|
||||
for config in profile.configs:
|
||||
parts = scaling.unpack_config(config)
|
||||
replicas, cpus, memory, _, db_cpus = parts
|
||||
key = scaling.config_key(*parts)
|
||||
cpu = replicas * float(cpus) + sum(
|
||||
float(value)
|
||||
for value in (
|
||||
profile.db_cpus,
|
||||
db_cpus or profile.db_cpus,
|
||||
profile.lb_cpus,
|
||||
profile.cache_cpus,
|
||||
profile.generator_cpus or "0",
|
||||
@@ -845,7 +883,10 @@ def vm_warnings(profile: Profile) -> list[str]:
|
||||
return []
|
||||
replicas = [(profile.replicas, profile.memory)]
|
||||
if profile.is_series:
|
||||
replicas = [(k, memory) for k, _, memory, _ in profile.configs]
|
||||
replicas = [
|
||||
(k, memory)
|
||||
for k, _, memory, *_ in map(scaling.unpack_config, profile.configs)
|
||||
]
|
||||
extra = (
|
||||
(profile.generator_memory, profile.sampler_memory)
|
||||
if profile.is_series
|
||||
|
||||
+79
-21
@@ -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} запросов/с",
|
||||
|
||||
Reference in New Issue
Block a user