Limit the number of sites the process manager keeps running - #3887
Conversation
📊 Performance Test ResultsComparing 421d6db vs trunk app-size
site-editor
site-startup
Results are median values from multiple test runs. Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change (<50ms diff) |
fredrikekelund
left a comment
There was a problem hiding this comment.
The basics are solid here 👍 Still, there are a few things I think we should tackle before landing this. Aside from the inline comments, I think we should also update apps/cli/commands/site/start.ts to write autoStart: false for the site if startWordPressServer throws.
| throw new Error( | ||
| `CAPACITY_LIMIT_REACHED: Cannot start site — the weighted capacity limit of ${ MAX_WEIGHTED_CAPACITY } has been reached (current usage: ${ currentUsage }, requested: ${ weight }). Stop some running sites first.` | ||
| ); |
There was a problem hiding this comment.
| throw new Error( | |
| `CAPACITY_LIMIT_REACHED: Cannot start site — the weighted capacity limit of ${ MAX_WEIGHTED_CAPACITY } has been reached (current usage: ${ currentUsage }, requested: ${ weight }). Stop some running sites first.` | |
| ); | |
| const errorMessage = | |
| runtime === SITE_RUNTIME_PLAYGROUND | |
| ? `Cannot start site. The maximum number of running sites has been reached (${ currentUsage }/${ MAX_WEIGHTED_CAPACITY }). Sandbox sites count as ${ weight } units. Stop some running sites first.` | |
| : `Cannot start site. The maximum number of running sites has been reached (${ currentUsage }/${ MAX_WEIGHTED_CAPACITY }). Stop some running sites first.`; | |
| throw new Error( `CAPACITY_LIMIT_REACHED: ${ errorMessage }` ); |
This message is displayed to users when starting a site using the CLI. I think we can simplify it along these lines. "Weighted capacity" doesn't mean much to a regular user.
| await Promise.allSettled( stoppedSites.map( ( site ) => startServer( site ) ) ); | ||
| for ( const site of stoppedSites ) { | ||
| const { capacityLimitReached } = await startServer( site ); | ||
| if ( capacityLimitReached ) { | ||
| break; | ||
| } | ||
| } |
There was a problem hiding this comment.
Again, this switches from parallel to sequential. I suggest reverting.
There was a problem hiding this comment.
Just noting that #3837 just landed, which changes where the autoStart props are stored. |
|
Thanks for the review @fredrikekelund - I will take a look at the comments now. |
…m:Automattic/studio into fix/limit-number-of-sites-process-manager
…umber-of-sites-process-manager
fredrikekelund
left a comment
There was a problem hiding this comment.
LGTM 👍 I pushed a fix for the thing I mentioned in my previous review about setting autoStart: false on sites that fail to start
Thank you 🙇 |
Related issues
Fixes STU-1841
How AI was used in this PR
Proposed Changes
This PR limits the amount of sites that can be started at the same time to avoid draining memory. We can start:
Testing Instructions
npm run cli:buildnode apps/cli/dist/cli/main.mjs site stop --allnpm startPre-merge Checklist