This module provides a general purpose benchmark for any Spring Boot jar. You pass it the jar file to measure on the command line. It works for fat and thin jars, created with the Spring Boot tooling.
Example usage:
$ java -jar target/benchmarks.jar ~/dev/spring/spring-petclinic/target/spring-petclinic-2.1.0.jar
...
# Run complete. Total time: 00:02:44
...
class, method, beans, classes, heap, memory, median, mean, range
com.example.MainBenchmark, jar, ≈ 0, 10775.000, 31.530, 125.987, 5.192, 5.289, 0.129
com.example.MainBenchmark, launcher, 367.000, 10799.000, 36.254, 130.941, 3.881, 4.025, 0.170
com.example.MainBenchmark, main, 365.000, 10752.000, 36.751, 130.943, 3.587, 3.679, 0.095
Note
|
If you are seeing "≈ 0" values for all the JVM metrics you probably don’t have a tools.jar on your classpath. You need to either use a full JDK, or supplement the boot classpath, e.g. add -Xbootclasspath/a:<path-to>/tools.jar to the command line.
|
For the "jar" benchmark the app has to emit a log containing "started on port" (by default) when it is ready. You can change the "marker" that the benchmark looks for with --marker='Foo Bar' (for instance). Multiple values are acceptable, and any will terminate the measurement.
For the "main" (exploded jar with main class) and "launcher" (exploded jar with Boot launcher) benchmarks it also installs a listener that prints the number of classes loaded and the number of beans.
To measure the time to first request, add -Drequest.uri=http://localhost:8080
(or whatever) and --server.port=8080
(by default the port will be set to 0). To add JVM command line options for the launched application processes, use -Dbench.args
.
To pass arguments to JMH you need to put them after a single argument of --
. E.g.
$ java -jar target/benchmarks.jar target/it/support/target/demo-1.0.0-exec.jar -- MainBenchmark.launcher