Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v7
- uses: astral-sh/setup-uv@v10.3.2 # no floating major tags since v8
- uses: astral-sh/setup-uv@v10.4.0 # no floating major tags since v8
- name: format
run: uv run --group dev ruff format --check .
- name: lint
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/launch-ec2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ jobs:
role-to-assume: ${{ vars.AWS_ROLE_ARN }}
aws-region: ${{ vars.AWS_REGION }}

- uses: astral-sh/setup-uv@v10.3.2 # no floating major tags since v8
- uses: astral-sh/setup-uv@v10.4.0 # no floating major tags since v8

- name: Build and push images
id: build
Expand Down
74 changes: 34 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,27 @@
Benchmarks comparing API frameworks using **idiomatic, framework-recommended code**
(no deep optimisations). The question: *how fast is each framework under best practices?*

**Results are per core:** every framework, in every language, gets one pinned CPU core
and one worker (Go `GOMAXPROCS=1`; the JVM's JIT and GC share the same core). See
[Fairness & methodology](#fairness--methodology) for why.

Everything runs inside docker. Frameworks are benched **one at a time** — for a given
run, exactly one framework container is ever alive alongside the dependent services
(Postgres, the upstream, the load-generator runner), so no two frameworks ever share a core or
contend for host resources.

> **Disclosure**: I'm also the author of [jero](https://pypi.org/project/jero/), one of
> the frameworks benchmarked here. Every measure in this repo — equal resource budgets,
> idiomatic code per framework, isolated single-framework runs, documented intended
> differences — applies identically to jero and everyone else; nothing here is tuned in
> its favor. Judge the methodology, not my word for it, and open an issue/PR if you spot
> a framework being shortchanged.
> the frameworks benchmarked here, and of the libraries the Python frameworks share:
> [ryjwt](https://pypi.org/project/ryjwt/) (JWT), [lothc](https://pypi.org/project/lothc/)
> (HTTP client) and [fastpg](https://pypi.org/project/fastpg/) (Postgres; Flask uses psycopg
> because fastpg is async-only). Because the Python frameworks share them, Python-vs-Python
> results compare the frameworks. Python-vs-Go/Java/Bun results also reflect these libraries
> versus each language's usual ones.
>
> Every measure in this repo (equal resource budgets, idiomatic code per framework,
> isolated single-framework runs, documented intended differences) applies identically to
> jero and everyone else; nothing here is tuned in its favor. Judge the methodology, not
> my word for it, and open an issue/PR if you spot a framework being shortchanged.

## Run

Expand Down Expand Up @@ -49,8 +59,8 @@ That's what the comparison tables use; every attempt is still recorded in TaglyD
**Load generator:** [wrk](https://github.com/wg/wrk) (C, default — what TechEmpower
uses) or [oha](https://github.com/hatoo/oha) (Rust, `--loadgen oha`), closed loop with
`--vus` connections, on two dedicated cores. On EC2 the two agreed within 1–7% on every
test (`reports/20261023T083334-{wrk,oha}`), wrk slightly higher throughout. k6 was dropped: on those two cores it saturated at
~40–50k req/s, so it was capping the fastest frameworks instead of measuring them.
test (`reports/20261023T083334-{wrk,oha}`), wrk slightly higher throughout. k6 isn't used: on those two cores it saturates at
~40–50k req/s, which would cap the fastest frameworks instead of measuring them.

**Success %** is the share of requests that got the expected status. Before the load, a
correctness pass also checks the *body* of 100 responses (key fields per test, e.g.
Expand All @@ -72,23 +82,23 @@ At the end of a run it prints one table per test — throughput, latency, succes
and per-container resource use (CPU/mem + sparklines), rows sorted by req/s with
vs-jero multipliers — and every attempt is recorded in TaglyDB. It also writes a full
report (markdown, chart, raw JSON) to `reports/<run-id>/`; see
`reports/20261023T091453/report.md` for a complete one.
[`reports/20261130T122942/report.md`](reports/20261130T122942/report.md) for the latest full run.

## Frameworks & servers

| Framework | Language | Server (1 worker) | Outbound HTTP client | DB driver |
| --- | --- | --- | --- | --- |
| jero, FastAPI, Litestar, Blacksheep | Python 3.14 | [peregrine](https://github.com/grepjava/peregrine) ASGI (uvloop) | lothc | fastpg |
| Flask | Python 3.14 | peregrine WSGI (views inline) | lothc (sync) | psycopg |
| Robyn, Django Bolt | Python 3.14 | built-in Rust server (Bolt: `manage.py runbolt`) | lothc | fastpg |
| jero, FastAPI, Litestar, Blacksheep | Python 3.15 | [peregrine](https://github.com/grepjava/peregrine) ASGI (uvloop) | lothc | fastpg |
| Flask | Python 3.15 | peregrine WSGI (views inline) | lothc (sync) | psycopg |
| Django Bolt | Python 3.15 | built-in Rust server (`manage.py runbolt`) | lothc | fastpg |
| Gin | Go | net/http (`GOMAXPROCS=1`) | net/http | pgx |
| Elysia | Bun / TS | Bun native | `fetch` | Bun `SQL` |
| Spring Boot | Java 25 | embedded Tomcat, virtual threads | RestClient (Apache HttpClient5) | JdbcTemplate (HikariCP) |

All apps use idiomatic, framework-recommended code (no deep optimisations). The Python
ASGI frameworks and Flask share peregrine as the server so the variable under test is the
*framework*, not the server (Robyn and Django Bolt ship their own servers and
aren't run under peregrine). peregrine was chosen on evidence: on identical images it beat
*framework*, not the server (Django Bolt ships its own server and isn't run under
peregrine). peregrine was chosen on evidence: on identical images it beat
granian on every test, for jero (1.12–2.06×), FastAPI (1.04–1.59×) and Flask (1.31–1.43×);
see `reports/20261023T135721/`. Python ASGI apps run on uvloop. Django Bolt queries
the shared `users` table with raw fastpg — the same driver every other async framework in
Expand All @@ -97,11 +107,13 @@ doing different work than everyone else rather than a fair idiomatic difference.
itself still depends on psycopg internally for its own `DATABASES` config to boot, even
though the benchmarked query path never touches it.)

The whole Python field runs **Python 3.14.9** (pinned base image): fastpg needs
t-strings (>= 3.14.3), and its vendored wheel is cp314-only, which also rules out 3.15
for now. **Robyn** publishes no cp314 wheels (and no sdist), so its Dockerfile stage
builds the v0.88.0 release tarball with a Rust toolchain. Flask stays on psycopg because
fastpg is async-only.
The whole Python field runs **Python 3.15.2** (pinned base image). Flask stays on psycopg
because fastpg is async-only.

**Robyn** is left out for now: it doesn't support Python 3.15 yet (v0.88.0 builds against
PyO3 0.27, which stops at 3.14). On 3.14 it was close to Litestar on every test: 43.6k vs
49.2k, 26.7k vs 30.3k, 23.1k vs 26.6k and 22.1k vs 22.0k req/s on tests 1–4
(`reports/20261113T094529/`).


## Tests
Expand All @@ -112,9 +124,7 @@ fastpg is async-only.
3. **GET /catalog** — fetches a static JSON payload from the fast Rust (axum) `upstream`
service and returns it. Public endpoint; the service-to-service call carries a bearer
API key the upstream verifies. With every Python framework on the same Rust-backed HTTP
client (lothc, a typed wrapper over pyreqwest), this test differentiates *frameworks* —
historically, a pure-Python client (niquests) capped everyone at ~3k req/s and masked
the framework entirely.
client (lothc, a typed wrapper over pyreqwest), this test differentiates *frameworks*.
4. **GET /users/me** — JWT-authenticated; id from the token, the rest from a Postgres
`users` row.

Expand All @@ -132,14 +142,12 @@ The goal is *idiomatic per framework*, held to equal conditions and made scrutab
torn down before the next one starts. Every framework gets an identical,
contention-free environment — the same core, the same otherwise-idle host — so
absolute numbers are comparable both within a run *and* across separate runs, so long
as the host itself is otherwise idle. (Earlier versions of this benchmark ran the full
fleet concurrently, each pinned to its own core; that measures *"the framework under
fleet-wide contention,"* a different and reasonable question, but not what this repo
now measures.)
as the host itself is otherwise idle. (Running the whole fleet concurrently, one core
each, would measure *the framework under fleet-wide contention*, a different question.)
- **Nothing else on the measured core.** Each framework's healthcheck probes every 1s
only until it's healthy, then hourly, so no probe runs mid-bench (a Python probe starts
a whole interpreter, so this would otherwise cost some frameworks more than others).
Request/access logging is off everywhere (Robyn explicitly, via `--log-level WARNING`).
Request/access logging is off everywhere.
- **One worker each.** Every service runs 1 worker: peregrine `--workers 1`, Gin
`GOMAXPROCS=1`, Bun's single JS thread, Bolt `--processes 1`. Flask is synchronous
(peregrine WSGI, views called inline — no `--wsgi-threads` pool). A thread sweep
Expand Down Expand Up @@ -185,7 +193,6 @@ The goal is *idiomatic per framework*, held to equal conditions and made scrutab
| FastAPI | pydantic | typed (pydantic) + response-model re-validate | pydantic |
| Litestar | msgspec Struct | typed (msgspec) | msgspec |
| Blacksheep | pydantic (`FromJSON`) | typed (pydantic) | stdlib `json` (BlackSheep's default) |
| Robyn | pydantic (native param) | typed (pydantic) | orjson (`jsonify`/dicts) / pydantic |
| Flask | pydantic | typed (pydantic) | stdlib `json` |
| Django Bolt | msgspec Struct | typed (msgspec) + response re-validate | msgspec |
| Gin | `ShouldBindJSON` struct | typed struct | `encoding/json` |
Expand Down Expand Up @@ -223,19 +230,6 @@ excluded**, so you see each framework's own cost.
> actually delivers*. (`docker stats` needs ~1–2s per sample, so runs shorter than a few
> seconds yield too few CPU samples to be meaningful — use `-s 5`+ for the CPU columns.)

## HTTP client shootout

A separate, standalone benchmark: which Python HTTP client is fastest for the outbound
call every framework makes in test 3? One core vs the `upstream` service, sequential
then concurrent, pyreqwest vs httpx2 vs aiohttp vs niquests.

```bash
task bench-http-clients # 10s/client, concurrency 64
task bench-http-clients -- -d 20 -c 128 # override duration / concurrency
```

Builds and tears down its own stack (`compose.http-clients.yml`) — unrelated to `task bench`.

## Adding a Python framework

1. Add a `[dependency-groups]` entry in `services/python/pyproject.toml`.
Expand Down
15 changes: 1 addition & 14 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ tasks:
down:
desc: Tear down any framework stack left running (safety net — `task bench` already cleans up after itself).
cmd: |
files=$(ls compose.*.yml | grep -v compose.http-clients.yml | sed 's/^/-f /' | tr '\n' ' ')
files=$(ls compose.*.yml | sed 's/^/-f /' | tr '\n' ' ')
docker compose $files down -v

upstream-native:
Expand All @@ -50,19 +50,6 @@ tasks:
UPSTREAM_API_KEY="{{.UPSTREAM_API_KEY | default "upk_bench_9f8e7d6c5b4a32100fedcba987654321"}}" \
PORT="{{.PORT | default "6700"}}" cargo run --release

bench-http-clients:
desc: 'Outbound HTTP client shootout on one core vs the upstream. Override: task bench-http-clients -- -d 20 -c 128.'
cmds:
- defer: docker compose -f compose.http-clients.yml down -v
- |
d=$(echo "{{.CLI_ARGS}}" | sed -n 's/.*-d[= ]\{0,1\}\([0-9]*\).*/\1/p'); d=${d:-10}
c=$(echo "{{.CLI_ARGS}}" | sed -n 's/.*-c[= ]\{0,1\}\([0-9]*\).*/\1/p'); c=${c:-64}
echo "==> HTTP client shootout: ${d}s per client, concurrency ${c}"
DURATION="${d}" CONCURRENCY="${c}" \
docker compose -f compose.http-clients.yml up --build \
--abort-on-container-exit --exit-code-from bench


format:
desc: Format all Python code with ruff.
cmd: uv run --group dev ruff format .
Expand Down
1 change: 0 additions & 1 deletion bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class ResultsBackendSettings(BaseSettings):
"litestar",
"flask",
"blacksheep",
"robyn",
"gin",
"elysia",
"spring-boot",
Expand Down
2 changes: 1 addition & 1 deletion compose.base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ x-mem: &mem

services:
postgres:
image: postgres:18-alpine
image: postgres:19-alpine
deploy: *mem
cpuset: "1,2"
# Only one framework's pool (64 connections) is ever live at a time;
Expand Down
53 changes: 0 additions & 53 deletions compose.http-clients.yml

This file was deleted.

31 changes: 0 additions & 31 deletions compose.robyn.yml

This file was deleted.

2 changes: 1 addition & 1 deletion compose.spring-boot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ services:
cpuset: "0"
# No process/thread-per-worker knob to map WORKERS onto (see
# services/spring-boot/src/main/resources/application.yaml) — ignored,
# like Robyn/Django Bolt's own servers.
# like Django Bolt's own server.
environment:
JWT_SECRET: "b7c1e9a4f2d68350a1c9e7b5d3f10864a2c6e8b0d4f79351"
UPSTREAM_URL: http://upstream:8000
Expand Down
2 changes: 1 addition & 1 deletion ec2/user-data.sh.template
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ for pair in __IMAGES__; do
svc="${pair%%=*}"
ref="$REPO:$svc-${pair#*=}"
local_name="jero-benchmarks-$svc"
if [ "$svc" = postgres ]; then local_name=postgres:18-alpine; fi
if [ "$svc" = postgres ]; then local_name=postgres:19-alpine; fi
(docker pull -q "$ref" && docker tag "$ref" "$local_name") &
pids="$pids $!"
done
Expand Down
5 changes: 2 additions & 3 deletions ec2_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def _pushed_commit() -> str:
_SHARED_IMAGES = ["postgres", "upstream", "runner"]
_TAG_RE = re.compile(r"(?P<service>.+)-(?P<version>\d{4}\.\d{2}\.\d{2}\.\d{2})")
_SRC_TAG_RE = re.compile(r"(?P<service>.+)-src-(?P<key>[0-9a-f]{12})")
_POSTGRES = "postgres:18-alpine"
_POSTGRES = "postgres:19-alpine"
# The Python frameworks share one build context (services/python); each image
# COPYs only its own app files on top of the shared ones (see its Dockerfile).
_PYTHON_OWN_FILES = {
Expand All @@ -116,7 +116,6 @@ def _pushed_commit() -> str:
"litestar": ["apps/litestar_app.py"],
"flask": ["apps/flask_app.py"],
"blacksheep": ["apps/blacksheep_app.py"],
"robyn": ["apps/robyn_app.py"],
"django-bolt": ["manage.py", "django_app"],
}

Expand All @@ -134,7 +133,7 @@ def _git_files(*pathspecs: str) -> str:


def _postgres_digest() -> str:
"""Digest of postgres:18-alpine's current arm64 image on Docker Hub."""
"""Digest of the postgres image's current arm64 build on Docker Hub."""
index = json.loads(local["docker"]["buildx", "imagetools", "inspect", "--raw", _POSTGRES]())
for entry in index["manifests"]:
platform = entry.get("platform", {})
Expand Down
Loading