Skip to content

Limit the number of sites the process manager keeps running - #3887

Merged
katinthehatsite merged 14 commits into
trunkfrom
fix/limit-number-of-sites-process-manager
Jun 24, 2026
Merged

Limit the number of sites the process manager keeps running#3887
katinthehatsite merged 14 commits into
trunkfrom
fix/limit-number-of-sites-process-manager

Conversation

@katinthehatsite

@katinthehatsite katinthehatsite commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Related issues

Fixes STU-1841

How AI was used in this PR

  • It was used to plan and implement the feature

Proposed Changes

This PR limits the amount of sites that can be started at the same time to avoid draining memory. We can start:

  • 24 native-php sites (24 × 1 = 24)
  • 4 playground sites (4 × 6 = 24)
  • Or any mix, e.g. 3 playground + 6 native-php (18 + 6 = 24)
Screenshot 2026-06-18 at 4 56 11 PM

Testing Instructions

  • Pull the changes from this branch
  • Build CLI npm run cli:build
  • Run node apps/cli/dist/cli/main.mjs site stop --all
  • Start Studio with npm start
  • Try starting 5 Plaground sites and confirm that on the fifth one, you get the warning about the running limit as indicated on the screenshot above

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?
@katinthehatsite katinthehatsite self-assigned this Jun 18, 2026
@katinthehatsite
katinthehatsite marked this pull request as draft June 18, 2026 13:51
@wpmobilebot

wpmobilebot commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

📊 Performance Test Results

Comparing 421d6db vs trunk

app-size

Metric trunk 421d6db Diff Change
App Size (Mac) 1311.86 MB 1311.86 MB +0.00 MB ⚪ 0.0%

site-editor

Metric trunk 421d6db Diff Change
load 1097 ms 1117 ms +20 ms ⚪ 0.0%

site-startup

Metric trunk 421d6db Diff Change
siteCreation 6537 ms 6504 ms 33 ms ⚪ 0.0%
siteStartup 6563 ms 6578 ms +15 ms ⚪ 0.0%

Results are median values from multiple test runs.

Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change (<50ms diff)

@katinthehatsite
katinthehatsite marked this pull request as ready for review June 19, 2026 08:28
@katinthehatsite
katinthehatsite requested a review from a team June 19, 2026 08:28

@fredrikekelund fredrikekelund left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread apps/cli/process-manager-daemon.ts Outdated
Comment thread apps/cli/process-manager-daemon.ts Outdated
Comment on lines +245 to +247
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.`
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Made adjustments in 4f1be5a

Comment thread apps/studio/src/hooks/use-site-details.tsx Outdated
Comment on lines +597 to +623
await Promise.allSettled( stoppedSites.map( ( site ) => startServer( site ) ) );
for ( const site of stoppedSites ) {
const { capacityLimitReached } = await startServer( site );
if ( capacityLimitReached ) {
break;
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Again, this switches from parallel to sequential. I suggest reverting.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Comment thread apps/studio/src/hooks/use-site-details.tsx
@fredrikekelund

Copy link
Copy Markdown
Contributor

autoStart: false

Just noting that #3837 just landed, which changes where the autoStart props are stored.

@katinthehatsite

Copy link
Copy Markdown
Contributor Author

Thanks for the review @fredrikekelund - I will take a look at the comments now.

@fredrikekelund fredrikekelund left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM 👍 I pushed a fix for the thing I mentioned in my previous review about setting autoStart: false on sites that fail to start

@katinthehatsite

Copy link
Copy Markdown
Contributor Author

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 🙇

@katinthehatsite
katinthehatsite merged commit 9fe8226 into trunk Jun 24, 2026
11 checks passed
@katinthehatsite
katinthehatsite deleted the fix/limit-number-of-sites-process-manager branch June 24, 2026 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants