N
Neon•2w ago
absent-sapphire

extremely high latency when using neon

our stack uses cf worker + hyperdrive + neon we're are seeing some nasty latency, ranging from 1-4 seconds
+65ms <-- GET /api/users/me
| +65ms starting workos auth
| +336ms after workos auth
| +336ms starting me
| +336ms before db user query
| +2.51s after db user query
| +2.51s --> GET /api/users/me 200 2s
+65ms <-- GET /api/users/me
| +65ms starting workos auth
| +336ms after workos auth
| +336ms starting me
| +336ms before db user query
| +2.51s after db user query
| +2.51s --> GET /api/users/me 200 2s
we found that using hyperdrive, the walltime is ~400ms, and it worsens to 1s if using direct connection w/ or w/o pool we checked neon's dashboard and latency seems fine < 20ms, and we tested it in <5min interval so unlikely the cold start. can anyone please help take a look? this is very frustrating and we're seriously considering moving off neon
3 Replies
absent-sapphire
absent-sapphireOP•2w ago
equal-jade
equal-jade•2w ago
Hey! Hyperdrive is supposed to keep your database connections open for you. Assuming it's set up correctly, the delay is probably not due establishing a DB connection but due to the distance between the Cloudflare Worker (region) and your database (region). Cloudflare Workers are distributed globally. Can you log what region your Workers are running in? I think you can get that via request.cf.region in your request handler but make sure to double check 🙏
You can expect sub 10 ms latency when querying Neon databases from within the same region but this quickly increases when leaving datacenter, region, and continents. Review where you're currently hosting your database. We have a latency dashboard here that visualizes this nicely: https://neon.com/demos/regional-latency
Neon Latency Dashboard
30-day average latency of Neon databases from different serverless functions.
absent-sapphire
absent-sapphireOP•2w ago
thanks -- turns out worker's in london and our DB is in us-east-2, now it's fixed:) appreciate the help

Did you find this page helpful?