Batcher: a request that reaches an idle worker waits about 4 ms before dispatch

Open
#373 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@YeonwooSung is already working on this.

Since Oct 9, 2026.

  • #658 by @YeonwooSung — open

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

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, WorkerConfig in core/worker/types.py). ModelWorker._get_next_batch_fcfs (core/worker/model_worker.py) passes it as coalesce_cap_ms when 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:

  1. 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.
  2. 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.
  3. Replace the 1 ms poll with an event. Waiting on an asyncio.Event that submit() 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-Time on 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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from superlinked/sie

All issues in superlinked/sie

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.