Skip to content
Fast & Non-blocking Clojure wrapper for Undertow
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
perf/pohjavirta Alpha1 Jul 9, 2019
src Fixed typo and updated to use protocol function instead of keyword Jul 14, 2019
test/pohjavirta Alpha1 Jul 9, 2019
.gitignore Initial commit Jul 2, 2019
README.md Tune README Jul 9, 2019
deps.edn Alpha1 Jul 9, 2019
pom.xml Release aplha3 with headers fix Jul 9, 2019

README.md

pohjavirta

Fast & Non-blocking Clojure wrapper for Undertow.

Latest version

Clojars Project

Usage

(require '[pohjavirta.server :as server])

(defn handler [_]
  {:status 200,
   :headers {"Content-Type" "text/plain"}
   :body "Hello, World!"})

;; create and start the server
(-> #'handler server/create server/start)

By default, the server listens to localhost on port 8080. Trying with HTTPie:

$ http :8080

HTTP/1.1 200 OK
Content-Length: 13
Content-Type: text/plain
Date: Tue, 02 Jul 2019 13:21:59 GMT
Server: pohjavirta

Hello, World!

Let's run some load with wrk:

$ wrk -t16 -c16 -d2s http://127.0.0.1:8080

Running 2s test @ http://127.0.0.1:8080
  16 threads and 16 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   125.96us   37.69us   1.61ms   94.95%
    Req/Sec     7.82k   530.24     8.55k    83.63%
  261483 requests in 2.10s, 32.42MB read

Requests/sec: 124548.75
Transfer/sec:     15.44MB

Async responses, using promesa:

(require '[promesa.core :as p])

(defn handler [_]
  (-> (p/promise "Hello, Async!")
      (p/then (fn [message]
                {:status 200,
                 :headers {"Content-Type" "text/plain"}
                 :body message}))))

We redefined the handler, so no need to restart the server:

$ http :8080

HTTP/1.1 200 OK
Content-Length: 13
Content-Type: text/plain
Date: Tue, 02 Jul 2019 13:27:35 GMT
Server: pohjavirta

Hello, Async!

Performance is still good:

$ wrk -t16 -c16 -d2s http://127.0.0.1:8080

Running 2s test @ http://127.0.0.1:8080
  16 threads and 16 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   144.56us   50.60us   1.86ms   96.96%
    Req/Sec     6.86k   329.73     7.34k    76.79%
  229225 requests in 2.10s, 29.51MB read

Requests/sec: 109145.61
Transfer/sec:     14.05MB

Status

WIP. See issues for Roadmap.

License

Copyright © 2019 Metosin Oy

Distributed under the Eclipse Public License, the same as Clojure.

You can’t perform that action at this time.