Kest

Search

Search the documentation

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).

ServerEndpointRequests/sp50p99p99.9Server CPU per request
raw Netty (event loop)GET /plaintext77,2120.80 ms1.6 ms3.9 ms21.4 µs
raw NettyGET /json77,8110.80 ms1.5 ms3.1 ms21.1 µs
raw NettyGET /param/4274,6970.80 ms2.0 ms6.4 ms22.2 µs
Kest on Netty, event-loop dispatchGET /plaintext75,8810.81 ms1.7 ms4.3 ms23.4 µs
Kest, event loopGET /json76,5020.80 ms1.6 ms3.7 ms23.7 µs
Kest, event loopGET /param/4278,2430.80 ms1.2 ms3.0 ms23.2 µs
Kest, event loopPOST /echo (JSON in, JSON out)75,9590.81 ms1.6 ms4.5 ms27.0 µs
Kest on Netty, virtual-thread dispatch (default)GET /plaintext57,2110.87 ms7.2 ms23.5 ms46.2 µs
Kest, virtual threadsGET /json59,2750.85 ms8.6 ms24.8 ms57.3 µs
Kest, virtual threadsGET /param/4268,8450.85 ms4.3 ms15.5 ms58.9 µs
Kest, virtual threadsPOST /echo67,4940.84 ms4.6 ms13.7 ms57.4 µs
raw JDK HttpServerGET /plaintext50,1001.25 ms1.9 ms3.5 ms39.8 µs
raw JDKGET /json49,8281.25 ms2.1 ms4.9 ms39.5 µs
raw JDKGET /param/4247,9321.27 ms2.5 ms9.1 ms40.4 µs
Kest on the JDK engineGET /plaintext48,9281.26 ms2.2 ms7.4 ms41.3 µs
Kest, JDK engineGET /json49,0231.26 ms2.3 ms6.0 ms42.6 µs
Kest, JDK engineGET /param/4248,0131.27 ms2.5 ms4.4 ms43.2 µs
Kest, JDK enginePOST /echo49,7121.26 ms2.0 ms4.1 ms45.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_LOOP for handlers that never block (no JDBC, no remote calls). Keep the default for handlers that do.
    • This is what @NonBlocking addresses, see the next section.
  • 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 engineRequests/sp50p99p99.9Server CPU per request
GET /plaintext (virtual thread)72,6970.85 ms2.1 ms6.0 ms46.7 µs
GET /json (virtual thread)72,5680.85 ms2.0 ms6.0 ms51.6 µs
GET /param/42 (virtual thread)71,8850.85 ms2.2 ms6.6 ms50.3 µs
POST /echo (virtual thread)71,1270.84 ms3.6 ms9.7 ms59.2 µs
GET /nb/plaintext (@NonBlocking)77,8160.80 ms1.4 ms2.9 ms23.6 µs
GET /nb/json78,3340.80 ms1.2 ms2.6 ms24.1 µs
GET /nb/param/4278,1870.80 ms1.3 ms2.6 ms23.7 µs
POST /nb/echo78,3260.80 ms1.2 ms2.5 ms25.9 µs
(reference) raw Netty, GET /json74,8770.81 ms2.0 ms4.3 ms21.5 µs
  • A @NonBlocking route 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 @NonBlocking is 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.

OperationThreadsJDBC (ops/s)Kest (ops/s)Kest / JDBC
findById18,2749,591115.9 %
findByEmail (derived query)19,7459,841101.0 %
list 100 rows16,8016,849100.7 %
update with version check11,1621,01787.5 %
insert, generated key11,2791,26398.7 %
batch insert 100 (one transaction)1359367102.2 %
findById1638,15937,47798.2 %
findByEmail (derived query)1640,32835,18687.2 %
list 100 rows1625,88225,934100.2 %
update with version check168,23310,775130.9 %
insert, generated key1610,2919,41191.4 %
batch insert 100 (one transaction)161,8502,015108.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.md promised; only against hand-written JDBC (the ceiling).