-
Notifications
You must be signed in to change notification settings - Fork 0
/
ring_request.clj
152 lines (127 loc) · 5.78 KB
/
ring_request.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
(ns benchmark.ring-request
(:require [immutant.web.internal.ring :as immutant]
[immutant.web.internal.undertow]
[java-http-clj.core :as http]
[ring.adapter.undertow.request :as luminus]
[strojure.ring-undertow.impl.request :as impl]
[strojure.undertow.api.types :as types]
[strojure.undertow.handler :as handler]
[strojure.undertow.server :as server]
[strojure.zmap.core :as zmap])
(:import (io.undertow.server HttpServerExchange)))
(set! *warn-on-reflection* true)
;;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
(declare ^:private -exchange)
(def ^:private -handler
(handler/with-exchange
(fn [exchange]
#_:clj-kondo/ignore
(def ^HttpServerExchange -exchange exchange))))
(def ^:private -request-headers
{"User-Agent",,,,, "Mozilla /5.0 (Windows NT 10.0 ; Win64; x64; rv:107.0) Gecko/20100101 Firefox/107.0"
"Accept",,,,,,,,, "text/html, application/xhtml+xml, application/xml ;q=0.9,image/avif,image/webp,*/*;q=0.8"
"Accept-Language" "ru, en ;q=0.8,de;q=0.6,uk;q=0.4,be;q=0.2"
"Accept-Encoding" "gzip, deflate, br"
"Cookie",,,,,,,,, "secret=dfe83f04-2d13-4914-88dd-5005ac317936"
"Upgrade-Insecure-Requests" "1"})
(with-open [server (server/start {:handler -handler :port 0})]
(http/send {:uri (str "http://localhost:"
(-> server types/bean* :listenerInfo first :address :port)
"/path?param=value")
:headers -request-headers})
(println "\nServer exchange:" -exchange "\n"))
;;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
;; ## Build request
(comment
(impl/build-request -exchange)
; Execution time mean : 697,643335 ns
; Execution time std-deviation : 16,956270 ns
; Execution time lower quantile : 678,883685 ns ( 2,5%)
; Execution time upper quantile : 721,282042 ns (97,5%)
(luminus/build-exchange-map -exchange)
; Execution time mean : 4,317021 µs
; Execution time std-deviation : 60,236093 ns
; Execution time lower quantile : 4,237576 µs ( 2,5%)
; Execution time upper quantile : 4,391014 µs (97,5%)
;; Immutant is fast but it returns java.util.Map which is converted on change.
(immutant/ring-request-map -exchange)
; Execution time mean : 678,031637 ns
; Execution time std-deviation : 61,080265 ns
; Execution time lower quantile : 623,968094 ns ( 2,5%)
; Execution time upper quantile : 745,429229 ns (97,5%)
)
;;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
;; ## Build request + add 1 key
(comment
(-> (impl/build-request -exchange)
(assoc :a 1))
; Execution time mean : 880,222280 ns
; Execution time std-deviation : 24,823099 ns
; Execution time lower quantile : 847,510288 ns ( 2,5%)
; Execution time upper quantile : 907,850522 ns (97,5%)
(-> (luminus/build-exchange-map -exchange)
(assoc :a 1))
; Execution time mean : 4,493658 µs
; Execution time std-deviation : 102,608011 ns
; Execution time lower quantile : 4,329457 µs ( 2,5%)
; Execution time upper quantile : 4,592031 µs (97,5%)
(-> (immutant/ring-request-map -exchange)
(assoc :a 1))
; Execution time mean : 2,304262 µs
; Execution time std-deviation : 45,636796 ns
; Execution time lower quantile : 2,259740 µs ( 2,5%)
; Execution time upper quantile : 2,363342 µs (97,5%)
)
;;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
;; ## Build request + get header
(comment
(-> (impl/build-request -exchange)
:headers (get "cookie"))
; Execution time mean : 750,271305 ns
; Execution time std-deviation : 25,946630 ns
; Execution time lower quantile : 722,563834 ns ( 2,5%)
; Execution time upper quantile : 785,599982 ns (97,5%)
(-> (luminus/build-exchange-map -exchange)
:headers (get "cookie"))
; Execution time mean : 4,483495 µs
; Execution time std-deviation : 82,596506 ns
; Execution time lower quantile : 4,389776 µs ( 2,5%)
; Execution time upper quantile : 4,581021 µs (97,5%)
(-> (immutant/ring-request-map -exchange)
:headers (get "cookie"))
; Execution time mean : 8,169952 µs
; Execution time std-deviation : 219,081729 ns
; Execution time lower quantile : 7,831553 µs ( 2,5%)
; Execution time upper quantile : 8,376565 µs (97,5%)
)
;;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
;; ## Various operations with exchange
(comment
(.getRequestHeaders -exchange)
;Execution time mean : 5,305030 ns
(.get (.getRequestHeaders -exchange) "Host")
;Execution time mean : 26,361309 ns
(.getHostPort -exchange)
;Execution time mean : 36,396907 ns
(.getDestinationAddress -exchange)
;Execution time mean : 52,344103 ns
(.getPort (.getDestinationAddress -exchange))
;Execution time mean : 53,875708 ns
(zmap/delay (.getPort (.getDestinationAddress -exchange)))
;Execution time mean : 30,838876 ns
(.getHostName -exchange)
;Execution time mean : 30,924280 ns
(.getHostAddress (.getAddress (.getSourceAddress -exchange)))
;Execution time mean : 90,639418 ns
(.getRequestScheme -exchange)
;Execution time mean : 5,233583 ns
(.getResolvedPath -exchange)
;Execution time mean : 5,686585 ns
(.getRequestURI -exchange)
;Execution time mean : 5,320602 ns
(.getRequestPath -exchange)
;Execution time mean : 4,877129 ns
(.getQueryString -exchange)
;Execution time mean : 5,775425 ns
)
;;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,