Next.js Discord

Discord Forum

Slow POST route handler with Mongoose DB connection

Unanswered
Balinese posted this in #help-forum
Open in Discord
Avatar
BalineseOP
What can I do about slow POST route handler taking ~2s?

I have the same exact handler in a non-Nextjs app (pre-migration) that ran <100ms. Now, after migrating to Next.js, it is taking ~2s. The cold boot time is around ~200ms (which is ok-ish), I imagine the rest of the time goes to initiating the DB client connection.

Does Next.js not have away to initiate and persist DB client connections on boot of the server?

I understand the idea of edge functions and what not, but if the endpoint is ~2s slow, it sort of defeats the whole purpose.

6 Replies

Avatar
BalineseOP
Something seems REALLY wrong, I am testing the endpoint locally and seeing terrible times.
Original function with logic
Image
Empty function 0 logic, just responds
Image
Even an empty API that just responds back takes ~700ms??????
🤯 🤯 🤯
AND this is locally