Operations: readiness, shutdown, the queue cap and upgrades¶
This page says how a running qix server tells you it is ready, what it does when it is stopped, how to put a rank to sleep and wake it, what it does when too many requests wait, and what a package upgrade keeps. Every statement names the code that does it.
Terms used on this page:
- Rank: one
python -m tnd.serveprocess with its own HTTP port. - Copy: one rank (or one lockstep group of ranks) that serves requests on its own.
- Node router:
tnd-node-router, the front endqix-servestarts when it runs more than one rank on a host. Clients talk to the router; the router talks to the copies. - Supervisor:
qix-serveitself, when it starts several ranks and the router and waits on them (csrc/serve_auto/launch.cpp). - EP convoy: the expert-parallel mode, where several ranks run each step together.
- Packaged build: an install made from a qix
.debpackage, with its systemd units. That packaging is not in the open source tree. A passage marked "packaged build only" does not apply to a build from source or to apipinstall.
Readiness¶
A single rank¶
A rank opens its HTTP port only after the model is loaded. python -m tnd.serve builds the server
after the weights load (python/tnd/serve.py:5747) and the server binds and listens when it starts
serving (csrc/server/py_module.cpp:350). Before that, a connection to the port is refused.
Once the port is open, GET /health answers 200 {"status":"ok","model":"<id>"}
(csrc/server/http_server.cpp:1035).
Several copies behind the node router¶
The router listens at once, before the copies are up. Until every copy has passed one health probe, the router refuses work:
GET /healthanswers503with"status":"starting", adetailline that says how many copies are up, andRetry-After: 2(csrc/distributed/node_router.cpp:1872,csrc/distributed/node_router.cpp:1875).POST /v1/chat/completionsand/v1/completionsanswer503withRetry-After: 2(csrc/distributed/node_router.cpp:1461,csrc/distributed/node_router.cpp:1342).GET /v1/modelsanswers the same way (csrc/distributed/node_router.cpp:1882).GET /metricsis served during start-up. The router's own gauges say how many copies answered (see metrics.md).
The router stops waiting for a copy whose process has exited, or after 3600 s
(--ready-deadline, csrc/distributed/node_router.h:140). It then serves with the copies it has.
The gate applies only when there are two or more copies.
After start-up, the router probes each copy's /health every 2 s
(csrc/distributed/node_router.h:338). A copy that does not answer 200 is marked dead
(csrc/distributed/node_router.cpp:1966) and gets no new requests. A later probe that gets 200
marks it alive again (csrc/distributed/node_router.cpp:1956-1958).
Use the router's /health as the load balancer's readiness check. Wait for 200.
Shutdown: SIGTERM and the drain¶
What a rank does on SIGTERM¶
On SIGTERM a rank drains before it stops. On SIGINT (Ctrl-C) it stops at once
(drain_then_stop, python/tnd/serve.py:644-683).
The drain, in order:
/healthanswers503 {"status":"draining"}(csrc/server/http_server.cpp:1046-1049). A router or load balancer that probes it stops sending new work to this rank.- A new inference request is refused with
503and the errorengine unavailable. The request is not queued (csrc/server/serve_loop.cpp:1206,csrc/server/http_server.cpp:1393-1410). - The listener stays open. Every request already accepted keeps running until its last byte, a
stream's final chunk included, is written (
csrc/server/http_server.cpp:64, theDrainGate). - The rank waits until no inference request is in flight, or until the grace cap passes
(
csrc/server/py_module.cpp:362-371). - The rank then stops as it did before the drain existed: the HTTP server closes, and the requests
still in flight are aborted (
python/tnd/serve.py:682).
The rank logs the result: either every request finished, with the time it took, or the number of requests still in flight when the cap passed.
How long the grace cap is¶
The cap is computed, not set. Its inputs are the two stop deadlines a rank must beat
(csrc/serve_auto/stop_deadlines.h):
| Value | How it is computed | Result | Line |
|---|---|---|---|
| supervisor stop wait | 300 polls x 100 ms, then SIGKILL | 30 s | csrc/serve_auto/stop_deadlines.h:23 |
| router stop deadline | the router exits by itself after this | 20 s | csrc/serve_auto/stop_deadlines.h:27 |
| outer bound | the earlier of the two | 20 s | csrc/serve_auto/stop_deadlines.h:32 |
| teardown margin | the gap between the two | 10 s | csrc/serve_auto/stop_deadlines.h:41 |
| drain grace cap | outer bound minus teardown margin | 10 s | csrc/serve_auto/stop_deadlines.h:48 |
The teardown margin is not measured. It is time kept back for the rank to stop HTTP, join its
driver thread and leave the interpreter after the drain. A rank prints the cap and its inputs once
at start-up (csrc/server/py_module.cpp:326-334).
Packaged build only. The systemd unit tnd-server allows 30 s between SIGTERM and SIGKILL
(TimeoutStopSec=30). The unit tnd-server-tp allows 90 s.
When there is no drain¶
- EP convoy. Under the expert-parallel convoy the ranks leave together, so a rank does not
drain. SIGTERM aborts the requests in flight (
csrc/server/serve_loop.cpp:3386-3390). The rank logsshutdown drain: off under the EP convoyat start-up (csrc/server/py_module.cpp:336). - Behind the node router. When
qix-serveruns several copies, it sends SIGTERM to every process at the same moment, the router included (csrc/serve_auto/launch.cpp:331). On SIGTERM the router closes its listener and cuts every request it is forwarding (csrc/distributed/node_router_main.cpp:255,csrc/distributed/node_router.cpp:2063). The copies drain, but a client that came through the router has already lost its connection. In this release, a client of a multi-copy launch is not protected by the drain. - SIGINT. Ctrl-C stops at once.
To take one copy out of service, send SIGTERM to that copy's process, not to qix-serve. This
works only in the replicas layout. There the supervisor logs exited; the router reroutes its
traffic and keeps the other copies serving (csrc/serve_auto/launch.cpp:401). In the ep layout a
rank that exits makes the supervisor log exited while serving -- tearing the launch down and stop
every process on the node (csrc/serve_auto/launch.cpp:404). Under the EP convoy a rank does not
drain at all (csrc/server/serve_loop.cpp:3386-3390).
In the replicas layout, the copy's /health turns 503 and the copy finishes what it has for up
to 10 s. Three things still hold:
- The supervisor never restarts the copy. The node serves with one copy fewer until
qix-serveis restarted. - From the SIGTERM until the router's next probe (up to 2 s), the router still sends new requests to
that copy. The copy refuses them with
503engine unavailable, and the router passes that answer to the client without trying another copy (csrc/distributed/node_router.cpp:1643). This answer carries noRetry-Afterheader. - After the probe, the router marks the copy dead and sends new requests to the other copies.
Sleep and wake¶
A rank can free its GPU memory without exiting, and take it back later. Three routes do this, on
the rank's own HTTP port (csrc/server/http_server.cpp:1081-1119; the state machine is
csrc/server/sleep_control.h). The node router does not forward them.
| Route | What it does |
|---|---|
POST /sleep?level=1 |
Level 1, the default: copies the weights to host memory, frees their GPU storage, and drops the KV cache. |
POST /sleep?level=2 |
Level 2: drops the weights and the KV cache. Waking reloads the weights from the model source. |
POST /wake_up |
Restores what the sleep released, at the level it slept with, and takes requests again. A ?tags= parameter is ignored: qix wakes weights and KV cache together. |
GET /is_sleeping |
{"is_sleeping": <bool>, "state": "<state>"}, plus level while asleep. is_sleeping is true only in the state sleeping. |
What POST /sleep does, in order (csrc/server/sleep_control.cpp:104-166):
- It refuses new inference requests, the same way the shutdown drain does.
- It waits for the open responses to finish and for the step loop to stop, for at most the drain
grace cap (10 s, above). If they do not finish in time, the rank stays awake, keeps serving them
and answers
409. - It drops the prefix cache.
- It releases the GPU memory at the level asked for.
The states are awake, draining, quiesced, sleeping and waking. In every state but awake:
- an inference request gets
503with"code":"engine_sleeping"and aRetry-Afterheader (csrc/server/http_server.cpp:243-250); GET /healthanswers503with the state name asstatusand aRetry-Afterheader (csrc/server/http_server.cpp:1037-1045). Behind the node router, the next probe marks the copy dead, and the router sends new requests to the other copies until the copy answers200again.
Retry-After is the time the last wake took, and 1 s before any wake was measured
(csrc/server/sleep_control.cpp:95-98).
Each call blocks until the transition is done. The answer is JSON: status, seconds, level
when one applies, and error with a message when the call failed.
| Status | When |
|---|---|
200 |
The transition ran. status is sleeping or awake. A call that changes nothing also answers 200, with already_sleeping or already_awake. |
400 |
level is not 1 or 2. |
403 |
The peer is not a loopback address and the rank runs without --sleep-remote. |
409 |
The rank cannot stop taking requests now (it runs under the EP convoy, or a shutdown drain is under way), or the open requests did not finish within the cap. The rank stays awake. |
500 |
The release or the restore failed. A failed release is undone and the rank stays awake; if the undo fails too, the rank stays asleep and refuses requests until a wake succeeds. A failed restore leaves the rank asleep. |
501 |
This rank cannot sleep. The body says why. |
A rank answers 501 when one of these holds (sleep_unavailable_reason,
python/tnd/sleep_mode.py:267-287):
- it is part of a tensor-parallel or expert-parallel group;
- its KV host tier is on;
- its window KV ring is on;
- its model keeps per-request state slots;
- its model holds state outside its parameters and buffers.
The rank logs at start-up whether sleep is on, and the reason when it is off
(python/tnd/serve.py:616-641).
The sleep routes answer loopback peers only: 127.0.0.0/8, ::1 and ::ffff:127.x.y.z. The
check reads the socket's peer address, never a header. --sleep-remote on tnd.serve lets any
peer call them (python/tnd/serve.py:1675-1681). This is a peer-address check, not
authentication; see trusted-network.md.
The queue cap¶
A rank holds at most a fixed number of waiting requests. A waiting request is one that was accepted but has no place in a batch yet. A request that arrives when the waiting set is full is refused, not queued.
How the cap is derived¶
At start-up, and again each time the KV pool grows, the rank computes
(csrc/server/serve_loop.cpp:1275-1280):
queue cap = max(max_num_seqs, (GPU KV blocks + host-tier block slots) / max_blocks_per_seq)
The second term is the number of sessions the KV pool holds when each one is at the per-sequence
cap. Every input comes from auto-config. There is no setting for the cap. The rank logs the cap and
each input on a line that starts with [tnd] auto-config: queue cap =
(csrc/server/serve_loop.cpp:1289).
What a refused request gets¶
HTTP 503 with a Retry-After header and a JSON error (csrc/server/http_server.cpp:226-239):
{"error": {"message": "...", "type": "service_unavailable", "code": "queue_full",
"requests_ahead": 512, "queue_cap": 512, "retry_after_ms": 4200,
"deadline_ms": 0, "waited_ms": 0}}
Retry-Afterisretry_after_msrounded up to whole seconds (csrc/server/http_server.cpp:237).retry_after_msis the requests ahead times the measured mean time per admission. Before the first admission nothing is measured, and it is 1000 ms (csrc/server/serve_loop.cpp:1227-1229).- Nothing is queued. Retrying after
Retry-Afteris safe.
The node router passes a copy's 503 and its Retry-After to the client
(csrc/distributed/node_router.cpp:1646).
Requests with a deadline¶
A client may send X-Request-Deadline-Ms: <ms> (csrc/server/http_server.cpp:194). Two more
refusals use it:
- At submit, when the predicted wait is past the deadline:
503,code: "queue_full",Retry-After(csrc/server/serve_loop.cpp:1232-1247). - While waiting, when the deadline passes before the request is placed:
503,code: "queue_timeout",Retry-After(csrc/server/http_server.cpp:253-260).
How these refusals are counted is in metrics.md.
Request priority¶
A request may carry priority, an integer; lower runs first, and the default is 0
(openai-server.md). A negative value from a client is clamped to 0
(csrc/server/openai_schema.cpp:401-417).
Upgrades and the listen address¶
Packaged build only. This whole section describes the .deb package and its systemd units.
A build from source has no package scripts and no unit; its listen address is the --host you
pass, default 127.0.0.1.
Older packages listened on 0.0.0.0 by default. This release listens on 127.0.0.1
(TND_HOST=127.0.0.1 in the shipped /etc/tnd-server/tnd-server.conf). An upgrade does not
silently move a server off its network address:
- Before the new files unpack, the package saves the
TND_HOSTthe host was running with. Whentnd-server.confset noTND_HOST, it saves the default the old launchers used. - After the unpack, when the saved value differs from the new file's value, the package writes it
to
/etc/tnd-server/tnd-server.conf.d/host.confand prints aNOTICEthat names the value and the file. - The units read
host.confaftertnd-server.conf, so the kept value wins.tnd-serve-tp-launchreads it too when run by hand. tnd-server.confitself is not edited by the package.
To move to loopback after an upgrade, delete host.conf and restart the service. A later upgrade
prints a NOTICE while host.conf still sets a non-loopback address.
A fresh install has no saved value and listens on 127.0.0.1.