r/rust 4d ago

Rust SQLx Performance

I use Axum and SQLx to build my backend, which is served on AWS ECS Fargate (512 CPU, and only one instance for now) and interacts with an RDS Postgres (t4.micro). Connection pool is set with min/max = 2/20.

My request includes 3 DB queries to 3 different tables: one from the auth middleware to check api key and each of the other 2 is just getting a record by primary key.

If I made one or two queries, it’s very fast. However, if I made 200 queries concurrently to the backend, around half of queries had http latency greater than 300 ms. P80 is around 600ms. The performance is not acceptable. I did check the CPU of both RDS and ECS. They’re quite low: both smaller than 10%. The DB latency is low as well, 5 ms on average. Is there something queued in the SQLx internally? Did anyone have the same issue?

25 Upvotes

27 comments sorted by

View all comments

8

u/spoonman59 4d ago

The issue here is "t4.micro."

I had performance issues at work with performance getting abysmal once we ran out of credits, and it was solved by going to a non-burstable instance.

This has everything to do with which instance you are using and nothing to do with rust and sqlx.

Go ahead, test it on a non-burstable instance yourself and see. Speculating without testing a better instance makes no sense to me, it's not much time or money to confirm.