Skip to content

Warm up reports at start-up, and add GET /warmup - #65

Open
ejanalysis wants to merge 1 commit into
mainfrom
warmup-at-startup
Open

ejanalysis wants to merge 1 commit into
mainfrom
warmup-at-startup

Conversation

@ejanalysis

@ejanalysis ejanalysis commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Addresses Public-Environmental-Data-Partners/EJAM#771 (part of the API cold-start plan, Public-Environmental-Data-Partners/EJAM#720).

Problem: on a new container, the first report takes 20–35 s longer than later ones. It loads about 29 more R packages, more data files, pandoc and (for PDF) headless Chrome.

Changes (additions only):

  • New warmup.R: before the API accepts requests, builds one point report (3 mi) as PDF, the default for one-site report links, and one county report as HTML. Each step is wrapped: a failure is logged and the API starts anyway. EJAM_WARMUP=false skips it. Start-up log lines begin with EJAM warm-up:.
  • main.r: runs the warm-up just before r$run().
  • rest_controller.r: new GET /warmup, which answers {"status":"ok"} at once with Cache-Control: no-store. The EJAM app (Web app: wake the EJAM API when an EJAM user clicks Start (#772) EJAM#783) and EJSCREEN (EJSCREEN: wake the API when a user picks a Reports tool EJAM#773) will call it to wake the API before a report is needed. The Cloudflare Worker caches only GET /report, so /warmup always reaches Cloud Run.

Local test (Mac, EJAM 4.2024.0, API run from main.r):

No warm-up With warm-up
Start-up until it answers 1.6 s 13.5 s
1st point PDF report 17.0 s (first run), 8.9 s (repeat) 6.4 s
2nd point PDF report 7.2–7.5 s 6.3 s
1st / 2nd county HTML report 1.7 / 1.4 s 1.5 / 1.5 s

Trade-off: start-up takes about 12 s longer locally. A report request that itself wakes the API still waits for the whole start-up, so it gains little. The gain comes when something else wakes the API first.

Not tested: Docker build, or Cloud Run. No overlap with #64 (that changes only Dockerfile and cloudbuild.yaml).

After merge: re-sync the EJAM repo's copy of rest_controller.r (inst/plumber/ejam-api/, steps in its SYNC.md); EJAM's mirror test fails until then. warmup.R is not mirrored, like main.r.

— Claude (AI assistant), posting from ejanalysis account
🤖 Generated with Claude Code

Before the API accepts requests, build one point report (PDF) and one
county report (HTML), so the first real report on a new container is as
fast as later ones. A failure is logged and never stops the API.
EJAM_WARMUP=false skips it. GET /warmup answers at once so apps can wake
the API before a report is needed (Public-Environmental-Data-Partners/EJAM#771).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ejanalysis

Copy link
Copy Markdown
Contributor Author

After this gets merged into main, you'd need to merge main into version4-2024-0 since the test API is built from that branch not from main. @ericnost

@ejanalysis
ejanalysis marked this pull request as ready for review November 19, 2026 17:44
@ejanalysis
ejanalysis requested a review from ericnost November 19, 2026 19:09
@ejanalysis ejanalysis self-assigned this Nov 19, 2026
@ejanalysis ejanalysis added this to the v4.2024.1 milestone Nov 20, 2026
@ejanalysis

Copy link
Copy Markdown
Contributor Author

Codex review of head b1fd8347: no actionable defects found.

  • It checked the warm-up's failure handling (the API still starts if the warm-up fails), the EJAM_WARMUP=false opt-out, and the clean-up of the warm-up's report files. All passed.
  • This PR and /data: a FIPS code without scale analyzes the area as given (EJAM#764) #66 are ready for a merge decision. After both merge into main, main needs to be merged into version4-2024-0, which the v4 test API is built from (steps 20c and 20e in STEP BY STEP PLAN FOR VINTAGE SWITCH TO v4 EJAM#681).
  • One condition: please confirm that merging into main won't deploy to production automatically. If it would, test this version first.
  • Still to do before production: build the Docker image and check start-up on Cloud Run, then test reports on the hosted test API (EJAM#681 step 20j). The warm-up adds work at start-up, so this check matters most for this PR. Ready to merge does not mean tested in production.

Nothing was merged or deployed.

— Claude (AI assistant), posting from ejanalysis account, relaying a review by Codex (AI assistant)

🤖 Generated with Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant