From dbb9ca60fcf93c6cbe69026cf3a77dad6941115f Mon Sep 17 00:00:00 2001 From: Hauser Zhi Date: Fri, 27 Nov 2026 00:37:05 +0800 Subject: [PATCH] fix(perf): validate steady Warp rates and tail latency (#9637) * fix(perf): validate steady Warp rates and tail latency Co-Authored-By: heihutu Co-Authored-By: zhi22915 Co-Authored-By: qunjiazhu * test(server): count plaintext SSE-C warnings directly Co-Authored-By: heihutu Co-Authored-By: zhi22915 Co-Authored-By: qunjiazhu --------- Co-authored-by: heihutu Co-authored-by: zhi22915 Co-authored-by: qunjiazhu Co-authored-by: Chris An --- .config/make/tests.mak | 1 + scripts/test_warp_raw_quality.py | 46 +++++++++++++++++++++++++++++--- scripts/warp_raw_quality.py | 32 +++++++++++++++++----- 3 files changed, 70 insertions(+), 9 deletions(-) diff --git a/.config/make/tests.mak b/.config/make/tests.mak index e22cb49b3f..800750a450 100644 --- a/.config/make/tests.mak +++ b/.config/make/tests.mak @@ -43,6 +43,7 @@ script-tests: ## Run shell script tests $(RUSTFS_PYTHON_BIN) ./scripts/test_internode_msgpack_peer_canary.py ./scripts/test_internode_msgpack_peer_canary_runner.sh ./scripts/test_object_batch_bench_enhanced.sh + $(RUSTFS_PYTHON_BIN) ./scripts/test_warp_raw_quality.py $(RUSTFS_PYTHON_BIN) ./scripts/test_inline_docker_lab.py ./scripts/test_package_service_scripts.sh ./scripts/test_hotpath_warp_ab_gate.sh diff --git a/scripts/test_warp_raw_quality.py b/scripts/test_warp_raw_quality.py index 27ade91e3b..e605e3d1e8 100755 --- a/scripts/test_warp_raw_quality.py +++ b/scripts/test_warp_raw_quality.py @@ -1,5 +1,7 @@ #!/usr/bin/env python3 +from __future__ import annotations + import importlib.util import json import subprocess @@ -19,11 +21,13 @@ SPEC.loader.exec_module(MODULE) HEADER = "thread\top\tn_objects\tbytes\tendpoint\terror\tstart\tend\tduration_ns\n" -def row(thread: int, endpoint: str, start: int, end: int, error: str = "") -> str: +def row(thread: int, endpoint: str, start: int, end: int, error: str = "", *, duration_ns: int | None = None) -> str: def stamp(second: int) -> str: - return f"2026-01-01T00:00:{second:02d}Z" + minute, second = divmod(second, 60) + return f"2026-01-01T00:{minute:02d}:{second:02d}Z" - return f"{thread}\tPUT\t1\t100\t{endpoint}\t{error}\t{stamp(start)}\t{stamp(end)}\t{(end-start)*1_000_000_000}\n" + duration = (end - start) * 1_000_000_000 if duration_ns is None else duration_ns + return f"{thread}\tPUT\t1\t100\t{endpoint}\t{error}\t{stamp(start)}\t{stamp(end)}\t{duration}\n" class WarpRawQualityTest(unittest.TestCase): @@ -65,6 +69,8 @@ class WarpRawQualityTest(unittest.TestCase): self.assertEqual(status, 0) self.assertEqual(result["status"], "pass") self.assertEqual(result["steady"]["completed_objects"], 2) + self.assertEqual(result["steady"]["completed_requests"], 2) + self.assertEqual(result["steady"]["p99_ms"], 2000) self.assertEqual(result["steady"]["start_ns"], result["measure_start_ns"] + 1_000_000_000) self.assertEqual(result["steady"]["duration_secs"], 2) self.assertEqual(result["steady"]["completed_objects_per_second"], 1) @@ -81,8 +87,39 @@ class WarpRawQualityTest(unittest.TestCase): self.assertEqual(status, 1) self.assertEqual(result["reason"], "steady completion rate below minimum") self.assertEqual(result["steady"]["completed_objects"], 0) + self.assertIsNone(result["steady"]["p99_ms"]) self.assertEqual(result["reqps"], old_result["reqps"]) + def test_steady_rate_upper_bound_rejects_overshoot_and_accepts_equality(self) -> None: + source = self.fixture() + flags = ("--steady-after-seconds", "1", "--min-steady-rps", "0.5", "--max-steady-rps") + status, result = self.run_cli(source, *flags, "0.9") + self.assertEqual(status, 1) + self.assertEqual(result["reason"], "steady completion rate above maximum") + self.assertEqual(result["steady"]["completed_objects_per_second"], 1) + self.assertEqual(result["steady"]["max_completed_objects_per_second"], 0.9) + status, result = self.run_cli(source, *flags, "1") + self.assertEqual(status, 0) + self.assertEqual(result["status"], "pass") + + def test_steady_p99_excludes_completions_at_right_edge(self) -> None: + source = self.fixture() + intervals = ((0, 0, 8), (0, 8, 10), (0, 10, 15), (0, 15, 35), (1, 0, 1), (1, 1, 2), (1, 2, 15), (1, 20, 40)) + source.write_text(HEADER + "".join(row(thread, "a", start, end) for thread, start, end in intervals)) + result = MODULE.parse(source, {"a"}, steady_after_seconds=2) + self.assertEqual(result["steady"]["completed_requests"], 1) + self.assertEqual(result["steady"]["p99_ms"], 2000) + + def test_steady_p99_ranks_recorded_request_durations(self) -> None: + source = self.fixture() + # Use different wall-clock spans and recorded durations to verify both the + # source of latency and the 99th (not the largest) of 100 observations. + samples = (row(0, "a", i, i + 1, duration_ns=i * 1_000_000) for i in range(1, 101)) + source.write_text(HEADER + row(0, "a", 0, 1) + "".join(samples) + row(0, "a", 102, 103)) + result = MODULE.parse(source, {"a"}, steady_after_seconds=1) + self.assertEqual(result["steady"]["completed_requests"], 100) + self.assertEqual(result["steady"]["p99_ms"], 99) + def test_invalid_steady_gate_rejects_missing_empty_and_nonfinite_options(self) -> None: source = self.fixture() cases = ( @@ -90,6 +127,9 @@ class WarpRawQualityTest(unittest.TestCase): ("--steady-after-seconds", "3", "--min-steady-rps", "1"), ("--steady-after-seconds", "-1", "--min-steady-rps", "1"), ("--steady-after-seconds", "1", "--min-steady-rps", "nan"), + ("--max-steady-rps", "1"), + ("--steady-after-seconds", "1", "--min-steady-rps", "1", "--max-steady-rps", "0.9"), + ("--steady-after-seconds", "1", "--min-steady-rps", "1", "--max-steady-rps", "inf"), ) for args in cases: with self.subTest(args=args): diff --git a/scripts/warp_raw_quality.py b/scripts/warp_raw_quality.py index d2d7f946aa..35f3e77d58 100755 --- a/scripts/warp_raw_quality.py +++ b/scripts/warp_raw_quality.py @@ -87,7 +87,7 @@ def parse(path: Path, expected_hosts: set[str] | None, *, steady_after_seconds: host_counts[row["endpoint"]] += objects first_end[thread] = min(first_end.get(thread, end), end) last_start[thread] = max(last_start.get(thread, start), start) - rows.append((start, end, objects, error)) + rows.append((start, end, objects, duration_ns)) if not rows or raw_errors: raise ValueError("Warp raw input is empty or contains request errors") if expected_hosts is not None and set(host_counts) != expected_hosts: @@ -96,11 +96,11 @@ def parse(path: Path, expected_hosts: set[str] | None, *, steady_after_seconds: window_end = min(last_start.values()) if window_end <= window_start: raise ValueError("Warp common active window is not positive") - completed_objects = sum(objects for _, end, objects, error in rows if not error and window_start <= end < window_end) - completed_requests = sum(1 for _, end, _, error in rows if not error and window_start <= end < window_end) + completed_objects = sum(objects for _, end, objects, _ in rows if window_start <= end < window_end) + completed_requests = sum(1 for _, end, _, _ in rows if window_start <= end < window_end) fractional_objects = 0.0 - for start, end, objects, error in rows: - if error or end <= start: + for start, end, objects, _ in rows: + if end <= start: continue overlap = max(0, min(end, window_end) - max(start, window_start)) fractional_objects += objects * overlap / (end - start) @@ -129,13 +129,24 @@ def parse(path: Path, expected_hosts: set[str] | None, *, steady_after_seconds: if steady_start >= window_end: raise ValueError("steady cutoff leaves no common active window") steady_duration = (window_end - steady_start) / 1_000_000_000 - steady_objects = sum(objects for _, end, objects, error in rows if not error and steady_start <= end < window_end) + steady_objects = 0 + steady_latencies_ns = [] + for _, end, objects, duration_ns in rows: + if steady_start <= end < window_end: + steady_objects += objects + steady_latencies_ns.append(duration_ns) + steady_latencies_ns.sort() + steady_requests = len(steady_latencies_ns) + # Nearest-rank p99 over the same successful requests used for the completion rate. + p99_ns = steady_latencies_ns[(99 * steady_requests + 99) // 100 - 1] if steady_requests else None result["steady"] = { "start_ns": steady_start, "end_exclusive_ns": window_end, "duration_secs": steady_duration, "completed_objects": steady_objects, "completed_objects_per_second": steady_objects / steady_duration, + "completed_requests": steady_requests, + "p99_ms": p99_ns / 1_000_000 if p99_ns is not None else None, } return result finally: @@ -153,12 +164,17 @@ def main() -> int: parser.add_argument("--expected-host", action="append") parser.add_argument("--steady-after-seconds", type=int, help="Seconds to exclude from the start of the common active window") parser.add_argument("--min-steady-rps", type=float, help="Minimum successful object completions per second in the steady window") + parser.add_argument("--max-steady-rps", type=float, help="Optional maximum steady completion rate, used with the minimum") args = parser.parse_args() try: if (args.steady_after_seconds is None) != (args.min_steady_rps is None): raise ValueError("--steady-after-seconds and --min-steady-rps must be used together") if args.min_steady_rps is not None and (not math.isfinite(args.min_steady_rps) or args.min_steady_rps <= 0): raise ValueError("minimum steady rate must be finite and positive") + if args.max_steady_rps is not None and ( + args.min_steady_rps is None or not math.isfinite(args.max_steady_rps) or args.max_steady_rps < args.min_steady_rps + ): + raise ValueError("maximum steady rate must be finite and at least the configured minimum") result = parse( Path(args.input), set(args.expected_host) if args.expected_host else None, @@ -171,8 +187,12 @@ def main() -> int: if args.min_steady_rps is not None: steady = result["steady"] steady["min_completed_objects_per_second"] = args.min_steady_rps + if args.max_steady_rps is not None: + steady["max_completed_objects_per_second"] = args.max_steady_rps if steady["completed_objects_per_second"] < args.min_steady_rps: result.update(status="fail", reason="steady completion rate below minimum") + elif args.max_steady_rps is not None and steady["completed_objects_per_second"] > args.max_steady_rps: + result.update(status="fail", reason="steady completion rate above maximum") Path(args.output).write_text(json.dumps(result, indent=2, sort_keys=True) + "\n") return int(result["status"] == "fail")