[PR #4049] [Engine] replicas: each replica its own server on its own port, with one shared expert arena #4887

Open
opened 2026-11-07 16:31:07 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/4049
Author: @furkangkhsn
Created: 10/25/2026
Status: 🔄 Open

Base: main ← Head: replica-ports


📝 Commits (8)

  • f33d5e1 serve: replicas port mode - the config check (all entries have a port, or none)
  • 9560c58 serve: replicas port mode - each replica's run config and command line
  • 062bf2e serve: replicas port mode - the supervisor (one server per replica port, shared arena)
  • 27edc17 docs: replicas port mode and the shared arena
  • 440ab2b serve: replicas port mode - probe over loopback, refuse lazy, keep each replica's shared settings next to the config
  • 60522a5 serve: replicas port mode - each replica's run config is a new owner-only file
  • 6d16f66 serve: replicas port mode - refuse split_serve, as the in-process replicas do
  • 26ee90f serve: replicas port mode - the shared arena follows the server's own plan

📊 Changes

4 files changed (+491 additions, -1 deletions)

View changed files

📝 docs/MULTI_GPU.md (+28 -0)
📝 serve/replicas.py (+198 -0)
📝 serve/server.py (+16 -1)
📝 serve/test_replicas.py (+249 -0)

📄 Description

Problem and result

Running one engine per card with one shared arena (#127, #129) needs hand-written run configs, a start script that waits for each server, and manual cleanup. With this PR, a run config whose replicas entries all have a "port" does it in one start:

  • Startup: one ordinary server per port, started one after another so the first fills replica_shared_arena and the next ones attach, each pinned to its own cores.
  • Stop: Ctrl+C / SIGTERM stops them all and deletes the arena file.
  • Unchanged: without ports, nothing changes.

Issue #4047; the design follows #127 (independent lanes) and uses the arena from #129. Scope not yet agreed: draft until you answer.

Approach

  • Shared arena: 0.2.9 gave the routed replicas "replica_shared_arena": true (a memfd, or a file in /dev/shm). Port mode now takes the same value through the same shared_arena_plan, so a memfd is used here too; a file path still names the file. The option no longer implies ports, and the earlier --replica-shared-arena FILE flag is gone.
  • Where the code lives: serve/replicas.py (port_mode, port_child_cfg, child_argv, run_port_mode) plus one branch early in main(), before saved tuning and flag handling, because each child applies those itself. No Service, endpoint or engine change.
  • Children:
    • Started with lifeline.popen (parent-death signal on Linux, job object on Windows) in their own session.
    • Ready when /health reports loaded: true, probed over loopback with no proxy.
    • Each child's run config is written next to the main config as <name>.replica<i>.json, owner-only and removed at stop, so its shared Chat settings file survives restarts.
  • Refused at start:
    • mixed, duplicate or busy ports;
    • --lazy / lazy_load (a lazy child never reports loaded);
    • --ready-file / --owner-fd;

Validation

Passed:

  • python -m unittest discover -t . -s serve -p 'test_*.py' on main c62d5e3a (0.2.9) + this branch, Linux, Python 3.14: 1316 tests, 2 failures: GpuChoice.test_hip_ordinal and test_keepawake...early_close. Clean main c62d5e3a has the same two (1298 tests). Earlier the same on 0.2.7.1, 0.2.6, v0.2.4.2 and v0.2.3.1. New tests in serve/test_replicas.py: real servers with --engine mock, covering:
    • two ports, two servers;
    • stop ends the children and deletes the arena;
    • Ctrl+C to the process group;
    • a SIGKILLed supervisor's children end;
    • a busy port is refused;
    • a child failing to start stops the others;
    • mixed ports refused, lazy refused, split_serve refused (it starts its own engines, as the in-process replicas already say);
    • readiness probe with HTTP_PROXY set and --host 0.0.0.0;
    • each replica's shared settings kept, run config file is 0600.
  • The same tests on v0.2.3.1: 989 tests, only the pre-existing failures.
  • Manual, mock engine: 4 replicas on 4 ports came up, got disjoint core sets, and stopped with exit 0 with the arena deleted.
  • Real hardware: Linux, RTX 3090 24 GB (PCIe x16) + RTX 4070 Ti 12 GB (PCIe x4), Ryzen 9 9950X, 91 GB RAM, Qwen3.8-Flash-Next IQ3_XXS. Engine 0.1.45.3 (0.2.0-beta build); this branch's serve/ changes applied to that tree's identical server.py / replicas.py / lifeline.py. One run config, "gpu": [0, 1], two replicas entries with ports 8080 (--max-context 524288, YaRN x2) and 8081 (--max-context 131072), "replica_shared_arena": "/tmp/strata-iq3xxs.arena".
    • Startup: both servers up 42 s after the start; /health showed 524288 and 131072. The second replica attached to the arena the first one filled.

    • One arena copy: the 42.9 GB file was mapped by both engines and Shmem was 43.5 GB. Each child server was pinned to its own half of the cores (0-7,16-23 / 8-15,24-31).

    • Concurrent decode, one streamed 512-token request per port at the same time, 3 rounds, medians:

      8080 8081
      this branch 116.5 tok/s 57.5 tok/s
      two hand-started servers on the same arena, same script, minutes before 117.3 tok/s 53.5 tok/s
    • Engine killed: kill -9 of the 8081 engine left 8080 untouched (same engine, answered at once). 8081's own server restarted its engine and answered again 31 s later, and the supervisor did not react.

    • Stop: SIGTERM to the supervisor ended both servers and both engines in 5 s. Both ports were closed, the arena file and the per-replica run configs were deleted, and Shmem was back to 0.6 GB.

Failed: none observed.

Not run:

  • "replica_shared_arena": true (the memfd) in port mode on real hardware: tested with --engine mock only, which does not open the arena. The real-hardware run above used a file path on an older tree.
  • Windows and macOS (lifeline paths there are upstream's; the Windows stop is TerminateProcess).

Limits

  • A file path as the arena is Linux-only (#129).
  • A replica server that exits by itself stops the others.
  • The supervisor waits a fixed 60 s for each child at stop.
  • strata launch / the app do not write port mode yet; a setup option can follow if this is accepted.

🤖 Generated with Claude Code


🔄 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/4049 **Author:** [@furkangkhsn](https://github.com/furkangkhsn) **Created:** 10/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `replica-ports` --- ### 📝 Commits (8) - [`f33d5e1`](https://github.com/Niko1221/Strata/commit/f33d5e14a57752b2f510b69e71ca20af34529080) serve: replicas port mode - the config check (all entries have a port, or none) - [`9560c58`](https://github.com/Niko1221/Strata/commit/9560c580e41dc67ac275889fd7121cb7522a1091) serve: replicas port mode - each replica's run config and command line - [`062bf2e`](https://github.com/Niko1221/Strata/commit/062bf2eecbac674cda578b093a976a8309a33412) serve: replicas port mode - the supervisor (one server per replica port, shared arena) - [`27edc17`](https://github.com/Niko1221/Strata/commit/27edc17fccc64187a6a3f069e8b862f219d4dbbf) docs: replicas port mode and the shared arena - [`440ab2b`](https://github.com/Niko1221/Strata/commit/440ab2bd62d319b8e6745f6fc6fadbb82d765afa) serve: replicas port mode - probe over loopback, refuse lazy, keep each replica's shared settings next to the config - [`60522a5`](https://github.com/Niko1221/Strata/commit/60522a5dfef02c23a07424d4a1ab9e6223ab169d) serve: replicas port mode - each replica's run config is a new owner-only file - [`6d16f66`](https://github.com/Niko1221/Strata/commit/6d16f660af4bcfbbe77ba8fcd4970bbe8d9fa969) serve: replicas port mode - refuse split_serve, as the in-process replicas do - [`26ee90f`](https://github.com/Niko1221/Strata/commit/26ee90feae6d67490dda918675826e94f322ad0d) serve: replicas port mode - the shared arena follows the server's own plan ### 📊 Changes **4 files changed** (+491 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `docs/MULTI_GPU.md` (+28 -0) 📝 `serve/replicas.py` (+198 -0) 📝 `serve/server.py` (+16 -1) 📝 `serve/test_replicas.py` (+249 -0) </details> ### 📄 Description ### Problem and result Running one engine per card with one shared arena (#127, #129) needs hand-written run configs, a start script that waits for each server, and manual cleanup. With this PR, a run config whose `replicas` entries all have a `"port"` does it in one start: - **Startup:** one ordinary server per port, started one after another so the first fills `replica_shared_arena` and the next ones attach, each pinned to its own cores. - **Stop:** Ctrl+C / SIGTERM stops them all and deletes the arena file. - **Unchanged:** without ports, nothing changes. ### Related discussion Issue #4047; the design follows #127 (independent lanes) and uses the arena from #129. Scope not yet agreed: draft until you answer. ### Approach - **Shared arena:** 0.2.9 gave the routed replicas `"replica_shared_arena": true` (a memfd, or a file in `/dev/shm`). Port mode now takes the same value through the same `shared_arena_plan`, so a memfd is used here too; a file path still names the file. The option no longer implies ports, and the earlier `--replica-shared-arena FILE` flag is gone. - **Where the code lives:** `serve/replicas.py` (`port_mode`, `port_child_cfg`, `child_argv`, `run_port_mode`) plus one branch early in `main()`, before saved tuning and flag handling, because each child applies those itself. No `Service`, endpoint or engine change. - **Children:** - Started with `lifeline.popen` (parent-death signal on Linux, job object on Windows) in their own session. - Ready when `/health` reports `loaded: true`, probed over loopback with no proxy. - Each child's run config is written next to the main config as `<name>.replica<i>.json`, owner-only and removed at stop, so its shared Chat settings file survives restarts. - **Refused at start:** - mixed, duplicate or busy ports; - `--lazy` / `lazy_load` (a lazy child never reports loaded); - `--ready-file` / `--owner-fd`; ### Validation **Passed:** - `python -m unittest discover -t . -s serve -p 'test_*.py'` on main c62d5e3a (0.2.9) + this branch, Linux, Python 3.14: 1316 tests, 2 failures: `GpuChoice.test_hip_ordinal` and `test_keepawake...early_close`. Clean main c62d5e3a has the same two (1298 tests). Earlier the same on 0.2.7.1, 0.2.6, v0.2.4.2 and v0.2.3.1. New tests in `serve/test_replicas.py`: real servers with `--engine mock`, covering: - two ports, two servers; - stop ends the children and deletes the arena; - Ctrl+C to the process group; - a SIGKILLed supervisor's children end; - a busy port is refused; - a child failing to start stops the others; - mixed ports refused, lazy refused, `split_serve` refused (it starts its own engines, as the in-process replicas already say); - readiness probe with `HTTP_PROXY` set and `--host 0.0.0.0`; - each replica's shared settings kept, run config file is 0600. - The same tests on v0.2.3.1: 989 tests, only the pre-existing failures. - Manual, mock engine: 4 replicas on 4 ports came up, got disjoint core sets, and stopped with exit 0 with the arena deleted. - **Real hardware**: Linux, RTX 3090 24 GB (PCIe x16) + RTX 4070 Ti 12 GB (PCIe x4), Ryzen 9 9950X, 91 GB RAM, Qwen3.8-Flash-Next IQ3_XXS. Engine 0.1.45.3 (0.2.0-beta build); this branch's `serve/` changes applied to that tree's identical `server.py` / `replicas.py` / `lifeline.py`. One run config, `"gpu": [0, 1]`, two `replicas` entries with ports 8080 (`--max-context 524288`, YaRN x2) and 8081 (`--max-context 131072`), `"replica_shared_arena": "/tmp/strata-iq3xxs.arena"`. - **Startup:** both servers up 42 s after the start; `/health` showed 524288 and 131072. The second replica attached to the arena the first one filled. - **One arena copy:** the 42.9 GB file was mapped by both engines and `Shmem` was 43.5 GB. Each child server was pinned to its own half of the cores (`0-7,16-23` / `8-15,24-31`). - **Concurrent decode**, one streamed 512-token request per port at the same time, 3 rounds, medians: | | 8080 | 8081 | |---|---:|---:| | this branch | 116.5 tok/s | 57.5 tok/s | | two hand-started servers on the same arena, same script, minutes before | 117.3 tok/s | 53.5 tok/s | - **Engine killed:** `kill -9` of the 8081 engine left 8080 untouched (same engine, answered at once). 8081's own server restarted its engine and answered again 31 s later, and the supervisor did not react. - **Stop:** SIGTERM to the supervisor ended both servers and both engines in 5 s. Both ports were closed, the arena file and the per-replica run configs were deleted, and `Shmem` was back to 0.6 GB. **Failed:** none observed. **Not run:** - `"replica_shared_arena": true` (the memfd) in port mode on real hardware: tested with `--engine mock` only, which does not open the arena. The real-hardware run above used a file path on an older tree. - Windows and macOS (lifeline paths there are upstream's; the Windows stop is TerminateProcess). ### Limits - A file path as the arena is Linux-only (#129). - A replica server that exits by itself stops the others. - The supervisor waits a fixed 60 s for each child at stop. - `strata launch` / the app do not write port mode yet; a setup option can follow if this is accepted. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#4887
No description provided.