Skip to content

Commit 6d24c1e

Browse files
jjruroru
authored andcommitted
Add crud for aleph
Also remove /db handler from ring-http-exchange
1 parent 971c9e4 commit 6d24c1e

10 files changed

Lines changed: 268 additions & 179 deletions

File tree

frameworks/aleph/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
FROM clojure:temurin-21-lein AS builder
1+
FROM clojure:temurin-26-lein-trixie AS builder
22
WORKDIR /app
33
COPY project.clj ./
44
COPY resources ./resources
55
RUN lein deps
66
COPY src ./src
77
RUN lein with-profile uberjar uberjar
88

9-
FROM eclipse-temurin:25-jre
9+
FROM eclipse-temurin:26-jre
1010
RUN mkdir -p /data/static
1111
WORKDIR /app
1212
COPY --from=builder /app/target/aleph-bench-0.1.0-standalone.jar /app/app.jar

frameworks/aleph/meta.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@
1515
"noisy",
1616
"short-lived",
1717
"mixed",
18+
"json-tls",
1819
"api-4",
1920
"api-16",
2021
"async-db",
2122
"sync-db",
2223
"static",
23-
"tcp-frag"
24+
"tcp-frag",
25+
"crud"
2426
]
2527
}

frameworks/aleph/project.clj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@
2424
io.netty/netty-transport-native-kqueue
2525
io.netty/netty-transport-native-unix-common]]
2626
[io.netty/netty-all "4.2.12.Final"]
27-
[org.clojars.jj/tassu "1.0.3"]
27+
[org.clojars.jj/tassu "1.0.4"]
2828
[org.clojars.jj/boa-sql "1.0.10"]
2929
[org.clojars.jj/async-boa-sql "1.0.10"]
3030
[org.clojars.jj/next-jdbc-adapter "1.0.10"]
3131
[org.clojars.jj/vertx-pg-client-async-boa-adapter "1.0.1"]
32-
[org.xerial/sqlite-jdbc "3.49.1.0"]
3332
[metosin/jsonista "1.0.0"]
34-
[com.github.seancorfield/next.jdbc "1.3.1093"]]
33+
34+
[org.clojure/core.cache "1.2.263"]]
3535

3636
:main ^:skip-aot aleph-bench.core
3737

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
INSERT INTO items (id, name, category, price, quantity, active, tags, rating_score, rating_count) VALUES (:id, :name, :category, :price, :quantity, true, '["bench"]', 0, 0) ON CONFLICT (id) DO UPDATE SET name = EXCLUDED.name, price = EXCLUDED.price, quantity = EXCLUDED.quantity RETURNING id
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SELECT id, name, category, price, quantity, active, tags, rating_score, rating_count FROM items WHERE category = :category ORDER BY id LIMIT :limit OFFSET :offset
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SELECT id, name, category, price, quantity, active, tags, rating_score, rating_count FROM items WHERE id = :id LIMIT 1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
UPDATE items SET name = :name, price = :price, quantity = :quantity WHERE id = :id RETURNING id

frameworks/aleph/src/aleph_bench/core.clj

Lines changed: 255 additions & 140 deletions
Large diffs are not rendered by default.

frameworks/ring-http-exchange/project.clj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
[org.clojars.jj/tassu "1.0.4"]
1010
[org.clojars.jj/boa-sql "1.0.10"]
1111
[org.clojars.jj/next-jdbc-adapter "1.0.10"]
12-
[org.xerial/sqlite-jdbc "3.49.1.0"]
1312
[org.postgresql/postgresql "42.7.5"]
1413
[metosin/jsonista "1.0.0"]
1514
[com.zaxxer/HikariCP "6.2.1"]

frameworks/ring-http-exchange/src/ring/core.clj

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
[jj.sql.boa.query.next-jdbc :refer [->NextJdbcAdapter]]
77
[jj.tassu :refer [GET POST PUT route]]
88
[jsonista.core :as json]
9-
[next.jdbc :as jdbc]
109
[ring-http-exchange.core :as server]
1110
[ring-http-exchange.ssl :as ssl])
1211
(:import (com.zaxxer.hikari HikariConfig HikariDataSource)
@@ -32,7 +31,6 @@
3231
(def ^:private ^:const dot ".")
3332
(def ^:private ^:const not-found-body "Not found")
3433
(def ^:private ^:const dataset-path "/data/dataset.json")
35-
(def ^:private ^:const db-path "/data/benchmark.db")
3634
(def ^:private ^:const static-dir "/data/static")
3735
(def ^:private ^:const param-min "min")
3836
(def ^:private ^:const param-max "max")
@@ -50,7 +48,6 @@
5048
(def ^:private json-gzip-headers {hdr-ct ct-json hdr-ce enc-gzip hdr-server server-name})
5149
(def ^:private text-headers {hdr-ct ct-text hdr-server server-name})
5250

53-
(def ^:private sqlite-query (boa/build-query (->NextJdbcAdapter) "sql/db-query"))
5451
(def ^:private pg-query (boa/build-query (->NextJdbcAdapter) "sql/pg-query"))
5552
(def ^:private crud-list-query (boa/build-query (->NextJdbcAdapter) "sql/crud-list"))
5653
(def ^:private crud-read-query (boa/build-query (->NextJdbcAdapter) "sql/crud-read"))
@@ -136,16 +133,6 @@
136133
ext (if (>= dot-index 0) (subs name dot-index) "")]
137134
(get extension-map ext ct-octet)))
138135

139-
(defn- transform-sqlite-row [row]
140-
{:id (:id row)
141-
:name (:name row)
142-
:category (:category row)
143-
:price (:price row)
144-
:quantity (:quantity row)
145-
:active (== 1 (long (:active row)))
146-
:tags (json/read-value (:tags row) json/keyword-keys-object-mapper)
147-
:rating {:score (:rating_score row) :count (:rating_count row)}})
148-
149136
(defn- transform-pg-row [row]
150137
{:id (:id row)
151138
:name (:name row)
@@ -196,10 +183,6 @@
196183
(println (str "Failed to start server on port " port
197184
": " (.getMessage e))))))))
198185

199-
(defn- init-sqlite []
200-
(when (.exists (io/file db-path))
201-
(jdbc/get-datasource {:dbtype "sqlite" :dbname db-path :read-only true})))
202-
203186
(defn- init-postgres []
204187
(when-let [url (System/getenv "DATABASE_URL")]
205188
(try
@@ -242,22 +225,10 @@
242225
(with-open [^InputStream in (:body req)]
243226
(text-response (.transferTo in (OutputStream/nullOutputStream)))))
244227

245-
(defn- query-sqlite-items [ds params]
246-
(try (mapv transform-sqlite-row (sqlite-query ds params))
247-
(catch Exception _ [])))
248-
249228
(defn- query-pg-items [ds params]
250229
(try (mapv transform-pg-row (pg-query ds params))
251230
(catch Exception _ [])))
252231

253-
(defn- handle-sqlite [ds req]
254-
(let [params (parse-qs (:query-string req))
255-
min-p (safe-parse-double (get params param-min) 10.0)
256-
max-p (safe-parse-double (get params param-max) 50.0)
257-
limit (safe-parse-long (get params param-limit) 50)
258-
items (query-sqlite-items ds {:min min-p :max max-p :limit limit})]
259-
(json-response {:items items :count (clojure.core/count items)})))
260-
261232
(defn- handle-pg [ds req]
262233
(let [params (parse-qs (:query-string req))
263234
min-p (safe-parse-double (get params param-min) 10.0)
@@ -353,13 +324,12 @@
353324
:body f}
354325
{:status 404 :body not-found-body})))
355326

356-
(defn- build-handler [{:keys [dataset sqlite-ds pg-ds]}]
327+
(defn- build-handler [{:keys [dataset pg-ds]}]
357328
(route
358329
{"/baseline11" [(GET handle-baseline-get)
359330
(POST handle-baseline-post)]
360331
"/json/:count" [(GET (fn [req] (handle-json dataset req)))]
361332
"/upload" [(POST handle-upload)]
362-
"/db" [(GET (fn [req] (handle-sqlite sqlite-ds req)))]
363333
"/async-db" [(GET (fn [req] (handle-pg pg-ds req)))]
364334
"/crud/items" [(GET (fn [req] (handle-crud-list pg-ds req)))
365335
(POST (fn [req] (handle-crud-create pg-ds req)))]
@@ -371,7 +341,6 @@
371341
(defn -main [& _]
372342
(let [dataset (load-json (or (System/getenv "DATASET_PATH") dataset-path))
373343
handler (build-handler {:dataset dataset
374-
:sqlite-ds (init-sqlite)
375344
:pg-ds (init-postgres)})]
376345
(start-server! handler plain-port)
377346
(start-server! handler tls-port (load-ssl-context))))

0 commit comments

Comments
 (0)