This benchmark repository provides methods for benchmarking the OkHttp Client and Java HTTP Client (introduced in Java 11) in a dapr-java-sdk environment.
The DaprHttp class from the dapr-java-sdk is turned into a simplified interface. For both clients, an equal implementation of this interface has been made to get a fair comparison. JMH (Java Microbenchmark Harness) uses both implementations for performance testing.
Both HTTP clients send their requests to an Nginx webserver that serves a static JSON response. ApacheBench (also provided in this repository) can be used to performance test this Nginx Webserver, to get an idea of how fast the webserver can go. The result of the ApacheBench test can be used as baseline measurement for the comparison of the results of the HTTP clients performance tests.
All measurements will be shown in milliseconds per operation (ms/op). Keep in mind that the results of the benchmarks depend on the environment you run the benchmarks in. That's why ApacheBench is also provided in this repository, to get a baseline measurement before running JMH.
Make sure you have the following prerequisites installed on your machine.
- Docker for Desktop
- Java 11 or above
- Apache Maven 3.6.3 or above
In order to run everything in the right way and get good measurements, you can follow the following steps:
To send HTTP requests to the webserver, you first have to start the Nginx webserver that serves a static JSON response in a Docker container. You can execute the run_nginx.sh
shell script in the infrastructure/nginx
folder to start the webserver.
The static JSON response will be served at http://localhost:4005/employees.json
When the Nginx webserver is running you can performance test the webserver using ApacheBench to get a baseline measurement. To do this you can execute the run_apache_bench.sh
shell script in the infrastructure/ab
folder.
To run JMH for the OkHttp Client an Java HTTP client you can execute the following command in the root of the repository
mvn clean compile exec:java
You can also run the nl.julian.benchmark.BenchMarkRunner
mainClass from your IDE (IntelliJ).
After running the ApacheBench benchmark and JMH benchmarks you can compare the measurements.