Search code examples
performancenuxt.jsserver-side-renderingpm2openlitespeed

Nuxt 3 stress testing overloads the server, how do you limit the SSR load?


I have deployed a Nuxt 3 web application with a Strapi CMS backend using PM2 and an OpenLiteSpeed reverse proxy. The server has 4 cores and I have 4 Strapi instances and 2 Nuxt 3 Nitro server instances. The number of instances is pretty random, I'm not sure how big the cluster should be.

I am trying to load test the website with Artillery:

config:
  target: "[url]"
  phases:
    - duration: 60
      arrivalRate: 50

scenarios:
  - flow:
    - get:
        url: "/"

The Artillery configuration is also pretty random.

When I launch the test, the server completely hangs. SSH becomes laggy and all 4 cores jump to 100%. I can launch the same test calling one of the backend endpoints and the server will be fine. I'm pretty sure that means that the SSR is overloading the server. The frontend stays unresponsive for quite some time while processing the queue of requests. After testing I can manually restart the PM2 instances and the frontend will become responsive instantly.

I have tried applying stricter OpenLiteSpeed per-client throttling but it doesn't seem to make much of a difference, just increases load times for general usage.

I am thinking about using Cloudflare, would that take load off of the server and put it on the CDN? Are there any other Nitro/Nuxt/OpenLiteSpeed caching or build configuration parameters that I am missing? Should I configure PM2 to restart the frontend on reaching specific CPU usage?


Solution

  • The average application with SSR does not maintain more than 30-50 RPS. To get around this you need a cache for the SSR.

    For example: nuxt-ssr-cache