From b4b1260099f2ae3869412a9fe659029299d409c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9?= Date: Wed, 30 Sep 2026 22:53:16 +0500 Subject: [PATCH] Overview: world speed (ticks per second) from the server's own timing report Co-Authored-By: Claude Sonnet 5.5 --- crates/coa-core/src/ra.rs | 58 ++++++++++++++++++++++++++++++++++++++- src-tauri/src/lib.rs | 15 ++++++++++ src/dev/mock.ts | 1 + src/i18n/locales/de.ts | 9 ++++++ src/i18n/locales/en.ts | 9 ++++++ src/i18n/locales/es.ts | 9 ++++++ src/i18n/locales/fr.ts | 9 ++++++ src/i18n/locales/ru.ts | 9 ++++++ src/lib/api.ts | 10 +++++++ src/screens/Overview.tsx | 46 ++++++++++++++++++++++++++++++- 10 files changed, 173 insertions(+), 2 deletions(-) diff --git a/crates/coa-core/src/ra.rs b/crates/coa-core/src/ra.rs index 933b11e..e590e09 100644 --- a/crates/coa-core/src/ra.rs +++ b/crates/coa-core/src/ra.rs @@ -6,7 +6,7 @@ use std::net::{SocketAddr, TcpStream}; use std::path::Path; use std::time::Duration; -use serde::Deserialize; +use serde::{Deserialize, Serialize}; use crate::error::{Error, Result}; use crate::fsx; @@ -92,6 +92,12 @@ impl Ra { } /// Ask the bot module to create `count` leveling bots (throttled by the module itself). Only a number is sent. + /// World update timing from the server's own `server info` report (mean/median/percentiles of the last 500 updates). + pub fn performance(&mut self) -> Result> { + let out = self.command("server info")?; + Ok(parse_server_info(&out)) + } + pub fn spawn_bots(&mut self, count: u32) -> Result { if !(1..=2000).contains(&count) { return Err(Error::Invalid("Choose between 1 and 2000 companions.".into())); @@ -112,6 +118,41 @@ impl Ra { } } +/// How fast the world loop is running, read from `server info`. +#[derive(Debug, Clone, Serialize, PartialEq)] +pub struct Performance { + pub mean_ms: u32, + pub median_ms: u32, + pub p95_ms: u32, + pub p99_ms: u32, + pub max_ms: u32, + /// World updates per second implied by the mean update time. + pub ticks_per_sec: f32, +} + +fn ms(text: &str) -> Option { + text.trim().trim_end_matches("ms").trim().parse().ok() +} + +pub fn parse_server_info(text: &str) -> Option { + let (mut mean, mut median, mut pct) = (None, None, None); + for line in text.lines() { + let line = line.trim().trim_start_matches('|').trim_start_matches('-').trim(); + if let Some(v) = line.strip_prefix("Mean:") { + mean = ms(v); + } else if let Some(v) = line.strip_prefix("Median:") { + median = ms(v); + } else if let Some(v) = line.strip_prefix("Percentiles (95, 99, max):") { + let p: Vec> = v.split(',').map(ms).collect(); + if p.len() == 3 { + pct = Some((p[0]?, p[1]?, p[2]?)); + } + } + } + let (mean_ms, median_ms, (p95_ms, p99_ms, max_ms)) = (mean?, median?, pct?); + Some(Performance { mean_ms, median_ms, p95_ms, p99_ms, max_ms, ticks_per_sec: 1000.0 / mean_ms.max(1) as f32 }) +} + /// Account names are letters/digits (3-17); passwords are 6-16 printable characters without spaces or quotes. pub fn validate_account(name: &str, password: &str) -> Result<()> { let bad = |m: &str| Err(Error::Invalid(m.into())); @@ -169,6 +210,21 @@ mod tests { (port, h) } + #[test] + fn server_info_timing_is_parsed_and_unrelated_text_is_ignored() { + let text = "AzerothCore rev. x +Connected players: 0. Characters in world: 0. +Update time diff: 1ms. Last 500 diffs summary: +|- Mean: 14ms +|- Median: 15ms +|- Percentiles (95, 99, max): 24ms, 30ms, 61ms +AC>"; + let p = parse_server_info(text).unwrap(); + assert_eq!((p.mean_ms, p.median_ms, p.p95_ms, p.p99_ms, p.max_ms), (14, 15, 24, 30, 61)); + assert!((p.ticks_per_sec - 71.4).abs() < 0.2); + assert!(parse_server_info("Connected players: 0.").is_none()); + } + #[test] fn creates_an_account_over_ra_with_the_expected_commands() { let _lock = serial(); diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 22f12bb..29c7c9b 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -497,6 +497,20 @@ async fn get_population(state: State<'_, AppState>, id: String) -> std::result:: .unwrap_or(None)) } +#[tauri::command] +async fn get_performance(state: State<'_, AppState>, id: String) -> std::result::Result, UiError> { + let root = path_of(&state, &id)?; + Ok(tauri::async_runtime::spawn_blocking(move || { + let o = coa_core::process::observe(&root, &layout::read_ports(&root)); + if o.world.state != coa_core::process::ServiceState::Running { + return None; + } + Ra::connect(&root).and_then(|mut r| r.performance()).ok().flatten() + }) + .await + .unwrap_or(None)) +} + #[derive(Serialize)] struct CompanionSizes { hardware: coa_core::population::Hardware, @@ -839,6 +853,7 @@ pub fn run() { apply_update, rollback_update, get_population, + get_performance, companion_sizes, add_companions, client_info, diff --git a/src/dev/mock.ts b/src/dev/mock.ts index 4e26717..e42c383 100644 --- a/src/dev/mock.ts +++ b/src/dev/mock.ts @@ -31,6 +31,7 @@ export {}; if(cmd==="preview_preset"){const a=args;const sc=a.scope==="server"?serverSchema:botsSchema;const pr=(a.scope==="server"?serverPresets:botsPresets).presets as any[];const p=pr.find(x=>x.id===a.preset)??{id:a.preset??"defaults",title:"Recommended defaults",description:"Every setting returns to its default value."};const st=(sc.settings as any[]).filter(x=>x.type==="int"||x.type==="float"||x.type==="enum").slice(0,3);return {id:p.id,title:p.title,description:p.description,changes:st.map(x=>({key:x.key,title:x.title,from:x.default,to:x.type==="enum"?(x.options?.[1]?.value??x.default):(Number(x.default)||1)*2,dangerous:false}))};} if(cmd==="companion_sizes") return {hardware:{cores:16,ram_gb:31,free_ram_gb:12},sizes:[{id:"small",title:"Small",bots:50,warning:null},{id:"medium",title:"Medium",bots:250,warning:null},{id:"large",title:"Large",bots:500,warning:"500 companions may need more CPU and memory than this computer has (8 cores, 16 GB)."}]}; if(cmd==="get_population") return null; + if(cmd==="get_performance") return running?{mean_ms:14,median_ms:15,p95_ms:24,p99_ms:30,max_ms:61,ticks_per_sec:71.4}:null; if(cmd==="run_diagnostics") return {problems:2,checks:[{id:"files",title:"Server files",level:"ok",detail:"All expected server parts were found."},{id:"world",title:"World server",level:"warn",detail:"Not running."},{id:"disk",title:"Free disk space",level:"warn",detail:"Only 3 GB free; backups and updates need room."},{id:"exposure",title:"Private services",level:"ok",detail:"Database and server console are not reachable from the network."}]}; if(cmd==="plugin:event|listen") return 1; if(cmd==="plugin:event|unlisten") return null; diff --git a/src/i18n/locales/de.ts b/src/i18n/locales/de.ts index 3bd82f3..0b2c841 100644 --- a/src/i18n/locales/de.ts +++ b/src/i18n/locales/de.ts @@ -497,6 +497,15 @@ const de: Partial> = { "scan.label.companions": "CoA-Begleiter (Bots)", "scan.label.client": "Spielclient", "placeholder.soon": "Dieser Bereich entsteht in einer späteren Version.", + + // Tick rate + "overview.tick": "Weltgeschwindigkeit", + "overview.tickUnit": "Ticks/s", + "overview.tickGood": "Flüssig", + "overview.tickBusy": "Ausgelastet", + "overview.tickLag": "Ruckelt", + "overview.tickDetail": "durchschnittlich {mean} ms pro Tick · 95 % unter {p95} ms · Spitze {max} ms", + "overview.tickHint": "Wie schnell der Weltserver läuft. Über 20 Ticks pro Sekunde fühlt sich das Spiel flüssig an, unter 10 ruckelt es.", }; export default de; diff --git a/src/i18n/locales/en.ts b/src/i18n/locales/en.ts index 3ac7bd5..5dcb7d0 100644 --- a/src/i18n/locales/en.ts +++ b/src/i18n/locales/en.ts @@ -497,6 +497,15 @@ const en = { "scan.label.companions": "CoA Companions (bots)", "scan.label.client": "Game client", "placeholder.soon": "This section is being built in a later release.", + + // Tick rate + "overview.tick": "World speed", + "overview.tickUnit": "ticks/s", + "overview.tickGood": "Smooth", + "overview.tickBusy": "Busy", + "overview.tickLag": "Lagging", + "overview.tickDetail": "average {mean} ms per tick · 95% under {p95} ms · peak {max} ms", + "overview.tickHint": "How fast the world server runs. Above 20 ticks per second the game feels smooth; below 10 it lags.", } as const; export default en; diff --git a/src/i18n/locales/es.ts b/src/i18n/locales/es.ts index d0550d1..e33a7f3 100644 --- a/src/i18n/locales/es.ts +++ b/src/i18n/locales/es.ts @@ -497,6 +497,15 @@ const es: Partial> = { "scan.label.companions": "Compañeros de CoA (bots)", "scan.label.client": "Cliente del juego", "placeholder.soon": "Esta sección se está desarrollando para una versión posterior.", + + // Tick rate + "overview.tick": "Velocidad del mundo", + "overview.tickUnit": "ticks/s", + "overview.tickGood": "Fluido", + "overview.tickBusy": "Cargado", + "overview.tickLag": "Con retrasos", + "overview.tickDetail": "media de {mean} ms por tick · 95 % por debajo de {p95} ms · pico de {max} ms", + "overview.tickHint": "Qué tan rápido funciona el servidor del mundo. Por encima de 20 ticks por segundo el juego va fluido; por debajo de 10 se retrasa.", }; export default es; diff --git a/src/i18n/locales/fr.ts b/src/i18n/locales/fr.ts index ef1b9c3..551ef81 100644 --- a/src/i18n/locales/fr.ts +++ b/src/i18n/locales/fr.ts @@ -497,6 +497,15 @@ const fr: Partial> = { "scan.label.companions": "Compagnons CoA (bots)", "scan.label.client": "Client du jeu", "placeholder.soon": "Cette section sera développée dans une prochaine version.", + + // Tick rate + "overview.tick": "Vitesse du monde", + "overview.tickUnit": "ticks/s", + "overview.tickGood": "Fluide", + "overview.tickBusy": "Chargé", + "overview.tickLag": "Saccadé", + "overview.tickDetail": "en moyenne {mean} ms par tick · 95 % sous {p95} ms · pic {max} ms", + "overview.tickHint": "La vitesse du serveur de monde. Au-dessus de 20 ticks par seconde le jeu est fluide, sous 10 il saccade.", }; export default fr; diff --git a/src/i18n/locales/ru.ts b/src/i18n/locales/ru.ts index 8fbba7c..5d1113b 100644 --- a/src/i18n/locales/ru.ts +++ b/src/i18n/locales/ru.ts @@ -497,6 +497,15 @@ const ru: Partial> = { "scan.label.companions": "Компаньоны CoA (боты)", "scan.label.client": "Клиент игры", "placeholder.soon": "Этот раздел появится в одном из следующих выпусков.", + + // Tick rate + "overview.tick": "Скорость мира", + "overview.tickUnit": "тиков/с", + "overview.tickGood": "Плавно", + "overview.tickBusy": "Нагружен", + "overview.tickLag": "Лагает", + "overview.tickDetail": "в среднем {mean} мс на тик · 95% быстрее {p95} мс · пик {max} мс", + "overview.tickHint": "Как быстро работает игровой сервер. Выше 20 тиков в секунду игра идёт плавно, ниже 10 — лагает.", }; export default ru; diff --git a/src/lib/api.ts b/src/lib/api.ts index 9a7423c..637d0c3 100644 --- a/src/lib/api.ts +++ b/src/lib/api.ts @@ -204,6 +204,15 @@ export interface Population { bots_total: number; } +export interface Performance { + mean_ms: number; + median_ms: number; + p95_ms: number; + p99_ms: number; + max_ms: number; + ticks_per_sec: number; +} + export interface CompanionSizes { hardware: { cores: number; ram_gb: number; free_ram_gb: number }; sizes: { id: string; title: string; bots: number; warning: string | null }[]; @@ -278,6 +287,7 @@ export const api = { invoke<{ txn: UpdateTxn }>("apply_update", { id, source: source ?? null, resolutions }), rollbackUpdate: (id: string, txn: string) => invoke("rollback_update", { id, txn }), population: (id: string) => invoke("get_population", { id }), + performance: (id: string) => invoke("get_performance", { id }), companionSizes: () => invoke("companion_sizes"), addCompanions: (id: string, count: number) => invoke<{ spawned: string | null }>("add_companions", { id, count }), clientInfo: (id: string) => invoke("client_info", { id }), diff --git a/src/screens/Overview.tsx b/src/screens/Overview.tsx index e68a28b..1cd0192 100644 --- a/src/screens/Overview.tsx +++ b/src/screens/Overview.tsx @@ -1,6 +1,6 @@ import { useCallback, useEffect, useRef, useState } from "react"; import { Loader2 } from "lucide-react"; -import { api, asUiError, type ClientInfo, type Human, type Population, type ServerSummary, type ServiceStatus, type StatusView } from "@/lib/api"; +import { api, asUiError, type ClientInfo, type Human, type Performance, type Population, type ServerSummary, type ServiceStatus, type StatusView } from "@/lib/api"; import { cn, formatUptime } from "@/lib/utils"; import { useHuman, useT } from "@/i18n"; import { Button } from "@/components/ui/button"; @@ -9,6 +9,31 @@ import { Card } from "@/components/ui/card"; type Action = "starting" | "stopping" | "restarting" | null; type Failure = { human: Human; technical: string }; +/** World loop speed from the server's own timing report, with a simple smooth / busy / lagging verdict. */ +function TickRate({ perf }: { perf: Performance }) { + const t = useT(); + const level = perf.mean_ms <= 50 ? "good" : perf.mean_ms <= 100 ? "busy" : "lag"; + const tone = { good: "text-ok bg-ok/15", busy: "text-warn bg-warn/15", lag: "text-bad bg-bad/15" }[level]; + const bar = { good: "bg-ok", busy: "bg-warn", lag: "bg-bad" }[level]; + const fill = Math.max(4, Math.min(100, Math.round(100 - perf.mean_ms))); + return ( +
+
+ {t("overview.tick")} + {t(level === "good" ? "overview.tickGood" : level === "busy" ? "overview.tickBusy" : "overview.tickLag")} +
+
+ {Math.round(perf.ticks_per_sec)} + {t("overview.tickUnit")} +
+
+
+
+

{t("overview.tickDetail", { mean: perf.mean_ms, p95: perf.p95_ms, max: perf.max_ms })}

+
+ ); +} + function Row({ label, s }: { label: string; s: ServiceStatus }) { const t = useT(); const running = s.state === "running"; @@ -43,6 +68,7 @@ export function Overview({ server, onForget }: { server: ServerSummary; onForget const [pop, setPop] = useState(null); const [client, setClient] = useState(null); const [playing, setPlaying] = useState(false); + const [perf, setPerf] = useState(null); const alive = useRef(true); const poll = useCallback(async () => { @@ -58,6 +84,23 @@ export function Overview({ server, onForget }: { server: ServerSummary; onForget } }, [server.id]); + // The tick rate comes from the server console (one short connection per reading), so it is read less often. + const worldUp = status?.observed.world.state === "running"; + useEffect(() => { + if (!worldUp) { + setPerf(null); + return; + } + let live = true; + const read = () => void api.performance(server.id).then((p) => live && setPerf(p)).catch(() => {}); + read(); + const iv = setInterval(read, 10000); + return () => { + live = false; + clearInterval(iv); + }; + }, [worldUp, server.id]); + useEffect(() => { alive.current = true; void api.clientInfo(server.id).then(setClient).catch(() => setClient(null)); @@ -170,6 +213,7 @@ export function Overview({ server, onForget }: { server: ServerSummary; onForget
{pop ? `${pop.players_online}` : "—"}{pop && pop.bots_online > 0 ? {t("overview.companions", { n: pop.bots_online })} : null}
+ {perf && }
{running ? (