You signed in with another
8000
tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Throttle builds by builder pressure: AIMD limit fed by a pushed PSI agent #776
High static pool limits need a brake that follows the builder's real load.
Findings (2026-10-12)
LocalPSIMonitor (removed in 10a4757b) was erratic and hungry: psi_trigger_poll always returns DEFAULT_POLLMASK (includes EPOLLIN), and loop.add_reader waits for EPOLLIN. The callback ran on every loop iteration, cleared the gate and logged. A trigger needs POLLPRI.
ResourceGate.wait_mem_clear runs in every ConnectionPool.acquire, reads included, and raises ResourceExhaustedError after 5 s.
An idle nix-daemon worker costs ~1 MiB (Private_Dirty 725 KiB + page tables 268 KiB, Nix 2.35.2), plus ~0.46 MiB kernel memory. A pynixd client session costs below what RSS resolves; upstream workers follow pool slots. 1000 slots ≈ 1 GiB: the brake reads MemAvailable and PSI, not a per-slot constant.
Design (decided)
AIMD build limit per store, between 1 and the static ceiling. Memory/io full pressure or low MemAvailable halve it; quiet pressure with waiting builds adds one per interval; hysteresis band and cooldown. Pending builds wait (waits_for=pressure). Transfers and reads are never gated. Running builds are never killed.
Local signal is machine-wide (/proc/pressure, /proc/meminfo, /proc/loadavg).
Remote: a small static agent, shipped as a store path. pynixd copies it into the builder's store and execs it over one SSH channel. It waits on PSI triggers with POLLPRI plus a heartbeat and writes raw files; pynixd parses. Stdin EOF ends it. Fallback: SFTP polling, then load average.
Always monitored.
Metrics: per store pressure, build limit, sample age; pynixd state shows them.
Measured on dynhetz: the agent (agent/pynixd-agent.c, pkgsStatic) is 73 KiB with no references. Unprivileged triggers arm on kernel 7.2. A cpu:some trigger below the host's load fires once per 2 s window, and the agent used 0.00 s CPU in 9 s.
Delivery, two routes:
The agent for pynixd's own system ships in pynixd's closure. pynixd uploads it over SFTP to ~/.cache/pynixd/<store-name> and execs it. The store hash in the name is the version.
Any other system (aarch64, darwin): no cross toolchain. pynixd sends the agent's .drv to that builder, builds it there, and execs the output path. The builder is a Nix builder already. Proposed by @Lillecarl.
Landed in pynixd develop 77277218 (umbrella main 9e2e6b2):
77b65d7b: build limit per store (AIMD, hysteresis, settle). It replaces ResourceGate, so reads never wait on pressure. Adds waits_for=pressure, metrics, and a limit column in pynixd state.
a364df96: pynixd-agent, uploaded to SSH builders over SFTP. A refused upload or a forced command falls back to SFTP polling.
36add073: max_connections / transfer_connections per store spec.
1aee6740 and b162baaf: the default local store is monitored and runs the agent as a subprocess for its triggers.
Verified: all guest suites pass. Over a real sshd to localhost: upload, exec, samples every second, and no agent process after close.
Open:
Build the agent's .drv on a builder of another system (aarch64, darwin).
Darwin samples: sysctl (vm.loadavg, kern.memorystatus_level); there is no PSI.
An agent that answered once and is then lost keeps retrying (backoff up to 60 s), and the limit freezes at its last value. sample_age_s shows this, but nothing acts on it. Options: fall back to SFTP after N losses, or move a stale limit back toward the ceiling.
"1000 slots ≈ 1 GiB" counts the daemon workers only. pynixd's own cost per pooled connection is not measured: RSS could not resolve it. Measure it with tracemalloc around N build_pool.acquire calls.
Verified on the packaged path (PYNIXD_AGENTS set): the local store runs AgentMonitor (16 cores, limit 16), and monitor.stop() ends the agent process while pynixd keeps running.
The agent is now Rust (pynixd develop 4c1d0002): std, no crates, one unsafe for poll(2). It builds with the cached rustc through pkgsCross.musl64, statically linked: 424 KB, no store references. Measured alternatives: static glibc 1.18 MB, no_std 18 KB. Simpler code was worth the 400 KB. Behaviour is unchanged, and all guest suites pass.
Activity
Lillecarl commentedon Oct 12, 2026
Measured on dynhetz: the agent (
agent/pynixd-agent.c,pkgsStatic) is 73 KiB with no references. Unprivileged triggers arm on kernel 7.2. Acpu:sometrigger below the host's load fires once per 2 s window, and the agent used 0.00 s CPU in 9 s.Delivery, two routes:
~/.cache/pynixd/<store-name>and execs it. The store hash in the name is the version..drvto that builder, builds it there, and execs the output path. The builder is a Nix builder already. Proposed by @Lillecarl.Assisted-By: Opus 5
Throttle builds by host pressure, never transfers
Sample SSH builders with an uploaded pynixd-agent
Let a store's configuration size its pools
Monitor the local store a configuration does not name
Run pynixd-agent for the local store too
Lillecarl commentedon Oct 12, 2026
Landed in pynixd develop 77277218 (umbrella main 9e2e6b2):
waits_for=pressure, metrics, and a limit column inpynixd state.max_connections/transfer_connectionsper store spec.Verified: all guest suites pass. Over a real sshd to localhost: upload, exec, samples every second, and no agent process after close.
Open:
.drvon a builder of another system (aarch64, darwin).sysctl(vm.loadavg,kern.memorystatus_level); there is no PSI.Assisted-By: Opus 5
Lillecarl commentedon Oct 12, 2026
Two more open points:
sample_age_sshows this, but nothing acts on it. Options: fall back to SFTP after N losses, or move a stale limit back toward the ceiling.build_pool.acquirecalls.Verified on the packaged path (
PYNIXD_AGENTSset): the local store runs AgentMonitor (16 cores, limit 16), andmonitor.stop()ends the agent process while pynixd keeps running.Assisted-By: Opus 5
Write pynixd-agent in Rust
Lillecarl commentedon Oct 12, 2026
The agent is now Rust (pynixd develop 4c1d0002): std, no crates, one
unsafefor poll(2). It builds with the cached rustc throughpkgsCross.musl64, statically linked: 424 KB, no store references. Measured alternatives: static glibc 1.18 MB,no_std18 KB. Simpler code was worth the 400 KB. Behaviour is unchanged, and all guest suites pass.Assisted-By: Opus 5