Snails vs Rails API benchmark with PostgreSQL

DatabasesRuby/Rails

Spinel’s roughly 20× compute lead did not survive this Snails vs Rails API benchmark. On one x86-64 machine, Snails, a Rails-like API framework that Spinel compiles to one native binary, served 1.66× the requests of Rails + YJIT on a PostgreSQL read. On a 20-core ARM64 server the order reversed: 9,962 req/s for Snails, 13,757 for Rails + YJIT. Its clear advantages on x86-64 are memory and cold start.

Bold values passed the 5% check. Values marked † did not, so all three runs are shown and they should not be quoted as one number.

Capacity in requests per second over three runs, for Snails, Rails with YJIT and Rails with ZJIT, on JSON echo and a PostgreSQL read median of 3 runs each run † >5% apart 0 10,000 20,000 30,000 40,000 JSON echo Snails27,266–29,555 † Rails + YJIT24,638 Rails + ZJIT17,499 PostgreSQL read Snails31,827 Rails + YJIT19,176 Rails + ZJIT13,699 req/s
Capacity at saturation, 32 connections. Solid bars are medians of three runs that agree within 5%. A dashed bar marked † stops at the lowest run, and its three runs do not agree. Ticks are the three runs.
Capacity in requests per second over three runs, for Snails, Rails with YJIT and Rails with ZJIT, on JSON echo and a PostgreSQL read median each run † >5% apart 0 20,000 40,000 JSON echo Snails27,266–29,555 † Rails + YJIT24,638 Rails + ZJIT17,499 PostgreSQL read Snails31,827 Rails + YJIT19,176 Rails + ZJIT13,699 req/s
Capacity at saturation, 32 connections. Solid bars are medians of three runs that agree within 5%. A dashed bar marked † stops at the lowest run, and its three runs do not agree. Ticks are the three runs.

JSON echo benchmark

Capacity
req/s
p50
ms
p99
ms
Snails29,555
27,266
28,141 †
1.11
1.04
1.07 †
10.64
4.91
8.54 †
Rails + YJIT24,6381.263.70
6.91
33.18 †
Rails + ZJIT17,4991.3322.08
9.79
3.69 †

PostgreSQL read benchmark

Capacity
req/s
p50
ms
p99
ms
Snails31,8271.182.86
2.76
3.16 †
Rails + YJIT19,1761.49
1.38
1.40 †
3.60
Rails + ZJIT13,6991.5642.14
37.85
28.37 †

Memory, cold start and size

Peak, echo
MiB
Peak, DB
MiB
Snails30.6
21.9
22.2 †
22.2
Rails + YJIT554.5
483.8
573.3 †
561.8
Rails + ZJIT449.8
535.6
450.6 †
547.7
599.5
488.3 †
Cold start
ms
Image
MiB
Snails9.9
9.8
8.5 †
91
Rails + YJIT884.0308
Rails + ZJIT905.3308

Cold start is process launch to the first 200 from /up, inside the container, median of 5 starts per run. Image sizes are the x86-64 images. In a separate ARM64 smoke build, the Snails binary was about 4 MB.

What did not reproduce

Capacity agreed on 5 of 6 rows. p99 agreed on 1 of 6, with foreign CPU at 0.0% and no memory-pressure stalls recorded. The cause is unknown, which is why these runs are shown rather than averaged.

Latency is measured at 50% of capacity because of one single-pass calibration on the ARM64 server below (Rails + YJIT, database route, 4 workers × 5 threads, results/calibration-arm64.txt): p99 was 4.26 ms at 50% and 1,280 ms at 70%.

Results depend on the hardware

The same harness on a 20-core ARM64 server (results/run4.json), sharing the host with CI, with the server on Cortex-X925 cores and the database and load generator on Cortex-A725, reversed the order on the database route: Snails 9,962 req/s, Rails + YJIT 13,757. Both capacities agreed across three runs (spread 0.6% and 4.3%). Rails + YJIT’s p99 did not (3,961%), and 5 of that run’s 6 rows failed the full check. The 1.66× above should not be taken as portable. Measure on your own hardware.

FAQ

Is Snails faster than Rails?

On the PostgreSQL read on this x86-64 machine, yes: 1.66× Rails + YJIT and 2.32× Rails + ZJIT. On JSON echo its lead over Rails + YJIT is small and its three runs disagree. On the ARM64 server, Rails + YJIT was faster on the database route.

Does Spinel’s 20× speed-up survive in a web framework?

Not in this benchmark. The roughly 20× comes from CPU-bound programs on an ARM64 host. With HTTP and PostgreSQL in the path, Snails led Rails + YJIT by 1.66×.

How much less memory does Snails use than Rails?

On the database route, Snails peaked at 22.2 MiB and Rails + YJIT, with 4 Puma workers, at 561.8 MiB, about 25× more.

How fast does a Snails app start?

8.5–9.9 ms from process launch to the first response, against 884 ms for Rails + YJIT.

Is YJIT or ZJIT faster for a Rails API?

YJIT, in this benchmark: 1.40× ZJIT’s capacity on the PostgreSQL read and 1.41× on JSON echo.

Method

Snailsv1.2.1 (bed5b3e), Spinel 858dde41b, installer pinned by commit and SHA-256, PostgreSQL adapter, one process, one OS worker per core plus main, request logging off
Rails8.1.4.1 API on Ruby 4.0.9, Puma 8.0.2, 4 workers × 5 threads, preload_app!, jemalloc, bootsnap, request logging off
JIT--yjit or --zjit, and the app refuses to boot if any other JIT is active
DatabasePostgreSQL 15 over loopback TCP, 10,000 rows · 20 connections in total on both: one pool of 20 for Snails, 5 per Puma worker for Rails
RoutesPOST /echo returns a 1 KiB JSON body · GET /items/:id reads a random row by primary key and returns five fields
Imagespinned by digest in the harness: ruby:4.0.9-slim-bookworm, postgres:15-bookworm, debian:12, debian:12-slim
Loadwrk2 at a pinned commit, with the source patches its ARM64 build needs applied on both architectures, 2 threads, 32 keep-alive connections
CPUAMD Ryzen AI Max+ 395 (x86-64), one whole L3 group reserved: server on 4 cores, PostgreSQL on 2, wrk2 on 2, their SMT siblings idle
Isolationevery other process, kernel workqueues and 109 movable interrupts on the other L3 group (78 kernel-managed interrupts cannot move, log in results/x86-64-run1.reserve.log) · energy preference performance on the reserved cores · other services kept running, so memory bandwidth is shared
Method3 interleaved runs · 15 s warm-up → 20 s saturated for capacity → 120 s at 50% of that target’s own capacity for latency · a fresh server for each route
Validitya value is a result only if its 3 runs agree within 5% (max − min over median) · foreign CPU on the reserved cores was 0.0% in every run · 0 socket errors, 0 non-2xx, 0 timeouts · responses byte-identical across targets

Reproduce the benchmark

cd benchmarks/snails-vs-rails
export BENCH_SECRET_KEY_BASE=$(openssl rand -hex 32)
VENDOR_SHA=1ea5860cabe5be7b36f8eea3d7f844d1bc55e7e6 ./build.sh
docker build -t snails568-wrk2:bench wrk2
./parity.sh <app-port> <db-port>
./reserve.sh <benchmark-cpus> <other-cpus> 3900 -- python3 run.py \
  --server-cpus <4 cores> --db-cpus <2 cores> --load-cpus <2 cores> --sibling-cpus <their SMT siblings> \
  --app-port <app-port> --db-port <db-port> --load-fraction 0.5 --latency 120 --out results/my-run

The Rails app starts from the Snails project’s own benchmark (MIT), moved to PostgreSQL. Its published figures use SQLite and a different load generator, so they are not comparable with these.

The published run predates two harness changes. The base images and the Snails installer were pinned after it: the images to the digests then on the host, which the run itself did not record, and the installer to a commit whose file has the same checksum as the tag it used. The release of the reserved cores was also hardened. results/x86-64-run1.reserve.log is that run’s own log. Its results file and output label were renamed afterwards, with no measured value changed.

Questions? Let's Chat :)

ruby