Связки клиент → серверы в конфиге, итоговая таблица по клиентам

- у клиента можно указать servers = [...] — с какими серверами его проверять
- итоговая таблица сгруппирована по клиентам: сервер, отдача, приём
- iperf3 на клиенте запускается через timeout и с --connect-timeout

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
vrubel 2026-10-13 09:58:42 +03:00
parent 9d1dd38c5b
commit 50304b6048

View file

@ -231,27 +231,40 @@ def schedule(clients: list[Host], servers: list[Host], concurrent: bool) -> list
return rounds
def fmt_table(results: list[Result], clients: list[Host], servers: list[Host], direction: str) -> str:
by_pair = {(r.client, r.server): r for r in results if r.direction == direction}
header = ["клиент \\ сервер", *[s.name for s in servers]]
rows = []
def fmt_table(results: list[Result], clients: list[Host], servers: list[Host], directions: list[str]) -> str:
"""Таблица, сгруппированная по клиентам: для каждого — его серверы с отдачей и приёмом."""
by_key = {(r.client, r.server, r.direction): r for r in results}
def cell(r: Result | None) -> str:
if r is None:
return "—"
return "ОШИБКА" if r.mbps is None else f"{r.mbps:,.1f}".replace(",", " ")
titles = {"upload": "отдача ↑", "download": "приём ↓"}
header = ["клиент", "сервер", *[titles[d] for d in directions]]
groups = []
for c in clients:
row = [c.name]
for srv in servers:
r = by_pair.get((c.name, srv.name))
row.append("—" if r is None else ("ОШИБКА" if r.mbps is None else f"{r.mbps:,.1f}".replace(",", " ")))
rows.append(row)
widths = [max(len(x[i]) for x in [header, *rows]) for i in range(len(header))]
tested = [srv for srv in servers if any((c.name, srv.name, d) in by_key for d in directions)]
if tested:
groups.append([[c.name if i == 0 else "", srv.name, *[cell(by_key.get((c.name, srv.name, d))) for d in directions]]
for i, srv in enumerate(tested)])
if not groups:
return "Нет результатов."
widths = [max(len(x[i]) for x in [header, *[row for g in groups for row in g]]) for i in range(len(header))]
def line(cells):
return "│ " + " │ ".join(
cell.ljust(w) if i == 0 else cell.rjust(w) for i, (cell, w) in enumerate(zip(cells, widths))
cell.ljust(w) if i < 2 else cell.rjust(w) for i, (cell, w) in enumerate(zip(cells, widths))
) + " │"
sep = lambda l, m, r: l + m.join("─" * (w + 2) for w in widths) + r
title = ("Отдача: клиент → сервер" if direction == "upload" else "Загрузка: сервер → клиент") + ", Мбит/с"
return "\n".join([title, sep("┌", "┬", "┐"), line(header), sep("├", "┼", "┤"),
*[line(r) for r in rows], sep("└", "┴", "┘")])
out = ["Скорость, Мбит/с (отдача — клиент → сервер, приём — сервер → клиент)",
sep("┌", "┬", "┐"), line(header)]
for g in groups:
out.append(sep("├", "┼", "┤"))
out.extend(line(row) for row in g)
out.append(sep("└", "┴", "┘"))
return "\n".join(out)
def save(results: list[Result], path: Path) -> None:
@ -320,8 +333,8 @@ def main() -> None:
done = 0
log(f"Тестов: {total}, по {s.duration}с (+{s.omit}с прогрев) каждый")
try:
for direction in directions:
for rnd in rounds:
for direction in directions:
with ThreadPoolExecutor(max_workers=len(rnd)) as pool:
futures = [pool.submit(run_test, c, srv, direction, s) for c, srv in rnd]
for fut in futures:
@ -340,8 +353,7 @@ def main() -> None:
stop_server(h, s)
print()
for direction in directions:
print(fmt_table(results, clients, servers, direction))
print(fmt_table(results, clients, servers, directions))
print()
if failed := [r for r in results if r.error]:
print("Ошибки:")