Repository navigation
Scale the marriage household API to zero when idle - #130
Merged
Merged
Conversation
Set min_containers=0 on the HouseholdAPI Modal class so no container runs while the app receives no requests. Between 30 Sep and 29 Oct 2026 the app cost $114.50, of which $114.19 was the one 2-CPU / 8 GiB container that min_containers=1 kept running continuously. Memory snapshots stay enabled, so a new container restores the loaded model from the snapshot. Update the load_model comment and the backend README, which said one container stays warm. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully deployed
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.
Summary
The Modal app
marriage-household-apicurrently keeps one container running at all times (min_containers=1onHouseholdAPI, added in #126). This PR setsmin_containers=0, so Modal stops every container once the app has gone 300 seconds (scaledown_window) without requests, and starts one again when the next request arrives.Everything else in the Modal configuration is unchanged: 2 CPUs and 8 GiB per container, at most 8 containers, three concurrent requests per container, a 120-second timeout, and memory snapshots enabled.
Why
Modal billing for 30 Sep to 29 Oct 2026:
With
min_containers=0, the app is billed only while a container is serving requests or waiting out the 300-second idle period after the last one.Trade-off: cold starts
The first request after about 5 minutes with no traffic will wait for Modal to start a new container. Because memory snapshots stay enabled (
enable_memory_snapshot=Truewith@modal.enter(snap=True)onload_model), the new container restores the already-initialized PolicyEngine US systems and metadata from the snapshot instead of rebuilding them.One data point reviewers should weigh: the description of #126 reports that, before that PR, a new container took about 70 seconds to answer the browser's CORS preflight request, and that the first browser calculation could fail as a result. Snapshots were already enabled then (the container had 4 GiB of memory and handled one request at a time). The browser client in
lib/api.jsaborts a calculation request after 120 seconds. After this is deployed, it is worth timing one request against an idle app to confirm the snapshot restore is well under that limit.Changes
backend/modal_app.py:min_containers=1becomesmin_containers=0. Theload_modelcomment now says containers scale to zero after 300 seconds idle and that a new container restores the loaded model from the snapshot, instead of saying one worker is kept running.backend/README.md: the deployment section no longer says one container stays running; it describes the scale-to-zero behaviour and the cold start the first request after an idle period waits for.Deployment
No GitHub Actions workflow in this repository deploys to Modal.
.github/workflows/ci.ymlruns linting, tests and the Next.js build, and.github/workflows/live-uk.ymlruns the live UK integration tests on manual dispatch; neither callsmodal deploy. Merging this PR does not change the running Modal app. Someone with access to the PolicyEngine Modal workspace must deploy it by hand, as described inbackend/README.md:Testing
ruff check backend/modal_app.pyandruff format --check backend/modal_app.pypass.min_containers=0.🤖 Generated with Claude Code