Expand description
Staying out of the way on a loaded production server.
Priority, not thread starvation, is the primary lever: a nice’d worker uses
idle capacity and is preempted the instant Apache wants the core. Measured
separately on 610 MB of real archives: FADV_DONTNEED takes page-cache
residency from 610 MB to 0 MB at no cost in wall time or CPU (33.68 s vs
34.14 s, within noise), where zgrep -a, rg -za and rg -za -j1 all
leave the full 610 MB resident and evict whatever Apache and MariaDB had
warm.
The platform asymmetry is real and is not papered over. FADV_DONTNEED
evicts pages after reading; macOS has no posix_fadvise at all and its
nearest equivalent, fcntl(fd, F_NOCACHE, 1), prevents caching before
reading. So there are two hooks — prepare at open and finish after
the archive has been read — and each platform does its real work in a
different one:
Functions§
- clamp_
jobs - Clamp the concurrency to 1 when the box is already busier than the operator said they would tolerate. No source of load (anything but Linux) means no clamping, never a guess.
- finish
- Called after an archive has been fully read.
- load_
average_ 1m - One-minute load average, Linux only. Deliberately read once at startup — no feedback loop.
- prepare
- Called immediately after opening an archive, before it is read.
- set_
io_ idle - Put our reads in the idle I/O class so they queue behind Apache’s.
- set_
priority - Lower our own scheduling priority. Unprivileged processes may always lower (never raise) their own, so this needs no capabilities and cannot fail in a way worth reporting.