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

[2.x] SSR clustering #2206

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

RobertBoes
Copy link
Contributor

@RobertBoes RobertBoes commented Jan 23, 2025

Reattempt of #1909 for 2.x

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 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( ... ),
  {
    cluster: true,
  }
)

Massive thanks to @christianschoenmakers 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?
discord.com/channels/592327939920494592/758259460920573992/1255111006384820234

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