N
Neon3w ago
correct-apricot

Performance issues *potentially* related to location?

Hi all! After 2 weeks of hard work I'm almost done migrating from Supabase to Neon and overall the experience has been FANTASTIC I'm completely in love with Neon! But I have one annoying issue... Please bear in mind that I'm not skilled/knowledgeable with databases and this is most likely a skill issue on my part and not an issue with Neon: My overall stack: - Hono + Drizzle + Neon + Better auth backend - Deployed to cloudflare workers I'm having some pretty bad performance issues: I'm based in São Paulo, so I chose "AWS South America East 1 (São Paulo)" for my DB region. In my mind this would be enough to ensure a somewhat good speed at least developing locally. But everything is VERY slow, like 2 seconds per requests on average getting to up to 50s. My first concern was to fix it in production. I implemented Hyperdrive on Cloudflare (where my app is hosted) and this kinda fixed the issue in production (staging actually). Locally I kept getting very slow requests and my app kept crashing. So I tested a few things and after when I changed from "drizzle-orm/node-postgres" to "drizzle-orm/neon-http" I noticed a drastic improvement in performance, but then I started to get errors because some endpoints were relying on transactions which are not supported by drizzle-orm/neon-http. I then tried "drizzle-orm/neon-serverless" and apparently everything is working nicely now. But to be honest I don't really understand whats going on... If I'm in São Paulo and the Neon region is São Paulo, shouldn't I get at least decent speeds always? Why does the driver affect the performance so drastically? And is it really related to locations given that it got drastically better in production with Hyperdrive? Sorry if this question is stupid...
1 Reply
passive-yellow
passive-yellow3w ago
Glad to hear you're loving Neon, and it's these are not stupid questions at all, there's a lot to choosing the right connection method, especially when dealing with serverless environments! I will admit, The 50s latency you saw is extreme (and mostly not related to Neon), even establishing a fresh connection on a cold started Neon database wouldn't explain that. For the rest, it can be explained by the following - Hyperdrive allows for connection reuse, so you don't need to create a fresh connection to the database on each request, which explains your performance boost there (connecting can easily be 6+ round trips from TLS, TCP, and auth between your Cloudflare server and the AWS server that your Neon database is hosted on) - Locally, you most likely were creating a fresh connection on each request, which is why you saw big performance increases when switching to our SQL-over-HTTP drivers (drizzle-orm/neon-http and drizzle-orm/neon-serverless) - One thing to watch for is double pooling, Neon runs pgbouncer which is basically connection pooling on your database server. If you have a client pool too, they can often not play nice together. We offer both pooled and non-pooled connection strings in the console! This piece of documentation might be useful to help understand the different ways to connect to your database, and their trade offs Hope this clears things up!
Neon
Choosing your driver and connection type - Neon Docs
When setting up your application’s connection to your Neon Postgres database, you need to make two main choices The right driver for your deployment &8212; Neon Serverless driver or a TCP based driver...

Did you find this page helpful?