From 3f297a10a7cdb1a688a16cb7847146bf4d948d82 Mon Sep 17 00:00:00 2001 From: Anthony Volk <14987227+anth-volk@users.noreply.github.com> Date: Tue, 1 Dec 2026 00:30:45 +0400 Subject: [PATCH 1/3] Test that the API v2 segment worker requests 1 CPU and 12 GiB Production statistics for 1,480 segment calls show one core busy, with bursts to about 1.3, and up to 8.6 GiB in a container that calculated several years without a prebuilt year file and baseline. The class and the plain function share the options, so both tests fail until the request changes. Co-Authored-By: Claude Opus 5.5 --- .../tests/test_v2_worker_classes.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/projects/policyengine-simulation-executor/tests/test_v2_worker_classes.py b/projects/policyengine-simulation-executor/tests/test_v2_worker_classes.py index 3bd539706..4cb4775e4 100644 --- a/projects/policyengine-simulation-executor/tests/test_v2_worker_classes.py +++ b/projects/policyengine-simulation-executor/tests/test_v2_worker_classes.py @@ -74,8 +74,11 @@ def _expected_worker_options(v2_app) -> dict[str, dict]: }, "run_single_simulation_segment_us": { "image": v2_app.us_worker_image, - "cpu": 8.0, - "memory": 32768, + # One region group in one process: about one core busy. In + # production, a container that calculated several years without a + # prebuilt year file and baseline reached 8.6 GiB (its p99). + "cpu": 1.0, + "memory": 12288, "timeout": 3600, "retries": 0, "max_containers": 1000, From 3aa626bf257d1b7bb5f2e08cb8cccc3a2e7670e4 Mon Sep 17 00:00:00 2001 From: Anthony Volk <14987227+anth-volk@users.noreply.github.com> Date: Tue, 1 Dec 2026 01:28:50 +0400 Subject: [PATCH 2/3] Request 1 CPU and 12 GiB for the API v2 segment worker SimulationSegmentWorkerUS and the plain run_single_simulation_segment_us take SEGMENT_WORKER_RESOURCES, which asked for 8 CPUs and 32 GiB. In production a segment keeps about one core busy, and Modal lets a container use free cores beyond its request. Containers that calculated several years without a prebuilt year file and baseline reached 8.6 GiB (per-container p99; Modal reports no maximum). Adding 0.3 GiB for the snapshot hook's warm-up calculation, and 0.36 GiB (13 %) measured locally for a cliff calculation's segment, which runs on this worker too, gives about 9.3-10.1 GiB. 12 GiB leaves 1.9-2.7 GiB above that. Co-Authored-By: Claude Opus 5.5 --- .../src/modal/v2_worker_resources.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/projects/policyengine-simulation-executor/src/modal/v2_worker_resources.py b/projects/policyengine-simulation-executor/src/modal/v2_worker_resources.py index 91b15f829..ab79e7859 100644 --- a/projects/policyengine-simulation-executor/src/modal/v2_worker_resources.py +++ b/projects/policyengine-simulation-executor/src/modal/v2_worker_resources.py @@ -16,8 +16,13 @@ ) SEGMENT_WORKER_RESOURCES: dict[str, Any] = { - "cpu": 8.0, - "memory": 32768, + # A segment calculates one region group in one process, which keeps about + # one core busy; Modal lets a container use free cores beyond its request. + # Memory is a request, not a limit: production segments reached 8.6 GiB in + # a container that calculated several years without a prebuilt year file + # and baseline. + "cpu": 1.0, + "memory": 12288, "timeout": US_SEGMENT_TIMEOUT_SECONDS, "retries": 0, # Every segment of every US simulation call that may run at once: a From 27aa28cdb30ac05a971223cf59c55b67303bd39d Mon Sep 17 00:00:00 2001 From: Anthony Volk <14987227+anth-volk@users.noreply.github.com> Date: Tue, 1 Dec 2026 00:31:14 +0400 Subject: [PATCH 3/3] Add a changelog fragment for the API v2 segment worker's resources Co-Authored-By: Claude Opus 5.5 --- changelog.d/v2-segment-worker-resources.changed.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/v2-segment-worker-resources.changed.md diff --git a/changelog.d/v2-segment-worker-resources.changed.md b/changelog.d/v2-segment-worker-resources.changed.md new file mode 100644 index 000000000..22694bc2f --- /dev/null +++ b/changelog.d/v2-segment-worker-resources.changed.md @@ -0,0 +1 @@ +The API v2 simulation app's US segment worker (the `SimulationSegmentWorkerUS` class and the plain `run_single_simulation_segment_us` function) requests 1 CPU and 12 GiB instead of 8 CPUs and 32 GiB, about a quarter of the list price per container-second. In production, segments kept about one core busy, and the containers that used the most memory reached 8.6 GiB (each container's 99th percentile).