JMH (Java Microbenchmark Harness) benchmarks for Ktor server performance testing.
This module contains comprehensive JMH benchmarks for testing Ktor server components, integration scenarios, and performance characteristics across different server engines.
Full end-to-end server benchmarks with real HTTP clients:
- IntegrationBenchmark - Generic integration tests
- AsyncIntegrationBenchmark - Async client integration tests
- CIOIntegrationBenchmark - CIO engine-specific tests
- NettyIntegrationBenchmark - Netty engine-specific tests
- JettyIntegrationBenchmark - Jetty engine-specific tests
- TestIntegrationBenchmark - TestHost engine tests
Individual component performance tests:
- PipelineBenchmark - HTTP pipeline execution performance
- RoutingBenchmark - Routing resolution performance
- ChannelBenchmarks - ByteChannel operations
- CodecsBenchmark - Encoding/decoding operations
- StringValuesBenchmark - Headers and parameters parsing
- CIOChunkedBenchmark - Chunked transfer encoding (CIO)
Engine-specific platform tests:
- PlatformBenchmark - Generic platform tests
- CIOPlatformBenchmark - CIO platform tests
- NettyPlatformBenchmark - Netty platform tests
- JettyPlatformBenchmark - Jetty platform tests
- CoroutineCancellationBenchmark - Coroutine cancellation overhead
# Run all configured benchmarks
./gradlew jmhNote: By default, only specific benchmarks run. Edit build.gradle.kts to configure which benchmarks to run:
jmh {
// Change this list for different benchmarks
includes = listOf(
"io.ktor.benchmarks.cio.CIOIntegrationBenchmark"
)
}JMH settings in build.gradle.kts:
jmh {
warmupIterations = 2 // Warmup iterations
fork = 2 // Number of forks
iterations = 10 // Measurement iterations
threads = 32 // Thread count
}Benchmark results are written to:
- Console output
jmh-result.csv- CSV format for analysis
Different benchmarks use different JMH modes:
- Throughput - Operations per time unit
- AverageTime - Average time per operation
- SampleTime - Sampling time distribution
Benchmarks use various HTTP clients to test servers:
- Apache HttpClient
- OkHttp
- Ktor test client
- Plain text response - Minimal overhead baseline
- Chunked transfer - Streaming response performance
- Large payloads - Performance under load
- Concurrent requests - Multi-threaded throughput
To run specific benchmarks:
- Edit
build.gradle.kts - Update the
includeslist with desired benchmark classes - Run
./gradlew jmh
Example:
includes = listOf(
"io.ktor.benchmarks.IntegrationBenchmark",
"io.ktor.benchmarks.RoutingBenchmark"
)To run all benchmarks (warning: very time-consuming):
includes = listOf() // Empty list = run all- Higher throughput (ops/s) is better
- Lower average time (ms/op) is better
- Check error margins (±) for result stability
- Compare across engines and configurations
- Significant CPU and memory resources
- Multiple runs recommended for consistent results
- Quiet system (minimal background processes)