Skip to content

Commit 6ba61ce

Browse files
rurorujj
andauthored
uplift dependencies in clojure aleph (#10182)
* uplift dependencies in clojure aleph Removed unneeded and unmaintained libs also uplift jdk to 25 for clojure kit * update donkey deps --------- Co-authored-by: jj <[email protected]>
1 parent 69a2bff commit 6ba61ce

File tree

7 files changed

+110
-156
lines changed

7 files changed

+110
-156
lines changed
Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
1-
FROM clojure:temurin-19-lein
1+
FROM clojure:lein as lein
22
WORKDIR /aleph
33
COPY src src
44
COPY project.clj project.clj
55
RUN lein uberjar
66

7-
# HTTP server
8-
EXPOSE 8080
9-
# async-profiler HTTP-server
10-
EXPOSE 8081
11-
# JMX port
12-
EXPOSE 9999
7+
FROM openjdk:25-jdk-slim
138

14-
RUN apt update -y
15-
RUN apt install perl -y
9+
WORKDIR /aleph
10+
COPY --from=lein /aleph/target/hello-aleph-standalone.jar app.jar
1611

17-
CMD ["java", "-server", "-Xms2G", "-Xmx2G", "-XX:+UseNUMA", "-XX:+UseParallelGC", "-Djava.net.preferIPv4Stack=true", "-Dio.netty.leakDetection.level=disabled", "-jar", "target/hello-aleph-standalone.jar"]
12+
EXPOSE 8080
1813

19-
# To enable JMX and async-profiler
20-
#CMD ["java", "-XX:+UnlockDiagnosticVMOptions", "-XX:+DebugNonSafepoints", "-Djdk.attach.allowAttachSelf", "-Dcom.sun.management.jmxremote=true", "-Djava.rmi.server.hostname=0.0.0.0","-Dcom.sun.management.jmxremote.rmi.port=9999" ,"-Dcom.sun.management.jmxremote.port=9999", "-Dcom.sun.management.jmxremote.ssl=false", "-Dcom.sun.management.jmxremote.authenticate=false", "-server", "-Xms2G", "-Xmx2G", "-XX:+UseNUMA", "-XX:+UseParallelGC", "-Djava.net.preferIPv4Stack=true", "-jar", "target/hello-aleph-standalone.jar"]
14+
CMD ["java", "-server", "--enable-native-access=ALL-UNNAMED", "-XX:+UseParallelGC", "-jar", "app.jar"]
Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,12 @@
11
(defproject hello "aleph"
22
:description "Aleph benchmarks"
3-
:dependencies [[org.clojure/clojure "1.11.1"]
4-
[aleph "0.6.1"]
5-
[metosin/jsonista "0.3.7"]
6-
[hiccup "1.0.5"]
7-
[com.github.arnaudgeiser/porsas "0.0.1-alpha14"
8-
:exclusions [io.netty/netty-codec-dns
9-
io.netty/netty-codec
10-
io.netty/netty-buffer
11-
io.netty/netty-common
12-
io.netty/netty-codec-http
13-
io.netty/netty-codec-http2
14-
io.netty/netty-codec-socks
15-
io.netty/netty-handler
16-
io.netty/netty-handler-proxy
17-
io.netty/netty-transport
18-
io.netty/netty-resolver-dns
19-
io.netty/netty-resolver]]
20-
[com.clojure-goes-fast/clj-async-profiler "1.0.3"]]
3+
:dependencies [[org.clojure/clojure "1.12.3"]
4+
[aleph "0.9.3"]
5+
[metosin/jsonista "0.3.13"]
6+
[hiccup "2.0.0"]
7+
[seancorfield/next.jdbc "1.2.659"]
8+
[hikari-cp "3.3.0"]
9+
[org.postgresql/postgresql "42.7.8"]
10+
]
2111
:main hello.handler
22-
:jvm-opts ^:replace ["-Dclojure.compiler.direct-linking=true"]
2312
:aot :all)
Lines changed: 90 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,87 @@
11
(ns hello.handler
22
(:require
3-
[aleph.http :as http]
4-
[aleph.netty :as netty]
5-
[byte-streams :as bs]
6-
[clj-async-profiler.core :as prof]
7-
[hiccup.page :as hp]
8-
[hiccup.util :as hu]
9-
[jsonista.core :as json]
10-
[manifold.deferred :as d]
11-
[porsas.async :as async])
12-
(:import (clojure.lang IDeref)
13-
(io.netty.channel ChannelOption)
3+
[aleph.http :as http]
4+
[aleph.netty :as netty]
5+
[hiccup.page :as hp]
6+
[hiccup.util :as hu]
7+
[jsonista.core :as json]
8+
[manifold.deferred :as d]
9+
[next.jdbc :as jdbc]
10+
[next.jdbc.connection :as connection]
11+
[next.jdbc.result-set :as rs])
12+
13+
(:import (com.zaxxer.hikari HikariDataSource)
1414
(io.netty.buffer PooledByteBufAllocator)
15-
(java.util.function Supplier)
16-
(java.util.concurrent ThreadLocalRandom)
17-
(porsas.async Context))
15+
(io.netty.channel ChannelOption)
16+
(java.util.concurrent ThreadLocalRandom))
1817
(:gen-class))
1918

19+
(def jdbc-opts {:builder-fn rs/as-unqualified-maps})
20+
21+
(def db-spec
22+
{:jdbcUrl "jdbc:postgresql://tfb-database/hello_world?user=benchmarkdbuser&password=benchmarkdbpass"})
23+
24+
(def datasource
25+
(connection/->pool HikariDataSource db-spec))
26+
2027
(def plaintext-response
21-
{:status 200
28+
{:status 200
2229
:headers {"Content-Type" "text/plain"}
23-
:body (bs/to-byte-array "Hello, World!")})
30+
:body (.getBytes "Hello, World!")})
2431

2532
(def json-response
26-
{:status 200
33+
{:status 200
2734
:headers {"Content-Type" "application/json"}})
2835

2936
(def html-response
30-
{:status 200
37+
{:status 200
3138
:headers {"Content-Type" "text/html; charset=utf-8"}})
3239

33-
(def db-spec
34-
{:uri "postgresql://tfb-database:5432/hello_world"
35-
:user "benchmarkdbuser"
36-
:password "benchmarkdbpass"
37-
:size 1})
38-
39-
(defmacro thread-local [& body]
40-
`(let [tl# (ThreadLocal/withInitial (reify Supplier (get [_] ~@body)))]
41-
(reify IDeref (deref [_] (.get tl#)))))
4240

43-
(def pool
44-
"PostgreSQL pool of connections (`PgPool`)."
45-
(thread-local (async/pool db-spec)))
46-
47-
(defn random
41+
(defn- random
4842
"Generate a random number between 1 and 10'000."
4943
[]
5044
(unchecked-inc (.nextInt (ThreadLocalRandom/current) 10000)))
5145

52-
(defn sanitize-queries-param
53-
"Sanitizes the `queries` parameter. Clamps the value between 1 and 500.
54-
Invalid (string) values become 1."
46+
(defn- sanitize-queries-param
5547
[request]
5648
(let [queries (-> request
5749
:query-string
5850
(subs 8))
5951
n (try (Integer/parseInt queries)
60-
(catch Exception _ 1))] ; default to 1 on parse failure
52+
(catch Exception _ 1))] ; default to 1 on parse failure
6153
(cond
6254
(< n 1) 1
6355
(> n 500) 500
6456
:else n)))
6557

66-
(def ^Context
67-
query-mapper
68-
"Map each row into a record."
69-
(async/context {:row (async/rs->compiled-record)}))
7058

71-
(defn query-one-random-world
72-
"Query a random world on the database.
73-
Return a `CompletableFuture`."
74-
[]
75-
(async/query-one query-mapper
76-
@pool
77-
["SELECT id, randomnumber FROM world WHERE id=$1" (random)]))
78-
79-
(defn update-world
80-
"Update a world on the database.
81-
Return a `CompletableFuture`."
82-
[{:keys [randomNumber id]}]
83-
(async/query @pool
84-
["UPDATE world SET randomnumber=$1 WHERE id=$2" randomNumber id]))
85-
86-
(defn run-queries
59+
(defn- query-one-random-world []
60+
(jdbc/execute-one! datasource
61+
["select * from \"World\" where id = ?;" (random)]
62+
jdbc-opts))
63+
64+
(defn- update-world
65+
[{:keys [randomnumber id]}]
66+
(jdbc/execute-one! datasource
67+
["update \"World\" set randomNumber = ? where id = ? returning *;" randomnumber id]
68+
jdbc-opts))
69+
70+
(defn- run-queries
8771
"Run a number of `queries` on the database to fetch a random world.
8872
Return a `manifold.deferred`."
8973
[queries]
9074
(apply d/zip
9175
(take queries
9276
(repeatedly query-one-random-world))))
9377

94-
(defn query-fortunes
95-
"Query the fortunes on database.
96-
Return a `CompletableFuture`."
97-
[]
98-
(async/query query-mapper @pool ["SELECT id, message from FORTUNE"]))
9978

100-
(defn get-fortunes
79+
(defn query-fortunes []
80+
(jdbc/execute! datasource
81+
["select * from \"Fortune\";"]
82+
jdbc-opts))
83+
84+
(defn- get-fortunes
10185
"Fetch the full list of Fortunes from the database, sort them by the fortune
10286
message text.
10387
Return a `CompletableFuture` with the results."
@@ -106,83 +90,70 @@
10690
(fn [fortunes]
10791
(sort-by :message
10892
(conj fortunes
109-
{:id 0
93+
{:id 0
11094
:message "Additional fortune added at request time."})))))
11195

112-
(defn update-and-persist
113-
"Fetch a number of `queries` random world from the database.
114-
Compute a new `randomNumber` for each of them a return a `CompletableFuture`
115-
with the updated worlds."
116-
[queries]
96+
(defn- update-and-persist [queries]
11797
(d/chain' (run-queries queries)
11898
(fn [worlds]
119-
(let [worlds' (mapv #(assoc % :randomNumber (random)) worlds)]
99+
(let [worlds' (mapv #(assoc % :randomnumber (random)) worlds)]
120100
(d/chain' (apply d/zip (mapv update-world worlds'))
121101
(fn [_] worlds'))))))
122102

123-
(defn fortunes-hiccup
103+
(defn- fortunes-hiccup
124104
"Render the given fortunes to simple HTML using Hiccup."
125105
[fortunes]
126106
(hp/html5
127-
[:head
128-
[:title "Fortunes"]]
129-
[:body
130-
[:table
131-
[:tr
132-
[:th "id"]
133-
[:th "message"]]
134-
(for [x fortunes]
135-
[:tr
136-
[:td (:id x)]
137-
[:td (hu/escape-html (:message x))]])]]))
107+
[:head
108+
[:title "Fortunes"]]
109+
[:body
110+
[:table
111+
[:tr
112+
[:th "id"]
113+
[:th "message"]]
114+
(for [x fortunes]
115+
[:tr
116+
[:td (:id x)]
117+
[:td (hu/escape-html (:message x))]])]]))
138118

139119
(defn handler
140120
"Ring handler representing the different tests."
141121
[req]
142122
(let [uri (:uri req)]
143123
(cond
144124
(.equals "/plaintext" uri) plaintext-response
145-
(.equals "/json" uri) (assoc json-response
146-
:body (json/write-value-as-bytes {:message "Hello, World!"}))
147-
(.equals "/db" uri) (-> (query-one-random-world)
148-
(d/chain (fn [world]
149-
(assoc json-response
150-
:body (json/write-value-as-bytes world)))))
151-
(.equals "/queries" uri) (-> (sanitize-queries-param req)
152-
(run-queries)
153-
(d/chain (fn [worlds]
154-
(assoc json-response
155-
:body (json/write-value-as-bytes worlds)))))
156-
(.equals "/fortunes" uri) (d/chain' (get-fortunes)
157-
fortunes-hiccup
158-
(fn [body]
159-
(assoc html-response :body body)))
160-
(.equals "/updates" uri) (-> (sanitize-queries-param req)
161-
(update-and-persist)
162-
(d/chain (fn [worlds]
163-
(assoc json-response
164-
:body (json/write-value-as-bytes worlds)))))
165-
:else {:status 404})))
166-
167-
;;;
125+
(.equals "/json" uri) (assoc json-response
126+
:body (json/write-value-as-bytes {:message "Hello, World!"}))
127+
(.equals "/db" uri) (-> (query-one-random-world)
128+
(d/chain (fn [world]
129+
(assoc json-response
130+
:body (json/write-value-as-bytes world)))))
131+
(.equals "/queries" uri) (-> (sanitize-queries-param req)
132+
(run-queries)
133+
(d/chain (fn [worlds]
134+
(assoc json-response
135+
:body (json/write-value-as-bytes worlds)))))
136+
(.equals "/fortunes" uri) (d/chain' (get-fortunes)
137+
fortunes-hiccup
138+
(fn [body]
139+
(assoc html-response :body body)))
140+
(.equals "/updates" uri) (-> (sanitize-queries-param req)
141+
(update-and-persist)
142+
(d/chain (fn [worlds]
143+
(assoc json-response
144+
:body (json/write-value-as-bytes worlds)))))
145+
:else {:body "Not found"
146+
:status 404})))
147+
168148

169149
(defn -main [& _]
170150
(netty/leak-detector-level! :disabled)
171-
(http/start-server handler {:port 8080
172-
:raw-stream? true
173-
:epoll? true
174-
:executor :none
151+
(println "starting server on port 8080")
152+
(http/start-server handler {:port 8080
153+
:raw-stream? true
154+
:executor :none
175155
:bootstrap-transform (fn [bootstrap]
176156
(.option bootstrap ChannelOption/ALLOCATOR PooledByteBufAllocator/DEFAULT)
177157
(.childOption bootstrap ChannelOption/ALLOCATOR PooledByteBufAllocator/DEFAULT))
178-
:pipeline-transform (fn [pipeline]
179-
(.remove pipeline "continue-handler"))})
180-
;; Uncomment to enable async-profiler
181-
#_
182-
(do
183-
(prof/profile-for 60
184-
#_
185-
{:transform (fn [s]
186-
(when-not (re-find #"(writev|__libc|epoll_wait|write|__pthread)" s)
187-
s))})
188-
(prof/serve-files 8081)))
158+
:pipeline-transform (fn [pipeline]
159+
(.remove pipeline "continue-handler"))}))

frameworks/Clojure/donkey/donkey.dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
FROM clojure:openjdk-11-lein-2.9.3 as lein
1+
FROM clojure:lein as lein
22
WORKDIR /donkey
33
COPY src src
44
COPY project.clj project.clj
55
RUN lein uberjar
66

7-
FROM openjdk:11.0.9.1-jdk-slim
7+
FROM openjdk:25-jdk-slim
88
COPY --from=lein /donkey/target/hello-donkey-standalone.jar app.jar
99

1010
EXPOSE 8080
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(defproject hello "donkey"
22
:description "Donkey Server"
3-
:dependencies [[org.clojure/clojure "1.10.1"]
4-
[com.appsflyer/donkey "0.4.1"]]
3+
:dependencies [[org.clojure/clojure "1.12.3"]
4+
[com.appsflyer/donkey "0.5.2"]]
55
:jvm-opts ^:replace ["-Dclojure.compiler.direct-linking=true"]
66
:main hello.handler
77
:aot :all)

frameworks/Clojure/kit/kit-majavat.dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ COPY . /
66

77
RUN clj -Sforce -T:build all
88

9-
FROM azul/zulu-openjdk-alpine:17
9+
FROM openjdk:25-jdk-slim
1010

1111
COPY --from=build /target/te-bench-standalone.jar /te-bench/te-bench-standalone.jar
1212

frameworks/Clojure/kit/kit.dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ COPY . /
66

77
RUN clj -Sforce -T:build all
88

9-
FROM azul/zulu-openjdk-alpine:17
9+
FROM openjdk:25-jdk-slim
1010

1111
COPY --from=build /target/te-bench-standalone.jar /te-bench/te-bench-standalone.jar
1212

0 commit comments

Comments
 (0)