perf(kvb-check-security): MEDUSA uses 95 % of the physical cores
security.py ran medusa with at most 4 workers since 6540e4e, a cap set without a measurement, so scans left most of the host idle. Operator rule 2026-11-17: always 95 % of the cores, at least one left free. Workers are now max(1, min(floor(0.95 x cores), cores - 1)) over the physical cores /proc/cpuinfo lists (the logical count where it lists none), 13 on this 14-core host, still at most one per scanned file. The argv test computes the expected count instead of pinning the old cap.
🎯 Fix: 92 %
💥 Break: 4 %
💸 Tokens: 100 %
⏱️ Velocity: 100 %
🛡️ Security: 100 %
🏆 Score: 88
🚦 Gate: ✅ 90/5, tokens and velocity <= 100, security 100 %
Created-with: https://s.veen.world/skills
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b95af2a8e0
commit
ff9bbc19c2
2 files changed
+59
-4
No files matched your search
+24
-1
@@ -111,6 +111,28 @@ def ended(pids: list[int]) -> None:
|
||||
pass
|
||||
|
||||
|
||||
def security_module():
|
||||
spec = importlib.util.spec_from_file_location("kvb_check_security_workers", SECURITY)
|
||||
security = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(security)
|
||||
return security
|
||||
|
||||
|
||||
class TestScanWorkers(unittest.TestCase):
|
||||
def test_medusa_takes_95_percent_of_the_physical_cores_and_leaves_one_free(self):
|
||||
security = security_module()
|
||||
for cores, workers in ((1, 1), (2, 1), (4, 3), (14, 13), (20, 19), (40, 38), (100, 95)):
|
||||
with self.subTest(cores=cores):
|
||||
self.assertEqual(security.scan_workers(cores), workers)
|
||||
|
||||
def test_physical_cores_count_core_ids_per_socket_and_skip_hyperthreads(self):
|
||||
security = security_module()
|
||||
block = "processor\t: {n}\nphysical id\t: {socket}\ncore id\t\t: {core}\n\n"
|
||||
cpuinfo = "".join(block.format(n=n, socket=n // 4, core=n % 2) for n in range(8))
|
||||
self.assertEqual(security.physical_cores(cpuinfo), 4)
|
||||
self.assertEqual(security.physical_cores(""), os.cpu_count())
|
||||
|
||||
|
||||
class TestSecurity(unittest.TestCase):
|
||||
def setUp(self):
|
||||
tmp = tempfile.TemporaryDirectory()
|
||||
@@ -199,7 +221,8 @@ class TestSecurity(unittest.TestCase):
|
||||
self.assertEqual(result.returncode, 3, result.stderr)
|
||||
argv = json.loads((self.bin / "argv.json").read_text(encoding="utf-8"))
|
||||
self.assertEqual(
|
||||
[argv[0], *argv[2:4], argv[4], *argv[6:]], ["scan", "--format", "json", "-o", "--no-cache", "--workers", "2"]
|
||||
[argv[0], *argv[2:4], argv[4], *argv[6:]],
|
||||
["scan", "--format", "json", "-o", "--no-cache", "--workers", str(min(2, security_module().host_workers()))],
|
||||
)
|
||||
result = self.scan("--json", env=self.env)
|
||||
self.assertNotIn(PLACEHOLDER, result.stdout + result.stderr)
|
||||
|
||||
Reference in new issue
Block a user