xmrig-auto-pause: add hysteresis to prevent stop/start thrashing
xmrig's RandomX pollutes the L3 cache, making other processes appear ~3-8% busier. With a single 5% threshold for both stopping and resuming, the script oscillates: start xmrig -> cache pressure inflates CPU -> stop xmrig -> CPU drops -> restart -> repeat. Split into CPU_STOP_THRESHOLD (15%) and CPU_RESUME_THRESHOLD (5%). The stop threshold sits above xmrig's indirect pressure, so only genuine workloads trigger a pause. The resume threshold confirms the system is truly idle before restarting.
This commit is contained in:
@@ -39,13 +39,15 @@ pkgs.testers.runNixOSTest {
|
||||
# POLL_INTERVAL=1 keeps detection latency low.
|
||||
# GRACE_PERIOD=5 is long enough to verify "stays stopped" but short
|
||||
# enough that the full test completes in reasonable time.
|
||||
# CPU_THRESHOLD=10 catches a single busy-loop on a 1-2 core VM.
|
||||
# CPU_STOP_THRESHOLD=20 catches a busy-loop on a 1-2 core VM (50-100%)
|
||||
# without triggering from normal VM noise.
|
||||
# CPU_RESUME_THRESHOLD=10 is the idle cutoff for a 1-2 core VM.
|
||||
POLL_INTERVAL = "1"
|
||||
GRACE_PERIOD = "5"
|
||||
CPU_THRESHOLD = "10"
|
||||
CPU_STOP_THRESHOLD = "20"
|
||||
CPU_RESUME_THRESHOLD = "10"
|
||||
STARTUP_COOLDOWN = "4"
|
||||
STATE_DIR = "/tmp/xap-state"
|
||||
|
||||
def start_cpu_load(name):
|
||||
"""Start a non-nice CPU burn as a transient systemd unit."""
|
||||
machine.succeed(
|
||||
@@ -62,13 +64,16 @@ pkgs.testers.runNixOSTest {
|
||||
f"systemd-run --unit={unit_name} "
|
||||
f"--setenv=POLL_INTERVAL={POLL_INTERVAL} "
|
||||
f"--setenv=GRACE_PERIOD={GRACE_PERIOD} "
|
||||
f"--setenv=CPU_THRESHOLD={CPU_THRESHOLD} "
|
||||
f"--setenv=CPU_STOP_THRESHOLD={CPU_STOP_THRESHOLD} "
|
||||
f"--setenv=CPU_RESUME_THRESHOLD={CPU_RESUME_THRESHOLD} "
|
||||
f"--setenv=STARTUP_COOLDOWN={STARTUP_COOLDOWN} "
|
||||
f"--setenv=STATE_DIR={STATE_DIR} "
|
||||
f"{PYTHON} {SCRIPT}"
|
||||
)
|
||||
# Monitor needs two consecutive polls to compute a CPU delta.
|
||||
time.sleep(3)
|
||||
# Monitor needs two consecutive polls to compute a CPU delta.
|
||||
time.sleep(3)
|
||||
|
||||
start_all()
|
||||
machine.wait_for_unit("multi-user.target")
|
||||
|
||||
Reference in New Issue
Block a user