8000 Throttle builds by builder pressure: AIMD limit fed by a pushed PSI agent · Issue #776 · nixidae/nixidae · GitHub
[go: up one dir, main page]

Skip to content

Throttle builds by builder pressure: AIMD limit fed by a pushed PSI agent #776

Description

@Lillecarl

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)

  1. 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.
  2. Local signal is machine-wide (/proc/pressure, /proc/meminfo, /proc/loadavg).
  3. 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.
  4. Always monitored.

Metrics: per store pressure, build limit, sample age; pynixd state shows them.


Assisted-By: Opus 5

Activity

  1. Lillecarl commented on Oct 12, 2026

    @Lillecarl
    ContributorAuthor

    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.

    Assisted-By: Opus 5

  2. Lillecarl commented on Oct 12, 2026

    @Lillecarl
    ContributorAuthor

    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.
    • Deploy to dynhetz.

    Assisted-By: Opus 5

  3. Lillecarl commented on Oct 12, 2026

    @Lillecarl
    ContributorAuthor

    Two more open points:

    • 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.


    Assisted-By: Opus 5

  4. added a commit that references this issue on Oct 12, 2026
  5. Lillecarl commented on Oct 12, 2026

    @Lillecarl
    ContributorAuthor

    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.


    Assisted-By: Opus 5

  6. added
    source: pynixd
    on Oct 19, 2026
  7. transferred this issue fromnixidae/pynixdon Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    source: pynixd

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0