Batcher: a request that reaches an idle worker waits about 4 ms before dispatch
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 40/100
- Issue type
- Refactor
- Clarity
- Mostly clear
- Activity status
- Quiet
- Tech stack
- python
- Domain
- backend, performance
Research direction
Start in ModelWorker._get_next_batch_fcfs in core/worker/model_worker.py, where idle_coalesce_ms becomes coalesce_cap_ms for an idle worker, and in the 1 ms asyncio.sleep poll that the issue describes. Read WorkerConfig in core/worker/types.py and the existing idle-window tests in tests/core/test_batcher.py and tests/core/test_worker_core.py. Done means a lone sequential request shows X-Queue-Time under 1 ms while a concurrent burst still forms one batch and throughput is unchanged. The issue leaves the choice between the three proposals open, so agree the approach with maintainers first.
Written by the indexing model from the issue text.
Description
Problem
A request that reaches an idle model worker waits about 4 ms before its batch is dispatched. With one client sending one request at a time to an L4, X-Queue-Time is 3.8 to 4.2 ms on every request, for knowledgator/gliformer-large-v1 and knowledgator/gliclass-large-v1.0 alike. The wait is:
- the idle accumulation window,
idle_coalesce_ms(default 3.0 ms,WorkerConfigincore/worker/types.py).ModelWorker._get_next_batch_fcfs(core/worker/model_worker.py) passes it ascoalesce_cap_mswhen the worker was idle, so a lone request waits until arrivals have been quiet for 3 ms; - the idle poll,
await asyncio.sleep(0.001), which checks for new requests once per millisecond.
For short requests this is a noticeable share of latency:
| Workload | Median per record | Batcher wait | Share |
|---|---|---|---|
| GLiFormer-large, one extract call per record (typed-decision records, 40 to 140 tokens) | about 65 ms | about 4 ms | about 6% |
| GLiClass-large, three extract calls per record | about 190 ms | about 12 ms | about 6% |
The window exists for a reason: without it, a burst that reaches an idle worker was split into a train of small serialized forwards. The cost is that sequential and low-rate traffic, which has nothing to coalesce, pays the full window on every request.
Proposal
Keep coalescing for bursts, and stop charging it to requests that arrive alone:
- Dispatch at once when nothing else is arriving. When the worker is idle and only one request is pending, dispatch it immediately unless another request arrived within the last few milliseconds. The first request of a burst then runs alone and the rest coalesce behind it: two forwards instead of one, not one per request.
- Or adapt the window to the arrival rate. Track an exponentially weighted mean of inter-arrival gaps per model and use
min(idle_coalesce_ms, k * gap)when the gap is short and 0 when it is long, so the wait follows the traffic instead of a constant. - Replace the 1 ms poll with an event. Waiting on an
asyncio.Eventthatsubmit()sets wakes the worker when a request arrives instead of on the next poll tick.
Setting idle_coalesce_ms: 0 already restores immediate dispatch globally, so a quick experiment can confirm the size of the saving before any code changes.
Acceptance
- With one sequential client,
X-Queue-Timeon an idle worker is under 1 ms. - A burst of concurrent requests reaching an idle worker still forms one batch, as the existing idle-window tests (
tests/core/test_batcher.py,tests/core/test_worker_core.py) check. - Throughput under concurrent load is unchanged within noise.
- Dominant language
- Python
- Stars
- 3.5k
- Forks
- 328
- Avg merge
- 17h 8m
- Merged PRs (30d)
- 108
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from superlinked/sie
-
Difficulty 1/5 Under an hour Newbie friendliness 86/100
superlinked/sie#1033 ·
Maintainers usually reply within 1 day
-
LoRA source resolver rejects shared cache blobs accepted by serving-artifact validationPossibly taken @draarivpatel-ui claimed this 2 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
superlinked/sie#1001 ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 5/5 Over a week Newbie friendliness 15/100
superlinked/sie#1013 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 42/100
superlinked/sie#969 ·
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
superlinked/sie#892 ·
Maintainers usually reply within 1 day
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 78/100
reflex-dev/reflex#8026 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
apache/ponymail-foal#365 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
NousResearch/hermes-labs-plugins#116 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
gcivil-nyu-org/team-3-fall26#192 ·
Maintainers usually reply within 1 day
-
[Study plan] Study sessions can be rescheduled to any length (e.g. 72 hours) with no length checkOpen
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
gcivil-nyu-org/team-2-fall26#159 ·
Maintainers usually reply within 1 day