mirror of
https://github.com/metosin/reitit.git
synced 2026-02-18 00:35:55 +00:00
Server benchmarks
This commit is contained in:
parent
dc2519238a
commit
277faf48f5
2 changed files with 51 additions and 12 deletions
|
|
@ -2,9 +2,13 @@
|
||||||
(:require [criterium.core :as cc]
|
(:require [criterium.core :as cc]
|
||||||
[reitit.perf-utils :refer :all]
|
[reitit.perf-utils :refer :all]
|
||||||
|
|
||||||
|
;; aleph
|
||||||
|
[aleph.http :as http]
|
||||||
|
|
||||||
;; reitit
|
;; reitit
|
||||||
[reitit.ring :as ring]
|
[reitit.ring :as ring]
|
||||||
[muuntaja.middleware :as mm]
|
[muuntaja.core :as m]
|
||||||
|
[reitit.ring.middleware.muuntaja :as rm]
|
||||||
|
|
||||||
;; bidi-yada
|
;; bidi-yada
|
||||||
[yada.yada :as yada]
|
[yada.yada :as yada]
|
||||||
|
|
@ -14,7 +18,8 @@
|
||||||
;; defaults
|
;; defaults
|
||||||
[ring.middleware.defaults :as defaults]
|
[ring.middleware.defaults :as defaults]
|
||||||
[compojure.core :as compojure]
|
[compojure.core :as compojure]
|
||||||
[clojure.string :as str]))
|
[clojure.string :as str]
|
||||||
|
[muuntaja.middleware :as mm]))
|
||||||
|
|
||||||
;;
|
;;
|
||||||
;; start repl with `lein perf repl`
|
;; start repl with `lein perf repl`
|
||||||
|
|
@ -31,16 +36,16 @@
|
||||||
;; Memory: 16 GB
|
;; Memory: 16 GB
|
||||||
;;
|
;;
|
||||||
|
|
||||||
;; TODO: naive implementation
|
|
||||||
(defn- with-security-headers [response]
|
(defn- with-security-headers [response]
|
||||||
(update
|
(assoc
|
||||||
response
|
response
|
||||||
:headers
|
:headers
|
||||||
(fn [headers]
|
(reduce-kv
|
||||||
(-> headers
|
assoc
|
||||||
(assoc "x-frame-options" "SAMEORIGIN")
|
{"x-frame-options" "SAMEORIGIN"
|
||||||
(assoc "x-xss-protection" "1; mode=block")
|
"x-xss-protection" "1; mode=block"
|
||||||
(assoc "x-content-type-options" "nosniff")))))
|
"x-content-type-options" "nosniff"}
|
||||||
|
(:headers response))))
|
||||||
|
|
||||||
(def security-middleware
|
(def security-middleware
|
||||||
{:name ::security
|
{:name ::security
|
||||||
|
|
@ -53,7 +58,8 @@
|
||||||
(ring/router
|
(ring/router
|
||||||
["/api/ping"
|
["/api/ping"
|
||||||
{:get {:handler (fn [_] {:status 200, :body {:ping "pong"}})}}]
|
{:get {:handler (fn [_] {:status 200, :body {:ping "pong"}})}}]
|
||||||
{:data {:middleware [mm/wrap-format
|
{:data {:muuntaja (m/create (assoc m/default-options :return :bytes))
|
||||||
|
:middleware [rm/format-middleware
|
||||||
security-middleware]}})))
|
security-middleware]}})))
|
||||||
|
|
||||||
(def bidi-yada-app
|
(def bidi-yada-app
|
||||||
|
|
@ -87,7 +93,7 @@
|
||||||
|
|
||||||
(defn perf-test []
|
(defn perf-test []
|
||||||
|
|
||||||
;; 176µs
|
;; 206µs
|
||||||
(title "compojure + ring-defaults")
|
(title "compojure + ring-defaults")
|
||||||
(let [f (fn [] (defaults-app request))]
|
(let [f (fn [] (defaults-app request))]
|
||||||
(expect! (-> (f) :body slurp))
|
(expect! (-> (f) :body slurp))
|
||||||
|
|
@ -99,7 +105,7 @@
|
||||||
(expect! (-> (f) deref :body bs/to-string))
|
(expect! (-> (f) deref :body bs/to-string))
|
||||||
(cc/quick-bench (f)))
|
(cc/quick-bench (f)))
|
||||||
|
|
||||||
;; 5.0µs
|
;; 6.0µs
|
||||||
(title "reitit-ring")
|
(title "reitit-ring")
|
||||||
(let [f (fn [] (reitit-app request))]
|
(let [f (fn [] (reitit-app request))]
|
||||||
(expect! (-> (f) :body slurp))
|
(expect! (-> (f) :body slurp))
|
||||||
|
|
@ -107,3 +113,20 @@
|
||||||
|
|
||||||
(comment
|
(comment
|
||||||
(perf-test))
|
(perf-test))
|
||||||
|
|
||||||
|
(comment
|
||||||
|
|
||||||
|
;; 10198
|
||||||
|
;; http :3000/api/ping
|
||||||
|
;; wrk -d ${DURATION:="30s"} http://127.0.0.1:3000/api/ping
|
||||||
|
(http/start-server defaults-app {:port 3000})
|
||||||
|
|
||||||
|
;; 16230
|
||||||
|
;; http :3001/api/ping
|
||||||
|
;; wrk -d ${DURATION:="30s"} http://127.0.0.1:3001/api/ping
|
||||||
|
(http/start-server bidi-yada-app {:port 3001})
|
||||||
|
|
||||||
|
;; 48084
|
||||||
|
;; http :3002/api/ping
|
||||||
|
;; wrk -d ${DURATION:="30s"} http://127.0.0.1:3002/api/ping
|
||||||
|
(http/start-server reitit-app {:port 3002}))
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,9 @@
|
||||||
(for [name ["product" "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "twenty"]]
|
(for [name ["product" "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "twenty"]]
|
||||||
[(str "/" name "/:id") {:get (partial h name)}]))))
|
[(str "/" name "/:id") {:get (partial h name)}]))))
|
||||||
|
|
||||||
|
(for [name ["product" "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "twenty"]]
|
||||||
|
[(str "/" name "/:id") {:get (partial h name)}])
|
||||||
|
|
||||||
(app {:request-method :get, :uri "/product/foo"})
|
(app {:request-method :get, :uri "/product/foo"})
|
||||||
|
|
||||||
(defn routing-test []
|
(defn routing-test []
|
||||||
|
|
@ -79,3 +82,16 @@
|
||||||
(comment
|
(comment
|
||||||
(web/run app {:port 2048, :dispatch? false, :server {:always-set-keep-alive false}})
|
(web/run app {:port 2048, :dispatch? false, :server {:always-set-keep-alive false}})
|
||||||
(routing-test))
|
(routing-test))
|
||||||
|
|
||||||
|
(comment
|
||||||
|
(require '[compojure.core :as c])
|
||||||
|
(def app (apply
|
||||||
|
c/routes
|
||||||
|
(for [name ["product" "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "twenty"]]
|
||||||
|
(eval `(c/GET ~(str "/" name "/:id") [~'id] (str "Got " ~name " id " ~'id))))))
|
||||||
|
|
||||||
|
(require '[ring.adapter.jetty :as jetty])
|
||||||
|
;; 57862 / 54290
|
||||||
|
;; wrk -d ${DURATION:="30s"} http://127.0.0.1:8080/product/foo
|
||||||
|
;; wrk -d ${DURATION:="30s"} http://127.0.0.1:8080/twenty/bar
|
||||||
|
(jetty/run-jetty app {:port 8080}))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue