|
|
@@ -1,27 +1,30 @@
|
|
|
(ns ring-http-exchange.benchmark
|
|
|
(:gen-class)
|
|
|
(:require
|
|
|
- [jsonista.core :as json]
|
|
|
[jj.majavat :as majavat]
|
|
|
[jj.majavat.renderer :refer [->StringRenderer]]
|
|
|
[jj.majavat.renderer.sanitizer :refer [->Html]]
|
|
|
- [ring-http-exchange.core :as server]
|
|
|
- [next.jdbc :as jdbc]
|
|
|
- [next.jdbc.connection :as connection])
|
|
|
+ [jj.sql.boa :as boa]
|
|
|
+ [jsonista.core :as json]
|
|
|
+ [next.jdbc.connection :as connection]
|
|
|
+ [ring-http-exchange.core :as server])
|
|
|
(:import
|
|
|
(com.zaxxer.hikari HikariDataSource)
|
|
|
- (java.util.concurrent Executors)))
|
|
|
+ (io.netty.channel.epoll EpollEventLoopGroup)))
|
|
|
|
|
|
-(def db-spec
|
|
|
- {:jdbcUrl "jdbc:postgresql://tfb-database/hello_world?user=benchmarkdbuser&password=benchmarkdbpass"})
|
|
|
+(def query-fortunes (boa/execute (boa/->NextJdbcAdapter) "fortune.sql"))
|
|
|
|
|
|
-(def datasource
|
|
|
- (connection/->pool HikariDataSource db-spec))
|
|
|
-
|
|
|
-(defn query-fortunes []
|
|
|
- (jdbc/execute! datasource
|
|
|
- ["SELECT * FROM \"Fortune\""]
|
|
|
- {:builder-fn next.jdbc.result-set/as-unqualified-lower-maps}))
|
|
|
+(def db-spec {:auto-commit true
|
|
|
+ :read-only false
|
|
|
+ :connection-timeout 30000
|
|
|
+ :validation-timeout 5000
|
|
|
+ :idle-timeout 600000
|
|
|
+ :max-lifetime 1800000
|
|
|
+ :minimum-idle 10
|
|
|
+ :maximum-pool-size 520
|
|
|
+ :minimum-pool-size 512
|
|
|
+ :register-mbeans false
|
|
|
+ :jdbcUrl "jdbc:postgresql://tfb-database/hello_world?user=benchmarkdbuser&password=benchmarkdbpass"})
|
|
|
|
|
|
(def ^:private ^:const additional-message {:id 0
|
|
|
:message "Additional fortune added at request time."})
|
|
|
@@ -37,23 +40,27 @@
|
|
|
{:renderer (->StringRenderer
|
|
|
{:sanitizer (->Html)})}))
|
|
|
|
|
|
+(defn- get-body [datasource]
|
|
|
+ (let [context (as-> (query-fortunes datasource) fortunes
|
|
|
+ (conj fortunes additional-message)
|
|
|
+ (sort-by :message fortunes))]
|
|
|
+ (render-fortune {:messages context})))
|
|
|
+
|
|
|
(defn -main
|
|
|
[& _]
|
|
|
(println "Starting server on port 8080")
|
|
|
- (server/run-http-server
|
|
|
- (fn [req]
|
|
|
- (case (req :uri)
|
|
|
- "/json" {:status 200
|
|
|
- :headers json-headers
|
|
|
- :body (json/write-value-as-bytes {:message "Hello, World!"})}
|
|
|
- "/fortunes" (let [input (as-> (query-fortunes) fortunes
|
|
|
- (conj fortunes additional-message)
|
|
|
- (sort-by :message fortunes))
|
|
|
- body (render-fortune {:messages input})]
|
|
|
- {:status 200
|
|
|
- :headers fortune-headers
|
|
|
- :body body})
|
|
|
- plaintext-response))
|
|
|
- {:port 8080
|
|
|
- :host "0.0.0.0"
|
|
|
- :executor (Executors/newVirtualThreadPerTaskExecutor)}))
|
|
|
+ (let [datasource (connection/->pool HikariDataSource db-spec)]
|
|
|
+ (server/run-http-server
|
|
|
+ (fn [req]
|
|
|
+ (case (req :uri)
|
|
|
+ "/json" {:status 200
|
|
|
+ :headers json-headers
|
|
|
+ :body (json/write-value-as-bytes {:message "Hello, World!"})}
|
|
|
+ "/fortunes" (let [body (get-body datasource)]
|
|
|
+ {:status 200
|
|
|
+ :headers fortune-headers
|
|
|
+ :body body})
|
|
|
+ plaintext-response))
|
|
|
+ {:port 8080
|
|
|
+ :host "0.0.0.0"
|
|
|
+ :executor (EpollEventLoopGroup.)})))
|