Skip to content
Closed
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
59 changes: 33 additions & 26 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 Down Expand Up @@ -78,17 +88,17 @@ report (markdown, chart, raw JSON) to `reports/<run-id>/`; see

| 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
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
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
36 changes: 20 additions & 16 deletions export_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def _render_markdown_table(test: str, results: list[Result]) -> list[str]:
# frameworks that were actually part of this run.
FRAMEWORK_FACTS: dict[str, dict[str, str]] = {
"jero": {
"language": "Python 3.14",
"language": "Python 3.15",
"server": "peregrine ASGI",
"http_client": "lothc",
"db_driver": "fastpg",
Expand All @@ -261,7 +261,7 @@ def _render_markdown_table(test: str, results: list[Result]) -> list[str]:
"serializer": "msgspec",
},
"fastapi": {
"language": "Python 3.14",
"language": "Python 3.15",
"server": "peregrine ASGI",
"http_client": "lothc",
"db_driver": "fastpg",
Expand All @@ -270,7 +270,7 @@ def _render_markdown_table(test: str, results: list[Result]) -> list[str]:
"serializer": "pydantic",
},
"litestar": {
"language": "Python 3.14",
"language": "Python 3.15",
"server": "peregrine ASGI",
"http_client": "lothc",
"db_driver": "fastpg",
Expand All @@ -279,25 +279,16 @@ def _render_markdown_table(test: str, results: list[Result]) -> list[str]:
"serializer": "msgspec",
},
"blacksheep": {
"language": "Python 3.14",
"language": "Python 3.15",
"server": "peregrine ASGI",
"http_client": "lothc",
"db_driver": "fastpg",
"validates_body": "pydantic (FromJSON)",
"parses_upstream": "typed (pydantic)",
"serializer": "stdlib json (BlackSheep default)",
},
"robyn": {
"language": "Python 3.14",
"server": "built-in Rust server",
"http_client": "lothc",
"db_driver": "fastpg",
"validates_body": "pydantic (native param)",
"parses_upstream": "typed (pydantic)",
"serializer": "orjson (dicts) / pydantic",
},
"flask": {
"language": "Python 3.14",
"language": "Python 3.15",
"server": "peregrine WSGI",
"http_client": "lothc (sync)",
"db_driver": "psycopg",
Expand All @@ -306,7 +297,7 @@ def _render_markdown_table(test: str, results: list[Result]) -> list[str]:
"serializer": "stdlib json",
},
"django-bolt": {
"language": "Python 3.14",
"language": "Python 3.15",
"server": "built-in Rust server",
"http_client": "lothc",
"db_driver": "fastpg",
Expand Down Expand Up @@ -612,6 +603,12 @@ def _render_report(
"",
f"_Generated {datetime.now(UTC).isoformat(timespec='seconds')}_",
"",
(
"**Per-core results:** 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)."
),
"",
"## Run configuration",
"",
"| | |",
Expand Down Expand Up @@ -654,7 +651,14 @@ def _render_report(
(
"The author of this benchmark suite is also the author of "
"[jero](https://pypi.org/project/jero/), one of the frameworks benchmarked "
"here. Every measure above -- equal resource budgets, idiomatic code per "
"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). Python-vs-Python results therefore compare "
"the frameworks. Python-vs-Go/Java/Bun results also reflect these libraries "
"versus each language's usual ones. "
"Every measure above -- 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."
Expand Down
6 changes: 3 additions & 3 deletions loadtest/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# layout (/app/vendor + /app/loadtest).
FROM alpine:3.24 AS build
RUN apk add --no-cache python3
COPY --from=ghcr.io/astral-sh/uv:0.13.5 /uv /bin/uv
COPY --from=ghcr.io/astral-sh/uv:0.13.10 /uv /bin/uv
WORKDIR /app
COPY vendor ./vendor
WORKDIR /app/loadtest
Expand All @@ -25,8 +25,8 @@ RUN apk add --no-cache python3 docker-cli wrk
# oha's release binary is static, so it runs on Alpine as-is. arm64 only, like
# the rest of this fleet (Apple Silicon locally, Graviton on EC2).
ADD --chmod=755 \
--checksum=sha256:99a790eb8c3e0feaca974bd6b32f0f8d4426a0c5b289f39e833e5b2c7529cd39 \
https://github.com/hatoo/oha/releases/download/v1.16.0/oha-linux-arm64 /usr/local/bin/oha
--checksum=sha256:0b360c858f6277a5fca691d38adbd2dbc8c344d049ddf1a12fee8a762351ea24 \
https://github.com/hatoo/oha/releases/download/v1.17.0/oha-linux-arm64 /usr/local/bin/oha
WORKDIR /app/loadtest
ENV PATH="/app/loadtest/.venv/bin:$PATH"
COPY --from=build /app/loadtest/.venv /app/loadtest/.venv
Expand Down
2 changes: 1 addition & 1 deletion loadtest/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Settings(BaseSettings):
tests: str = "test1 test2 test3 test4"
runs: int = 3
duration: str = "10s"
vus: str = "50"
vus: str = "100"
workers: int = 1
loadgen: str = "wrk"
jwt_secret: str
Expand Down
Loading