Next.js Discord

Discord Forum

Next.js <> Vercel, getServerSideProps really slow

Answered
Siamese Crocodile posted this in #help-forum
Open in Discord
Siamese CrocodileOP
Hi there!

We are using Next.js + Vercel for our project, and unfortunately the loading time is really long when we have a getServerSideProps (for a server side api call), really depends on each user, but can takes between 2 and 7 seconds
However if we deployed the project on a private server, the loading is completely normal !
In both case the request takes 100/150ms

Any thoughts ?
Thank you guys!

enzo:ahhhhhhhhh:
Answered by Asian black bear
If your testing reveals it is fast after the initial cold load, then everything should be fine. How long a handler will stay warm is not documented, but it is thought to be around 45-60 minutes. More used ones tend to stay around longer than idle ones.
View full answer

21 Replies

did you measure elapsed time in gSSP. especially calling the upstream API or DB. so you can nail down the culprit.
7 seconds are too long so most probably network issues
or fetch enormously huge payloads from upstream, while your self hosted version sits the upstream closely so fetched faster
Siamese CrocodileOP
Hi @tafutada777

Im living in Canada and the personal server is hosted in Paris
Regarding the "huge payloads", unfortunately this is not the current issue, the payload is really small, like ~10 fields and only strings (small ones as well)

With insomnia the request tooks like 200ms maximum
On my private server, almost the same, or at least very close
On Vercel takes 5 seconds, but only the first request, once this is one is done, the next ones will be fast, as it should be
thank you for your answer 👌
Asian black bear
It sounds like cold start on lambda. Is your getServerSideProps calling an external api or one in your next project?
Asian black bear
So, usually in production a busy site will keep its functions "warm" except right after redeployment. For testing sites they are often cold starts
Are you having a production issue?
@Asian black bear Are you having a production issue?
Siamese CrocodileOP
website has been deployed on vercel, with the default configuration, and looks like a production deployment, even if I missed something ?
so yes i'd say it's a production issue

Even if a friend go on the website right after me, he'll get the long first loading as well
Asian black bear
Looks like a production deployment in terms of traffic?
Siamese CrocodileOP
Oh no, not yet at least
Website is still "private", so only the devs got the access
Should be the issue ?
I mean, once we'll release it in public and get more traffic, the cold start issue won't be there anymore ? or just after a re-deployment ?
Asian black bear
If your testing reveals it is fast after the initial cold load, then everything should be fine. How long a handler will stay warm is not documented, but it is thought to be around 45-60 minutes. More used ones tend to stay around longer than idle ones.
Answer
Asian black bear
There can also be cold starts with a rapid increase in traffic as more handlers are provisioned, but that is likely to outperform what a self-hosted solution would do
Siamese CrocodileOP
Ok thank you @Asian black bear ! really appreciate, we'll monitor this issue once we'll release the new website!
Thanks again, and have a nice day!
@Siamese Crocodile Ok thank you <@611000252438413342> ! really appreciate, we'll monitor this issue once we'll release the new website! Thanks again, and have a nice day!
BTW, I have that problem while using nextauth ( since it is using getServersideProps) . In the web application we have like 60 test users and they are using website at least 2 hours a day.

We couldn't improve the page speed. It was on vercel and i also tried to deploy it on AWS Amplify
The website is app.globalturkish.org , its on AWS Amplify, and all of microservices and CDNs are also deployed in frankfurt
If you find any optimization solutions would happy to hear from you !
Asian black bear
Another thing to consider is using the edge runtime when possible