Low Level Web Frameworks
Introduction
Damn I'm too lazy to write another introduction LOL!! You can check the article on High-Level Web Frameworks to read the intro.
Coverage: Zig and Rust
For the low-level web frameworks, I've selected options from Zig and Rust, two languages I've been actively working with (I love 'em both!). This allows me to leverage my existing knowledge and experience to provide a more in-depth evaluation of these frameworks.
- Zig: Jetzig
- Rust: Rocket
- Python: Propeller (just kidding!)
Test setup
- I will be using wrk which is a C library to test the web framework throughput. The wrk command template I'm using:
wrk -t1 -c10 -d10 --latency http://localhost:5000
Note there will be variations of the wrk command.
- CPU: Ryzen 4800u 16 cores, 8GB RAM.
- The test run multiple times using a variation of threads and connections.
- Both Zig and Rust I'm including both optimized and non-optimized version.
- Primary metrics: request per second and average latency.
Benchmark results
Zig
Framework | req/s | avg latency | thread - conn | Notes |
---|---|---|---|---|
Jetzig | 50,854 | 172 us | t1 - c10 | logging |
--optimized | 60,729 | 104 us | t1 - c10 | no-logging |
--optimized | 171,304 | 263 us | t4 - c50 | no-logging |
--optimized | 179,793 | 960 us | t4 - c250 | no-logging |
Rust
Framework | req/s | avg latency | thread - conn | Notes |
---|---|---|---|---|
Rocket | 6,197 | 1,620 us | t1 - c10 | logging |
--optimized | 48,098 | 166 us | t1 - c10 | no-logging |
--optimized | 151,511 | 279 us | t4 - c50 | no-logging |
--optimized | 171,916 | 1,170 us | t4 - c250 | no-logging |
Conclusion
Zig:
Jetzig even in the non-optimized version is performing very well and in the optimized version it scale up nicely when I increased the number of threads and connections.
Rust:
Rocket in the non-optimized version shows dismal performance for a low-level web framework, however this issue become irrelevant as it maintained high performance once I apply --release build (optimized).
Both Jetzig and Rocket are highly performant web frameworks. One important key thing I need to address: at the moment Zig does not support asynchronous, while Rust does. This means in a situation where async framework would gain advantage (high I/O operation such as connecting to database), Rust and its Rocket framework should gain the upper hand.
Pick whatever fits your needs, I will be using both!