Hmm how does Neon perform with
Hmm how does Neon perform with transactions? Just added a Pooled connections with my Drizzle ORM. Basically the transaction performs 500 inserts in to 1 table, and the result of the main ID is used to create related records that is usually
1 -> 1.2
in relation ratio. but each batch with related data transactions takes about 40-50 seconds to insert. (using Drizzle ORM) R and W comes from the same Neon DB instance11 Replies
correct-apricot•15mo ago
And the pooled connection is created like this:
and with imports (as I'm using HTTP for other things):
well if it would matter, here's my whole drizzle-neon file:
So - inserting about 12k records with about 1.2 ratio related records using transactions took about 12 minutes, which feels like either I'm doing sometjing insalely dumb or I haven't understood transactions and pooling correclty
subsequent-cyan•15mo ago
@martin is it possible to try not using the http client and instead use a postgres client. I'd like to understand the http overhead
correct-apricot•15mo ago
I'm getting the slowness from running
dbPool
. Not sure if I understand correctly if I can switch that one. Anyway it all came from the error of not being able to use transactions: Error: No transactions support in neon-http driver
thus I ended up with creating a pooled client using the info from: https://github.com/neondatabase/serverless#pool-and-client and https://orm.drizzle.team/docs/get-started-postgresql#neon
The transaction / update script looks like this
I've tried various batch sizes as well but the same resultsubsequent-cyan•15mo ago
@Mahmoud do you have any insight here since you're much more familiar with Drizzle?
stormy-gold•15mo ago
Hmm @martin Are you connecting to Neon from a long-running server?
correct-apricot•15mo ago
Sorry been out sick a few days, currently this is just running locally off my computer (M3 Pro)
stormy-gold•15mo ago
Are you planning on deploying your app to a long-running server or a serverless platform?
If it's a long-running server then you shouldn't be using the serverless driver
correct-apricot•15mo ago
The code is shared between both, so the main app is running serverless, thus the serverless connection, but some background stuff are deployed on another service that's long running (e.g. in my case doing a lot of background data syncing, thus why I wanted DB transactions)
stormy-gold•15mo ago
Hmm, do you mind sharing the query you're using?
correct-apricot•15mo ago
Let me try to rewrite the script a bit so it makes some more sense and not have a ton of weird business logic. But I think as well it might be me using transactions the wrong way
But basically, my idea was to use the Pool and transactions for long running jobs in the BG that needs to read and insert a ton of data
The normal read/writes for user facing things uses the serverless adapter (as it's all deployed on Vercel anyway)
stormy-gold•15mo ago
makes sense. But the perf issue you're seeing is probably related to the queries themselves. Not something related in particular to Neon