This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-07-05
Channels
- # announcements (13)
- # aws (1)
- # bangalore-clj (4)
- # beginners (66)
- # boot (11)
- # calva (27)
- # cider (27)
- # clj-kondo (76)
- # cljdoc (6)
- # cljs-dev (38)
- # clojars (3)
- # clojure (143)
- # clojure-dev (2)
- # clojure-europe (6)
- # clojure-greece (10)
- # clojure-italy (10)
- # clojure-nl (5)
- # clojure-norway (2)
- # clojure-sweden (1)
- # clojure-uk (19)
- # clojurescript (49)
- # cursive (13)
- # datomic (14)
- # duct (6)
- # figwheel-main (3)
- # fulcro (31)
- # funcool (7)
- # jobs (3)
- # keechma (142)
- # liberator (1)
- # off-topic (15)
- # om (2)
- # reagent (1)
- # reitit (2)
- # remote-jobs (1)
- # rewrite-clj (73)
- # shadow-cljs (21)
- # spacemacs (18)
- # sql (5)
- # tools-deps (10)
- # yada (1)
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
; Running 10s test @
; 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
; Running 10s test @
; 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
; Running 10s test @
; 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