Skip to content

Run frontier MoE models on hardware you already own — pure C, zero deps, experts streamed from disk. Tiny engine, immense model. 🐦

C

Add reproducible Poisson arrivals to HTTP benchmark

ZacharyZcR965d175ff354
diff --git a/c/tests/test_benchmark_http_serving.py b/c/tests/test_benchmark_http_serving.py
index 90a8cf90..bc143b28 100644
--- a/c/tests/test_benchmark_http_serving.py
+++ b/c/tests/test_benchmark_http_serving.py
@@ -289,6 +289,29 @@ class BenchmarkTest(unittest.TestCase):
self.assertEqual(report["summary"]["latency_slo"]["requests_met"], 1 - exit_code)
+ def test_poisson_cli_reports_seed_and_requires_rate(self):
+ with tempfile.TemporaryDirectory() as directory:
+ workload = Path(directory) / "workload.jsonl"
+ output = Path(directory) / "report.json"
+ workload.write_text('{"messages":[{"role":"user","content":"hello"}]}\n')
+ argv = [bench.__file__, "--base-url", self.url.removesuffix("/chat/completions"),
+ "--model", "fixture", "--workload", str(workload), "--output", str(output),
+ "--arrival-distribution", "poisson", "--seed", "42"]
+ with patch.object(sys, "argv", argv), patch.object(sys, "stderr", io.StringIO()), \
+ self.assertRaises(SystemExit) as error:
+ bench.main()
+ self.assertEqual(error.exception.code, 2)
+ self.assertFalse(output.exists())
+ with patch.object(sys, "argv", argv + ["--request-rate", "1000"]), \
+ patch.object(sys, "stdout", io.StringIO()):
+ self.assertEqual(bench.main(), 0)
+ report = json.loads(output.read_text())
+ self.assertEqual(report["config"]["load_model"], "poisson")
+ self.assertEqual(report["config"]["arrival_distribution"], "poisson")
+ self.assertEqual(report["config"]["arrival_seed"], 42)
+ self.assertEqual(report["requests"][0]["scheduled_seconds"], 0)
+
+
class ColibriIntegrationTest(unittest.TestCase):
def test_real_gateway_with_fake_engine(self):
class Engine:
@@ -339,6 +362,7 @@ class ColibriIntegrationTest(unittest.TestCase):
thread.join()
+
class ParsingTest(unittest.TestCase):
def test_sse_multiline_comments_crlf_and_partial_eof(self):
raw = b': ping\r\nevent: message\r\ndata: {"choices":\r\ndata: []}\r\n\r\ndata: truncated'
@@ -417,6 +441,40 @@ class ParsingTest(unittest.TestCase):
for row, expected in zip(rows, [0, .11, .21]):
self.assertAlmostEqual(row["start_seconds"], expected)
+ def test_poisson_schedule_is_seeded_and_keeps_backlog_in_slo(self):
+ def measure(seed, service_time):
+ now = [100.0]
+ def submit(_fn, _url, _payload, _key, _timeout, index, origin):
+ future = Future()
+ future.set_result({"index": index, "start_seconds": now[0] - origin,
+ "success": True, "first_output_seconds": .01,
+ "duration_seconds": .02, "completion_tokens": 1})
+ now[0] += service_time
+ return future
+ def sleep(delay):
+ now[0] += delay
+ with patch.object(bench.time, "perf_counter", side_effect=lambda: now[0]), \
+ patch.object(bench.time, "sleep", side_effect=sleep), \
+ patch.object(bench.concurrent.futures, "ThreadPoolExecutor") as executor:
+ executor.return_value.__enter__.return_value.submit.side_effect = submit
+ return bench.run("unused", [{"messages": []}], "fixture", 1, 5, 8, 0, "", 2,
+ request_rate=10, arrival_distribution="poisson", seed=seed,
+ slo_duration=.1)
+ fast, fast_summary = measure(42, .001)
+ slow, slow_summary = measure(42, 1)
+ other, _ = measure(43, .001)
+ expected = [0, .1020060287274801, .104538912631754, .1367013190392506,
+ .161959937606262]
+ for row, deadline in zip(fast, expected):
+ self.assertAlmostEqual(row["scheduled_seconds"], deadline)
+ self.assertEqual([r["scheduled_seconds"] for r in fast],
+ [r["scheduled_seconds"] for r in slow])
+ self.assertNotEqual([r["scheduled_seconds"] for r in fast],
+ [r["scheduled_seconds"] for r in other])
+ self.assertEqual(fast_summary["latency_slo"]["requests_met"], 5)
+ self.assertEqual(slow_summary["latency_slo"]["requests_met"], 1)
+ self.assertAlmostEqual(slow[1]["arrival_duration_seconds"], 1 - expected[1] + .02)
+
def test_warmup_time_is_excluded_from_measured_throughput(self):
now = [0.0]
calls = []
diff --git a/c/tools/benchmark_http_serving.py b/c/tools/benchmark_http_serving.py
index 438e6fe2..cd21f88e 100644
--- a/c/tools/benchmark_http_serving.py
+++ b/c/tools/benchmark_http_serving.py
@@ -6,6 +6,7 @@ import hashlib
import json
import math
import os
+import random
from pathlib import Path
import time
import urllib.error
@@ -224,15 +225,23 @@ def summarize(results, elapsed, slo_first_output=None, slo_duration=None):
def run(url, workload, model, concurrency, repeats, max_tokens, temperature, key, timeout,
- slo_first_output=None, slo_duration=None, request_rate=None):
+ slo_first_output=None, slo_duration=None, request_rate=None,
+ arrival_distribution="periodic", seed=0):
+ count = len(workload) * repeats
+ scheduled = [0.0] * count
+ if request_rate is not None:
+ rng = random.Random(seed)
+ for index in range(1, count):
+ scheduled[index] = (index / request_rate if arrival_distribution == "periodic"
+ else scheduled[index - 1] + rng.expovariate(request_rate))
origin = time.perf_counter()
# Without a rate, workers immediately take the next request. With a rate,
# absolute arrival deadlines keep submission independent of response time.
with concurrent.futures.ThreadPoolExecutor(max_workers=concurrency) as pool:
futures = []
- for index in range(len(workload) * repeats):
+ for index in range(count):
if request_rate is not None:
- delay = origin + index / request_rate - time.perf_counter()
+ delay = origin + scheduled[index] - time.perf_counter()
if delay > 0:
time.sleep(delay)
payload = dict(workload[index % len(workload)], model=model, stream=True,
@@ -242,7 +251,7 @@ def run(url, workload, model, concurrency, repeats, max_tokens, temperature, key
results = [future.result() for future in futures]
if request_rate is not None:
for row in results:
- row["scheduled_seconds"] = row["index"] / request_rate
+ row["scheduled_seconds"] = scheduled[row["index"]]
wait = max(0.0, row["start_seconds"] - row["scheduled_seconds"])
row["dispatch_delay_seconds"] = wait
row["arrival_duration_seconds"] = wait + row["duration_seconds"]
@@ -282,7 +291,10 @@ def main():
parser.add_argument("--repeats", type=positive_int, default=1)
parser.add_argument("--warmup-requests", type=nonnegative_int, default=0,
help="unmeasured requests before the timed phase (default: 0)")
- parser.add_argument("--request-rate", type=positive_float, help="fixed scheduled arrivals per second")
+ parser.add_argument("--request-rate", type=positive_float, help="mean scheduled arrivals per second")
+ parser.add_argument("--arrival-distribution", choices=("periodic", "poisson"),
+ default="periodic", help="arrival intervals when --request-rate is set")
+ parser.add_argument("--seed", type=int, default=0, help="Poisson arrival seed (default: 0)")
parser.add_argument("--max-tokens", type=positive_int, default=128)
parser.add_argument("--temperature", type=float, default=0)
parser.add_argument("--timeout", type=positive_float, default=60, help="socket operation timeout in seconds")
@@ -290,6 +302,8 @@ def main():
parser.add_argument("--slo-first-output", type=positive_float, help="first output latency target, seconds")
parser.add_argument("--slo-duration", type=positive_float, help="completed request latency target, seconds")
args = parser.parse_args()
+ if args.arrival_distribution == "poisson" and args.request_rate is None:
+ parser.error("--arrival-distribution poisson requires --request-rate")
try:
url = endpoint(args.base_url)
workload, digest = load_workload(args.workload)
@@ -310,11 +324,15 @@ def main():
if warmup is None or warmup["summary"]["failed"] == 0:
results, summary = run(url, workload, args.model, args.concurrency, args.repeats,
args.max_tokens, args.temperature, key, args.timeout,
- args.slo_first_output, args.slo_duration, args.request_rate)
+ args.slo_first_output, args.slo_duration, args.request_rate,
+ args.arrival_distribution, args.seed)
report = {"schema_version": 1, "config": {
"endpoint": url, "model": args.model, "workload_sha256": digest,
"workload_rows": len(workload), "concurrency": args.concurrency,
- "load_model": "fixed_rate" if args.request_rate is not None else "closed_loop",
+ "load_model": ("closed_loop" if args.request_rate is None else
+ "poisson" if args.arrival_distribution == "poisson" else "fixed_rate"),
+ "arrival_distribution": args.arrival_distribution if args.request_rate is not None else None,
+ "arrival_seed": args.seed if args.arrival_distribution == "poisson" else None,
"request_rate": args.request_rate, "warmup_requests": args.warmup_requests,
"repeats": args.repeats, "max_tokens": args.max_tokens,
"temperature": args.temperature, "socket_timeout_seconds": args.timeout,
diff --git a/docs/benchmarking.md b/docs/benchmarking.md
index 23875486..db318765 100644
--- a/docs/benchmarking.md
+++ b/docs/benchmarking.md
@@ -181,7 +181,7 @@ successful requests divided by the entire batch wall time). Without thresholds,
this field is null. Failures never qualify, even if they emitted output before
failing. When a first-output target is set, empty-output successes also do not
qualify. Missing token usage does not prevent evaluating these latency targets. In
-closed-loop mode the targets start at the HTTP request; fixed-rate mode uses
+closed-loop mode the targets start at the HTTP request; scheduled-arrival mode uses
the scheduled arrival time and includes client dispatch delay.
This follows the latency-constrained goodput approach used by
@@ -197,7 +197,8 @@ Keep the load model fixed when comparing reports.
[SGLang's serving benchmark](https://github.com/sgl-project/sglang/blob/main/python/sglang/benchmark/serving.py)
also supports request-rate-driven arrivals and trace timestamps. This tool uses
closed-loop concurrency by default; `--request-rate` selects periodic arrivals
-as described below. Neither mode alone establishes a production SLO guarantee;
+by default, or Poisson arrivals with `--arrival-distribution poisson`,
+as described below. None of these modes alone establishes a production SLO guarantee;
warmup/cache policy, workload representativeness and repeated-run controls still
matter.
@@ -206,7 +207,20 @@ matter.
Add `--request-rate 5` to schedule five arrivals per second. Request `i` is due at
`i / rate` seconds from batch start; the first is due immediately. Absolute
monotonic deadlines prevent accumulated timer drift. This is a deterministic
-periodic schedule, not Poisson traffic or trace replay. Requests are not retried
+periodic schedule. Add `--arrival-distribution poisson --seed 42` for
+independent exponential intervals with mean `1 / rate`. The first request is
+still immediate; subsequent deadlines accumulate sampled intervals. This follows
+the arrival model supported by
+[vLLM](https://docs.vllm.ai/en/latest/cli/bench/serve/#--burstiness) and SGLang;
+it does not reproduce their random-number sequences or implement trace replay.
+The default seed is 0. Equal seeds, rates and request counts reproduce planned
+arrivals independently of warmup and response time, not actual network timing.
+Finite Poisson samples need not realize the configured mean rate. The report
+records the distribution and seed; retain per-request scheduled times for exact
+schedule comparison. Compare identical schedules across servers, then repeat
+with multiple seeds to measure sensitivity to arrival patterns.
+
+Requests are not retried
or dropped, and the finite workload drains before the report is written.
`--concurrency` still caps simultaneous HTTP requests. Arrivals accumulate in
@@ -216,7 +230,7 @@ Delayed producer wakeups also contribute to dispatch delay; inspect client load
before attributing all delay to the server. The queue and retained results can
grow to the workload's total request count, so size workloads accordingly.
-Fixed-rate per-request records add:
+Scheduled-arrival per-request records add:
- `scheduled_seconds`: planned arrival relative to batch start;
- `dispatch_delay_seconds`: actual worker start minus scheduled arrival;