Granian vs Uvicorn: An unscientific RAM usage comparison
Part of a new "microblog" series (click to read more)
Writing long, insightful blog posts is pretty hard, but sharing my random findings is fun (and maybe even slightly useful :O). So I've decided to start writing some shorter blog posts with things I've recently done or learnt - this is the first one!The background
I’ve noticed that whenever I write a simple Python API (usually with FastAPI), its Docker container takes something like 60 MB of RAM. (Which isn’t a lot, but when you’re running 10 of them on a Pi, it adds up.) I thought perhaps swapping the default server program (Uvicorn) with Granian might help - after all, it’s written in Rust so it must be blazingly fast and efficient, right??
The findings
I tested switching out the web server used for my My myLboro project. (that’s a mouthful)
I fetched the root page once and then checked memory usage with docker stats. As I said, this is not a scientific analysis.
- With Uvicorn, memory usage was at 66 MiB
- With Granian, memory usage was at 133 MiB
So this is actually a win for Uvicorn! I’m sure Granian is perfectly fast, but low-memory-footprint it is not.