3

We noticed an interesting issue regarding our serverside rendering of our NextJs application.

The issue occurred when we decided to add fetching of our translation key values (which are fetched via API) on our serverside calls.

We made this decision to reduce CLS and give the user a better overal experience on first load. We didn't think much of it, since it's just another api call being handled returning the json before rendering the page.

Below you see a graph of our cpu usage on AWS, between 10:00 (10AM) and 14:00 (2PM) the fetching of the translation keys was live on production. We had to manually restart every 2h in order for the servers to survive (That is the peak you are seeing). After 16:00 (4PM) We removed this api call from that specific serverside call and you see that the server is stable. From 20:00 (8PM) we enabled an automatic restart to be sure that the servers would survive the night, but as you can see this was not necessary.

enter image description here

The API call in question, just returns a JSON object. It can contain up to 700lines of values which should be fine as our Product listing page can have a larger responses (up to 10k lines). Everything has caching on enabled, so next/static and the api responses. We were also thinking that it might have something to do with outgoing connections not closing in time. But I am making this post because no one really knows why this is an issue.

We are running the following setup:

  • Dockerized Application
  • Running on AWS Beanstalk
  • Cloudfront + Akamai
  • NextJs v12.2
  • Node v14.16

If anyone has the smallest idea in which direction to look, please let me know. We appreciate it.

Wesley Janse
  • 1,244
  • 1
  • 7
  • 14
  • Can you share the code where you're calling the API endpoint and also the API endpoint code itself? – juliomalves Jun 04 '22 at 16:37
  • Did you ever identify any common thread here? We've noticed similar issues with outbound network requests in server side rendering causing CPU spikes, in a Kubernetes context. Wondering if this is something internal to Next's SSR implementation? – Chris Van Patten Feb 02 '23 at 23:15
  • Hey Chriss, nope we still haven't identified the root cause of the issue. We almost refactored the entire application to be statically rendered. Which reduced the amount of spiking. But we still need to restart ocassionally. – Wesley Janse Feb 06 '23 at 12:59

0 Answers0