[PR #4601] [CLOSED] [Engine] serve: replicas: a request waits for a free card instead of being given one on arrival #5106

Closed
opened 2026-11-07 16:32:44 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/4601
Author: @liangzelong
Created: 10/29/2026
Status: ❌ Closed

Base: main ← Head: main


📄 Description

Problem and result

With "replicas", a request is given a card as soon as it arrives, even when that card is busy. It then waits on that
card's lock while the other card may sit idle. Clients that send the same long system prompt — every agent session
does — all want the card that holds that prefix, so with two of them at once the requests pile onto one card and the
other one stays at 0%. This is what a multi-agent task does (the captain and every member share the system prompt and
the tools) and what two sessions of the same framework do (their prompts differ only in the message).

With "replica_pull": true a request waits for a free card and takes the first one that frees up, so an idle card is
always used; among the waiting requests the one that would read the fewest prompt tokens again goes first.

Measured on 2x RTX 4090 (Linux, WSL2, 128 threads), Qwen3.8-Flash-Next UD-Q4_K_XL, 262,144-token context,
"replicas": 2, "parallel": 1, two sessions of one agent framework sending the same ~19,500-token system prompt and
differing only in their last message:

one card at a time "replica_pull": true
cards busy one at 96%, the other at 0-1% both at 97-99%
a second request with the same 19,500-token prompt its prefix was cached (544 tokens read) but the first token came after 60 s: it waited for the other request's whole turn the two requests ran on the two cards; the one that found no free slot waited 16.8 s for one, then started
output tokens per second, both cards 60 90-130

none

Approach

  • serve/replicas.py: ReplicaEngine gets an opt-in pull scheduler. The requests wait in one pending pool; when a
    replica has a free slot, the pool hands it the request that would read the fewest tokens again on that replica (the
    prefix bookkeeping is read at that moment, not at arrival). A request that has waited longer than replica_starve_s
    goes first whatever it costs. A request that was given a card then runs as before.

    This is the order the mode is for: a layer split keeps one conversation on the same cards to read as little of it
    again as possible, while the replicas mode runs a complete model on every card and serves its own conversations, so
    every card goes first and the reuse stays inside a card. A request that is given a card on arrival and waits there
    behind another one leaves a card idle, which is the split behaviour with more overhead.

  • serve/server.py: "replica_pull" and "replica_starve_s" in the run config, a start-up line that says which order
    is in use, and live.replica_pending in /metrics (the pool size).

  • serve/test_replicas.py: six tests for the new order; the old order is left as it was.

  • docs/DETAILS.md, docs/MULTI_GPU.md: the two config keys, and the feature itself, which had no user documentation.

Without "replica_pull" nothing changes: a request is still given a card on arrival and waits there.

Validation

Passed:

  • python -m unittest serve.test_replicas — 25 tests OK (19 before, 6 new), Python 3.10.9, Linux, engine 0.1.53,
    source tree at 46c152a1 (v0.2.7.1) with this change.
  • python -m unittest serve.test_parallel serve.test_slots serve.test_queue_keepalive serve.test_admit_order serve.test_request_accounting serve.test_request_hardening — 82 tests OK, same tree.
  • The two-arm run above: 2x RTX 4090 (Linux, WSL2), engine 0.1.53, Qwen3.8-Flash-Next UD-Q4_K_XL, 262,144-token
    context, "replicas": 2, "parallel": 1, "max_queue": 2. Two requests with a 26,987-token shared prefix whose last
    message differs by one word, sent at the same time:
    • without replica_pull: both requests to one card; the second first token after 5.6 s (the first request's whole
      turn); GPU 96% / 0%.
    • with replica_pull: the two requests to the two cards; the second first token after 1.5 s; GPU 97% / 99%.
  • The start-up line names the order in use, and /metrics reports live.replica_pending.

Failed: none observed.

Not run:

  • CUDA, HIP, SYCL and Metal builds: no engine source is touched.
  • Multi-GPU beyond the two RTX 4090 of the measurement, and other models: not qualified here.
  • The prompt cache's own reuse on the card that did not serve the first turn: each replica keeps its own cache, so that
    read was not measured.

Limits

  • The order only differs with "replica_pull": true; the default path is unchanged.
  • A request that was given a card keeps it. It is not moved when the other card frees up later.
  • A conversation that changes card reads its own history again: the shared part of a prompt is counted for the card
    that holds it, so a session whose prompt is cached on no card pays a full read on the card it is given.
  • The first request on a card is slower: its experts are not in that card's VRAM yet and have to be fetched over PCIe.
  • The pool is bounded by the server's admission cap (max_queue), not by the pull scheduler.
  • queue_timeout is not checked on this path; it is only checked on the single-slot queue.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/4601 **Author:** [@liangzelong](https://github.com/liangzelong) **Created:** 10/29/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `main` --- ### 📄 Description ## Problem and result With `"replicas"`, a request is given a card as soon as it arrives, even when that card is busy. It then waits on that card's lock while the other card may sit idle. Clients that send the same long system prompt — every agent session does — all want the card that holds that prefix, so with two of them at once the requests pile onto one card and the other one stays at 0%. This is what a multi-agent task does (the captain and every member share the system prompt and the tools) and what two sessions of the same framework do (their prompts differ only in the message). With `"replica_pull": true` a request waits for a free card and takes the first one that frees up, so an idle card is always used; among the waiting requests the one that would read the fewest prompt tokens again goes first. Measured on 2x RTX 4090 (Linux, WSL2, 128 threads), Qwen3.8-Flash-Next UD-Q4_K_XL, 262,144-token context, `"replicas": 2`, `"parallel": 1`, two sessions of one agent framework sending the same ~19,500-token system prompt and differing only in their last message: | | one card at a time | `"replica_pull": true` | | --- | --- | --- | | cards busy | one at 96%, the other at 0-1% | both at 97-99% | | a second request with the same 19,500-token prompt | its prefix was cached (544 tokens read) but the first token came after 60 s: it waited for the other request's whole turn | the two requests ran on the two cards; the one that found no free slot waited 16.8 s for one, then started | | output tokens per second, both cards | 60 | 90-130 | ## Related discussion none ## Approach - `serve/replicas.py`: `ReplicaEngine` gets an opt-in pull scheduler. The requests wait in one pending pool; when a replica has a free slot, the pool hands it the request that would read the fewest tokens again on that replica (the prefix bookkeeping is read at that moment, not at arrival). A request that has waited longer than `replica_starve_s` goes first whatever it costs. A request that was given a card then runs as before. This is the order the mode is for: a layer split keeps one conversation on the same cards to read as little of it again as possible, while the replicas mode runs a complete model on every card and serves its own conversations, so every card goes first and the reuse stays inside a card. A request that is given a card on arrival and waits there behind another one leaves a card idle, which is the split behaviour with more overhead. - `serve/server.py`: `"replica_pull"` and `"replica_starve_s"` in the run config, a start-up line that says which order is in use, and `live.replica_pending` in `/metrics` (the pool size). - `serve/test_replicas.py`: six tests for the new order; the old order is left as it was. - `docs/DETAILS.md`, `docs/MULTI_GPU.md`: the two config keys, and the feature itself, which had no user documentation. Without `"replica_pull"` nothing changes: a request is still given a card on arrival and waits there. ## Validation **Passed:** - `python -m unittest serve.test_replicas` — 25 tests OK (19 before, 6 new), Python 3.10.9, Linux, engine 0.1.53, source tree at `46c152a1` (v0.2.7.1) with this change. - `python -m unittest serve.test_parallel serve.test_slots serve.test_queue_keepalive serve.test_admit_order serve.test_request_accounting serve.test_request_hardening` — 82 tests OK, same tree. - The two-arm run above: 2x RTX 4090 (Linux, WSL2), engine 0.1.53, Qwen3.8-Flash-Next UD-Q4_K_XL, 262,144-token context, `"replicas": 2`, `"parallel": 1`, `"max_queue": 2`. Two requests with a 26,987-token shared prefix whose last message differs by one word, sent at the same time: - without `replica_pull`: both requests to one card; the second first token after 5.6 s (the first request's whole turn); GPU 96% / 0%. - with `replica_pull`: the two requests to the two cards; the second first token after 1.5 s; GPU 97% / 99%. - The start-up line names the order in use, and `/metrics` reports `live.replica_pending`. **Failed:** none observed. **Not run:** - CUDA, HIP, SYCL and Metal builds: no engine source is touched. - Multi-GPU beyond the two RTX 4090 of the measurement, and other models: not qualified here. - The prompt cache's own reuse on the card that did not serve the first turn: each replica keeps its own cache, so that read was not measured. ## Limits - The order only differs with `"replica_pull": true`; the default path is unchanged. - A request that was given a card keeps it. It is not moved when the other card frees up later. - A conversation that changes card reads its own history again: the shared part of a prompt is counted for the card that holds it, so a session whose prompt is cached on no card pays a full read on the card it is given. - The first request on a card is slower: its experts are not in that card's VRAM yet and have to be fetched over PCIe. - The pool is bounded by the server's admission cap (`max_queue`), not by the pull scheduler. - `queue_timeout` is not checked on this path; it is only checked on the single-slot queue. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 16:32:44 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#5106
No description provided.