mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-06 10:59:59 +00:00
_ram_gb read mem_total_mb while mem_available_mb sat next to it, added by
3e9deab6f7 for the drill abort and never carried over here. The ceiling exists
to stop the sidecar from competing with what already runs, so measuring the
machine instead of what is free made the term inert: on a 16 GB runner it
computed five workers while 5.5 GB was actually available, and the CI cap was
the only thing that ever bound.
Reading MemAvailable makes the guard real and self-limiting, which matters now
that the onion case raises the count. Against the memory the run itself reports:
PASS 1, 9113M free clearnet 1 onion 2
PASS 2, 5550M free clearnet 1 onion 1
Also withdraws a CI CPU divisor I had added on a false premise. It cited the
matrix telemetry stall60 as evidence that reserving three cores of four buys
nothing on a CI runner - but mem_stall_pct reads /proc/pressure/memory
(utils/env/runtime.py:84), so that figure proves memory headroom and says
nothing about CPU. Raising the clearnet count needs CPU evidence this run does
not carry, and a contention flake would cost coverage, so the divisor stays at
four until something measures the CPU side.
The onion lift keeps its own justification, which never rested on that number:
a browser waiting on Tor circuits does not consume CPU, measured at 4817s over
Tor against 911s on clearnet for the same specs on the same cores.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
65 lines
2.3 KiB
Python
65 lines
2.3 KiB
Python
import unittest
|
|
|
|
from plugins.lookup.playwright_workers import LookupModule, compute_workers
|
|
|
|
|
|
class TestComputeWorkers(unittest.TestCase):
|
|
def test_local_20c_64g(self):
|
|
self.assertEqual(compute_workers(20, 64.0, False), 5)
|
|
|
|
def test_local_12c_31g(self):
|
|
self.assertEqual(compute_workers(12, 31.0, False), 3)
|
|
|
|
def test_hard_cap_binds(self):
|
|
self.assertEqual(compute_workers(64, 256.0, False), 6)
|
|
|
|
def test_ram_binds(self):
|
|
self.assertEqual(compute_workers(20, 3.0, False), 1)
|
|
|
|
def test_ci_cap_binds(self):
|
|
self.assertEqual(compute_workers(16, 64.0, True), 2)
|
|
|
|
def test_ci_small_runner(self):
|
|
self.assertEqual(compute_workers(2, 8.0, True), 1)
|
|
|
|
def test_floor_is_one(self):
|
|
self.assertEqual(compute_workers(1, 1.0, False), 1)
|
|
|
|
def test_kwargs_override(self):
|
|
self.assertEqual(
|
|
compute_workers(20, 64.0, False, cpu_divisor=2, hard_cap=100), 10
|
|
)
|
|
|
|
def test_onion_lifts_the_latency_bound_phase(self):
|
|
"""Tor makes the phase wait on circuits, so cores stop describing it.
|
|
|
|
The 4-core runner yields one worker because a quarter of four cores is
|
|
one. Over Tor the browser waits rather than computes, so the count is
|
|
raised from that base instead of derived from cores again.
|
|
"""
|
|
self.assertEqual(compute_workers(4, 16.0, True), 1)
|
|
self.assertEqual(compute_workers(4, 16.0, True, onion=True), 2)
|
|
|
|
def test_onion_yields_to_a_machine_with_no_memory_left(self):
|
|
"""Free memory, not total, decides: a busy runner keeps one worker."""
|
|
self.assertEqual(compute_workers(4, 5.5, True, onion=True), 1)
|
|
|
|
def test_onion_still_respects_memory(self):
|
|
"""Circuits are cheap, browsers are not: RAM keeps its veto."""
|
|
self.assertEqual(compute_workers(20, 3.0, False, onion=True), 1)
|
|
|
|
def test_onion_cap_binds_on_a_large_host(self):
|
|
self.assertEqual(compute_workers(64, 256.0, False, onion=True), 3)
|
|
|
|
|
|
class TestLookup(unittest.TestCase):
|
|
def test_returns_single_int_ge_1(self):
|
|
out = LookupModule().run([], variables={})
|
|
self.assertEqual(len(out), 1)
|
|
self.assertIsInstance(out[0], int)
|
|
self.assertGreaterEqual(out[0], 1)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|