Home | Benchmarks | Categories | Atom Feed

Posted on Sun 03 July 2022 under Rust

Minimalist Guide to Axum

This post is a part of a series exploring Rust-based Web Frameworks.

Axum is a web framework written in Rust. It provides an API for building web applications and helps remove much of the underlying detail of the libraries it's built upon.

The project is primarily the work of David Pedersen, a software engineer at the Stockholm-based video game studio Embark Studios. Axum belongs to the Tokio organisation on GitHub which also hosts an asynchronous runtime for Rust by the same name that has seen 57M downloads and is the 58th most downloaded crate of all time.

Work on Axum began a little over a year ago and has since seen 107 contributors work on the project. It's made up of 13K lines of Rust, has amassed almost 1.6 million downloads on crates.io and has 1,460 closed issues on GitHub.

The documentation is largely a single page with code examples and links to an extensive repository of 39 example projects. These examples are religiously kept up to date as the project develops and matures.

In this post, I'll take a look at some of Axum's features and characteristics.

Axum Up & Running

The system used in this post is running Ubuntu 20.04 LTS. I'll use Rustup to install Rust version 1.62.0.

$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

I'll clone Axum's Repository and launch the chat example.

$ git clone https://github.com/tokio-rs/axum
$ cd axum/examples
$ cargo run -p example-chat

Opening in a web browser will present you with a form asking you to set a username and join a chat group. After doing so, you'll be able to send messages into a single chat channel via WebSockets.

The above uses 102 lines of Rust and a single 43-line HTML file with no external dependencies. Despite the concise size of the code, it's one of the larger examples.

When I compiled a release version of the above it resulted in a 2 MB binary when GZIP-compressed. I'm sure research into stripping this binary down further would bear fruit.

Features & Support

There is an example demonstrating how to use SQLx with Axum. SQLx provides asynchronous support for communicating with PostgreSQL, MySQL, SQLite and MSSQL. I haven't come across any ORMs being demonstrated in the examples but Axum doesn't appear to be too opinionated on external data access.

There is an example demonstrating support for TLS via Rustls. Rustls supports TLS 1.2 and 1.3 and Curve25519, a safe elliptic curve also used by WireGuard. Last year curl added support for Post-Quantum TLS but as of this writing, I can't see any support in Rustls for curl's supported algorithms.

The Askama template rendering engine, which is based on Jinja, is supported. I couldn't find examples for any other templating engine but templates appear to be reasonably decoupled in the example where Askama's use is demonstrated.

I couldn't find any examples or mention of Zstandard or Brotli in the Axum code base. It could be at this point that Axum would be better placed behind a dedicated reverse proxy if this sort of support is important to you.

It doesn't appear that Axum aims to be a "batteries included" framework and prefers to be non-opinionated compared to some of its Rust-based counterparts. For anyone familiar with the Python world's web frameworks, Axum is more like Flask and less like Django. David said himself that the examples provided by the project are not intended to define best practice, but merely be an example of how you might go about implementing a given feature.

Benchmarking Axum

I came across a synthetic benchmark comparing several web frameworks and Axum seems to break away from the Rust-based pack as the number of concurrent requests increases. In the highest concurrent setting benchmarked, Axum came second only to warp among its Rust-based competitors.

Of the 250+ benchmarks across all the languages listed, Axum came 30th overall when ranked by the highest concurrent setting.

Thank you for taking the time to read this post. I offer both consulting and hands-on development services to clients in North America and Europe. If you'd like to discuss how my offerings can help your business please contact me via LinkedIn.

Copyright © 2014 - 2024 Mark Litwintschik. This site's template is based off a template by Giulio Fidente.