Skip to content

Commit 0e4c956

Browse files
author
jj
committed
Add majavat templating engine
Only clojure ring-http-exchange and kit are impacted
1 parent 53e2e9d commit 0e4c956

File tree

17 files changed

+217
-227
lines changed

17 files changed

+217
-227
lines changed

frameworks/Clojure/kit/benchmark_config.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,24 @@
2525
"display_name": "Kit",
2626
"notes": "",
2727
"versus": "None"
28+
},
29+
"majavat": {
30+
"fortune_url": "/majavat-fortunes",
31+
"port": 8080,
32+
"approach": "Realistic",
33+
"classification": "Platform",
34+
"database": "postgres",
35+
"framework": "None",
36+
"language": "Clojure",
37+
"flavor": "None",
38+
"orm": "Raw",
39+
"platform": "None",
40+
"webserver": "None",
41+
"os": "Linux",
42+
"database_os": "Linux",
43+
"display_name": "kit-majavat",
44+
"notes": "",
45+
"versus": "kit"
2846
}
2947
}
3048
]

frameworks/Clojure/kit/deps.edn

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
{:paths ["src/clj"
22
"resources"]
33

4-
:deps {org.clojure/clojure {:mvn/version "1.11.1"}
4+
:deps {org.clojure/clojure {:mvn/version "1.12.3"}
55

66
;; Routing
7-
metosin/reitit {:mvn/version "0.5.18"}
7+
metosin/reitit {:mvn/version "0.9.1"}
88

99
;; Ring
10-
metosin/ring-http-response {:mvn/version "0.9.3"}
11-
ring/ring-core {:mvn/version "1.9.5"}
10+
ring/ring-core {:mvn/version "1.15.3"}
1211

1312
;; Data coercion
14-
metosin/muuntaja {:mvn/version "0.6.8"}
13+
metosin/muuntaja {:mvn/version "0.6.11"}
1514

1615
;; HTML templating
17-
selmer/selmer {:mvn/version "1.12.55"}
16+
selmer/selmer {:mvn/version "1.12.62"}
17+
org.clojars.jj/majavat {:mvn/version "1.12.1"}
1818

1919
;; Database
20-
org.postgresql/postgresql {:mvn/version "42.5.1"}
20+
org.postgresql/postgresql {:mvn/version "42.7.8"}
2121

2222
;; kit Libs
23-
io.github.kit-clj/kit-core {:mvn/version "1.0.3"}
24-
io.github.kit-clj/kit-undertow {:mvn/version "1.0.4"}
25-
io.github.kit-clj/kit-sql-hikari {:mvn/version "1.0.2"}
26-
org.clojure/core.cache {:mvn/version "1.0.225"}
23+
io.github.kit-clj/kit-core {:mvn/version "1.0.9"}
24+
io.github.kit-clj/kit-undertow {:mvn/version "1.0.9"}
25+
io.github.kit-clj/kit-sql-hikari {:mvn/version "1.0.6"}
26+
org.clojure/core.cache {:mvn/version "1.1.234"}
2727

2828
}
2929

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# syntax = docker/dockerfile:1.2
2+
FROM clojure:openjdk-17 AS build
3+
4+
WORKDIR /
5+
COPY . /
6+
7+
RUN clj -Sforce -T:build all
8+
9+
FROM azul/zulu-openjdk-alpine:17
10+
11+
COPY --from=build /target/te-bench-standalone.jar /te-bench/te-bench-standalone.jar
12+
13+
EXPOSE 8080
14+
15+
ENV PORT=8080
16+
ENV JAVA_OPTS="-XX:+UseContainerSupport -Dfile.encoding=UTF-8"
17+
ENV JDBC_URL="jdbc:postgresql://tfb-database/hello_world?user=benchmarkdbuser&password=benchmarkdbpass"
18+
19+
ENTRYPOINT exec java $JAVA_OPTS -jar /te-bench/te-bench-standalone.jar

frameworks/Clojure/kit/src/clj/io/github/kit_clj/te_bench/core.clj

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@
1717

1818
;; log uncaught exceptions in threads
1919
(Thread/setDefaultUncaughtExceptionHandler
20-
(reify Thread$UncaughtExceptionHandler
21-
(uncaughtException [_ thread ex]
22-
(log/error {:what :uncaught-exception
23-
:exception ex
24-
:where (str "Uncaught exception on" (.getName thread))}))))
20+
(fn [thread ex]
21+
(log/error {:what :uncaught-exception
22+
:exception ex
23+
:where (str "Uncaught exception on" (.getName thread))})))
2524

2625
(defonce system (atom nil))
2726

frameworks/Clojure/kit/src/clj/io/github/kit_clj/te_bench/web/controllers/bench.clj

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
[clojure.core.cache :as cache]
44
[next.jdbc :as jdbc]
55
[next.jdbc.result-set :as rs]
6-
[ring.util.http-response :as http-response]
6+
[jj.majavat :as majavat]
7+
[jj.majavat.renderer :refer [->InputStreamRenderer]]
8+
[jj.majavat.renderer.sanitizer :refer [->Html]]
79
[selmer.parser :as parser]))
810

911
;; -----------
@@ -13,14 +15,25 @@
1315
(def ^:const HELLO_WORLD "Hello, World!")
1416
(def ^:const MAX_ID_ZERO_IDX 9999)
1517
(def ^:const CACHE_TTL (* 24 60 60))
16-
18+
(def ^:private render-fortune (majavat/build-renderer "html/fortunes.html"
19+
{:renderer (->InputStreamRenderer
20+
{:sanitizer (->Html)})}))
1721
(def selmer-opts {:custom-resource-path (clojure.java.io/resource "html")})
1822

19-
(defn html-response
23+
(defn selmer-html-response
2024
[template & [params]]
21-
(-> (parser/render-file template params selmer-opts)
22-
(http-response/ok)
23-
(http-response/content-type "text/html; charset=utf-8")))
25+
{:status 200
26+
:body (parser/render-file template params selmer-opts)
27+
:headers {"text/html; charset=utf-8"
28+
"Server" "Kit"}})
29+
30+
(defn majavat-html-response
31+
[context]
32+
{:status 200
33+
:body (render-fortune context)
34+
:headers {"text/html; charset=utf-8"
35+
"Server" "Kit"}})
36+
2437

2538
(defn rand-id
2639
[n]
@@ -31,7 +44,7 @@
3144
"Parse provided string value of query count, clamping values to between 1 and 500."
3245
[^String queries]
3346
(let [n (try (Integer/parseInt queries)
34-
(catch Exception _ 1))] ; default to 1 on parse failure
47+
(catch Exception _ 1))] ; default to 1 on parse failure
3548
(cond
3649
(< n 1) 1
3750
(> n 500) 500
@@ -101,7 +114,7 @@
101114

102115
(defn update-db-handler
103116
[db-conn request]
104-
(let [items (db-multi-query-world! db-conn request)]
117+
(let [items (db-multi-query-world! db-conn request)]
105118
(http-response/ok
106119
(mapv
107120
(fn [{:keys [id]}]
@@ -122,9 +135,16 @@
122135
[]
123136
(range-from-req request))))
124137

125-
(defn fortune-handler
138+
(defn selmer-fortune-handler
139+
[db-conn _request]
140+
(as-> (jdbc/execute! db-conn ["select * from \"Fortune\";"] jdbc-opts) fortunes
141+
(conj fortunes {:id 0 :message "Additional fortune added at request time."})
142+
(sort-by :message fortunes)
143+
(selmer-html-response "fortunes.html" {:messages fortunes})))
144+
145+
(defn majavat-fortune-handler
126146
[db-conn _request]
127147
(as-> (jdbc/execute! db-conn ["select * from \"Fortune\";"] jdbc-opts) fortunes
128148
(conj fortunes {:id 0 :message "Additional fortune added at request time."})
129149
(sort-by :message fortunes)
130-
(html-response "fortunes.html" {:messages fortunes})))
150+
(majavat-html-response {:messages fortunes})))
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
(ns io.github.kit-clj.te-bench.web.middleware.default-headers
2-
(:require
3-
[ring.util.http-response :as http-response]))
1+
(ns io.github.kit-clj.te-bench.web.middleware.default-headers)
42

53
(def default-headers-middleware
64
"Adds default headers required for TechEmpower benchmarks"
@@ -9,6 +7,6 @@
97
(fn [handler]
108
(fn
119
([request]
12-
(http-response/header (handler request) "Server" "Kit"))
10+
(handler request))
1311
([request respond raise]
14-
(handler request #(respond (http-response/header % "Server" "Kit")) raise)))))})
12+
(handler request respond raise)))))})

frameworks/Clojure/kit/src/clj/io/github/kit_clj/te_bench/web/routes/bench.clj

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,16 @@
1717
["/queries" {:get (partial bench/multi-db-handler db-conn)}]
1818
["/updates" {:get (partial bench/update-db-handler db-conn)}]
1919
["/cached-queries" {:get (partial bench/cached-query-handler db-conn cache)}]
20-
["/fortunes" {:get (partial bench/fortune-handler db-conn)}]])
20+
["/fortunes" {:get (partial bench/selmer-fortune-handler db-conn)}]
21+
["/majavat-fortunes" {:get (partial bench/majavat-fortune-handler db-conn)}]])
2122

2223
(defmethod ig/init-key :reitit.routes/bench
2324
[_ {:keys [base-path]
2425
:or {base-path ""}
2526
:as opts}]
2627
[base-path
2728
{:muuntaja formats/instance
28-
:middleware [;; query-params & form-params
29-
parameters/parameters-middleware
30-
;; encoding response body
29+
:middleware [parameters/parameters-middleware
3130
muuntaja/format-response-middleware
32-
;; default header middleware
3331
default-headers/default-headers-middleware]}
3432
(bench-routes opts)])

frameworks/Clojure/ring-http-exchange/benchmark_config.json

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55
"default": {
66
"json_url": "/json",
77
"plaintext_url": "/plaintext",
8+
"fortune_url": "/fortunes",
89
"port": 8080,
910
"approach": "Realistic",
1011
"classification": "Platform",
11-
"database": "None",
12+
"database": "postgres",
1213
"framework": "None",
1314
"language": "Clojure",
1415
"flavor": "None",
15-
"orm": "None",
16+
"orm": "Raw",
1617
"platform": "None",
1718
"webserver": "None",
1819
"os": "Linux",
@@ -24,14 +25,15 @@
2425
"robaho": {
2526
"json_url": "/json",
2627
"plaintext_url": "/plaintext",
28+
"fortune_url": "/fortunes",
2729
"port": 8080,
2830
"approach": "Realistic",
2931
"classification": "Platform",
30-
"database": "None",
32+
"database": "postgres",
3133
"framework": "None",
3234
"language": "Clojure",
3335
"flavor": "None",
34-
"orm": "None",
36+
"orm": "Raw",
3537
"platform": "None",
3638
"webserver": "None",
3739
"os": "Linux",
@@ -43,14 +45,15 @@
4345
"graalvm": {
4446
"json_url": "/json",
4547
"plaintext_url": "/plaintext",
48+
"fortune_url": "/fortunes",
4649
"port": 8080,
4750
"approach": "Realistic",
4851
"classification": "Platform",
49-
"database": "None",
52+
"database": "postgres",
5053
"framework": "None",
5154
"language": "Clojure",
5255
"flavor": "None",
53-
"orm": "None",
56+
"orm": "Raw",
5457
"platform": "None",
5558
"webserver": "None",
5659
"os": "Linux",
@@ -62,14 +65,15 @@
6265
"robaho-graalvm": {
6366
"json_url": "/json",
6467
"plaintext_url": "/plaintext",
68+
"fortune_url": "/fortunes",
6569
"port": 8080,
6670
"approach": "Realistic",
6771
"classification": "Platform",
68-
"database": "None",
72+
"database": "postgres",
6973
"framework": "None",
7074
"language": "Clojure",
7175
"flavor": "None",
72-
"orm": "None",
76+
"orm": "Raw",
7377
"platform": "None",
7478
"webserver": "None",
7579
"os": "Linux",

frameworks/Clojure/ring-http-exchange/config.toml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ name = "ring-http-exchange"
44
[main]
55
urls.plaintext = "/plaintext"
66
urls.json = "/json"
7+
urls.fortune = "/fortunes"
78
approach = "Realistic"
89
classification = "Platform"
9-
database = "None"
10+
database = "postgres"
1011
database_os = "Linux"
1112
os = "Linux"
1213
orm = "Raw"
@@ -18,9 +19,10 @@ versus = "httpserver"
1819
[graalvm]
1920
urls.plaintext = "/plaintext"
2021
urls.json = "/json"
22+
urls.fortune = "/fortunes"
2123
approach = "Realistic"
2224
classification = "Platform"
23-
database = "None"
25+
database = "postgres"
2426
database_os = "Linux"
2527
os = "Linux"
2628
orm = "Raw"
@@ -31,9 +33,10 @@ versus = "httpserver-graalvm"
3133
[robaho]
3234
urls.plaintext = "/plaintext"
3335
urls.json = "/json"
36+
urls.fortune = "/fortunes"
3437
approach = "Realistic"
3538
classification = "Platform"
36-
database = "None"
39+
database = "postgres"
3740
database_os = "Linux"
3841
os = "Linux"
3942
orm = "Raw"
@@ -44,9 +47,10 @@ versus = "httpserver-robaho"
4447
[robaho-graalvm]
4548
urls.plaintext = "/plaintext"
4649
urls.json = "/json"
50+
urls.fortune = "/fortunes"
4751
approach = "Realistic"
4852
classification = "Platform"
49-
database = "None"
53+
database = "postgres"
5054
database_os = "Linux"
5155
os = "Linux"
5256
orm = "Raw"

0 commit comments

Comments
 (0)