Kest
Benchmarks
HTTP engines, dispatch cost and ORM against hand-written code, with the caveats.
First measurements of Kest. Read the caveats: this is one laptop, with the load generator on the same machine, and each HTTP figure is a single run.
Reproduce with bench/scripts/run-http.sh and ./gradlew :bench:ormbench (the ORM one needs PostgreSQL: tools/test-infra.sh up db).
Machine: Apple M2 Pro (10 cores), 16 GB, macOS, JDK 21 (JetBrains Runtime). Servers run with -Xms512m -Xmx512m, one JVM each, the load generator in a separate JVM.
Netty: 4.2.0 with the NIO transport (the macOS native kqueue transport is not on the classpath, so these numbers are not what Linux with epoll would give).
HTTP engines
The same four endpoints written three ways, so the framework's own cost is visible:
raw-* is hand-written against Netty / the JDK server with no framework (the ceiling); kest-* is a Kest controller. 64 keep-alive connections, closed loop (the next request is sent when the previous answer arrives),
5 s warm-up then 10 s measured. "CPU" is the server process's CPU time during the measured window divided by requests served (includes JIT and GC threads).
| Server | Endpoint | Requests/s | p50 | p99 | p99.9 | Server CPU per request |
|---|---|---|---|---|---|---|
| raw Netty (event loop) | GET /plaintext | 77,212 | 0.80 ms | 1.6 ms | 3.9 ms | 21.4 µs |
| raw Netty | GET /json | 77,811 | 0.80 ms | 1.5 ms | 3.1 ms | 21.1 µs |
| raw Netty | GET /param/42 | 74,697 | 0.80 ms | 2.0 ms | 6.4 ms | 22.2 µs |
| Kest on Netty, event-loop dispatch | GET /plaintext | 75,881 | 0.81 ms | 1.7 ms | 4.3 ms | 23.4 µs |
| Kest, event loop | GET /json | 76,502 | 0.80 ms | 1.6 ms | 3.7 ms | 23.7 µs |
| Kest, event loop | GET /param/42 | 78,243 | 0.80 ms | 1.2 ms | 3.0 ms | 23.2 µs |
| Kest, event loop | POST /echo (JSON in, JSON out) | 75,959 | 0.81 ms | 1.6 ms | 4.5 ms | 27.0 µs |
| Kest on Netty, virtual-thread dispatch (default) | GET /plaintext | 57,211 | 0.87 ms | 7.2 ms | 23.5 ms | 46.2 µs |
| Kest, virtual threads | GET /json | 59,275 | 0.85 ms | 8.6 ms | 24.8 ms | 57.3 µs |
| Kest, virtual threads | GET /param/42 | 68,845 | 0.85 ms | 4.3 ms | 15.5 ms | 58.9 µs |
| Kest, virtual threads | POST /echo | 67,494 | 0.84 ms | 4.6 ms | 13.7 ms | 57.4 µs |
raw JDK HttpServer | GET /plaintext | 50,100 | 1.25 ms | 1.9 ms | 3.5 ms | 39.8 µs |
| raw JDK | GET /json | 49,828 | 1.25 ms | 2.1 ms | 4.9 ms | 39.5 µs |
| raw JDK | GET /param/42 | 47,932 | 1.27 ms | 2.5 ms | 9.1 ms | 40.4 µs |
| Kest on the JDK engine | GET /plaintext | 48,928 | 1.26 ms | 2.2 ms | 7.4 ms | 41.3 µs |
| Kest, JDK engine | GET /json | 49,023 | 1.26 ms | 2.3 ms | 6.0 ms | 42.6 µs |
| Kest, JDK engine | GET /param/42 | 48,013 | 1.27 ms | 2.5 ms | 4.4 ms | 43.2 µs |
| Kest, JDK engine | POST /echo | 49,712 | 1.26 ms | 2.0 ms | 4.1 ms | 45.7 µs |
What the numbers say
- The framework itself is cheap. On the event loop Kest costs 23-24 µs of CPU per GET against 21-22 µs for hand-written Netty: about 8-12 % more CPU, with the same throughput. That price buys routing, parameter binding, guards, pipes, JSON, error handling. The JDK engine shows the same thing (41-43 µs against 40 µs, 3-8 %).
- The default dispatch is the expensive part. With one virtual thread per request (the default, so blocking handlers are safe) CPU per request is 2.0-2.7x the event-loop figure, throughput drops 10-25 %, and the tail gets much worse (p99 4-9 ms against 1.2-1.7 ms; p99.9 14-25 ms). The cost is moving every request from the Netty event loop to a virtual thread and back (two thread hand-offs and a selector wake-up per request).
- Use
Dispatch.EVENT_LOOPfor handlers that never block (no JDBC, no remote calls). Keep the default for handlers that do. - This is what
@NonBlockingaddresses, see the next section.
- Use
- Throughput of the fast servers is capped by the load generator itself (about 77k requests/s on this machine), so for them CPU per request is the number to trust, not requests/s.
- The JDK engine is fine for tests and small services (about 48k requests/s here) but costs roughly twice the CPU of the event-loop Netty path.
Dispatch cost and @NonBlocking
The cost of the default dispatch is the hand-off from the Netty I/O thread to a virtual thread and back. It cannot be removed for a handler that blocks, but a handler that never blocks does not need it.
@NonBlocking on a route or controller (a promise that the handler and everything on its route never block) makes the Netty engine run it directly on the I/O thread. Middleware must also declare itself non-blocking
(the built-in CORS, compression, security-header and CSRF middleware do; session and static-file middleware do not). Routes without the annotation are untouched.
Same machine, same method as above, one run per cell (bench/scripts/run-dispatch.sh):
| Route on the default Netty engine | Requests/s | p50 | p99 | p99.9 | Server CPU per request |
|---|---|---|---|---|---|
| GET /plaintext (virtual thread) | 72,697 | 0.85 ms | 2.1 ms | 6.0 ms | 46.7 µs |
| GET /json (virtual thread) | 72,568 | 0.85 ms | 2.0 ms | 6.0 ms | 51.6 µs |
| GET /param/42 (virtual thread) | 71,885 | 0.85 ms | 2.2 ms | 6.6 ms | 50.3 µs |
| POST /echo (virtual thread) | 71,127 | 0.84 ms | 3.6 ms | 9.7 ms | 59.2 µs |
GET /nb/plaintext (@NonBlocking) | 77,816 | 0.80 ms | 1.4 ms | 2.9 ms | 23.6 µs |
| GET /nb/json | 78,334 | 0.80 ms | 1.2 ms | 2.6 ms | 24.1 µs |
| GET /nb/param/42 | 78,187 | 0.80 ms | 1.3 ms | 2.6 ms | 23.7 µs |
| POST /nb/echo | 78,326 | 0.80 ms | 1.2 ms | 2.5 ms | 25.9 µs |
| (reference) raw Netty, GET /json | 74,877 | 0.81 ms | 2.0 ms | 4.3 ms | 21.5 µs |
- A
@NonBlockingroute costs 24-26 µs of CPU per request, the same as the event-loop dispatch and about half the virtual-thread figure (47-59 µs), and its tail latency drops to match. - Why the default stays on virtual threads: a handler that really blocks (here a 2 ms sleep, standing in for a database call) does 19,077 requests/s on virtual threads, whose waits overlap, but only 3,539 requests/s (p50 15.5 ms against 3.0 ms) when run on the I/O threads, which stall. Marking a blocking handler
@NonBlockingis a mistake, and the framework cannot detect it. - The virtual-thread path itself was not made cheaper; the gain comes from skipping it where that is safe.
Caveats
- One run per cell. Variance is real: in an earlier full run the same virtual-thread Netty figures were 71-74k requests/s with p99 of 1.2-2.8 ms (against 57-69k and 4-9 ms above), and raw Netty was 81k. Differences under about 10 % between rows are not meaningful; the 2x CPU gap and the tail difference are.
- The load generator shares the machine with the servers, so they compete for CPU.
- The JDK server closes keep-alive connections periodically; the generator reconnects (13 times per run) and that is not counted as an error.
- Plain-text and small-JSON endpoints only. Nothing here says anything about large bodies, TLS, HTTP/2, or many thousands of connections.
- Not compared against Spring, Ktor, Vert.x, Helidon or Javalin. A fair comparison needs the same machine, the same load generator and the same endpoints for each; the harness is written to make that possible, but it has not been done.
ORM
Kest repositories against the same operations hand-written with JDBC (same HikariCP pool size 16, same prepared SQL, same result mapping by column index), on PostgreSQL 16 in Docker over localhost. Each cell is the mean of two phases, run in the order JDBC, Kest, Kest, JDBC so neither side benefits from running first. 2 s warm-up and 4 s measured per phase.
| Operation | Threads | JDBC (ops/s) | Kest (ops/s) | Kest / JDBC |
|---|---|---|---|---|
| findById | 1 | 8,274 | 9,591 | 115.9 % |
| findByEmail (derived query) | 1 | 9,745 | 9,841 | 101.0 % |
| list 100 rows | 1 | 6,801 | 6,849 | 100.7 % |
| update with version check | 1 | 1,162 | 1,017 | 87.5 % |
| insert, generated key | 1 | 1,279 | 1,263 | 98.7 % |
| batch insert 100 (one transaction) | 1 | 359 | 367 | 102.2 % |
| findById | 16 | 38,159 | 37,477 | 98.2 % |
| findByEmail (derived query) | 16 | 40,328 | 35,186 | 87.2 % |
| list 100 rows | 16 | 25,882 | 25,934 | 100.2 % |
| update with version check | 16 | 8,233 | 10,775 | 130.9 % |
| insert, generated key | 16 | 10,291 | 9,411 | 91.4 % |
| batch insert 100 (one transaction) | 16 | 1,850 | 2,015 | 108.9 % |
Reading it: the ratios scatter between 87 % and 131 % and average 102 %: at this resolution Kest is indistinguishable from hand-written JDBC. That is what you expect when each operation is dominated by a database round trip (about 100 µs or more) and the mapping code is generated, not reflective. Do not read a "win" into any single cell above 100 %: it is noise, and so is each cell below.
The first attempt at this benchmark produced misleading numbers because of three mistakes in the benchmark itself (shared rows between the two implementations, JDBC not reading back generated keys while Kest does, and JDBC always running first). They are fixed above.
Caveats
- Local PostgreSQL in a container: the round trip is short, so any per-call overhead is easier to see than against a remote database, and still none shows.
- Single table, small rows, no joins. The relation loader (
fetch) and MongoDB were not benchmarked. - Not compared against Exposed, jOOQ, Hibernate or Spring Data, which is what
docs/orm-design.mdpromised; only against hand-written JDBC (the ceiling).