node stats and benchmark, dynamic realocation working

This commit is contained in:
Dobromir Popov
2026-07-01 10:02:17 +03:00
parent b6272db93d
commit 278be49539
6 changed files with 279 additions and 14 deletions

View File

@@ -94,6 +94,19 @@ def _make_bar(pct: float, width: int = 10) -> str:
return "" * filled + "" * (width - filled)
def _node_stats(node) -> dict:
total = int(getattr(node, "total_requests", getattr(node, "chat_completion_count", 0)) or 0)
failed = int(getattr(node, "failed_requests", 0) or 0)
queue_depth = int(getattr(node, "queue_depth", 0) or 0)
success_rate = ((total - failed) / total * 100.0) if total else 100.0
return {
"total_requests": total,
"failed_requests": failed,
"queue_depth": queue_depth,
"success_rate": success_rate,
}
def run_dashboard(node, config: dict, start_time: float) -> None:
"""Start the live dashboard. Blocks until Ctrl-C. Returns cleanly."""
if not is_interactive_tty():
@@ -117,7 +130,8 @@ def _build_rich_renderable(
from rich.text import Text # type: ignore[import]
uptime = time.monotonic() - start_time
req_count = getattr(node, "chat_completion_count", 0)
stats = _node_stats(node)
req_count = stats["total_requests"]
# Tokens/sec EMA (approximate: 20 tokens per request heuristic when no real counter)
delta_req = req_count - prev_req[0]
@@ -163,6 +177,7 @@ def _build_rich_renderable(
stats_lines = [
f"Tokens/sec {tps_bar} {tps:.1f} t/s (EMA)",
f"Requests {req_count:,} served",
f"Success {stats['success_rate']:.1f}% failed {stats['failed_requests']:,} queue {stats['queue_depth']}",
f"Peers 0 connected (gossip: US-017)",
f"TAI earned 0.00 TAI (payments: US-006)",
f"Uptime {_format_uptime(uptime)}",
@@ -205,14 +220,17 @@ def _run_plain_loop(node, config: dict, start_time: float) -> None:
try:
while True:
uptime = time.monotonic() - start_time
req = getattr(node, "chat_completion_count", 0)
stats = _node_stats(node)
req = stats["total_requests"]
gpu_stats = _gpu_stats()
vram_str = ""
if gpu_stats:
g = gpu_stats[0]
vram_str = f" VRAM{g['used_gb']:.1f}GB"
print(
f"[{model_name} req{req}{vram_str} up{_format_uptime(uptime)}]",
f"[{model_name} req{req} ok{stats['success_rate']:.1f}% "
f"fail{stats['failed_requests']} q{stats['queue_depth']}"
f"{vram_str} up{_format_uptime(uptime)}]",
flush=True,
)
time.sleep(2)