Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
FROM gradle:9.5.1-jdk21-corretto AS build
FROM gradle:9.5.1-jdk25-corretto AS build
WORKDIR /app
COPY build.gradle.kts settings.gradle.kts gradle.properties ./
COPY gradle/libs.versions.toml ./gradle/
RUN gradle dependencies --no-daemon -q 2>/dev/null || true
COPY src ./src
RUN gradle buildFatJar --no-daemon -q

FROM eclipse-temurin:21-jre
FROM eclipse-temurin:25-jre
WORKDIR /app
COPY --from=build /app/build/libs/ktor-ghost-httparena.jar .
EXPOSE 8080 8443
COPY --from=build /app/build/libs/ktor-tuned-httparena.jar .
EXPOSE 8080 8081 8082 8443
ENTRYPOINT ["java", \
"-server", \
"-XX:+UseG1GC", \
"-XX:+UseNUMA", \
"-XX:+AlwaysPreTouch", \
"-XX:-OmitStackTraceInFastThrow", \
"-Dio.netty.transport.noNative=false", \
"-Dio.netty.buffer.checkBounds=false", \
"-Dio.netty.buffer.checkAccessible=false", \
"-Dio.netty.allocator.maxOrder=10", \
"-Dio.netty.leakDetection.level=disabled", \
"-Dio.netty.recycler.maxCapacityPerThread=4096", \
"-Dio.netty.eventLoopThreads=0", \
"-jar", "ktor-ghost-httparena.jar"]
"-jar", "ktor-tuned-httparena.jar"]
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
alias(libs.plugins.kotlin.jvm)
alias(libs.plugins.kotlin.serialization)
alias(ktorLibs.plugins.ktor)
alias(libs.plugins.ktor)
alias(libs.plugins.kotlin.ksp)
}

Expand Down Expand Up @@ -31,18 +31,19 @@ dependencies {
implementation(libs.logback.classic)
implementation(libs.postgresql)
implementation(libs.hikaricp)
runtimeOnly(libs.netty.native.epoll)
runtimeOnly(variantOf(libs.netty.native.epoll) { classifier("linux-aarch_64") })
runtimeOnly(variantOf(libs.netty.native.openssl) { classifier("linux-aarch_64") })

testImplementation(kotlin("test"))
testImplementation(ktorLibs.server.testHost)
}

ktor {
fatJar {
archiveFileName.set("ktor-ghost-httparena.jar")
archiveFileName.set("ktor-tuned-httparena.jar")
}
}

kotlin {
jvmToolchain(21)
jvmToolchain(25)
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
[versions]
exposed = "1.2.0"
kotlin = "2.3.21"
exposed = "1.5.0"
kotlin = "2.4.20"
ghost = "1.3.1"

[libraries]
logback-classic = { module = "ch.qos.logback:logback-classic", version = "1.5.15" }
netty-native-epoll = { module = "io.netty:netty-transport-native-epoll", version = "4.2.14.Final" }
logback-classic = { module = "ch.qos.logback:logback-classic", version = "1.5.38" }
netty-native-epoll = { module = "io.netty:netty-transport-native-epoll", version = "4.2.16.Final" }
netty-native-openssl = { module = "io.netty:netty-tcnative-boringssl-static", version = "2.0.81.Final" }

# Ghost Serializer
ghost-serialization = { module = "com.ghostserializer:ghost-serialization", version = "1.2.2" }
ghost-compiler = { module = "com.ghostserializer:ghost-compiler", version = "1.2.2" }
ghost-serialization = { module = "com.ghostserializer:ghost-serialization", version.ref = "ghost" }
ghost-compiler = { module = "com.ghostserializer:ghost-compiler", version.ref = "ghost" }

# Database
exposed-core = { module = "org.jetbrains.exposed:exposed-core", version.ref = "exposed" }
Expand All @@ -18,6 +20,7 @@ postgresql = { module = "org.postgresql:postgresql", version = "42.7.4" }
hikaricp = { module = "com.zaxxer:HikariCP", version = "6.2.1" }

[plugins]
ktor = { id = "io.ktor.plugin", version = "3.5.2" }
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
kotlin-ksp = { id = "com.google.devtools.ksp", version = "2.3.9" }
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"display_name": "ktor-ghost",
"display_name": "ktor-tuned",
"language": "Kotlin",
"type": "flagship",
"mode": "tuned",
Expand All @@ -10,12 +10,13 @@
"response": true
},
"engine": "netty",
"description": "JetBrains Ktor 3.x on Netty with Kotlin coroutines, Ghost Serializer, JDK 21.",
"description": "JetBrains Ktor 3.x on Netty with Ghost Serializer, JDK 25.",
"repo": "https://github.com/ktorio/ktor",
"enabled": true,
"tests": [
"baseline", "async", "latency-1m", "latency-10k", "latency-500k-8cpu",
"limited-conn",
"async",
"pipelined",
"json-comp",
"json-tls",
Expand All @@ -26,6 +27,8 @@
"static-h2",
"baseline-h2c",
"json-h2c",
"baseline-h3",
"static-h3",
"echo-ws",
"echo-ws-pipeline"],
"maintainers": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ dependencyResolutionManagement {
mavenCentral()
}
versionCatalogs {
create("ktorLibs").from("io.ktor:ktor-version-catalog:3.5.0")
create("ktorLibs").from("io.ktor:ktor-version-catalog:3.6.0")
}
}

rootProject.name = "ktor-ghost-httparena"
rootProject.name = "ktor-tuned-httparena"
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,34 @@ import org.jetbrains.exposed.v1.jdbc.upsert
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.io.File
import kotlin.time.Duration.Companion.milliseconds

fun main() {
Ghost.prewarm()
println("Ktor HttpArena server starting on :8080 (HTTP/1.1) and :8443 (HTTPS/HTTP+2)")
println("Ktor HttpArena server starting on :8080 (HTTP/1.1), :8081 (JSON + TLS), :8082 (H2C), :8443 (HTTPS/HTTP2/HTTP3)")
val deps = ArenaApplicationDepsFactory.load()
val environment = applicationEnvironment {}

@OptIn(ExperimentalKtorApi::class)
val server = embeddedServer(Netty, environment, {
enableHttp2 = true
shareWorkGroup = true
enableH2c = true

// HTTP/1.1
connector {
port = 8080
host = "0.0.0.0"
}
// h2c
connector {
port = 8082
host = "0.0.0.0"
}
deps.keyStore?.let { keyStore ->
enableHttp2 = true
enableHttp3()

// JSON + TLS
sslConnector(
keyStore = keyStore,
keyAlias = KEY_ALIAS,
Expand All @@ -59,6 +72,7 @@ fun main() {
port = 8081
host = "0.0.0.0"
}
// HTTP/2 HTTP/3
sslConnector(
keyStore = keyStore,
keyAlias = KEY_ALIAS,
Expand All @@ -73,31 +87,6 @@ fun main() {
mainModule(deps)
}

// Spin up a second server for H2C
embeddedServer(Netty, environment, {
enableH2c = true

connector {
port = 8082
host = "0.0.0.0"
}
}) {
// Reject any non-HTTP/2 request hitting the H2C connector
intercept(ApplicationCallPipeline.Plugins) {
val version = call.request.httpVersion
if (!version.startsWith("HTTP/2")) {
call.response.headers.append(HttpHeaders.Upgrade, "h2c")
call.response.headers.append(HttpHeaders.Connection, "Upgrade")
call.respond(HttpStatusCode.UpgradeRequired, "HTTP/2 (h2c) required")
finish()
return@intercept
}
}
// Import the same endpoints for this server
mainModule(deps)

}.start(wait = false)

server.start(wait = true)
}

Expand Down Expand Up @@ -151,6 +140,18 @@ private fun Application.configureRouting(appData: ArenaApplicationDeps) {
call.respondNumber(ms)
}

/**
* Async delay
* https://www.http-arena.com/docs/test-profiles/h1/isolated/async/
*/
get("/delay/{ms}") {
val ms = call.parameters["ms"]!!.toLong()
// delay() suspends the coroutine rather than parking the thread it runs on, so the
// waits in flight are bounded by memory and not by the size of the event-loop group.
if (ms > 0) delay(ms)
call.respondNumber(ms)
}

/**
* Baseline 1.1
* https://www.http-arena.com/docs/test-profiles/h1/isolated/baseline/
Expand Down Expand Up @@ -199,13 +200,15 @@ private fun Application.configureRouting(appData: ArenaApplicationDeps) {
if (count < 0) count = 0
if (count > appData.dataset.size) count = appData.dataset.size
val m = call.request.queryParameters["m"]?.toIntOrNull() ?: 1
val processed = appData.dataset.take(count).map { d ->
ProcessedItem(
id = d.id, name = d.name, category = d.category,
price = d.price, quantity = d.quantity, active = d.active,
tags = d.tags, rating = d.rating,
total = d.price.toLong() * d.quantity * m
)
val processed = buildList(count) {
for (i in 0..<count) {
add(appData.dataset[i].let { d -> ProcessedItem(
id = d.id, name = d.name, category = d.category,
price = d.price, quantity = d.quantity, active = d.active,
tags = d.tags, rating = d.rating,
total = d.price.toLong() * d.quantity * m
)})
}
}
call.respondGhost(JsonResponse(items = processed, count = count))
}
Expand Down Expand Up @@ -254,7 +257,7 @@ private fun Application.configureRouting(appData: ArenaApplicationDeps) {
* Static files
* https://www.http-arena.com/docs/test-profiles/h1/isolated/static/
*/
staticFiles("/static", File("/data/static")) {
staticFiles("/static", dir = File("/data/static"), index = null) {
preCompressed(CompressedFileType.BROTLI, CompressedFileType.GZIP)
}

Expand Down Expand Up @@ -314,6 +317,16 @@ private fun Application.configureRouting(appData: ArenaApplicationDeps) {
}
}

/**
* Async Delay benchmark. Measures what a framework does with a request it cannot answer yet.
* https://www.http-arena.com/docs/test-profiles/h1/isolated/async/implementation/
*/
get("/delay/{ms}") {
val delayParam = call.parameters["ms"] ?: "0"
delay(delayParam.toLong().milliseconds)
call.respond(TextContent(delayParam, ContentType.Text.Plain))
}

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,4 +259,12 @@ class ApplicationTest {
assertEquals(HttpStatusCode.NotFound.value, response.status.value)
}

@Test
fun delayTest() = testApplication {
setup()
val response = client.get("/delay/1000")
assertEquals(HttpStatusCode.OK.value, response.status.value)
assertEquals("1000", response.bodyAsText())
}

}
10 changes: 3 additions & 7 deletions frameworks/ktor/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
FROM gradle:9.5.1-jdk21-corretto AS build
FROM gradle:9.5.1-jdk25-corretto AS build
WORKDIR /app
COPY build.gradle.kts settings.gradle.kts gradle.properties ./
COPY gradle/libs.versions.toml ./gradle/
RUN gradle dependencies --no-daemon -q 2>/dev/null || true
COPY src ./src
RUN gradle buildFatJar --no-daemon -q

FROM eclipse-temurin:21-jre
FROM eclipse-temurin:25-jre
WORKDIR /app
COPY --from=build /app/build/libs/ktor-httparena.jar .
EXPOSE 8080 8443
EXPOSE 8080 8081 8082 8443
ENTRYPOINT ["java", \
"-server", \
"-XX:+UseG1GC", \
"-XX:+UseNUMA", \
"-XX:+AlwaysPreTouch", \
"-XX:-OmitStackTraceInFastThrow", \
"-Dio.netty.transport.noNative=false", \
"-Dio.netty.buffer.checkBounds=false", \
"-Dio.netty.buffer.checkAccessible=false", \
"-Dio.netty.allocator.maxOrder=10", \
"-Dio.netty.leakDetection.level=disabled", \
"-Dio.netty.recycler.maxCapacityPerThread=4096", \
"-Dio.netty.eventLoopThreads=0", \
"-jar", "ktor-httparena.jar"]
7 changes: 4 additions & 3 deletions frameworks/ktor/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
alias(libs.plugins.kotlin.jvm)
alias(libs.plugins.kotlin.serialization)
alias(ktorLibs.plugins.ktor)
alias(libs.plugins.ktor)
}

group = "com.httparena"
Expand All @@ -27,7 +27,8 @@ dependencies {
implementation(libs.logback.classic)
implementation(libs.postgresql)
implementation(libs.hikaricp)
runtimeOnly(libs.netty.native.epoll)
runtimeOnly(variantOf(libs.netty.native.epoll) { classifier("linux-aarch_64") })
runtimeOnly(variantOf(libs.netty.native.openssl) { classifier("linux-aarch_64") })

testImplementation(kotlin("test"))
testImplementation(ktorLibs.server.testHost)
Expand All @@ -40,5 +41,5 @@ ktor {
}

kotlin {
jvmToolchain(21)
jvmToolchain(25)
}
12 changes: 7 additions & 5 deletions frameworks/ktor/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
[versions]
exposed = "1.2.0"
kotlin = "2.3.21"
exposed = "1.5.0"
kotlin = "2.4.20"

[libraries]
logback-classic = { module = "ch.qos.logback:logback-classic", version = "1.5.15" }
netty-native-epoll = { module = "io.netty:netty-transport-native-epoll", version = "4.2.14.Final" }
logback-classic = { module = "ch.qos.logback:logback-classic", version = "1.5.38" }
netty-native-epoll = { module = "io.netty:netty-transport-native-epoll", version = "4.2.16.Final" }
netty-native-openssl = { module = "io.netty:netty-tcnative-boringssl-static", version = "2.0.81.Final" }

# Database
exposed-core = { module = "org.jetbrains.exposed:exposed-core", version.ref = "exposed" }
Expand All @@ -14,5 +15,6 @@ postgresql = { module = "org.postgresql:postgresql", version = "42.7.4" }
hikaricp = { module = "com.zaxxer:HikariCP", version = "6.2.1" }

[plugins]
ktor = { id = "io.ktor.plugin", version = "3.5.2" }
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
5 changes: 4 additions & 1 deletion frameworks/ktor/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
"response": true
},
"engine": "netty",
"description": "JetBrains Ktor 3.x on Netty with Kotlin coroutines, kotlinx.serialization, JDK 21.",
"description": "JetBrains Ktor 3.x on Netty with kotlinx.serialization, JDK 25.",
"repo": "https://github.com/ktorio/ktor",
"enabled": true,
"tests": [
"baseline", "async", "latency-1m", "latency-10k", "latency-500k-8cpu",
"limited-conn",
"async",
"pipelined",
"json-comp",
"json-tls",
Expand All @@ -26,6 +27,8 @@
"static-h2",
"baseline-h2c",
"json-h2c",
"baseline-h3",
"static-h3",
"echo-ws",
"echo-ws-pipeline",
"fortunes"
Expand Down
Loading
Loading