Answer principles round 1: 0 🔴, 4 🟡 (0 misread); exempt only a bare docker under run-heavy with no PATH of its own, drop the stale item citation, unit-test the slot share in MiB, place the limits by the subcommand's index; also a named Option, exit 126, clearer names and the launcher's import order
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
"""How much of the machine's memory is available, as /proc/meminfo's MemAvailable and MemTotal state it, whether at least ROOM_SHARE of it is available, which leaves room for a worker, and each heavy slot's share of the rest."""
|
||||
"""How much of the machine's memory is available, as /proc/meminfo's MemAvailable and MemTotal state it. A worker starts while at least ROOM_SHARE of it is available. The rest is split across the heavy slots, as the memory limit run-heavy gives each container."""
|
||||
import dataclasses
|
||||
import pathlib
|
||||
import re
|
||||
@@ -17,9 +17,9 @@ class Memory:
|
||||
def has_room(self) -> bool:
|
||||
return self.available >= ROOM_SHARE * self.total
|
||||
|
||||
def slot_share(self, slots: int) -> str:
|
||||
"""The memory each heavy slot's containers may take, as docker writes a size: what ROOM_SHARE leaves, split evenly across the slots."""
|
||||
return f"{int(self.total * (1 - ROOM_SHARE)) // slots // 1024}m"
|
||||
def slot_share(self, slots: int) -> int:
|
||||
"""The memory limit, in MiB, that run-heavy gives each container a slot's command makes: what ROOM_SHARE leaves, split evenly across the slots."""
|
||||
return int(self.total * (1 - ROOM_SHARE)) // slots // 1024
|
||||
|
||||
|
||||
def parsed(meminfo: str) -> Memory | None:
|
||||
|
||||
@@ -39,6 +39,12 @@ class MemoryShare(unittest.TestCase):
|
||||
self.assertIsNone(memory.read_memory(pathlib.Path(temp, "gone")))
|
||||
|
||||
|
||||
class SlotShare(unittest.TestCase):
|
||||
def test_splits_the_three_quarters_a_worker_leaves_evenly_across_the_slots_in_mib(self):
|
||||
self.assertEqual(memory.Memory(available=0, total=32 * 1024 * 1024).slot_share(4), 6144)
|
||||
self.assertEqual(memory.Memory(available=0, total=8000000).slot_share(2), 2929)
|
||||
|
||||
|
||||
class SlotFolder(unittest.TestCase):
|
||||
def test_every_session_shares_the_slots_under_the_users_state_folder(self):
|
||||
self.assertEqual(slots.slot_folder({}), pathlib.Path.home() / ".local" / "state" / "run-heavy")
|
||||
|
||||
Reference in New Issue
Block a user