Latency and Throughput of FastAPI Services Under Uvicorn: Effects of Handler Type, JSON Serialization and Worker Count

Python web services are often tuned by habit: use async def, switch to a faster JSON library, add worker processes. This report measures how much each of those choices matters for a small FastAPI service served by Uvicorn. Four factors were crossed (sync or async handler, 70-byte or 90 KB response, standard-library json or orjson, and 1, 2 or 4 Uvicorn workers), plus three ways of waiting 5 ms, for 135 closed-loop measurements (five repeats, 64 connections, 10 s windows) on one 2-vCPU Linux virtual machine. None of the 135 measurements recorded an error. For the 90 KB response, orjson gave 3.8 to 5.0 times the throughput of json and about a quarter of the p99 latency. For the 70-byte response the gain was about 5 to 10 percent. For small responses, async def handlers were about 1.4 to 1.5 times faster than def handlers (1.3 in one noisy case). Moving from one to two workers raised throughput by 1.1 to 1.3 times, and four workers gave no gain over two on this two-CPU machine. Calling time.sleep inside an async def handler cut throughput to 180 requests per second, 14 to 23 times lower than the other two ways of waiting. The results come from one machine, with the load generator and server sharing its two CPUs, so they show relative effects and will not transfer exactly to other hardware.

Authors

Publication Details

Journal
Zenodo (CERN European Organization for Nuclear Research)
Published
2026-11-03
DOI
https://doi.org/10.5281/zenodo.23899504
Primary Topic
Mobile and Web Applications
Type
preprint
Controls
|||
ALL TIME
JAN
FEB
MAR
APR
MAY
JUN
JUL
AUG
SEP
OCT
preprint

Latency and Throughput of FastAPI Services Under Uvicorn: Effects of Handler Type, JSON Serialization and Worker Count

Quenasha Byrd
Zenodo (CERN European Organization for Nuclear Research)
Mobile and Web Applications
preprint

Latency and Throughput of FastAPI Services Under Uvicorn: Effects of Handler Type, JSON Serialization and Worker Count

Quenasha Byrd
preprint en

Abstract

Python web services are often tuned by habit: use async def, switch to a faster JSON library, add worker processes. This report measures how much each of those choices matters for a small FastAPI service served by Uvicorn. Four factors were crossed (sync or async handler, 70-byte or 90 KB response, standard-library json or orjson, and 1, 2 or 4 Uvicorn workers), plus three ways of waiting 5 ms, for 135 closed-loop measurements (five repeats, 64 connections, 10 s windows) on one 2-vCPU Linux virtual machine. None of the 135 measurements recorded an error. For the 90 KB response, orjson gave 3.8 to 5.0 times the throughput of json and about a quarter of the p99 latency. For the 70-byte response the gain was about 5 to 10 percent. For small responses, async def handlers were about 1.4 to 1.5 times faster than def handlers (1.3 in one noisy case). Moving from one to two workers raised throughput by 1.1 to 1.3 times, and four workers gave no gain over two on this two-CPU machine. Calling time.sleep inside an async def handler cut throughput to 180 requests per second, 14 to 23 times lower than the other two ways of waiting. The results come from one machine, with the load generator and server sharing its two CPUs, so they show relative effects and will not transfer exactly to other hardware.

Zenodo (CERN European Organization for Nuclear Research)
Mobile and Web Applications
AI Navigator

Ask Laika to Summarize, Analyze, and Connect papers live on the map.

Summarize Papers & Methodologies

Extract key findings, datasets, and comparative methods across publications.

Benchmark Rankings & Visual Analytics

Rank top research institutions, authors, funders, topics, and journals by Field-Weighted Citation Impact (FWCI) and paper volume with instant charts.

Connect Distant Disciplines

Bridge topological clusters on the map to find hidden collaborative intersections.

Laika access coming soon
Latency and Throughput of FastAPI Services Under Uvicorn: Effects of Handler Type, JSON Serialization and Worker Count — Quenasha Byrd · Zenodo (CERN European Organization for Nuclear Research) (2026) | TGRS Research Map | TGRS