Streaming Faster Made Our LLM Hub Slower

May 5, 2026 · Andrew Schwabe

Originally published on HackerNoon

Streaming Faster Made Our LLM Hub Slower

We run an open-source mesh for LLM inference called LLMesh. A hub fans tasks out to a pool of agent nodes, Ollama, vLLM, MLX, and streams the results back to clients (and to a live dashboard) over SSE. Streaming is the obvious feature: tokens should appear as they're generated, not in a single dump after a 30-second wait.

So when we wired up real per-token streaming for vLLM, we did the obvious thing: as each token arrived from the model, the agent POSTed it to the hub, the hub fanned it out as an SSE frame, the client rendered it. Fast feedback. Felt great with one user.

Then we put a second user on the box. And a third. And the hub started getting unhappy.

This is the write-up of what we did about it. It's a small piece of code, 258 lines, lib/agent/streaming_batcher.py, but it sits at the intersection of three things that don't usually get discussed together in “how to stream LLM tokens” content: backpressure across multiple network hops, control-theory feedback loops, and network cost for invisible responsiveness.

Three flush triggers

The fix is to batch tokens at the agent before they hit the hub. Our StreamBatcher has three flush triggers, earliest-fires: a batch-size cap is reached, a roughly 100ms time cap is reached, or the stream finishes.

The 100ms time cap is set for a specific reason: that's the rough boundary at which a UI stops feeling instant (Jakob Nielsen's classic 100ms / 1s / 10s response-time tiers). Any token in the buffer is guaranteed to flush within 100ms of arrival, which is the _latency contract with the user_.

The size cap is the _throughput contract with the hub_, never POST more than target_pps batches per second, default 10.

Adaptive batching is then a single optimization: find the largest batch size that respects both contracts simultaneously, given a producer (the model) generating tokens at an unpredictable rate.

The almost-feedback-loop

Here's where we almost shipped a bug.

The first version of the auto-tune logic measured tokens-per-second from flush-to-flush, the obvious choice. Time between flushes is easy to measure, the events are right there, no extra bookkeeping.

Then we sat with it for a minute and realized: flush-to-flush time is _not_ the model's generation rate. It's the model's generation rate plus the hub's POST round-trip time. If the hub gets slow, for any reason, including being overloaded by other streams from the same agent, flush-to-flush time goes up. The batcher reads that as “the model slowed down.” If the model slowed down, the obvious correction is to shrink the batch (don't make users wait as long for fewer tokens).

A smaller batch means more POSTs per second. More POSTs per second means more load on the already-slow hub. Which means flush-to-flush time goes up further. Which the batcher reads as the model slowing down even more. Death spiral.

The fix is one line, but it's the one line that makes the system stable: **TPS is measured from** add() timestamps, not flushes.

  • def _retune(self) -> None:
  • if len(self._window) < 5:
  • return
  • first, last = self._window[0], self._window[-1]
  • elapsed = max(0.05, last - first)
  • tps = len(self._window) / elapsed
  • raw_target = round(tps / self._target_pps)

self._window is a deque of timestamps captured each time the model hands us a token. It's a measurement of the producer's actual generation rate, decoupled from what the consumer (the hub) does with the batches afterward. If the hub gets slow, the batcher correctly observes “the model is still producing at 120 tok/s” and keeps the batch size where it should be, which, conveniently, is the response that _helps_ the slow hub instead of the one that drowns it.

The pattern, stated generally: in any feedback loop, measure what the producer is doing, not what the round trip looks like. The round trip includes the thing you're trying to control.

Smoothing, because measurements are noisy

A naive controller would set the new batch size directly to tps / target_pps. We don't:

  • new = round(0.7 * self._size + 0.3 * target)

Exponential moving average, 70% old, 30% new. We do this for the same reason TCP smooths RTT estimates with the same family of formula: short-window measurements of a noisy stochastic process oscillate, and a controller that snaps to its target on every sample will hunt rather than settle. The 0.3 new-evidence weight is enough to track real changes in generation rate (cold start versus steady-state decode, prompt processing versus generation) but not enough to be perturbed by a single fast or slow token.

Network engineers solved this in the 1980s. We're not doing anything novel here, we're just applying a well-understood pattern to a domain that doesn't usually talk about controllers.

Operator knobs and failure budgets

Two more pieces, both of them about pooled inference specifically, rather than streaming in the abstract.

STREAM_BATCH_FIXED=N pins the batch and disables auto-tune. This is for workloads where predictability matters more than throughput optimization: benchmarks, CI, SLA-bounded tenants who want to reason about their own latency without modeling our control loop. The time cap is still honored, so worst-case latency is still bounded.

STREAM_BATCH_MAX_BUFFER=1000 is the per-stream blast-radius cap. If the hub becomes unreachable, or a downstream consumer stalls, or the model starts emitting an infinite repetition, the batcher's buffer is bounded. Hit the cap, raise StreamBatcherAborted, tear the stream down. In a pooled mesh, one misbehaving stream that can eat unbounded memory is one misbehaving stream that degrades every other tenant on the same node. We'd rather a single client see a clean error than have all clients see a slow death.

These two knobs aren't really features of the batcher. They're features of the fact that the batcher runs in a multi-tenant context. We mention them because they're the difference between an algorithm that works on a whiteboard and one that survives a Tuesday afternoon.

What it looks like in production

We graduated the vLLM streaming + adaptive batcher path from lab to default-on after the verification run completed cleanly. On real hardware: prompt 37 tokens, completion 451 tokens, 91 batches POSTed to the hub over the ~10-second run, adaptive size settled at 6. That's a steady-state regime where the model is producing roughly 60 tokens per second and the batcher is converging on 60 / 10 = 6, exactly what the math says it should do.

The whole thing is in lib/agent/streaming_batcher.py if you want to read it. 258 lines, including the asyncio.Lock plumbing for race-safety with the optional stall-case timer task.

What's next

Two open threads, in case you're working on something similar.

The Ollama agent path still flushes a token at a time and hasn't adopted the batcher yet. Ollama's tok/s is generally lower so the pressure on the hub is less acute, but the same logic applies, and we'll eventually want one batcher implementation behind both backends.

And we haven't addressed hub-side fairness. The agent-side batcher protects the hub from any single stream, but two well-behaved agents can collectively saturate it. The right fix is probably a per-tenant token bucket on the hub's /stream ingress, but we haven't needed it yet, so we haven't built it. If you've solved this on your own stack, we'd love to hear how.

LLMesh is the open-source piece. QCoda is the day job that funds this kind of thinking, pooled AI infrastructure that doesn't fall over the moment you put a second user on the box.

Andrew Schwabe is a serial entrepreneur, AI researcher, musician, father, and tinkerer. He founded ForMotiv and Saigon A.I. and has been featured in Forbes.