diff --git a/frameworks/Kotlin/hexagon/.dockerignore b/frameworks/Kotlin/hexagon/.dockerignore new file mode 100644 index 00000000000..5b154f2de67 --- /dev/null +++ b/frameworks/Kotlin/hexagon/.dockerignore @@ -0,0 +1,2 @@ + +**/build/ diff --git a/frameworks/Kotlin/hexagon/benchmark_config.json b/frameworks/Kotlin/hexagon/benchmark_config.json index 4bcc8b23f66..d5134ade6c8 100644 --- a/frameworks/Kotlin/hexagon/benchmark_config.json +++ b/frameworks/Kotlin/hexagon/benchmark_config.json @@ -136,6 +136,75 @@ "notes": "http://hexagonkt.com", "versus": "netty" }, + "netty-native": { + "json_url": "/json", + "db_url": "/db", + "query_url": "/query?queries=", + "fortune_url": "/fortunes", + "update_url": "/update?queries=", + "cached_query_url": "/cached-queries?count=", + "plaintext_url": "/plaintext", + "port": 9090, + "approach": "Realistic", + "classification": "Micro", + "database": "postgres", + "framework": "Hexagon", + "language": "Kotlin", + "orm": "Raw", + "platform": "Netty", + "webserver": "None", + "os": "Linux", + "database_os": "Linux", + "display_name": "Hexagon Netty Native PostgreSQL", + "notes": "http://hexagonkt.com", + "versus": "netty" + }, + "netty-async-pgclient": { + "json_url": "/json", + "db_url": "/db", + "query_url": "/query?queries=", + "fortune_url": "/fortunes", + "update_url": "/update?queries=", + "cached_query_url": "/cached-queries?count=", + "plaintext_url": "/plaintext", + "port": 9090, + "approach": "Realistic", + "classification": "Micro", + "database": "postgres", + "framework": "Hexagon", + "language": "Kotlin", + "orm": "Raw", + "platform": "Netty", + "webserver": "None", + "os": "Linux", + "database_os": "Linux", + "display_name": "Hexagon Netty Async PgClient", + "notes": "http://hexagonkt.com", + "versus": "netty" + }, + "vertx-pgclient": { + "json_url": "/json", + "db_url": "/db", + "query_url": "/query?queries=", + "fortune_url": "/fortunes", + "update_url": "/update?queries=", + "cached_query_url": "/cached-queries?count=", + "plaintext_url": "/plaintext", + "port": 9090, + "approach": "Realistic", + "classification": "Micro", + "database": "postgres", + "framework": "Hexagon", + "language": "Kotlin", + "orm": "Raw", + "platform": "Vertx", + "webserver": "None", + "os": "Linux", + "database_os": "Linux", + "display_name": "Hexagon Vertx PgClient", + "notes": "http://hexagonkt.com", + "versus": "vertx" + }, "tomcat": { "json_url": "/json", "db_url": "/db", diff --git a/frameworks/Kotlin/hexagon/build.gradle b/frameworks/Kotlin/hexagon/build.gradle index 4aad4ab8f98..755096930bc 100644 --- a/frameworks/Kotlin/hexagon/build.gradle +++ b/frameworks/Kotlin/hexagon/build.gradle @@ -1,6 +1,7 @@ plugins { - id "org.jetbrains.kotlin.jvm" version "1.8.10" apply false + id "org.jetbrains.kotlin.jvm" version "1.8.21" apply false + id "org.graalvm.buildtools.native" version "0.9.22" apply false } version = "1.0.0" @@ -8,19 +9,23 @@ description = "TFB benchmark" group = "com.hexagonkt" ext { - hexagonVersion = "2.6.6" + hexagonVersion = "3.0.0-B1" + jettyVersion = "11.0.15" + nettyVersion = "4.1.93.Final" + hikariVersion = "5.0.1" - jettyVersion = "11.0.14" postgresqlVersion = "42.6.0" - vertxVersion = "4.4.0" + vertxVersion = "4.4.2" cache2kVersion = "2.6.1.Final" - nettyVersion = "4.1.90.Final" + applicationClass = "com.hexagonkt.BenchmarkKt" + modules = "java.naming,java.sql,java.management" + options = "--enable-preview" gradleScripts = "https://raw.githubusercontent.com/hexagonkt/hexagon/$hexagonVersion/gradle" } -defaultTasks("build") - subprojects { + version = rootProject.version + apply(from: "$gradleScripts/kotlin.gradle") } diff --git a/frameworks/Kotlin/hexagon/config.toml b/frameworks/Kotlin/hexagon/config.toml index d51d0e8ccf6..baeb6ac78ad 100644 --- a/frameworks/Kotlin/hexagon/config.toml +++ b/frameworks/Kotlin/hexagon/config.toml @@ -73,6 +73,24 @@ platform = "Netty" webserver = "None" versus = "netty" +[netty-native] +urls.plaintext = "/plaintext" +urls.json = "/json" +urls.db = "/db" +urls.query = "/query?queries=" +urls.update = "/update?queries=" +urls.fortune = "/fortunes" +urls.cached_query = "/cached-queries?count=" +approach = "Realistic" +classification = "Micro" +database = "postgres" +database_os = "Linux" +os = "Linux" +orm = "Raw" +platform = "Netty" +webserver = "None" +versus = "netty" + [nettyepoll] urls.plaintext = "/plaintext" urls.json = "/json" @@ -109,6 +127,24 @@ platform = "Netty" webserver = "None" versus = "netty" +[nettyepoll-async-pgclient] +urls.plaintext = "/plaintext" +urls.json = "/json" +urls.db = "/db" +urls.query = "/query?queries=" +urls.update = "/update?queries=" +urls.fortune = "/fortunes" +urls.cached_query = "/cached-queries?count=" +approach = "Realistic" +classification = "Micro" +database = "postgres" +database_os = "Linux" +os = "Linux" +orm = "Raw" +platform = "Netty" +webserver = "None" +versus = "netty" + [tomcat] urls.plaintext = "/plaintext" urls.json = "/json" @@ -126,3 +162,21 @@ orm = "Raw" platform = "Servlet" webserver = "Tomcat" versus = "servlet" + +[vertx-pgclient] +urls.plaintext = "/plaintext" +urls.json = "/json" +urls.db = "/db" +urls.query = "/query?queries=" +urls.update = "/update?queries=" +urls.fortune = "/fortunes" +urls.cached_query = "/cached-queries?count=" +approach = "Realistic" +classification = "Micro" +database = "postgres" +database_os = "Linux" +os = "Linux" +orm = "Raw" +platform = "Vertx" +webserver = "None" +versus = "vertx" diff --git a/frameworks/Kotlin/hexagon/core/build.gradle b/frameworks/Kotlin/hexagon/core/build.gradle index af7552398d3..4cf6f44b80c 100644 --- a/frameworks/Kotlin/hexagon/core/build.gradle +++ b/frameworks/Kotlin/hexagon/core/build.gradle @@ -4,6 +4,7 @@ plugins { } dependencies { + api(project(":model")) api("com.hexagonkt:http_server:$hexagonVersion") api("com.hexagonkt:templates_rocker:$hexagonVersion") api("com.hexagonkt:logging_slf4j_jul:$hexagonVersion") @@ -13,11 +14,9 @@ dependencies { tasks.register("minimizeTemplate") { doLast { - [ "fortunes.pebble.html", "fortunes.rocker.html" ].forEach { t -> - File template = file("$buildDir/resources/main/$t") - List lines = template.readLines().collect { it.trim() } - template.write(lines.join("")) - } + File template = file("$buildDir/resources/main/fortunes.rocker.html") + List lines = template.readLines().collect { it.trim() } + template.write(lines.join("")) } } diff --git a/frameworks/Kotlin/hexagon/core/src/main/kotlin/Controller.kt b/frameworks/Kotlin/hexagon/core/src/main/kotlin/Controller.kt index b4714a76049..37ab786e791 100644 --- a/frameworks/Kotlin/hexagon/core/src/main/kotlin/Controller.kt +++ b/frameworks/Kotlin/hexagon/core/src/main/kotlin/Controller.kt @@ -8,9 +8,9 @@ import com.hexagonkt.http.model.ContentType import com.hexagonkt.http.model.Header import com.hexagonkt.http.model.Headers import com.hexagonkt.http.server.callbacks.DateCallback -import com.hexagonkt.http.server.handlers.HttpServerContext -import com.hexagonkt.http.server.handlers.PathHandler -import com.hexagonkt.http.server.handlers.path +import com.hexagonkt.http.handlers.HttpContext +import com.hexagonkt.http.handlers.PathHandler +import com.hexagonkt.http.handlers.path import com.hexagonkt.model.* import com.hexagonkt.serialization.jackson.json.Json import com.hexagonkt.serialization.serialize @@ -55,9 +55,9 @@ class Controller( private fun Message.toJson(): String = toMap().serialize(Json.raw) - private fun HttpServerContext.listFortunes( + private fun HttpContext.listFortunes( store: BenchmarkStore, templateUrl: URL, templateAdapter: TemplatePort - ): HttpServerContext { + ): HttpContext { val fortunes = store.findAllFortunes() + Fortune(0, "Additional fortune added at request time.") val sortedFortunes = fortunes.sortedBy { it.message } @@ -67,7 +67,7 @@ class Controller( return ok(body, contentType = html) } - private fun HttpServerContext.dbQuery(store: BenchmarkStore): HttpServerContext { + private fun HttpContext.dbQuery(store: BenchmarkStore): HttpContext { val ids = listOf(randomWorld()) val worlds = store.findWorlds(ids) val world = worlds.first().toMap() @@ -75,7 +75,7 @@ class Controller( return sendJson(world) } - private fun HttpServerContext.getWorlds(store: BenchmarkStore): HttpServerContext { + private fun HttpContext.getWorlds(store: BenchmarkStore): HttpContext { val worldsCount = getWorldsCount(queriesParam) val ids = (1..worldsCount).map { randomWorld() } val worlds = store.findWorlds(ids).map { it.toMap() } @@ -83,7 +83,7 @@ class Controller( return sendJson(worlds) } - private fun HttpServerContext.getCachedWorlds(store: BenchmarkStore): HttpServerContext { + private fun HttpContext.getCachedWorlds(store: BenchmarkStore): HttpContext { val worldsCount = getWorldsCount(cachedQueriesParam) val ids = (1..worldsCount).map { randomWorld() } val worlds = store.findCachedWorlds(ids).map { it.toMap() } @@ -91,7 +91,7 @@ class Controller( return sendJson(worlds) } - private fun HttpServerContext.updateWorlds(store: BenchmarkStore): HttpServerContext { + private fun HttpContext.updateWorlds(store: BenchmarkStore): HttpContext { val worldsCount = getWorldsCount(queriesParam) val worlds = (1..worldsCount).map { World(randomWorld(), randomWorld()) } @@ -100,11 +100,11 @@ class Controller( return sendJson(worlds.map { it.toMap() }) } - private fun HttpServerContext.sendJson(body: Any): HttpServerContext = + private fun HttpContext.sendJson(body: Any): HttpContext = ok(body.serialize(Json.raw), contentType = json) - private fun HttpServerContext.getWorldsCount(parameter: String): Int = - request.queryParameters[parameter]?.value?.toIntOrNull().let { + private fun HttpContext.getWorldsCount(parameter: String): Int = + request.queryParameters[parameter]?.string()?.toIntOrNull().let { when { it == null -> 1 it < 1 -> 1 diff --git a/frameworks/Kotlin/hexagon/core/src/main/resources/META-INF/native-image/com.hexagonkt.benchmark/core/native-image.properties b/frameworks/Kotlin/hexagon/core/src/main/resources/META-INF/native-image/com.hexagonkt.benchmark/core/native-image.properties new file mode 100644 index 00000000000..ee1c0199d95 --- /dev/null +++ b/frameworks/Kotlin/hexagon/core/src/main/resources/META-INF/native-image/com.hexagonkt.benchmark/core/native-image.properties @@ -0,0 +1,7 @@ +Args= \ + -H:IncludeResources=.*\\.(html|class) \ + --enable-preview \ + --static \ + --initialize-at-build-time=org.slf4j.jul.JDK14LoggerAdapter \ + --initialize-at-build-time=org.slf4j.jul.JDK14LoggerAdapter$1 \ + --initialize-at-build-time=org.slf4j.LoggerFactory diff --git a/frameworks/Kotlin/hexagon/core/src/main/resources/META-INF/native-image/com.hexagonkt.benchmark/core/reflect-config.json b/frameworks/Kotlin/hexagon/core/src/main/resources/META-INF/native-image/com.hexagonkt.benchmark/core/reflect-config.json new file mode 100644 index 00000000000..11815306be2 --- /dev/null +++ b/frameworks/Kotlin/hexagon/core/src/main/resources/META-INF/native-image/com.hexagonkt.benchmark/core/reflect-config.json @@ -0,0 +1,23 @@ +[ + { + "name": "fortunes", + "allPublicMethods": true, + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, + { + "name": "fortunes$Template", + "allPublicMethods": true, + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, + { + "name": "fortunes$PlainText", + "allPublicMethods": true, + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true + } +] diff --git a/frameworks/Kotlin/hexagon/core/src/main/resources/fortunes.pebble.html b/frameworks/Kotlin/hexagon/core/src/main/resources/fortunes.pebble.html deleted file mode 100644 index 1a74dd9800c..00000000000 --- a/frameworks/Kotlin/hexagon/core/src/main/resources/fortunes.pebble.html +++ /dev/null @@ -1,21 +0,0 @@ - - - - - Fortunes - - - - - - - - {% for fortune in fortunes %} - - - - - {% endfor %} -
idmessage
{{ fortune.id }}{{ fortune.message }}
- - diff --git a/frameworks/Kotlin/hexagon/core_async/build.gradle b/frameworks/Kotlin/hexagon/core_async/build.gradle new file mode 100644 index 00000000000..0a33387738e --- /dev/null +++ b/frameworks/Kotlin/hexagon/core_async/build.gradle @@ -0,0 +1,32 @@ + +plugins { + id("nu.studer.rocker") version("3.0.4") +} + +dependencies { + api(project(":model")) + api("com.hexagonkt:http_server_async:$hexagonVersion") + api("com.hexagonkt:templates_rocker:$hexagonVersion") + api("com.hexagonkt:logging_slf4j_jul:$hexagonVersion") + api("com.hexagonkt:serialization_jackson_json:$hexagonVersion") + api("org.cache2k:cache2k-core:$cache2kVersion") +} + +tasks.register("minimizeTemplate") { + doLast { + File template = file("$buildDir/resources/main/fortunes.rocker.html") + List lines = template.readLines().collect { it.trim() } + template.write(lines.join("")) + } +} + +jar.dependsOn("minimizeTemplate") + +rocker { + configurations { + create("main") { + templateDir.set(file("src/main/resources")) + optimize.set(true) + } + } +} diff --git a/frameworks/Kotlin/hexagon/core_async/src/main/kotlin/Benchmark.kt b/frameworks/Kotlin/hexagon/core_async/src/main/kotlin/Benchmark.kt new file mode 100644 index 00000000000..2bda28da73e --- /dev/null +++ b/frameworks/Kotlin/hexagon/core_async/src/main/kotlin/Benchmark.kt @@ -0,0 +1,28 @@ +package com.hexagonkt.async + +import com.hexagonkt.Settings +import com.hexagonkt.http.server.async.HttpServer +import com.hexagonkt.http.server.async.HttpServerPort +import com.hexagonkt.http.server.async.HttpServerSettings +import com.hexagonkt.async.store.BenchmarkStore +import com.hexagonkt.templates.TemplatePort +import java.net.InetAddress +import java.net.URL + +class Benchmark( + private val engine: HttpServerPort, + private val store: BenchmarkStore, + private val template: TemplatePort, + private val templateUrl: URL, + private val settings: Settings = Settings(), +) { + val server: HttpServer by lazy { + val controller = Controller(settings, store, template, templateUrl) + val serverSettings = HttpServerSettings( + bindAddress = InetAddress.getByName(settings.bindAddress), + bindPort = settings.bindPort, + ) + + HttpServer(engine, controller.path, serverSettings) + } +} diff --git a/frameworks/Kotlin/hexagon/core_async/src/main/kotlin/Controller.kt b/frameworks/Kotlin/hexagon/core_async/src/main/kotlin/Controller.kt new file mode 100644 index 00000000000..683d39f4ffa --- /dev/null +++ b/frameworks/Kotlin/hexagon/core_async/src/main/kotlin/Controller.kt @@ -0,0 +1,133 @@ +package com.hexagonkt.async + +import com.hexagonkt.Settings +import com.hexagonkt.core.fieldsMapOf +import com.hexagonkt.core.media.APPLICATION_JSON +import com.hexagonkt.core.media.TEXT_HTML +import com.hexagonkt.core.media.TEXT_PLAIN +import com.hexagonkt.handlers.async.done +import com.hexagonkt.http.model.ContentType +import com.hexagonkt.http.model.Header +import com.hexagonkt.http.model.Headers +import com.hexagonkt.http.server.async.callbacks.DateCallback +import com.hexagonkt.http.handlers.async.HttpContext +import com.hexagonkt.http.handlers.async.PathHandler +import com.hexagonkt.http.handlers.async.path +import com.hexagonkt.model.* +import com.hexagonkt.serialization.jackson.json.Json +import com.hexagonkt.serialization.serialize +import com.hexagonkt.async.store.BenchmarkStore +import com.hexagonkt.templates.TemplatePort +import java.net.URL +import java.util.concurrent.CompletableFuture +import java.util.concurrent.ThreadLocalRandom +import kotlin.text.Charsets.UTF_8 + +class Controller( + settings: Settings, + store: BenchmarkStore, + templateEngine: TemplatePort, + templateUrl: URL, +) { + private val queriesParam: String = settings.queriesParam + private val cachedQueriesParam: String = settings.cachedQueriesParam + private val worldRows: Int = settings.worldRows + private val textMessage: String = settings.textMessage + + private val plain: ContentType = ContentType(TEXT_PLAIN) + private val json: ContentType = ContentType(APPLICATION_JSON) + private val html: ContentType = ContentType(TEXT_HTML, charset = UTF_8) + + private val headers = Headers(Header("server", "Hexagon")) + + val path: PathHandler by lazy { + path { + on("*") { send(headers = headers).done() } + on("*", DateCallback()) + + get("/plaintext") { ok(textMessage, contentType = plain).done() } + get("/json") { ok(Message(textMessage).toJson(), contentType = json).done() } + get("/fortunes") { listFortunes(store, templateUrl, templateEngine) } + get("/db") { dbQuery(store) } + get("/query") { getWorlds(store) } + get("/cached-queries") { getCachedWorlds(store) } + get("/update") { updateWorlds(store) } + } + } + + private fun Message.toJson(): String = + toMap().serialize(Json.raw) + + private fun HttpContext.listFortunes( + store: BenchmarkStore, templateUrl: URL, templateAdapter: TemplatePort + ): CompletableFuture = + store + .findAllFortunes() + .thenApply { it + Fortune(0, "Additional fortune added at request time.") } + .thenApply { fortunes -> fortunes.sortedBy { it.message } } + .thenApply { sortedFortunes -> mapOf("fortunes" to sortedFortunes) } + .thenApply { context -> templateAdapter.render(templateUrl, context) } + .thenApply { body -> ok(body, contentType = html) } + + private fun HttpContext.dbQuery(store: BenchmarkStore): CompletableFuture { + val ids = listOf(randomWorld()) + return store.findWorlds(ids) + .thenApply { worlds -> worlds.first().toMap()} + .thenApply { world -> sendJson(world) } + } + + private fun HttpContext.getWorlds(store: BenchmarkStore): CompletableFuture { + val worldsCount = getWorldsCount(queriesParam) + val ids = (1..worldsCount).map { randomWorld() } + return store.findWorlds(ids) + .thenApply { worlds -> worlds.map { it.toMap() } } + .thenApply { worlds -> sendJson(worlds) } + } + + private fun HttpContext.getCachedWorlds(store: BenchmarkStore): CompletableFuture { + val worldsCount = getWorldsCount(cachedQueriesParam) + val ids = (1..worldsCount).map { randomWorld() } + val worlds = store.findCachedWorlds(ids).map { it.toMap() } + + return sendJson(worlds).done() + } + + private fun HttpContext.updateWorlds(store: BenchmarkStore): CompletableFuture { + val worldsCount = getWorldsCount(queriesParam) + val worlds = (1..worldsCount).map { World(randomWorld(), randomWorld()) } + + return store.replaceWorlds(worlds) + .thenApply { sendJson(worlds.map { it.toMap() }) } + } + + private fun HttpContext.sendJson(body: Any): HttpContext = + ok(body.serialize(Json.raw), contentType = json) + + private fun HttpContext.getWorldsCount(parameter: String): Int = + request.queryParameters[parameter]?.string()?.toIntOrNull().let { + when { + it == null -> 1 + it < 1 -> 1 + it > 500 -> 500 + else -> it + } + } + + private fun randomWorld(): Int = + ThreadLocalRandom.current().nextInt(worldRows) + 1 + + private fun Message.toMap(): Map = + fieldsMapOf(Message::message to message) + + private fun World.toMap(): Map = + fieldsMapOf( + World::id to id, + World::randomNumber to randomNumber, + ) + + private fun CachedWorld.toMap(): Map = + fieldsMapOf( + CachedWorld::id to id, + CachedWorld::randomNumber to randomNumber, + ) +} diff --git a/frameworks/Kotlin/hexagon/core_async/src/main/kotlin/store/BenchmarkStore.kt b/frameworks/Kotlin/hexagon/core_async/src/main/kotlin/store/BenchmarkStore.kt new file mode 100644 index 00000000000..13f5aae7108 --- /dev/null +++ b/frameworks/Kotlin/hexagon/core_async/src/main/kotlin/store/BenchmarkStore.kt @@ -0,0 +1,34 @@ +package com.hexagonkt.async.store + +import com.hexagonkt.model.CachedWorld +import com.hexagonkt.model.Fortune +import com.hexagonkt.Settings +import com.hexagonkt.model.World +import org.cache2k.Cache +import org.cache2k.Cache2kBuilder +import java.util.concurrent.CompletableFuture + +abstract class BenchmarkStore(settings: Settings) { + + abstract fun findAllFortunes(): CompletableFuture> + abstract fun findWorlds(ids: List): CompletableFuture> + abstract fun replaceWorlds(worlds: List): CompletableFuture<*> + abstract fun initWorldsCache(cache: Cache) + abstract fun loadCachedWorld(id: Int): CachedWorld + abstract fun close() + + private val worldsCache: Cache by lazy { + object : Cache2kBuilder() {} + .eternal(true) + .disableMonitoring(true) + .disableStatistics(true) + .entryCapacity(settings.worldRows.toLong()) + .loader { id -> loadCachedWorld(id) } + .build() + .apply { initWorldsCache(this) } + } + + fun findCachedWorlds(ids: List): List { + return ids.mapNotNull { worldsCache.get(it) } + } +} diff --git a/frameworks/Kotlin/hexagon/core_async/src/main/resources/META-INF/native-image/com.hexagonkt.benchmark/core/native-image.properties b/frameworks/Kotlin/hexagon/core_async/src/main/resources/META-INF/native-image/com.hexagonkt.benchmark/core/native-image.properties new file mode 100644 index 00000000000..ee1c0199d95 --- /dev/null +++ b/frameworks/Kotlin/hexagon/core_async/src/main/resources/META-INF/native-image/com.hexagonkt.benchmark/core/native-image.properties @@ -0,0 +1,7 @@ +Args= \ + -H:IncludeResources=.*\\.(html|class) \ + --enable-preview \ + --static \ + --initialize-at-build-time=org.slf4j.jul.JDK14LoggerAdapter \ + --initialize-at-build-time=org.slf4j.jul.JDK14LoggerAdapter$1 \ + --initialize-at-build-time=org.slf4j.LoggerFactory diff --git a/frameworks/Kotlin/hexagon/core_async/src/main/resources/META-INF/native-image/com.hexagonkt.benchmark/core/reflect-config.json b/frameworks/Kotlin/hexagon/core_async/src/main/resources/META-INF/native-image/com.hexagonkt.benchmark/core/reflect-config.json new file mode 100644 index 00000000000..11815306be2 --- /dev/null +++ b/frameworks/Kotlin/hexagon/core_async/src/main/resources/META-INF/native-image/com.hexagonkt.benchmark/core/reflect-config.json @@ -0,0 +1,23 @@ +[ + { + "name": "fortunes", + "allPublicMethods": true, + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, + { + "name": "fortunes$Template", + "allPublicMethods": true, + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, + { + "name": "fortunes$PlainText", + "allPublicMethods": true, + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true + } +] diff --git a/frameworks/Kotlin/hexagon/core_async/src/main/resources/fortunes.rocker.html b/frameworks/Kotlin/hexagon/core_async/src/main/resources/fortunes.rocker.html new file mode 100644 index 00000000000..c9a9d4037e5 --- /dev/null +++ b/frameworks/Kotlin/hexagon/core_async/src/main/resources/fortunes.rocker.html @@ -0,0 +1,24 @@ +@import java.util.* +@import com.hexagonkt.model.Fortune +@args(Map context) + + + + + Fortunes + + + + + + + + @for ((fortune) : (Collection)context.get("fortunes")) { + + + + + } +
idmessage
@fortune.getId()@fortune.getMessage()
+ + diff --git a/frameworks/Kotlin/hexagon/gradle/wrapper/gradle-wrapper.jar b/frameworks/Kotlin/hexagon/gradle/wrapper/gradle-wrapper.jar index 943f0cbfa75..c1962a79e29 100644 Binary files a/frameworks/Kotlin/hexagon/gradle/wrapper/gradle-wrapper.jar and b/frameworks/Kotlin/hexagon/gradle/wrapper/gradle-wrapper.jar differ diff --git a/frameworks/Kotlin/hexagon/gradle/wrapper/gradle-wrapper.properties b/frameworks/Kotlin/hexagon/gradle/wrapper/gradle-wrapper.properties index f0ae57febc4..ed4fda0fcea 100644 --- a/frameworks/Kotlin/hexagon/gradle/wrapper/gradle-wrapper.properties +++ b/frameworks/Kotlin/hexagon/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https://services.gradle.org/distributions/gradle-8.0.2-bin.zip +distributionUrl=https://services.gradle.org/distributions/gradle-8.1.1-bin.zip networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/frameworks/Kotlin/hexagon/gradlew b/frameworks/Kotlin/hexagon/gradlew index 65dcd68d65c..aeb74cbb43e 100755 --- a/frameworks/Kotlin/hexagon/gradlew +++ b/frameworks/Kotlin/hexagon/gradlew @@ -85,9 +85,6 @@ done APP_BASE_NAME=${0##*/} APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' - # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -144,7 +141,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac @@ -152,7 +149,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then '' | soft) :;; #( *) # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -197,6 +194,10 @@ if "$cygwin" || "$msys" ; then done fi + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + # Collect all arguments for the java command; # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of # shell script including quotes and variable substitutions, so put them in diff --git a/frameworks/Kotlin/hexagon/hexagon-jetty-native.dockerfile b/frameworks/Kotlin/hexagon/hexagon-jetty-native.dockerfile new file mode 100644 index 00000000000..223aae81894 --- /dev/null +++ b/frameworks/Kotlin/hexagon/hexagon-jetty-native.dockerfile @@ -0,0 +1,21 @@ +# +# BUILD +# +FROM ghcr.io/graalvm/native-image:ol9-java17-22.3.2 as build +USER root +WORKDIR /hexagon + +ADD . . +RUN microdnf -y install findutils +RUN ./gradlew --quiet classes +RUN ./gradlew --quiet -x test nativeCompile + +# +# RUNTIME +# +FROM scratch +ARG PROJECT=hexagon_jetty_postgresql + +COPY --from=build /hexagon/$PROJECT/build/native/nativeCompile/$PROJECT / + +ENTRYPOINT [ "/hexagon_jetty_postgresql" ] diff --git a/frameworks/Kotlin/hexagon/hexagon-jettyloom-pgclient.dockerfile b/frameworks/Kotlin/hexagon/hexagon-jettyloom-pgclient.dockerfile index f047e7e599b..804555dae57 100644 --- a/frameworks/Kotlin/hexagon/hexagon-jettyloom-pgclient.dockerfile +++ b/frameworks/Kotlin/hexagon/hexagon-jettyloom-pgclient.dockerfile @@ -1,24 +1,23 @@ # # BUILD # -FROM gradle:8.0.2-jdk17-alpine AS build +FROM docker.io/gradle:8.1.1-jdk17-alpine AS build USER root WORKDIR /hexagon ADD . . -RUN gradle --quiet compileRocker -RUN gradle --quiet -x test +RUN gradle --quiet classes +RUN gradle --quiet -x test installDist # # RUNTIME # -FROM eclipse-temurin:19-jre-alpine +FROM docker.io/eclipse-temurin:20-jre-alpine +ARG PROJECT=hexagon_jetty_pgclient + ENV POSTGRESQL_DB_HOST tfb-database -ENV PROJECT hexagon_jetty_pgclient ENV JDK_JAVA_OPTIONS --enable-preview -XX:+AlwaysPreTouch -XX:+UseParallelGC -XX:+UseNUMA -DvirtualThreads=true COPY --from=build /hexagon/$PROJECT/build/install/$PROJECT /opt/$PROJECT -EXPOSE 9090 - -ENTRYPOINT /opt/$PROJECT/bin/$PROJECT +ENTRYPOINT [ "/opt/hexagon_jetty_pgclient/bin/hexagon_jetty_pgclient" ] diff --git a/frameworks/Kotlin/hexagon/hexagon-jettyloom.dockerfile b/frameworks/Kotlin/hexagon/hexagon-jettyloom.dockerfile index 18963d4dfe1..1d64e9246dd 100644 --- a/frameworks/Kotlin/hexagon/hexagon-jettyloom.dockerfile +++ b/frameworks/Kotlin/hexagon/hexagon-jettyloom.dockerfile @@ -1,24 +1,23 @@ # # BUILD # -FROM gradle:8.0.2-jdk17-alpine AS build +FROM docker.io/gradle:8.1.1-jdk17-alpine AS build USER root WORKDIR /hexagon ADD . . -RUN gradle --quiet compileRocker -RUN gradle --quiet -x test +RUN gradle --quiet classes +RUN gradle --quiet -x test installDist # # RUNTIME # -FROM eclipse-temurin:19-jre-alpine +FROM docker.io/eclipse-temurin:20-jre-alpine +ARG PROJECT=hexagon_jetty_postgresql + ENV POSTGRESQL_DB_HOST tfb-database -ENV PROJECT hexagon_jetty_postgresql ENV JDK_JAVA_OPTIONS --enable-preview -XX:+AlwaysPreTouch -XX:+UseParallelGC -XX:+UseNUMA -DvirtualThreads=true COPY --from=build /hexagon/$PROJECT/build/install/$PROJECT /opt/$PROJECT -EXPOSE 9090 - -ENTRYPOINT /opt/$PROJECT/bin/$PROJECT +ENTRYPOINT [ "/opt/hexagon_jetty_postgresql/bin/hexagon_jetty_postgresql" ] diff --git a/frameworks/Kotlin/hexagon/hexagon-netty-async-pgclient.dockerfile b/frameworks/Kotlin/hexagon/hexagon-netty-async-pgclient.dockerfile new file mode 100644 index 00000000000..09845f263cb --- /dev/null +++ b/frameworks/Kotlin/hexagon/hexagon-netty-async-pgclient.dockerfile @@ -0,0 +1,23 @@ +# +# BUILD +# +FROM docker.io/gradle:8.1.1-jdk17-alpine AS build +USER root +WORKDIR /hexagon + +ADD . . +RUN gradle --quiet classes +RUN gradle --quiet -x test installDist + +# +# RUNTIME +# +FROM docker.io/eclipse-temurin:17-jre-alpine +ARG PROJECT=hexagon_netty_async_pgclient + +ENV POSTGRESQL_DB_HOST tfb-database +ENV JDK_JAVA_OPTIONS -XX:+AlwaysPreTouch -XX:+UseParallelGC -XX:+UseNUMA + +COPY --from=build /hexagon/$PROJECT/build/install/$PROJECT /opt/$PROJECT + +ENTRYPOINT [ "/opt/hexagon_netty_async_pgclient/bin/hexagon_netty_async_pgclient" ] diff --git a/frameworks/Kotlin/hexagon/hexagon-netty-native.dockerfile b/frameworks/Kotlin/hexagon/hexagon-netty-native.dockerfile new file mode 100644 index 00000000000..5443b48eb8f --- /dev/null +++ b/frameworks/Kotlin/hexagon/hexagon-netty-native.dockerfile @@ -0,0 +1,21 @@ +# +# BUILD +# +FROM ghcr.io/graalvm/native-image:ol9-java17-22.3.2 as build +USER root +WORKDIR /hexagon + +ADD . . +RUN microdnf -y install findutils +RUN ./gradlew --quiet classes +RUN ./gradlew --quiet -x test nativeCompile + +# +# RUNTIME +# +FROM scratch +ARG PROJECT=hexagon_netty_postgresql + +COPY --from=build /hexagon/$PROJECT/build/native/nativeCompile/$PROJECT / + +ENTRYPOINT [ "/hexagon_netty_postgresql" ] diff --git a/frameworks/Kotlin/hexagon/hexagon-netty.dockerfile b/frameworks/Kotlin/hexagon/hexagon-netty.dockerfile index e343078fb6e..18fce97d813 100644 --- a/frameworks/Kotlin/hexagon/hexagon-netty.dockerfile +++ b/frameworks/Kotlin/hexagon/hexagon-netty.dockerfile @@ -1,24 +1,23 @@ # # BUILD # -FROM gradle:8.0.2-jdk17-alpine AS build +FROM docker.io/gradle:8.1.1-jdk17-alpine AS build USER root WORKDIR /hexagon ADD . . -RUN gradle --quiet compileRocker -RUN gradle --quiet -x test +RUN gradle --quiet classes +RUN gradle --quiet -x test installDist # # RUNTIME # -FROM eclipse-temurin:17-jre-alpine +FROM docker.io/eclipse-temurin:17-jre-alpine +ARG PROJECT=hexagon_netty_postgresql + ENV POSTGRESQL_DB_HOST tfb-database -ENV PROJECT hexagon_netty_postgresql ENV JDK_JAVA_OPTIONS -XX:+AlwaysPreTouch -XX:+UseParallelGC -XX:+UseNUMA COPY --from=build /hexagon/$PROJECT/build/install/$PROJECT /opt/$PROJECT -EXPOSE 9090 - -ENTRYPOINT /opt/$PROJECT/bin/$PROJECT +ENTRYPOINT [ "/opt/hexagon_netty_postgresql/bin/hexagon_netty_postgresql" ] diff --git a/frameworks/Kotlin/hexagon/hexagon-nettyepoll-pgclient.dockerfile b/frameworks/Kotlin/hexagon/hexagon-nettyepoll-pgclient.dockerfile index d40959b0e0e..afe2e155ccc 100644 --- a/frameworks/Kotlin/hexagon/hexagon-nettyepoll-pgclient.dockerfile +++ b/frameworks/Kotlin/hexagon/hexagon-nettyepoll-pgclient.dockerfile @@ -1,24 +1,23 @@ # # BUILD # -FROM gradle:8.0.2-jdk17-alpine AS build +FROM docker.io/gradle:8.1.1-jdk17-alpine AS build USER root WORKDIR /hexagon ADD . . -RUN gradle --quiet compileRocker -RUN gradle --quiet -x test +RUN gradle --quiet classes +RUN gradle --quiet -x test installDist # # RUNTIME # -FROM eclipse-temurin:17-jre-alpine +FROM docker.io/eclipse-temurin:17-jre-alpine +ARG PROJECT=hexagon_nettyepoll_pgclient + ENV POSTGRESQL_DB_HOST tfb-database -ENV PROJECT hexagon_nettyepoll_pgclient ENV JDK_JAVA_OPTIONS -XX:+AlwaysPreTouch -XX:+UseParallelGC -XX:+UseNUMA COPY --from=build /hexagon/$PROJECT/build/install/$PROJECT /opt/$PROJECT -EXPOSE 9090 - -ENTRYPOINT /opt/$PROJECT/bin/$PROJECT +ENTRYPOINT [ "/opt/hexagon_nettyepoll_pgclient/bin/hexagon_nettyepoll_pgclient" ] diff --git a/frameworks/Kotlin/hexagon/hexagon-nettyepoll.dockerfile b/frameworks/Kotlin/hexagon/hexagon-nettyepoll.dockerfile index 575378b8583..c8a5592b67e 100644 --- a/frameworks/Kotlin/hexagon/hexagon-nettyepoll.dockerfile +++ b/frameworks/Kotlin/hexagon/hexagon-nettyepoll.dockerfile @@ -1,24 +1,23 @@ # # BUILD # -FROM gradle:8.0.2-jdk17-alpine AS build +FROM docker.io/gradle:8.1.1-jdk17-alpine AS build USER root WORKDIR /hexagon ADD . . -RUN gradle --quiet compileRocker -RUN gradle --quiet -x test +RUN gradle --quiet classes +RUN gradle --quiet -x test installDist # # RUNTIME # -FROM eclipse-temurin:17-jre-alpine +FROM docker.io/eclipse-temurin:17-jre-alpine +ARG PROJECT=hexagon_nettyepoll_postgresql + ENV POSTGRESQL_DB_HOST tfb-database -ENV PROJECT hexagon_nettyepoll_postgresql ENV JDK_JAVA_OPTIONS -XX:+AlwaysPreTouch -XX:+UseParallelGC -XX:+UseNUMA COPY --from=build /hexagon/$PROJECT/build/install/$PROJECT /opt/$PROJECT -EXPOSE 9090 - -ENTRYPOINT /opt/$PROJECT/bin/$PROJECT +ENTRYPOINT [ "/opt/hexagon_nettyepoll_postgresql/bin/hexagon_nettyepoll_postgresql" ] diff --git a/frameworks/Kotlin/hexagon/hexagon-tomcat.dockerfile b/frameworks/Kotlin/hexagon/hexagon-tomcat.dockerfile index 7ca5725be48..e35db7b9f68 100644 --- a/frameworks/Kotlin/hexagon/hexagon-tomcat.dockerfile +++ b/frameworks/Kotlin/hexagon/hexagon-tomcat.dockerfile @@ -1,21 +1,21 @@ # # BUILD # -FROM gradle:8.0.2-jdk17-alpine AS build +FROM docker.io/gradle:8.1.1-jdk17-alpine AS build USER root WORKDIR /hexagon ADD . . -RUN gradle --quiet compileRocker -RUN gradle --quiet -x test +RUN gradle --quiet classes +RUN gradle --quiet -x test war # # RUNTIME # -FROM tomcat:10.1.2-jre17-temurin +FROM docker.io/tomcat:10-jre17-temurin-jammy +ARG MODULE=/hexagon/hexagon_tomcat_postgresql + ENV POSTGRESQL_DB_HOST tfb-database -ENV MODULE /hexagon/hexagon_tomcat_postgresql ENV JDK_JAVA_OPTIONS -XX:+AlwaysPreTouch -XX:+UseParallelGC -XX:+UseNUMA COPY --from=build $MODULE/build/libs/ROOT.war /usr/local/tomcat/webapps/ROOT.war -EXPOSE 8080 diff --git a/frameworks/Kotlin/hexagon/hexagon-vertx-pgclient.dockerfile b/frameworks/Kotlin/hexagon/hexagon-vertx-pgclient.dockerfile new file mode 100644 index 00000000000..5b8ff2cd1b1 --- /dev/null +++ b/frameworks/Kotlin/hexagon/hexagon-vertx-pgclient.dockerfile @@ -0,0 +1,23 @@ +# +# BUILD +# +FROM docker.io/gradle:8.1.1-jdk17-alpine AS build +USER root +WORKDIR /hexagon + +ADD . . +RUN gradle --quiet classes +RUN gradle --quiet -x test installDist + +# +# RUNTIME +# +FROM docker.io/eclipse-temurin:17-jre-alpine +ARG PROJECT=hexagon_vertx_pgclient + +ENV POSTGRESQL_DB_HOST tfb-database +ENV JDK_JAVA_OPTIONS -XX:+AlwaysPreTouch -XX:+UseParallelGC -XX:+UseNUMA + +COPY --from=build /hexagon/$PROJECT/build/install/$PROJECT /opt/$PROJECT + +ENTRYPOINT [ "/opt/hexagon_vertx_pgclient/bin/hexagon_vertx_pgclient" ] diff --git a/frameworks/Kotlin/hexagon/hexagon.dockerfile b/frameworks/Kotlin/hexagon/hexagon.dockerfile index e228bd5a7db..6bc878580ab 100644 --- a/frameworks/Kotlin/hexagon/hexagon.dockerfile +++ b/frameworks/Kotlin/hexagon/hexagon.dockerfile @@ -1,24 +1,23 @@ # # BUILD # -FROM gradle:8.0.2-jdk17-alpine AS build +FROM docker.io/gradle:8.1.1-jdk17-alpine AS build USER root WORKDIR /hexagon ADD . . -RUN gradle --quiet compileRocker -RUN gradle --quiet -x test +RUN gradle --quiet classes +RUN gradle --quiet -x test installDist # # RUNTIME # -FROM eclipse-temurin:17-jre-alpine +FROM docker.io/eclipse-temurin:17-jre-alpine +ARG PROJECT=hexagon_jetty_postgresql + ENV POSTGRESQL_DB_HOST tfb-database -ENV PROJECT hexagon_jetty_postgresql ENV JDK_JAVA_OPTIONS -XX:+AlwaysPreTouch -XX:+UseParallelGC -XX:+UseNUMA COPY --from=build /hexagon/$PROJECT/build/install/$PROJECT /opt/$PROJECT -EXPOSE 9090 - -ENTRYPOINT /opt/$PROJECT/bin/$PROJECT +ENTRYPOINT [ "/opt/hexagon_jetty_postgresql/bin/hexagon_jetty_postgresql" ] diff --git a/frameworks/Kotlin/hexagon/hexagon_jetty_pgclient/build.gradle b/frameworks/Kotlin/hexagon/hexagon_jetty_pgclient/build.gradle index 71e2dc0f44f..3b3d4b51b92 100644 --- a/frameworks/Kotlin/hexagon/hexagon_jetty_pgclient/build.gradle +++ b/frameworks/Kotlin/hexagon/hexagon_jetty_pgclient/build.gradle @@ -1,13 +1,7 @@ apply(from: "$gradleScripts/application.gradle") -application { - mainClass.set("com.hexagonkt.BenchmarkKt") -} - dependencies { api(project(":store_pgclient")) api("com.hexagonkt:http_server_jetty:$hexagonVersion") } - -build.dependsOn("installDist") diff --git a/frameworks/Kotlin/hexagon/hexagon_jetty_postgresql/build.gradle b/frameworks/Kotlin/hexagon/hexagon_jetty_postgresql/build.gradle index 09dde4a8327..059804ac9ff 100644 --- a/frameworks/Kotlin/hexagon/hexagon_jetty_postgresql/build.gradle +++ b/frameworks/Kotlin/hexagon/hexagon_jetty_postgresql/build.gradle @@ -1,13 +1,8 @@ apply(from: "$gradleScripts/application.gradle") - -application { - mainClass.set("com.hexagonkt.BenchmarkKt") -} +apply(from: "$gradleScripts/native.gradle") dependencies { api(project(":store_sql")) api("com.hexagonkt:http_server_jetty:$hexagonVersion") } - -build.dependsOn("installDist") diff --git a/frameworks/Kotlin/hexagon/hexagon_netty_async_pgclient/build.gradle b/frameworks/Kotlin/hexagon/hexagon_netty_async_pgclient/build.gradle new file mode 100644 index 00000000000..f29d1703b61 --- /dev/null +++ b/frameworks/Kotlin/hexagon/hexagon_netty_async_pgclient/build.gradle @@ -0,0 +1,7 @@ + +apply(from: "$gradleScripts/application.gradle") + +dependencies { + api(project(":store_pgclient_async")) + api("com.hexagonkt:http_server_netty_async:$hexagonVersion") +} diff --git a/frameworks/Kotlin/hexagon/hexagon_netty_async_pgclient/src/main/kotlin/Benchmark.kt b/frameworks/Kotlin/hexagon/hexagon_netty_async_pgclient/src/main/kotlin/Benchmark.kt new file mode 100644 index 00000000000..e5a9de4c597 --- /dev/null +++ b/frameworks/Kotlin/hexagon/hexagon_netty_async_pgclient/src/main/kotlin/Benchmark.kt @@ -0,0 +1,25 @@ +package com.hexagonkt + +import com.hexagonkt.async.Benchmark +import com.hexagonkt.async.store.BenchmarkPgClientStore +import com.hexagonkt.http.server.netty.async.NettyServerAdapter +import com.hexagonkt.templates.rocker.RockerAdapter +import io.netty.util.ResourceLeakDetector +import io.netty.util.ResourceLeakDetector.Level.DISABLED +import java.net.URL + +fun main() { + ResourceLeakDetector.setLevel(DISABLED) + + System.setProperty("io.netty.buffer.checkBounds", "false") + System.setProperty("io.netty.buffer.checkAccessible", "false") + + val settings = Settings() + val store = BenchmarkPgClientStore("postgresql") + val templateEngine = RockerAdapter() + val templateUrl = URL("classpath:fortunes.rocker.html") + val engine = NettyServerAdapter(bossGroupThreads = 48) + + val benchmark = Benchmark(engine, store, templateEngine, templateUrl, settings) + benchmark.server.start() +} diff --git a/frameworks/Kotlin/hexagon/hexagon_netty_postgresql/build.gradle b/frameworks/Kotlin/hexagon/hexagon_netty_postgresql/build.gradle index e06ac14aff0..01884cb3583 100644 --- a/frameworks/Kotlin/hexagon/hexagon_netty_postgresql/build.gradle +++ b/frameworks/Kotlin/hexagon/hexagon_netty_postgresql/build.gradle @@ -1,13 +1,8 @@ apply(from: "$gradleScripts/application.gradle") - -application { - mainClass.set("com.hexagonkt.BenchmarkKt") -} +apply(from: "$gradleScripts/native.gradle") dependencies { api(project(":store_sql")) api("com.hexagonkt:http_server_netty:$hexagonVersion") } - -build.dependsOn("installDist") diff --git a/frameworks/Kotlin/hexagon/hexagon_netty_postgresql/src/main/kotlin/Benchmark.kt b/frameworks/Kotlin/hexagon/hexagon_netty_postgresql/src/main/kotlin/Benchmark.kt index 100af29d51e..2a95e7385fc 100644 --- a/frameworks/Kotlin/hexagon/hexagon_netty_postgresql/src/main/kotlin/Benchmark.kt +++ b/frameworks/Kotlin/hexagon/hexagon_netty_postgresql/src/main/kotlin/Benchmark.kt @@ -3,9 +3,16 @@ package com.hexagonkt import com.hexagonkt.http.server.netty.NettyServerAdapter import com.hexagonkt.store.BenchmarkSqlStore import com.hexagonkt.templates.rocker.RockerAdapter +import io.netty.util.ResourceLeakDetector +import io.netty.util.ResourceLeakDetector.Level.DISABLED import java.net.URL fun main() { + ResourceLeakDetector.setLevel(DISABLED) + + System.setProperty("io.netty.buffer.checkBounds", "false") + System.setProperty("io.netty.buffer.checkAccessible", "false") + val settings = Settings() val store = BenchmarkSqlStore("postgresql") val templateEngine = RockerAdapter() diff --git a/frameworks/Kotlin/hexagon/hexagon_nettyepoll_pgclient/build.gradle b/frameworks/Kotlin/hexagon/hexagon_nettyepoll_pgclient/build.gradle index 07ecf663690..0017123ec54 100644 --- a/frameworks/Kotlin/hexagon/hexagon_nettyepoll_pgclient/build.gradle +++ b/frameworks/Kotlin/hexagon/hexagon_nettyepoll_pgclient/build.gradle @@ -1,14 +1,8 @@ apply(from: "$gradleScripts/application.gradle") -application { - mainClass.set("com.hexagonkt.BenchmarkKt") -} - dependencies { api(project(":store_pgclient")) api("com.hexagonkt:http_server_netty_epoll:$hexagonVersion") api("io.netty:netty-transport-native-epoll:$nettyVersion:linux-x86_64") } - -build.dependsOn("installDist") diff --git a/frameworks/Kotlin/hexagon/hexagon_nettyepoll_pgclient/src/main/kotlin/Benchmark.kt b/frameworks/Kotlin/hexagon/hexagon_nettyepoll_pgclient/src/main/kotlin/Benchmark.kt index abe085171f2..cf1cf7d998e 100644 --- a/frameworks/Kotlin/hexagon/hexagon_nettyepoll_pgclient/src/main/kotlin/Benchmark.kt +++ b/frameworks/Kotlin/hexagon/hexagon_nettyepoll_pgclient/src/main/kotlin/Benchmark.kt @@ -3,9 +3,16 @@ package com.hexagonkt import com.hexagonkt.http.server.netty.epoll.NettyEpollServerAdapter import com.hexagonkt.store.BenchmarkPgClientStore import com.hexagonkt.templates.rocker.RockerAdapter +import io.netty.util.ResourceLeakDetector +import io.netty.util.ResourceLeakDetector.Level.DISABLED import java.net.URL fun main() { + ResourceLeakDetector.setLevel(DISABLED) + + System.setProperty("io.netty.buffer.checkBounds", "false") + System.setProperty("io.netty.buffer.checkAccessible", "false") + val settings = Settings() val store = BenchmarkPgClientStore("postgresql") val templateEngine = RockerAdapter() diff --git a/frameworks/Kotlin/hexagon/hexagon_nettyepoll_postgresql/build.gradle b/frameworks/Kotlin/hexagon/hexagon_nettyepoll_postgresql/build.gradle index b314102ff80..243fa57c121 100644 --- a/frameworks/Kotlin/hexagon/hexagon_nettyepoll_postgresql/build.gradle +++ b/frameworks/Kotlin/hexagon/hexagon_nettyepoll_postgresql/build.gradle @@ -1,14 +1,8 @@ apply(from: "$gradleScripts/application.gradle") -application { - mainClass.set("com.hexagonkt.BenchmarkKt") -} - dependencies { api(project(":store_sql")) api("com.hexagonkt:http_server_netty_epoll:$hexagonVersion") api("io.netty:netty-transport-native-epoll:$nettyVersion:linux-x86_64") } - -build.dependsOn("installDist") diff --git a/frameworks/Kotlin/hexagon/hexagon_nettyepoll_postgresql/src/main/kotlin/Benchmark.kt b/frameworks/Kotlin/hexagon/hexagon_nettyepoll_postgresql/src/main/kotlin/Benchmark.kt index d0c2aa58347..dcf1495705a 100644 --- a/frameworks/Kotlin/hexagon/hexagon_nettyepoll_postgresql/src/main/kotlin/Benchmark.kt +++ b/frameworks/Kotlin/hexagon/hexagon_nettyepoll_postgresql/src/main/kotlin/Benchmark.kt @@ -3,9 +3,16 @@ package com.hexagonkt import com.hexagonkt.http.server.netty.epoll.NettyEpollServerAdapter import com.hexagonkt.store.BenchmarkSqlStore import com.hexagonkt.templates.rocker.RockerAdapter +import io.netty.util.ResourceLeakDetector +import io.netty.util.ResourceLeakDetector.Level.DISABLED import java.net.URL fun main() { + ResourceLeakDetector.setLevel(DISABLED) + + System.setProperty("io.netty.buffer.checkBounds", "false") + System.setProperty("io.netty.buffer.checkAccessible", "false") + val settings = Settings() val store = BenchmarkSqlStore("postgresql") val templateEngine = RockerAdapter() diff --git a/frameworks/Kotlin/hexagon/hexagon_tomcat_postgresql/src/main/kotlin/WebListenerServer.kt b/frameworks/Kotlin/hexagon/hexagon_tomcat_postgresql/src/main/kotlin/WebListenerServer.kt index cdf911e1ee9..38a2731deee 100644 --- a/frameworks/Kotlin/hexagon/hexagon_tomcat_postgresql/src/main/kotlin/WebListenerServer.kt +++ b/frameworks/Kotlin/hexagon/hexagon_tomcat_postgresql/src/main/kotlin/WebListenerServer.kt @@ -2,8 +2,8 @@ package com.hexagonkt import com.hexagonkt.http.model.Header import com.hexagonkt.http.model.Headers -import com.hexagonkt.http.server.handlers.HttpHandler -import com.hexagonkt.http.server.handlers.OnHandler +import com.hexagonkt.http.handlers.HttpHandler +import com.hexagonkt.http.handlers.OnHandler import com.hexagonkt.http.server.servlet.ServletServer import com.hexagonkt.store.BenchmarkSqlStore import com.hexagonkt.templates.rocker.RockerAdapter diff --git a/frameworks/Kotlin/hexagon/hexagon_vertx_pgclient/build.gradle b/frameworks/Kotlin/hexagon/hexagon_vertx_pgclient/build.gradle new file mode 100644 index 00000000000..2d5cdaf23d7 --- /dev/null +++ b/frameworks/Kotlin/hexagon/hexagon_vertx_pgclient/build.gradle @@ -0,0 +1,9 @@ + +apply(from: "$gradleScripts/application.gradle") + +dependencies { + api(project(":store_pgclient_async")) + api("com.hexagonkt:http_server_vertx_async:$hexagonVersion") + api("io.vertx:vertx-io_uring-incubator:4.4.2") + api("io.netty:netty-transport-native-epoll:4.1.93.Final") +} diff --git a/frameworks/Kotlin/hexagon/hexagon_vertx_pgclient/src/main/kotlin/Benchmark.kt b/frameworks/Kotlin/hexagon/hexagon_vertx_pgclient/src/main/kotlin/Benchmark.kt new file mode 100644 index 00000000000..6b52be6d68f --- /dev/null +++ b/frameworks/Kotlin/hexagon/hexagon_vertx_pgclient/src/main/kotlin/Benchmark.kt @@ -0,0 +1,33 @@ +package com.hexagonkt + +import com.hexagonkt.async.Benchmark +import com.hexagonkt.async.store.BenchmarkPgClientStore +import com.hexagonkt.http.server.vertx.VertxServerAdapter +import com.hexagonkt.templates.rocker.RockerAdapter +import io.netty.util.ResourceLeakDetector +import io.netty.util.ResourceLeakDetector.Level.DISABLED +import java.net.URL + +fun main() { + ResourceLeakDetector.setLevel(DISABLED) + + System.setProperty("vertx.disableMetrics", "true") + System.setProperty("vertx.disableH2c", "true") + System.setProperty("vertx.disableWebsockets", "true") + System.setProperty("vertx.flashPolicyHandler", "false") + System.setProperty("vertx.threadChecks", "false") + System.setProperty("vertx.disableContextTimings", "true") + System.setProperty("vertx.disableTCCL", "true") + System.setProperty("vertx.disableHttpHeadersValidation", "true") + System.setProperty("io.netty.buffer.checkBounds", "false") + System.setProperty("io.netty.buffer.checkAccessible", "false") + + val settings = Settings() + val store = BenchmarkPgClientStore("postgresql") + val templateEngine = RockerAdapter() + val templateUrl = URL("classpath:fortunes.rocker.html") + val engine = VertxServerAdapter(preferNativeTransport = true) + + val benchmark = Benchmark(engine, store, templateEngine, templateUrl, settings) + benchmark.server.start() +} diff --git a/frameworks/Kotlin/hexagon/model/build.gradle b/frameworks/Kotlin/hexagon/model/build.gradle new file mode 100644 index 00000000000..bb97bfd9a3d --- /dev/null +++ b/frameworks/Kotlin/hexagon/model/build.gradle @@ -0,0 +1,4 @@ + +dependencies { + api("com.hexagonkt:core:$hexagonVersion") +} diff --git a/frameworks/Kotlin/hexagon/core/src/main/kotlin/Settings.kt b/frameworks/Kotlin/hexagon/model/src/main/kotlin/Settings.kt similarity index 100% rename from frameworks/Kotlin/hexagon/core/src/main/kotlin/Settings.kt rename to frameworks/Kotlin/hexagon/model/src/main/kotlin/Settings.kt diff --git a/frameworks/Kotlin/hexagon/core/src/main/kotlin/model/CachedWorld.kt b/frameworks/Kotlin/hexagon/model/src/main/kotlin/model/CachedWorld.kt similarity index 100% rename from frameworks/Kotlin/hexagon/core/src/main/kotlin/model/CachedWorld.kt rename to frameworks/Kotlin/hexagon/model/src/main/kotlin/model/CachedWorld.kt diff --git a/frameworks/Kotlin/hexagon/core/src/main/kotlin/model/Fortune.kt b/frameworks/Kotlin/hexagon/model/src/main/kotlin/model/Fortune.kt similarity index 100% rename from frameworks/Kotlin/hexagon/core/src/main/kotlin/model/Fortune.kt rename to frameworks/Kotlin/hexagon/model/src/main/kotlin/model/Fortune.kt diff --git a/frameworks/Kotlin/hexagon/core/src/main/kotlin/model/Message.kt b/frameworks/Kotlin/hexagon/model/src/main/kotlin/model/Message.kt similarity index 100% rename from frameworks/Kotlin/hexagon/core/src/main/kotlin/model/Message.kt rename to frameworks/Kotlin/hexagon/model/src/main/kotlin/model/Message.kt diff --git a/frameworks/Kotlin/hexagon/core/src/main/kotlin/model/World.kt b/frameworks/Kotlin/hexagon/model/src/main/kotlin/model/World.kt similarity index 100% rename from frameworks/Kotlin/hexagon/core/src/main/kotlin/model/World.kt rename to frameworks/Kotlin/hexagon/model/src/main/kotlin/model/World.kt diff --git a/frameworks/Kotlin/hexagon/settings.gradle b/frameworks/Kotlin/hexagon/settings.gradle index 2d571cdc706..7b6af470769 100644 --- a/frameworks/Kotlin/hexagon/settings.gradle +++ b/frameworks/Kotlin/hexagon/settings.gradle @@ -1,13 +1,18 @@ include( + "model", "core", + "core_async", "store_pgclient", + "store_pgclient_async", "store_sql", "hexagon_jetty_pgclient", "hexagon_jetty_postgresql", "hexagon_netty_postgresql", + "hexagon_netty_async_pgclient", "hexagon_nettyepoll_pgclient", "hexagon_nettyepoll_postgresql", + "hexagon_vertx_pgclient", "hexagon_tomcat_postgresql", ) diff --git a/frameworks/Kotlin/hexagon/store_pgclient/src/main/kotlin/BenchmarkPgClientStore.kt b/frameworks/Kotlin/hexagon/store_pgclient/src/main/kotlin/BenchmarkPgClientStore.kt index 5cd13ccee0a..1fb9547353f 100644 --- a/frameworks/Kotlin/hexagon/store_pgclient/src/main/kotlin/BenchmarkPgClientStore.kt +++ b/frameworks/Kotlin/hexagon/store_pgclient/src/main/kotlin/BenchmarkPgClientStore.kt @@ -24,7 +24,7 @@ class BenchmarkPgClientStore( private val connectOptions: PgConnectOptions by lazy { PgConnectOptions().apply { - host = Jvm.systemSettingOrNull("${engine.uppercase()}_DB_HOST") ?: "localhost" + host = Jvm.systemSettingOrNull("${engine.uppercase()}_DB_HOST") ?: "tfb-database" database = settings.databaseName user = settings.databaseUsername password = settings.databasePassword diff --git a/frameworks/Kotlin/hexagon/store_pgclient_async/build.gradle b/frameworks/Kotlin/hexagon/store_pgclient_async/build.gradle new file mode 100644 index 00000000000..65d4ca18f97 --- /dev/null +++ b/frameworks/Kotlin/hexagon/store_pgclient_async/build.gradle @@ -0,0 +1,6 @@ + +dependencies { + api(project(":core_async")) + implementation("io.vertx:vertx-pg-client:$vertxVersion") + implementation("com.ongres.scram:client:2.1") +} diff --git a/frameworks/Kotlin/hexagon/store_pgclient_async/src/main/kotlin/BenchmarkPgClientStore.kt b/frameworks/Kotlin/hexagon/store_pgclient_async/src/main/kotlin/BenchmarkPgClientStore.kt new file mode 100644 index 00000000000..8266b3120e4 --- /dev/null +++ b/frameworks/Kotlin/hexagon/store_pgclient_async/src/main/kotlin/BenchmarkPgClientStore.kt @@ -0,0 +1,114 @@ +package com.hexagonkt.async.store + +import com.hexagonkt.Settings +import com.hexagonkt.core.Jvm +import com.hexagonkt.model.CachedWorld +import com.hexagonkt.model.Fortune +import com.hexagonkt.model.World +import io.vertx.core.CompositeFuture.all +import io.vertx.core.Future +import io.vertx.core.Vertx.vertx +import io.vertx.pgclient.PgConnectOptions +import io.vertx.pgclient.PgPool +import io.vertx.sqlclient.* +import org.cache2k.Cache +import java.util.concurrent.CompletableFuture + +class BenchmarkPgClientStore( + engine: String, + private val settings: Settings = Settings(), +) : BenchmarkStore(settings) { + + companion object { + private const val SELECT_WORLD: String = "select * from world where id = $1" + private const val UPDATE_WORLD: String = "update world set randomNumber = $1 where id = $2" + private const val SELECT_ALL_FORTUNES: String = "select * from fortune" + } + + private val connectOptions: PgConnectOptions by lazy { + PgConnectOptions().apply { + host = Jvm.systemSettingOrNull("${engine.uppercase()}_DB_HOST") ?: "tfb-database" + database = settings.databaseName + user = settings.databaseUsername + password = settings.databasePassword + cachePreparedStatements = true + } + } + + private val poolOptions: PoolOptions by lazy { + PoolOptions().apply { + val environment = Jvm.systemSettingOrNull("BENCHMARK_ENV")?.lowercase() + maxSize = 8 + if (environment == "citrine") Jvm.cpuCount else Jvm.cpuCount * 2 + } + } + + private val dataSource: SqlClient by lazy { PgPool.pool(vertx(), connectOptions, poolOptions) } + + override fun findAllFortunes(): CompletableFuture> = + dataSource.preparedQuery(SELECT_ALL_FORTUNES) + .execute() + .map { rowSet -> + rowSet.map { row -> Fortune(row.getInteger(0), row.getString(1)) } + } + .toCompletionStage() + .toCompletableFuture() + + override fun findWorlds(ids: List): CompletableFuture> { + val futures = ids.map { findWorld(it, dataSource) } + return all(futures).map { it.list() }.toCompletionStage().toCompletableFuture() + } + + override fun replaceWorlds(worlds: List): CompletableFuture<*> { + val futures = worlds.map { + val worldId = it.id + val newRandomNumber = it.randomNumber + dataSource + .preparedQuery(SELECT_WORLD) + .execute(Tuple.of(worldId)) + .flatMap { rowSet -> + val row = rowSet.iterator().next() + row.getInteger(1) // Read 'randomNumber' to comply with Test type 5, point 6 + dataSource + .preparedQuery(UPDATE_WORLD) + .execute(Tuple.of(newRandomNumber, worldId)) + } + } + return all(futures).toCompletionStage().toCompletableFuture() + } + + override fun initWorldsCache(cache: Cache) { + dataSource + .preparedQuery("select * from world") + .execute() + .map { rowSet -> + rowSet.map { row -> + val id = row.getInteger(0) + val randomNumber = row.getInteger(1) + cache.put(id, CachedWorld(id, randomNumber)) + } + } + .toCompletionStage() + .toCompletableFuture() + .get() + } + + override fun loadCachedWorld(id: Int): CachedWorld = + findWorld(id, dataSource) + .map { world -> CachedWorld(world.id, world.randomNumber) } + .toCompletionStage() + .toCompletableFuture() + .get() + + override fun close() { + dataSource.close() + } + + private fun findWorld(id: Int, client: SqlClient): Future = + client + .preparedQuery(SELECT_WORLD) + .execute(Tuple.of(id)) + .map { rowSet -> + val row = rowSet.iterator().next() + World(row.getInteger(0), row.getInteger(1)) + } +} diff --git a/frameworks/Kotlin/hexagon/store_sql/src/main/kotlin/BenchmarkSqlStore.kt b/frameworks/Kotlin/hexagon/store_sql/src/main/kotlin/BenchmarkSqlStore.kt index ea871ec1b13..501a4d9ce34 100644 --- a/frameworks/Kotlin/hexagon/store_sql/src/main/kotlin/BenchmarkSqlStore.kt +++ b/frameworks/Kotlin/hexagon/store_sql/src/main/kotlin/BenchmarkSqlStore.kt @@ -22,7 +22,7 @@ class BenchmarkSqlStore( } private val dataSource: HikariDataSource by lazy { - val dbHost = Jvm.systemSettingOrNull("${engine.uppercase()}_DB_HOST") ?: "localhost" + val dbHost = Jvm.systemSettingOrNull("${engine.uppercase()}_DB_HOST") ?: "tfb-database" val environment = Jvm.systemSettingOrNull(String::class, "BENCHMARK_ENV")?.lowercase() val poolSize = 8 + if (environment == "citrine") Jvm.cpuCount else Jvm.cpuCount * 2 val postgresqlSettings = listOf(