Slow POST route handler with Mongoose DB connection
Unanswered
Balinese posted this in #help-forum
![Avatar](https://cdn.discordapp.com/embed/avatars/0.png)
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.
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](https://cdn.discordapp.com/embed/avatars/0.png)
BalineseOP
Something seems REALLY wrong, I am testing the endpoint locally and seeing terrible times.
Original function with logic
![Image](https://cdn.discordapp.com/attachments/1121192638612246589/1121195700680667246/Screenshot_2023-06-21_at_4.49.52_PM.png)
Empty function 0 logic, just responds
![Image](https://cdn.discordapp.com/attachments/1121192638612246589/1121195762613764246/Screenshot_2023-06-21_at_4.50.27_PM.png)
Even an empty API that just responds back takes ~700ms??????
🤯 🤯 🤯
AND this is locally