N
Neon13mo ago
optimistic-gold

Rust sqlx: Use sqlx pooler or Neon pooler?

Rust crate sqlx has a built in connection pool: https://docs.rs/sqlx/latest/sqlx/pool/index.html. You use it like this:
let pool = PgPoolOptions::new()
.max_connections(5)
.connect(database_url).await?;
let pool = PgPoolOptions::new()
.max_connections(5)
.connect(database_url).await?;
Should I just set max_connections to 1, and use the Neon pooler host? Or create some amount of connections with the sqlx PgPool, and use the non-pooled Neon host? Or perhaps a combination of the two? May not be a straightforward answer, and may be better suited for the sqlx maintainers. But wondering if you had any ideas off the bat. To further complicate this, the Rust code here will be running from AWS Lambda.
2 Replies
extended-salmon
extended-salmon13mo ago
If you can, I would use the sqlx pool A client-side pool is more efficient IME if you can consistently re-use the pool state for a long period of time The risk however is if you scale up your app to 100 instances, that 5 connections becomes 500 connections which is quite high for postgres (this is usually not a concern for the majority of people, you should be fine!)
optimistic-gold
optimistic-goldOP13mo ago
@Conrad Ludgate Okay thanks! In this case use the non-pooled Neon URL, then? Guessing using both is redundant. What do you think about this in a serverless context? It may not apply here, but I remember that in the past Prisma recommended a connection limit of 1 if deploying to serverless. I know for Neon this is no longer needed since we can use the PrismaNeon adapter...but wondering if similar considerations are needed here.

Did you find this page helpful?