Repository navigation
Request 1 CPU and 12 GiB for the API v2 segment worker - #1163
Merged
Merged
Conversation
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 <noreply@anthropic.com>
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 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1162
Same-Repository Draft PR Check
PolicyEngine/policyengine-sim-api, not a personal fork.Changelog
changelog.d/<name>.<type>.md, whose type is breaking, added, changed, fixed or removed. (changelog.d/v2-segment-worker-resources.changed.md)Summary
The API v2 simulation app's US segment worker now requests
cpu=1.0, memory=12288(1 CPU, 12 GiB) instead ofcpu=8.0, memory=32768. Both places that run a segment takeSEGMENT_WORKER_RESOURCESfromsrc/modal/v2_worker_resources.py, so both change:SimulationSegmentWorkerUSclass, which has memory snapshots and is what segmented US simulations and their cliff calculations spawn;run_single_simulation_segment_usfunction, kept without snapshots for callers still on older code.SimulationWorkerUSandSimulationWorkerUKkeep 8 CPUs and 32 GiB. The diff is the two values with a comment, their test and a changelog fragment.At list price, 1 CPU and 12 GiB cost $0.0000397 per container-second, against $0.000176 for 8 CPUs and 32 GiB: about 23 %.
Measured in production (read-only)
Modal's per-container statistics (
modal function stats --container) for every production segment container from 25 to 30 Nov: 1,480 calls in 947 containers, all with 8 CPUs and 32 GiB. Each call's year comes from Cloud Logging. Every production segment in that period ran in a shadow comparison of a run_simulation app job, and those jobs' records name the year.CPU (cores, per-container percentiles: median over containers [highest]):
A segment keeps about one core busy, and about 1.3 cores in its busiest tenth. Modal's Resources guide says
cpu=is a guaranteed minimum: by default a container may use up to 16 more cores when its host has them free, and Modal bills the larger of the request and the use.Memory (GiB, per-container p99: median over containers [90th percentile; highest]):
Cliff calculations, measured locally
A US national simulation's cliff calculation is split into region groups like its run (
cliff_results._calculation,should_segment_cliff_calculation), so it runs on this worker too. None of the production calls above was one. On a Mac, one region group's segment (state/ar+state/nc+state/nd) planned as a cliff calculation (resolve_cliff_output_plan) was compared with the same segment planned as a report run's reform child, each in a fresh process with the US models preloaded as the snapshot hook loads them (macOS physical footprint):So a cliff calculation adds up to 0.36 GiB (13 %). Adding that and 0.3 GiB for the snapshot hook's warm-up calculation to the 8.6 GiB above gives about 9.3–10.1 GiB, and 12 GiB leaves 1.9–2.7 GiB above that.
Not measured
A 1-CPU container's speed for the API v2 segment. The run_simulation app's segment worker runs the same calculation, and on Modal
testingits 1-CPU restored containers calculated at 0.98–1.03 times the 8-CPU medians (#1126). The production check below covers it here.Checked in production after deploy
With the read-only queries used for the before-and-after setup times of the API v2 workers (Cloud Logging operation records, Cloud Trace, Modal's container records and its "memory snapshot" log lines), compare restored segment containers after this deploys with the restored 8-CPU figures from 27–30 Nov:
stage12_calculation): 103.3 s median (n = 219), compared under the same reform and year where possible.Each median may be at most 10 % slower. A deploy takes new snapshots, so containers that take a snapshot are reported separately; #1147's warm-up calculation also deploys with or before this change and makes a restored container's first calculation faster, so the comparison says which deploys each side includes. Also read
modal function statsfor the class: memory p99 should stay below 12 GiB, and no call should end as "Evicted (over memory request)".Environment variables
The change reads and declares none. Both changed workers keep
secrets=worker_secrets: Modal secretsstage12-evaluation-gcp-credentials,pe-uk-private-hf-read-tokenandstage12-evaluation-runtime. The tests assert them.Testing
tests/test_v2_worker_classes.py::test_the_v2_simulation_workers_are_classes_restored_from_memory_snapshotsand::test_plain_functions_keep_the_workers_for_callers_on_older_codefail at3f297a10(8.0 and 32768 against 1.0 and 12288).3aa626bf.ruff checkandruff format --checkon the two changed Python files; the changelog fragment check (.github/scripts/check-changelog-fragment.sh);scripts/run_quality_guards.py(all guards pass, file length included).🤖 Generated with Claude Code