Skip to content

Prefetch grid files for cellpack studio - #482

Merged
ascibisz merged 2 commits into
mainfrom
fix/prefetch-grid-files
Nov 5, 2026
Merged

ascibisz merged 2 commits into
mainfrom
fix/prefetch-grid-files

Conversation

@ascibisz

@ascibisz ascibisz commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator

Problem

Graham ran into some performance issues and failures last week when running the cellpack studio. Upon further investigation, we noticed a CPU spike on our server at that time, which caused major performance for other requests at that time. After traffic died down, everything went back to normal. There are two takeaway problems that we wanted to address:

  1. Our AWS ECS cluster wasn't autoscaling as expected (that's not going to be addressed in this PR, AWS configurations are not handled here, it will be addressed separately)
  2. No one had hit the ECS instance in a while, so long that no packings had run on this specific instance before Graham started triggering requests (containers do restart periodically, so this case of someone being the first one to hit a fresh container is to be expected). When you're the first one to trigger a packing request for a given recipe, the server has to download the grid file from S3 for that recipe. For subsequent requests, that grid file will be cached locally. This isn't a crazy amount of work or anything, but it takes a couple seconds, so Ruge pointed out that we should just prefetch all these grid files whenever a cluster starts up, rather than just waiting until someone submits a request. That is what this PR is addressing.

Solution

When a new server instance starts up, proactively get the grid files for the example recipes on firebase (which are the recipes available in the recipe selection dropdown on cellpack studio) before we start accepting requests for new packings. This is only 4 grid files right now, so it takes like 10 seconds on startup, and it will allow for more consistent performance for users.

@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Packing analysis report

Analysis for packing results located at cellpack/tests/outputs/test_spheres/spheresSST

Ingredient name Encapsulating radius Average number packed
ext_A 25 236.0

Packing image

Packing image

Distance analysis

Expected minimum distance: 50.00
Actual minimum distance: 50.01

Ingredient key Pairwise distance distribution
ext_A Distance distribution ext_A

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

An unavailable grid URL can abort server initialization, preventing all endpoints—including health checks—from starting and blocking prefetching of the remaining grids.

1 open issue
What changed in this PR

This PR warms the server’s grid cache at startup to reduce first-request delays for Cellpack Studio’s example recipes.

Changes:

  • Fetch example recipe references from Firebase and cache their grid files locally.
  • Run prefetching during application initialization, before accepting packing requests.
File Description
docker/​server.py Adds example-grid prefetching and invokes it during server startup.

Review effort: Balanced

Comment thread docker/server.py Resolved
@ascibisz
ascibisz marked this pull request as ready for review November 4, 2026 22:26
@ascibisz
ascibisz requested a review from rugeli November 4, 2026 22:26

@rugeli rugeli left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

love it!

@ascibisz
ascibisz merged commit a576c5c into main Nov 5, 2026
10 checks passed
@ascibisz
ascibisz deleted the fix/prefetch-grid-files branch November 5, 2026 23:29
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.

3 participants