Coder Social home page Coder Social logo

pohjavirta's Introduction

pohjavirta

Fast & Non-blocking Clojure wrapper for Undertow.

STATUS: Pre-alpha, in design and prototyping phase.

Latest version

Clojars Project

Usage

(require '[pohjavirta.server :as server])
(require '[jsonista.core :as j])

(defn handler [_]
  {:status 200
   :headers {"Content-Type" "application/json"}
   :body (j/write-value-as-bytes {:message "hello"})})

;; 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: 19
Content-Type: application/json
Date: Sun, 29 Sep 2019 17:50:17 GMT
Server: pohjavirta

{
    "message": "hello"
}

Let's run some load with wrk:

~ wrk -t2 -c16 -d10s http://127.0.0.1:8080
Running 10s test @ http://127.0.0.1:8080
  2 threads and 16 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   106.47us   52.47us   3.20ms   98.73%
    Req/Sec    70.89k     2.49k   75.84k    79.21%
  1424471 requests in 10.10s, 199.70MB read
Requests/sec: 141036.08
Transfer/sec:     19.77MB

Async responses, using promesa:

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

(defn handler [_]
  (-> (a/promise {:message "async"})
      (a/then (fn [message]
                {:status 200,
                 :headers {"Content-Type" "application/json"}
                 :body (j/write-value-as-bytes message)}))))

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

~ http :8080
HTTP/1.1 200 OK
Content-Length: 19
Content-Type: application/json
Date: Sun, 29 Sep 2019 18:00:35 GMT
Server: pohjavirta

{
    "message": "async"
}

Performance is still good:

~ wrk -t2 -c16 -d10s http://127.0.0.1:8080
Running 10s test @ http://127.0.0.1:8080
  2 threads and 16 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   106.86us   33.93us   2.15ms   94.69%
    Req/Sec    70.41k     2.38k   78.25k    76.24%
  1414188 requests in 10.10s, 198.26MB read
Requests/sec: 140017.14
Transfer/sec:     19.63MB

Status

WIP. See issues for Roadmap.

License

Copyright © 2019 Metosin Oy

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

pohjavirta's People

Contributors

dependabot[bot] avatar ikitommi avatar kalekale avatar nikolap avatar plexus avatar rarous avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pohjavirta's Issues

How do you run tests?

Interested in contributing, but clj -A:test just puts me in a REPL and I don't know how to proceed.

Support request body

When doing a POST request the :body in the request map is nil.

  :body (if (.isBlocking exchange) (.getInputStream exchange))

Build instructions

Hey. The project has some Java code, but no instructions on how to build it.

Performance

Screenshot_20210720-051317_Chrome

The http webserver benchmark results went a lot faster for many webservers. It is amazing to see reitit/pohjavirta in the too league.

I hope one day this project gets to production stage :-)
Dotnet.core has already achieved super fast speed.. time for clojure to do the same.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.