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). 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 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,