Skip to content

api-refresh redoes work that did not change since the previous tick #847

Not planned

Description

@pithead-developer

What's the problem

After #818 one api-refresh tick still starts about 100 external programs (fixture: two pools, 20 control outcomes). Most of them redo work whose inputs did not change since the previous tick, 15 seconds earlier:

  • parse_config checks config.json again: about 29 jq calls plus the unknown-key check.
  • The config view, the config revision and the control history in the feed are rebuilt from the same files.
  • The hardware inventory is read again: RAM modules from dmidecode, board and firmware strings, CPU model, MAC, OS version.
  • The autotune unit values are read with systemctl cat again.

Separately, a design pass for the compiled tick of #717 found that a version the existing tests can check is about 3,000 lines in any compiled language. It is not a small change, and its gain over a cheaper shell tick is not measured.

What it impacts

Every rig: a steady CPU cost on cores meant for mining. On a 96-thread rig that was mining on every thread, before #818, one tick cost 2.5 CPU-seconds, about 17% of one core. It also decides whether, and in which language, the compiled tick of #717 is worth building.

How I found it

  • Counted on the container fixture of Each api-refresh tick starts more than 200 processes #818: 285 started programs before that change, 100 after (52 jq, about 29 of them in parse_config).
  • Timed stand-ins for a single-process tick on the same inputs, interleaved in one container session: about 50 times less CPU than the shell in C and about 30 times in Go. A Rust stand-in is being timed. The stand-ins skip checks the shell makes, so they are a ceiling, not a product.
  • A design pass for a compiled tick against the test stack (three code reads, a design, a critique): 2 tests run the tick as a command; 20 call the shell function in process, of which 12 could reach a binary and 8 replace helpers; the binary would still have to start curl, systemctl, journalctl and dmidecode by name for the stand-ins in the suite to work.
  • Unknown: how much a cache really saves (my estimate: from 100 to roughly 25 to 35 programs), how many real rig configs a cautious compiled tick would hand back to the shell, and hashrate with and without the refresh.

How important is it

Medium. No behaviour is wrong. It is the next cheap step after #818, and it is the measurement the port plan asks for before the tick is ported (#704, #717).

Acceptance criteria

  • One comparison on the same inputs, variants interleaved in one session: started programs and CPU per tick for develop, a caching shell tick, and the compiled stand-ins. Reported as ratios, with the method and the raw numbers.
  • The same before and after readings on a rig-class host while it mines, described by class only.
  • If caching is adopted: the four output files are byte-identical to the uncached tick, cold and warm; each cached value is dropped when one of its inputs changes, with a test per input; nothing a non-root account can write is trusted as a cache; a committed bound on started programs for a warm tick fails on the uncached code.
  • A written go or no-go for a compiled tick: the gain left after caching, the language, and what must exist first. Owner direction of 24 November 2026: a small, simple component may be C if it is tested properly; anything large is Rust.
  • Measure a baseline and a control arm for the RigForge refresh tick and verbs before porting #704 and Port the api-refresh tick to Rust #717 are updated with the result.

Possible solutions

Activity

  1. added this to the v1.20.0 milestone on Nov 24, 2026
  2. added
    performance
    on Nov 24, 2026
  3. added
    blocked
    on Nov 24, 2026
  4. pithead-developer commented on Nov 24, 2026

    @pithead-developer
    ContributorAuthor

    Blocked on #818

    The change for this issue touches the same functions as #818 and builds on it, so it lands after #818. The measurement for this issue is in progress.

  5. added
    operator-hold
    on Nov 24, 2026
  6. pithead-developer commented on Nov 24, 2026

    @pithead-developer
    ContributorAuthor

    Measured, 24 November 2026. One tick on the same inputs (two pools, 20 control outcomes), all variants interleaved in one container session pinned to four CPUs; medians of 45 idle ticks and 32 ticks with four busy loops. The machine was busy, so read the ratios, not the milliseconds.

    Variant Programs started CPU per tick, idle CPU per tick, busy Against develop
    develop before #818 285 405 ms 708 ms 1
    #818 (PR #848) 100 182 ms 293 ms 2.2 to 2.4 times less
    #848 plus a cache prototype, warm 41 86 ms 131 ms 4.7 to 5.4 times less
    the same, first tick after a change 102 to 103 193 ms 296 ms as #848, plus about 5%
    compiled stand-in, Rust 6 9 ms 14 ms 45 to 50 times less
    compiled stand-in, C 6 8 ms 13 ms about 50 times less
    compiled stand-in, Go 6 14 ms 23 ms about 30 times less

    About the cache prototype:

    • It keys the config results on one content hash over config.json and the 20 state files it depends on (one sha256sum, about 3 ms per tick) and keeps the hardware inventory per boot. The cache is data only and lives in a root-only folder.
    • 61 checks of changed inputs, changed configs and damaged caches gave the same output as the uncached tick, except two hardware cases that are kept per boot by design.
    • A second reader ran 99 attack cases and found two real faults. A config changed and restored inside one tick stayed wrong afterwards; adding the change time to the key fixed it. A warm tick skipped the online-CPU check; hashing that sysfs file fixed it. With both fixes a warm tick starts 42 programs. Dropping the per-boot memory and identity values gives 52.
    • It is a prototype: not run on bash 3.2, not linted, no tests of its own, and about 95 lines (a 69-line util file plus about 26 lines in rigforge.sh).

    About the compiled stand-ins: Rust and C are equal within the noise of the run, Go is about 1.5 times slower than Rust. Rust needed no unsafe. All three skip five config checks the shell makes, so they show a ceiling, not a product.

    Not measured: a rig-class host, and hashrate with and without the refresh. Those readings come next, after #848 is merged.

  7. pithead-developer commented on Nov 24, 2026

    @pithead-developer
    ContributorAuthor

    Owner decision, 24 November 2026: the compiled refresh (#717) is built now, in Rust.

    What that means for this issue:

    #704 and #717 no longer wait for this issue.

  8. pithead-architect commented on Nov 27, 2026

    @pithead-architect

    Release regroom (owner request, 2026-11-27): moved from v1.20.0 to v1.23.0. Trimmed from v1.20.0 (update API only) per the owner. Perf, hardening and measurement group.

  9. pithead-developer commented on Nov 27, 2026

    @pithead-developer
    ContributorAuthor

    Owner decision (2026-11-27): closed as superseded by the Rust refresh (#717), which makes this cache unnecessary. The measurements in this issue stay as the record.

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

    blockedoperator-holdperformance

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions