Why benchmark only diesel vs another framework it faster, but use with Actix it slower?

I want to choose between diesel vs tokio-postgres to use with Actix. But the TechpowerBenchmark show actix-diesel slower than 3x vs actix-pg (tokio-posgres). Is that correct?

actix-pg (653,529)

actix-diesel (251,953)

Generally, it is better to avoid diesel in async code because diesel is not an async library.


I would like too expand alice answer a bit:

First of all keep in mind that TechpowerBenchmark benchmarks are written with maximal performance in mind. That means you will likely not write similar code, as this is just not practical in most cases. Additionally as far as I'm aware there are more differences between the actix-pg and actix-diesel implementation than just swapping out the connection library. (I believe actix-diesel is much more in line with code you normally would write).
To summarize that: As always don't trust other peoples benchmarks but write your own for your own usecase.

Additionally, as alice wrote: Diesel is a sync library that means it could potentially block the executor of an async framework if used in the wrong way. That is relevant if you expect that your service sees a lot of traffic. (Where a lot of traffic really means more than most services will ever see. Crates.io for example uses a fully sync stack including diesel under the hood).
If you expect to see a lot of traffic you could use methods like tokio::task::spawn_blocking to workaround blocking the executor or just use an async connection implementation for diesel like:

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.