This repository contains benchmark tests for various Ktor performance metrics including memory allocation, throughput, I/O operations, and utilities.
- JDK 17 or higher
- Gradle (wrapper included)
Tests memory allocation on a given request to ensure Ktor maintains a low memory profile by avoiding erroneous allocations.
Tests:
ServerCallAllocationTest- Measures memory allocated per request for server engines (Jetty, Tomcat, Netty, CIO)ClientCallAllocationTest- Measures memory allocated per request for client engines (CIO, Apache, OkHttp, Java)
Running Tests:
cd allocation-benchmark
./gradlew test # Run all allocation tests
./gradlew serverTests # Run only server allocation tests
./gradlew dumpAllocations # Generate new allocation baselines
./gradlew reportServer # Start web server to view allocation reportsViewing Reports:
After running reportServer, open your browser to view:
previewClasses.html- Largest memory consumers by typepreviewSites.html- Code sites that allocate the most memory
TeamCity: Allocation Tests
JMH-based benchmarks for testing Ktor server performance under various scenarios including integration tests and specific feature benchmarks.
Running Benchmarks:
cd server-benchmarks
./gradlew jmh # Run benchmarks (configure includes in build.gradle.kts)Note: Edit build.gradle.kts to configure which benchmarks to run via the includes list.
Throughput benchmarks comparing different Ktor client engines (CIO, Apache, OkHttp, Java) against a local server.
Running Benchmarks:
cd client-benchmarks
./gradlew run # Run client throughput benchmarksThis will:
- Start a Netty server on port 8080
- Run concurrent requests using different client engines
- Report requests per second for each engine
JMH benchmarks for I/O operations including file reading and socket operations across different dispatchers and implementations.
Running Benchmarks:
cd io-benchmarks
./gradlew jmh # Run all I/O benchmarksBenchmarks include:
- File reading with various dispatchers (IO, Hot, Fixed, Blocking, etc.)
- Socket read/write operations
- Comparison between JVM native and Ktor implementations
See io-benchmarks/README.md for latest results.
JMH benchmarks for Ktor utility components, primarily focusing on pipeline execution performance.
Running Benchmarks:
cd utils-benchmarks
./gradlew jmh # Run pipeline benchmarksSee utils-benchmarks/README.md for latest results.
Gradle plugin providing test server infrastructure used by other benchmark modules. Contains reusable server configurations and routes.
To run all benchmarks:
# Allocation tests
cd allocation-benchmark && ./gradlew test && cd ..
# Server benchmarks
cd server-benchmarks && ./gradlew jmh && cd ..
# Client benchmarks
cd client-benchmarks && ./gradlew run && cd ..
# I/O benchmarks
cd io-benchmarks && ./gradlew jmh && cd ..
# Utils benchmarks
cd utils-benchmarks && ./gradlew jmh && cd ..- Allocation Benchmarks - Memory allocation testing using instrumentation agent
- JMH Benchmarks - Standard JMH microbenchmarks for throughput and average time measurements
- Throughput Benchmarks - Concurrent request testing for client/server performance
- JVM arguments and benchmark parameters are configured in each subproject's
build.gradle.kts - Allocation baselines are stored in
allocations/directories - JMH results may be output to CSV files in respective directories