How to make Spartacus Server Side Rendering perform under load?

Viewed 102

we activated SSR on our Spartacus frontend and tried to test if it worked. For this, we step SSR and run it in production mode. After that, we used JMeter to create the load of 10 simultaneous users requesting two simple CMS Sites. There was also a check added to verify that the answer was actually the SSR response and not the CSR "empty index html". About 80% of all requests did not do SSR, but fallback to the CSR response. If we lower the number of simultaneous users to only 2, it worked most of the time.

To prevent that this is caused by one of our customizations, we run the same experiment with the Spartacus OOTB code and it produced the same result.

Our SSR Optimizing Options were the following:

const engineConfig: SsrOptimizationOptions = {
  timeout: 5000, // spartacus default: 3000
  maxRenderTime: 300_000, // spartacus default: 300_000 (5min)
  concurrency: 20, // spartacus default: 20
  cache: false,
  cacheSize: 20,
  debug: false,
};

Is the SSR engine able to render this amount of simultaneous requests? If the cache is activated, it worked fine. But we are having thousands of pages and we most likely are not able to cache every page.

2 Answers

A single live SSR server cannot handle a big load. To mitigate the performance issues, you might need a cluster of Node.js processes and 2 layers of caching: both for your rendered html (on CDN) and for your OCC API calls.

If only the number of the pages you have at all is not huge, alternatively you might consider prerendering/SSG (Server Side Generate) all the pages ahead of time and putting the output html files in the CDN, instead of live SSR.

As the core team, we're going to publish soon the new docs on the optimal SSR setup for Spartacus. But before they are published, let me share the early drafts that might already be helpful for you (coming from the PR):

We kind of resolved this issue by using the (undocumented) SsrOptimizationOption Parameter reuseCurrentRendering. If this parameter is not set, the SSR renderer will abort SSR if another rendering of the same URL is in progress at the same time.

As we want to ensure the requests get a SSR Reponse for Crawlers (SEO reasons), we need to ensure the SSR is really done, also if some other customers are requesting the same URL at the same time.

I'm not sure if this causes any side effects or why the reuseCurrentRendering is not set to true by default...

Related