First step is to build the project and then start the server from terminal.
./gradlew clean build
$ cd build/libs $ java -Xms512m -jar <artifact.jar>
Now the server shall start on port 8080 ready for serving the requests.
wrk is a modern HTTP benchmarking tool capable of generating significant load when run on a single multi-core CPU. It combines a multithreaded design with scalable event notification systems such as epoll and kqueue.
To install wrk on ubuntu 18.04 system, just run the below command
sudo apt install wrk
Now wrk is ready for the testing.
Now start the Spring Boot application and run the below command from terminal
$ wrk -t8 -c40 -d30s http://localhost:8080/api/perf
This will launch 8 threads and keep 40 HTTP open connections for a duration of 30s and measure the results.
My machine is 16GB DDR3, Xeon E31245, 2011 Model Desktop
So we can see that a simple ping controller gives throughput of 31000 requests per second, which is not bad at all.
h2load is another high performance HTTP benchmarking tool that we can use to bench mark our API.
$ h2load -n100000 -c50 --h1 http://localhost:8080/api/perf
starting benchmark...
spawning thread #0: 50 total client(s). 100000 total requests
Application protocol: http/1.1
finished in 1.61s, 62089.09 req/s, 5.39MB/s
requests: 100000 total, 100000 started, 100000 done, 100000 succeeded, 0 failed, 0 errored, 0 timeout
status codes: 100000 2xx, 0 3xx, 0 4xx, 0 5xx
traffic: 8.68MB (9100000) total, 4.20MB (4400000) headers (space savings 0.00%), 1.91MB (2000000) data
min max mean sd +/- sd
time for request: 114us 11.88ms 801us 213us 98.82%
time for connect: 204us 3.11ms 1.64ms 817us 58.00%
time to 1st byte: 3.17ms 8.25ms 5.35ms 1.34ms 58.00%
req/s : 1242.20 1248.13 1244.66 1.22 70.00%
We can see that with latest version of Spring Boot 2.2.0, we can get a throughput of 62K requests/second
on the same Ubuntu 18.04.2 server.