are there any perf tests with Promesa for Clojure?
Interested in how it performs compared to plain Java’s CompletableFuture
.
looking at the code, in -bind
, there are lookups and writes to ThreadLocal state and the Executor seems to be dynamic Var. Would be interested to see how these effect the perf.
Is there a version of then
that would run the code in the same thread? If I have understood the code, it dispatches all the actions into the ForkJoin pool.
some quick server benchmarks (with async postgresql, returning CompletableFuture
), with Promesa & calling .thenApply
directly:
(defn handler [_]
(-> (pa/query-one mapper pool ["SELECT id, randomnumber from WORLD where id=$1" (random)])
(p/then (fn [world]
{:status 200
:headers {"Content-Type" "application/json"}
:body (j/write-value-as-bytes world)}))))
; ➜ pohjavirta git:(master) ✗ wrk -t128 -c128 -d10s <http://127.0.0.1:8080>
; Running 10s test @ <http://127.0.0.1:8080>
; 128 threads and 128 connections
; Thread Stats Avg Stdev Max +/- Stdev
; Latency 3.12ms 541.67us 6.68ms 74.21%
; Req/Sec 321.14 45.55 620.00 70.40%
; 413172 requests in 10.10s, 62.57MB read
; Requests/sec: 40890.19
; Transfer/sec: 6.19MB
(defn handler [_]
(-> (pa/query-one mapper pool ["SELECT id, randomnumber from WORLD where id=$1" (random)])
(.thenApply (reify Function
(apply [_ world]
{:status 200
:headers {"Content-Type" "application/json"}
:body (j/write-value-as-bytes world)})))))
; ➜ pohjavirta git:(master) ✗ wrk -t128 -c128 -d10s <http://127.0.0.1:8080>
; Running 10s test @ <http://127.0.0.1:8080>
; 128 threads and 128 connections
; Thread Stats Avg Stdev Max +/- Stdev
; Latency 2.37ms 347.58us 7.55ms 79.36%
; Req/Sec 423.41 26.18 820.00 95.55%
; 543764 requests in 10.10s, 82.34MB read
; Requests/sec: 53814.19
; Transfer/sec: 8.15MB
one more with .thenApplyAsync
, which also dispatches:
; ➜ pohjavirta git:(master) ✗ wrk -t128 -c128 -d10s <http://127.0.0.1:8080>
; Running 10s test @ <http://127.0.0.1:8080>
; 128 threads and 128 connections
; Thread Stats Avg Stdev Max +/- Stdev
; Latency 2.55ms 1.45ms 55.75ms 97.50%
; Req/Sec 405.81 45.27 717.00 82.73%
; 521651 requests in 10.10s, 78.99MB read
; Requests/sec: 51632.87
; Transfer/sec: 7.82MB
51k TPS (Java) vs 41k TPS (Promesa), so some overhead.