Home | Benchmarks | Categories | Atom Feed

Posted on Thu 07 July 2022 under Rust

Minimalist Guide to Poem

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

Poem is a web framework written in Rust. It provides a concise API and is feature-rich beyond what you typically find in a micro-framework. It does a lot to decouple itself from many primary functions of a web framework as to give developers as much flexibility as possible.

I haven't managed to uncover the full name of its primary developer but this person goes by Sunli online and GitHub states this person is based in China.

Work on Poem started in August of last year. The code repository contains 48 example projects with 14 of those being OpenAPI-specific. The code base comprises 32K lines of Rust and is well-organised.

Most of the documentation for this project is terse and kept within READMEs close to where the code and examples are. Other projects have gone out of their way to create dedicated websites that are approachable to people with little to no Rust experience. Poem does document its features and answers can be found. Still, there is an expectation you'll have gone through the whole GitHub repository rather than scrolling a single document or clicking around an animated, icon-drenched website.

Poem ranks ~25th in terms of downloads on crates.io's HTTP server category. The issue count on GitHub is also a lot lower than those found with Poem's competitors. As of this writing, there are 14 open issues and 135 closed ones. This shouldn't be surprising as the project has yet to celebrate its first birthday and I suspect the creator is more interested in engineering than marketing.

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

Poem 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 Poem's Repository and launch the chat example.

$ git clone https://github.com/poem-web/poem
$ cd poem/examples/poem/websocket-chat
$ cargo run

Opening http://127.0.0.1:3000/ 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 95 lines of Rust including an inline HTML template.

When I compiled a release version of the above and ran it through strip it resulted in a 1.44 MB binary when GZIP-compressed.

Features & Support

OpenAPI support is supported and well-documented including screenshots of examples being rendered in Swagger's UI.

There is a rate-limiting example in Poem's repository that is built on top of primitives found in Tokio and Tower. To add to this, Tokio's Metric middleware is also demonstrated and doesn't need too many lines of boilerplate code. I can imagine Poem being a contender for helping to build a bespoke and distinctly optimised CDN server.

There are four TLS-specific examples including demonstrating how to switch between OpenSSL and Rustls as well as a couple of Let's Encrypt examples.

On the data side, there are examples for MongoDB and Redis. There is also a session data-specific SQLx usage example kept embedded in a README rather than with the rest of the poem package's examples. SQLx is popular among Rust-based frameworks and offers support for MSSQL, MySQL, PostgreSQL and SQLite. It's also the 6th most downloaded database-specific create (arguably 5th as the top crate in this category is focused on Unicode codepoints).

There is also an AWS Lambda example. Like the database and OpenAPI examples, this is kept outside of the main poem package.

Benchmarking Poem

I came across a synthetic benchmark comparing several web frameworks and Poem at 64 current threads is out-performed by Warp, Axum and Salvo but it scored ahead of Gotham, Actix and Rocket. That said, it's still in the top 20% of benchmark results when frameworks across all languages are taken into consideration.

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 - 2022 Mark Litwintschik. This site's template is based off a template by Giulio Fidente.