Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow SSR server clustering #1909

Open
wants to merge 3 commits into
base: v1
Choose a base branch
from
Open

Conversation

RobertBoes
Copy link
Contributor

Currently the Inertia SSR server would only run on a single thread, so on high load this might have implications, since the Node process could only take 100% on a single core/thread.

Node has the cluster module https://nodejs.org/api/cluster.html, which would make it possible to start multiple Node servers on the same port, then each request would be dealt with by each thread in a round-robin way.

With this PR it's possible to enable clustering by using;

createServer(
  (page) => createInertiaApp( ... ),
  13714,
  true,
)

It's disabled by default. Kind of a downside of JS is that we can't use positional arguments, so you'd need to pass the port number along as well.

Massive thanks to ChristianQode who discovered the issue and asked about it on the Inertia.js Discord server:

Hi guys! I'm using Laravel Inertia + Vue with SSR. Sometimes the site is becoming really slow. I figured out this is because of the node SSR process is over 100% of CPU usage. However, this is only a single core, there are 7 cores idle. I want to make the node process capable of using multiple CPU cores to spread the load. What is the best way to do it? Should I spawn multiple processes with the inertia:start-ssr command, or should I implement node clustering somehow? Does anyone have a suggestion?
https://discord.com/channels/592327939920494592/758259460920573992/1255111006384820234

@driesvints
Copy link
Contributor

@RobertBoes seems the react build fails here. Not sure if that's got to do with this PR.

@RobertBoes
Copy link
Contributor Author

@driesvints Yeah, looking into why they're failing.. Tests first failed because it was using quite an old Node version which didn't support the features I used, now it fails early. So my suspicion is that the Inertia test suite doesn't work on newer node versions (though, tbh, v18 isn't that new). Also not sure if it's just the React tests, the other ones are cancelled because the React one fails to build 🤔

@jamesst20
Copy link
Contributor

@driesvints Yeah, looking into why they're failing.. Tests first failed because it was using quite an old Node version which didn't support the features I used, now it fails early. So my suspicion is that the Inertia test suite doesn't work on newer node versions (though, tbh, v18 isn't that new). Also not sure if it's just the React tests, the other ones are cancelled because the React one fails to build 🤔

It's likely failing because it is using npm under the hood which doesn't manage well dependencies across multiple workspaces.

There is already a PR to switch to PNPM #1875
and there is already a PR to update all dependencies #1874

@reinink reinink changed the base branch from master to v1 October 9, 2024 15:24
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