seatload

package
v0.207.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2026 License: Apache-2.0 Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package seatload reads how many requests an agent seat holds RIGHT NOW, through llama-swap. Two callers share it and must agree on the answer:

  • `gpu reserve --drain` (gpu_drain.go): a measurement must never start over a live request, so the drain polls this until two consecutive zero reads;
  • the delegator's spread deal (internal/delegate, 0.113.20): a local seat that already holds a request loses its rotation slot to a remote with room, so K delegating sessions do not stack on one seat.

The read is deliberately two-step: llama-swap's /running says whether the seat is loaded at all, and ONLY a loaded seat is asked for /metrics (or /slots) — at the seat's OWN address (the `proxy` /running reports for it), never through /upstream/<model>/…. That path is wrong twice over: it loads a model on demand, so probing it on an unloaded seat would do the exact thing a drain exists to avoid; and llama-swap counts every /upstream request as activity, so a gauge read through it resets the seat's idle timer — a reader that polls (the PAIR seat watcher, a status line, a drain) would keep an idle seat resident forever and defeat the 5-minute idle unload.

/running lists CANONICAL ids, while the harness binds seats by ALIAS on the reference deployment (agent-pool -> qwen3.8-27b-vllm, offload-e4b -> gemma-4-e4b). Matching /running by the configured name therefore read an alias-bound seat as "not loaded" and the drain returned at once on a seat that could be mid-request (silent from 0.113.16 to 0.113.19 on the box whose seat is alias-bound; the box whose seat is bound by its id was unaffected, which is why the live proofs passed). Inflight resolves the name through the roster first (swapclient.Roster.Canonical) and matches /running by BOTH the canonical id and the given name; when the roster cannot be read it falls back to the bare name — the pre-0.113.20 behaviour, never a refusal.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoSeatAddress = errors.New("llama-swap /running reports no `proxy` address for the seat (a llama-swap build too old to report it: upgrade llama-swap); the gauge is read at the seat itself, never through /upstream (which resets the idle unload timer), so it cannot be read")

ErrNoSeatAddress is Inflight's answer for a LOADED seat whose /running entry carries no `proxy`: the gauge has nowhere to be read from except /upstream/<seat>/…, and that path resets the seat's idle timer (see the package comment), so the reader reports "could not read" instead.

Every llama-swap build this repo's client models (tools/llamaswap) reports `proxy` in /running, so a missing field means a llama-swap too old to say where its seat listens; the message names the fix, because the drain prints it at its deadline and `gpu status` / offload_status show it as the seat's error — a silent drain timeout is what it replaces.

View Source
var ErrRemoteSeatUnreachable = errors.New("the seat runs behind a llama-swap on another machine and its own address is not reachable from here (a seat bound to 127.0.0.1, as the reference launcher binds it, can be read only by a harness on llama-swap's machine; /upstream is never used because it resets the idle unload timer)")

ErrRemoteSeatUnreachable is Inflight's answer when the llama-swap endpoint is ANOTHER machine, /running reports the seat at a loopback address there, and the re-pointed address (that machine's host, the seat's port) refuses or times out. The reference launcher binds the engine to 127.0.0.1 only (seat_fg.sh `--host 127.0.0.1`), so its gauge can be read only by a harness on llama-swap's own machine; /upstream would reach it across machines but resets the seat's idle unload timer on every read, so it is not a fallback. A seat that binds a routable address on that machine is read directly.

View Source
var InflightGauges = []string{
	"vllm:num_requests_running", "vllm:num_requests_waiting",
	"llamacpp:requests_processing", "llamacpp:requests_deferred",
}

InflightGauges are the counters that mean "a request is in flight" on the engines the harness fronts: vLLM (running + waiting) and llama-server (processing + deferred). Any other gauge is ignored.

Functions

func LiveRates

func LiveRates(prev, cur Activity) (genTokS, promptTokS float64, ok bool)

LiveRates is the throughput the engine achieved between two readings of the same seat, in tokens per second of wall: generated tokens and prompt tokens (vLLM credits a prompt when its prefill finishes). ok is false when either reading lacks the counters, the readings are out of order, or a counter went backwards (an engine restart between them).

func ParseInflight

func ParseInflight(r io.Reader) int

ParseInflight sums the in-flight gauges of a Prometheus exposition. A `_total` counter that merely shares a gauge's prefix is not counted.

func ParseSlotsInflight

func ParseSlotsInflight(r io.Reader) (int, error)

ParseSlotsInflight counts `is_processing` slots in a llama-server /slots body. A body that is not an array is an error, never zero in flight.

func SeatURL

func SeatURL(endpoint, proxy string) (string, error)

SeatURL resolves the address a seat's gauges are read at from the `proxy` llama-swap's /running reports for it. The proxy is written from llama-swap's point of view, so a loopback or unspecified host means "llama-swap's box". When the endpoint names THIS box — loopback, this machine's hostname, or a name or address that resolves to one of its interfaces (a MagicDNS name for itself) — a loopback proxy is kept as it is: the reference seat binds 127.0.0.1 only (seat_fg.sh `--host 127.0.0.1`), so re-pointing it at the box's own hostname would be refused on every read. Only a llama-swap on ANOTHER box has its loopback proxy re-pointed at that box's host — which reaches the seat only when it binds a routable address there; a loopback-bound seat on another box refuses, and Inflight reports that as ErrRemoteSeatUnreachable. The port is never guessed: two seats may share one port, and only the one /running lists as running owns it now.

Types

type Activity

type Activity struct {
	// Reading is the /running half (Loaded, Starting, Stopping, Proxy, …).
	// Starting or !Loaded means the engine was not asked.
	Reading
	// Fingerprint changes whenever the engine takes a step for any request.
	// "" when the engine was not asked or no counter could be read.
	Fingerprint string
	// TokenFingerprint changes only when the engine PRODUCES: generated or
	// prompt tokens credited (vLLM, llama-server --metrics), or a slot's
	// decoded / prompt-processed counts (/slots). An engine that keeps stepping
	// without producing — a preempt-and-recompute thrash moves the step count,
	// the KV gauge and the preemption counter, never a token — is caught by the
	// monitor's token bound on this, not by the work fingerprint.
	TokenFingerprint string
	// Running and Waiting are the engine's own request gauges (vLLM running
	// and waiting; llama-server processing and deferred; /slots processing).
	// Waiting is -1 when the source cannot see a queue (/slots lists no
	// deferred requests).
	Running, Waiting int
	// KVGaugeMissing: a vLLM exposition carried neither KV-usage gauge, so a
	// solo prefill (no token, no iteration stats) cannot move the fingerprint.
	// Named in Summary so a reader sees why a prefill looked flat.
	KVGaugeMissing bool
	// GenTokens and PromptTokens are the engine's lifetime counters, -1 when
	// the source has none (/slots). Two readings apart give the throughput
	// the seat is achieving NOW — throttled, shared or not (LiveRates).
	GenTokens, PromptTokens float64
	// Preemptions is vLLM's num_preemptions_total, -1 when unknown.
	Preemptions float64
	// ActSource names what answered: "vllm-metrics", "llamacpp-metrics" or
	// "slots".
	ActSource string
	// At is when the engine answered.
	At time.Time
}

Activity is one reading of a seat's engine.

func ReadActivity

func ReadActivity(ctx context.Context, client *http.Client, endpoint, seat string) (Activity, error)

ReadActivity reads the seat named `seat` (id or alias) behind the llama-swap at endpoint. A seat that is not loaded, or is loading/unloading, comes back with no fingerprint and no error: that is llama-swap's answer, and the caller's cold-load hold owns it. A loaded seat whose engine cannot be read is an error — "cannot tell" is never "idle" and never "busy".

func (Activity) Summary

func (a Activity) Summary() string

Summary is the reading in one short clause for a reason or a status line.

type Occupant

type Occupant struct {
	Model string `json:"model"`
	State string `json:"state"`
	Proxy string `json:"proxy"`
	// Cmd is the process argv llama-swap actually spawned for the seat, which is what is true of a loaded
	// seat when the serving config on disk has changed since. It carries paths and flags: a reader uses it
	// to tell an engine apart and never prints, logs or publishes it.
	Cmd string `json:"cmd"`
}

Occupant is one row of llama-swap's GET /running: a model holding (or loading onto, or leaving) the cards, by its CANONICAL id.

func Occupants

func Occupants(ctx context.Context, client *http.Client, endpoint string) ([]Occupant, error)

Occupants reads llama-swap's /running ONCE and returns every row, whatever its state. It is the read behind Running and Inflight (their first half), exported for the caller that needs the WHOLE picture rather than one seat's line in it: the cascade seat guard (internal/seatguard) must know every model holding the cards to reproduce llama-swap's eviction choice, and it reads that from this same decode so "is the seat loaded" means the same thing there as in offload_status and `gpu status`. It touches no seat and no /upstream path. endpoint is the llama-swap ROOT (swapclient.BaseURL); an unreadable or malformed answer is an error, never an empty list.

type Reading

type Reading struct {
	// Inflight is the number of requests the seat holds (running + waiting).
	// Meaningful only when Loaded.
	Inflight int
	// Loaded reports whether llama-swap lists the seat as running. false =
	// idle by definition, and the upstream was NOT probed.
	Loaded bool
	// Canonical is the roster id the name resolved to ("" when the roster
	// could not be read or does not serve the name).
	Canonical string
	// Source names what answered the count: "metrics" (vLLM/llama-server
	// exposition), "slots" (llama-server /slots), or "" when not loaded.
	Source string
	// RosterErr is the roster read's failure, when it failed. The reading then
	// matched /running by the bare name only, which cannot see an alias-bound
	// seat listed under its id.
	RosterErr error
	// RunningOthers is how many models /running listed that did NOT match the
	// seat. With RosterErr set and Loaded false, a non-zero value means the
	// seat may be one of them under a name this reading could not resolve.
	RunningOthers int
	// Ambiguous is exactly that case: not loaded by the bare name, the roster
	// unreadable, and /running not empty. "Could not tell" must never pass as
	// "idle" where idleness is load-bearing (the drain); a caller for whom the
	// reading is only an optimisation (the spread deal) may treat it as idle
	// and say so.
	Ambiguous bool
	// Starting reports that llama-swap lists the seat in state `starting` (or
	// `stopping`): Loaded is true, Inflight is NOT known (0 here means "not
	// asked"), and the upstream was NOT probed — llama-swap would hold that
	// request until the load completes (register D-92). A load in progress is
	// work in flight for the drain and "not yet a target" for the spread deal.
	Starting bool
	// Stopping is the `stopping` half of Starting: the seat is on its way OUT
	// (its ttl ran out, or an unload was asked), not loading. Starting stays
	// true with it, because the upstream is just as unaskable; callers that
	// report or act on "a load is happening" must tell the two apart (the
	// 2026-09-23 `gpu status` read "agent-pool is loading" during a ttl unload).
	Stopping bool
	// Proxy is the seat's own address as llama-swap's /running reports it —
	// the `proxy:` of the model entry that is running, after macro expansion.
	// It is what Inflight reads the gauge from. Empty when the seat is not
	// listed or the llama-swap build does not report it.
	Proxy string
}

Reading is one observation of a seat.

func Inflight

func Inflight(ctx context.Context, client *http.Client, endpoint, seat string) (Reading, error)

Inflight reads the seat named `seat` (id or alias) behind the llama-swap at endpoint. A metrics fetch that fails on a LOADED seat is an error — "could not read" must never pass as "idle".

func Running

func Running(ctx context.Context, client *http.Client, endpoint, seat string) (Reading, error)

Running answers the FIRST half of Inflight and stops there: what llama-swap's /running says about the seat (Loaded, Starting, Canonical, and the roster's own failure), with no /upstream read at all.

It exists because a caller can need the seat's LOAD STATE without being allowed to touch the seat: `/upstream/<seat>/…` starts an unloaded model on demand (register C-05 — 54 measured status probes each blocked ~186 s because asking whether the seat was up STARTED it), so anything on a health path may read /running and nothing else. Inflight is this call plus the gauge read that only a LOADED seat can answer.

Alias-awareness is the whole reason this is not two lines at the call site: /running lists CANONICAL ids while the harness binds seats by ALIAS, so a bare-name match reads a loaded seat as absent (the silent 0.113.16-19 drain defect). An unreadable roster falls back to the bare name and says so in RosterErr — never a refusal.

type StatusError

type StatusError struct{ Status int }

StatusError is a non-2xx answer to GET /running. It is a typed error so a reader can say which status answered (the text is unchanged).

func (*StatusError) Error

func (e *StatusError) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL