Aspen's blog

Aspen, I write this blog!

Benchmarked: The state of Rust web frameworks in 2021

I benchmarked wrong, and these benchmarks are misleading, as my custom bencher bottlenecked. I will update this article with better benchmarks later

There's many web frameworks for Rust. actix-web, warp, rocket, oh my! They all have their distinct ups and downs, but usually actix-web is known as the fastest (albeit not without controversy), and rocket as one of the more user-friendly frameworks.

There's been various benchmarks throughout the years, but how do they all stand in 2021, with tokio 1.0 out?

Today, we're going to be testing 3 separate web frameworks. This is nowhere near all of them, but these are likely the most popular ones, and also ones I know enough about to try to avoid inexperience bias:

The reason these are all master is that the latest versions with Tokio 1.0 support have not been released fully yet.

In addition, we're going to try to maximize optimization during these rounds: We're going to use snmalloc as our global allocator, to try to minimize allocator overhead, and turning on optimization parameters in Cargo.toml

[profile.release]
opt-level = 3
codegen-units = 1
lto = true
[profile.release.package.'*']
opt-level = 3
codegen-units = 1

The Setup

Here's the various benchmarks we're going to run:

Our "complex" JSON object is this mouthful of a type:

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ExampleReturn {
	pub a: String,
	pub b: u32,
	pub c: u64,
	pub d: f32,
	pub e: f64,
	pub f: Vec<u64>,
	pub g: Vec<f64>,
	pub h: Vec<String>,
	pub j: BTreeMap<String, u64>,
}

Relevant system info:

The source code for these benchmarks are on my Github, licensed under the BSD-3-Clause license.

There's not much more to explain, so let's get to the point (and probably the only reason you're reading this), the results!

The Results

GET /hello

requests/secondaverage timemin timemax time
actix-web8415.98118µs66µs15ms
rocket8230.11121µs67µs8ms
warp8293.88120µs60µs15ms

GET /json

requests/secondaverage timemin timemax time
actix-web8481.12117µs66µs12ms
rocket8563.68116µs67µs12ms
warp8671.42114µs67µs5ms

POST /json-sort

requests/secondaverage timemin timemax time
actix-web7333.80136µs78µs14ms
rocket7597.79131µs75µs11ms
warp7640.58130µs75µs10ms

POST /json-complex

requests/secondaverage timemin timemax time
actix-web7471.30133µs71µs13ms
rocket7802.98127µs72µs12ms
warp7576.59130µs73µs13ms

Latency

average request latencymax request latency
actix-web55µs6ms
rocket57µs7ms
warp52µs2ms

min request latency is not here due to the fact it was broken

average response latencymin response latencymax response latency
actix-web68µs21µs4ms
rocket70µs25µs10ms
warp63µs26µs3ms
average round-trip latencymin round-trip latencymax round-trip latency
actix-web124µs62µs7ms
rocket128µs60µs11ms
warp116µs
69µs
4ms

Please do not use the Brave browser

It's a just fork of Chromium with a sub-par adblocker and a really bad history.

See my blog post for more details.