Skip to content

Commit a14b2c9

Browse files
rurorujj
andauthored
Add minor improvements in clojure (#10279)
* Revert executor service to VirtualThreadPerTaskExecutor * Fix retit base image marked async as broken * Add hiccup to kit --------- Co-authored-by: jj <[email protected]>
1 parent 5060bd2 commit a14b2c9

File tree

12 files changed

+100
-24
lines changed

12 files changed

+100
-24
lines changed

frameworks/Clojure/kit/benchmark_config.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,24 @@
4343
"display_name": "kit-majavat",
4444
"notes": "",
4545
"versus": "kit"
46+
},
47+
"hiccup": {
48+
"fortune_url": "/hiccup-fortunes",
49+
"port": 8080,
50+
"approach": "Realistic",
51+
"classification": "Platform",
52+
"database": "postgres",
53+
"framework": "None",
54+
"language": "Clojure",
55+
"flavor": "None",
56+
"orm": "Raw",
57+
"platform": "None",
58+
"webserver": "None",
59+
"os": "Linux",
60+
"database_os": "Linux",
61+
"display_name": "kit-hiccup",
62+
"notes": "",
63+
"versus": "kit"
4664
}
4765
}
4866
]

frameworks/Clojure/kit/deps.edn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
;; HTML templating
1717
selmer/selmer {:mvn/version "1.12.62"}
1818
org.clojars.jj/majavat {:mvn/version "1.12.3"}
19+
hiccup/hiccup {:mvn/version "2.0.0"}
1920

2021
;; Database
2122
org.postgresql/postgresql {:mvn/version "42.7.8"}
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 amazoncorretto:25
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/web/controllers/bench.clj

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
[next.jdbc.result-set :as rs]
66
[jj.majavat :as majavat]
77
[jj.sql.boa :as boa]
8+
[hiccup.page :as hp]
9+
[hiccup.util :as hu]
810
[jj.majavat.renderer :refer [->StringRenderer]]
911
[jj.majavat.renderer.sanitizer :refer [->Html]]
1012
[ring.util.http-response :as http-response]
@@ -20,6 +22,21 @@
2022
(def ^:private render-fortune (majavat/build-renderer "html/fortunes.html"
2123
{:renderer (->StringRenderer
2224
{:sanitizer (->Html)})}))
25+
26+
(defn render-hiccup-fortune [fortunes]
27+
(hp/html5
28+
[:head
29+
[:title "Fortunes"]]
30+
[:body
31+
[:table
32+
[:tr
33+
[:th "id"]
34+
[:th "message"]]
35+
(for [x fortunes]
36+
[:tr
37+
[:td (:id x)]
38+
[:td (hu/escape-html (:message x))]])]]))
39+
2340
(def query-fortunes (boa/execute (boa/->NextJdbcAdapter) "sql/fortunes.sql"))
2441
(def selmer-opts {:custom-resource-path (clojure.java.io/resource "html")})
2542

@@ -35,6 +52,10 @@
3552
(http-response/ok)
3653
(http-response/content-type "text/html; charset=utf-8")))
3754

55+
(defn hiccup-html-response
56+
[body]
57+
(-> (http-response/ok body)
58+
(http-response/content-type "text/html; charset=utf-8")))
3859

3960
(defn rand-id
4061
[n]
@@ -148,4 +169,12 @@
148169
(as-> (query-fortunes db-conn) fortunes
149170
(conj fortunes {:id 0 :message "Additional fortune added at request time."})
150171
(sort-by :message fortunes)
151-
(majavat-html-response {:messages fortunes})))
172+
(majavat-html-response {:messages fortunes})))
173+
174+
(defn hiccup-fortune-handler
175+
[db-conn _request]
176+
(as-> (query-fortunes db-conn) fortunes
177+
(conj fortunes {:id 0 :message "Additional fortune added at request time."})
178+
(sort-by :message fortunes)
179+
(render-hiccup-fortune fortunes)
180+
(hiccup-html-response fortunes)))

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
["/updates" {:get (partial bench/update-db-handler db-conn)}]
1919
["/cached-queries" {:get (partial bench/cached-query-handler db-conn cache)}]
2020
["/fortunes" {:get (partial bench/selmer-fortune-handler db-conn)}]
21-
["/majavat-fortunes" {:get (partial bench/majavat-fortune-handler db-conn)}]])
21+
["/majavat-fortunes" {:get (partial bench/majavat-fortune-handler db-conn)}]
22+
["/hiccup-fortunes" {:get (partial bench/hiccup-fortune-handler db-conn)}]
23+
])
2224

2325
(defmethod ig/init-key :reitit.routes/bench
2426
[_ {:keys [base-path]

frameworks/Clojure/reitit/benchmark_config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@
5454
"database_os": "Linux",
5555
"display_name": "reitit-async",
5656
"notes": "",
57-
"versus": "undertow"
57+
"versus": "undertow",
58+
"tags": ["broken"]
5859
}
5960
}]
6061
}

frameworks/Clojure/reitit/reitit-async.dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ COPY project.clj project.clj
44
COPY src src
55
RUN lein uberjar
66

7-
FROM openjdk:25-jdk-slim
7+
FROM amazoncorretto:25
88
WORKDIR /reitit
99
COPY --from=lein /reitit/target/hello-reitit-standalone.jar app.jar
1010

frameworks/Clojure/reitit/reitit-jdbc.dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ COPY project.clj project.clj
44
COPY src src
55
RUN lein uberjar
66

7-
FROM openjdk:25-jdk-slim
7+
FROM amazoncorretto:25
88
WORKDIR /reitit
99
COPY --from=lein /reitit/target/hello-reitit-standalone.jar app.jar
1010

frameworks/Clojure/reitit/reitit.dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ COPY project.clj project.clj
44
COPY src src
55
RUN lein uberjar
66

7-
FROM openjdk:25-jdk-slim
7+
FROM amazoncorretto:25
88
WORKDIR /reitit
99
COPY --from=lein /reitit/target/hello-reitit-standalone.jar app.jar
1010

frameworks/Clojure/reitit/src/hello/handler.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
:else (constantly nil))]
8585
(-> (ring/ring-handler
8686
(ring/router
87-
[["/plaintext" (exchange/constantly plain-text-handler)]
87+
[["/plaintext" plain-text-handler]
8888
["/json" json-handler]
8989
["/db" db-handler]])
9090
(ring/create-default-handler)

0 commit comments

Comments
 (0)