In this module we study the effect of Spring and Spring Boot on startup time using the webflux and functional webflux programming models.
class method sample beans classes heap memory median mean range
MainBenchmark main empt 25.000 3222.000 5.058 38.559 0.532 0.537 0.006
MainBenchmark main jlog 77.000 3625.000 6.100 43.079 0.661 0.683 0.040
MainBenchmark main demo 90.000 4405.000 8.179 49.914 0.757 0.768 0.010
MainBenchmark main actr 176.000 5192.000 8.438 54.121 0.905 0.929 0.053
MainBenchmark main jdbc 128.000 5118.000 8.015 53.300 0.851 0.862 0.025
MainBenchmark main actj 216.000 5383.000 10.210 56.989 0.978 0.989 0.013
MiniBenchmark boot jlog 28.000 3250.000 6.692 41.158 0.562 0.571 0.013
MiniBenchmark boot demo 28.000 3931.000 6.335 45.057 0.659 0.666 0.007
MiniBenchmark mini jlog 27.000 2986.000 5.421 38.561 0.516 0.524 0.014
MiniBenchmark mini demo 27.000 3660.000 5.976 43.370 0.612 0.623 0.023
MiniBenchmark micro jlog 2.000 2215.000 4.817 33.320 0.339 0.344 0.007
MiniBenchmark micro demo 2.000 2948.000 7.514 40.747 0.440 0.444 0.005
Notes:
-
The
MainBenchmark.main(demo)
is full Boot + Webflux + autoconfiguration. -
The
boot
samples use Spring Boot but no autoconfiguration. -
The
jlog
samples exclude logback as well as Hibernate Validator and Jackson. -
The
mini
samples do not use Spring Boot (just@EnableWebFlux
). -
The
micro
samples do not use@EnableWebflux
, just a manual route registration.
Non-heap is really what matters for these smaller apps.
There’s a flag in Spring Boot 2.2 that makes all beans lazy by
default. It is switched on in all the above benchmarks.
Some of those beans end up being initialized on
the first HTTP request, but probably most of them are not needed in
this sample, so they could stay uninitialized and no-one would
care. We’d need more logic / conditions in @EnableWebFlux
to
capitalize on it without cheating
The results are quite variable with Open J9, but once the CDS cache is created you usually see about 10-15% improvement.
Comparison of different Webflux options in Spring Boot 2.0:
Benchmark (sample) Mode Cnt Score Error Units Webstack
MainBenchmark.main demo ss 10 1.124 ± 0.050 s/op mvc
MainBenchmark.main flux ss 10 1.023 ± 0.080 s/op webflux
MainBenchmark.main actr ss 10 1.548 ± 0.049 s/op mvc
MainBenchmark.main demo ss 10 0.993 ± 0.027 s/op flux.fn
MainBenchmark.main actr ss 10 1.397 ± 0.068 s/op webflux
Summary: webflux.fn and @webflux are comparable, and both are faster on Netty than MVC on Tomcat (>~10%).
Spring 5.1 had some performance improvements.
class method sample beans classes heap memory median mean range
MainBenchmark main empt 23.000 3203.000 5.203 38.715 0.544 0.550 0.009
MainBenchmark main jlog 85.000 4141.000 7.428 47.682 0.816 0.825 0.015
MainBenchmark main demo 100.000 4947.000 8.260 53.504 0.932 0.946 0.014
MainBenchmark main actr 229.000 6329.000 12.773 64.606 1.277 1.290 0.015
MainBenchmark main jdbc 138.000 5749.000 10.184 59.533 1.067 1.087 0.020
MainBenchmark main actj 269.000 6607.000 13.193 66.706 1.431 1.456 0.072
Benchmark (sample) Mode Cnt Score Error Units
MiniBenchmark.boot jlog ss 10 0.458 ± 0.007 s/op
MiniBenchmark.boot demo ss 10 0.572 ± 0.014 s/op
MiniBenchmark.micro jlog ss 10 0.199 ± 0.013 s/op
MiniBenchmark.micro demo ss 10 0.304 ± 0.003 s/op
MiniBenchmark.mini jlog ss 10 0.412 ± 0.022 s/op
MiniBenchmark.mini demo ss 10 0.529 ± 0.013 s/op
On J9:
MainBenchmark.main empt ss 10 0.455 ± 0.053 s/op
MainBenchmark.main jlog ss 10 0.644 ± 0.038 s/op
MainBenchmark.main demo ss 10 0.851 ± 0.026 s/op
MainBenchmark.main actr ss 10 1.231 ± 0.048 s/op
MainBenchmark.main jdbc ss 10 0.973 ± 0.040 s/op
MainBenchmark.main actj ss 10 1.389 ± 0.040 s/op
class method sample beans classes heap memory median mean range
MainBenchmark main empt 17.000 3136.000 5.297 38.537 0.525 0.532 0.007
MainBenchmark main jlog 68.000 3987.000 7.099 47.673 0.813 0.824 0.018
MainBenchmark main demo 85.000 4806.000 9.535 55.215 0.967 0.983 0.016
MainBenchmark main actr 207.000 6195.000 12.394 64.613 1.392 1.412 0.023
MainBenchmark main jdbc 123.000 5594.000 11.182 60.950 1.141 1.168 0.026
MainBenchmark main actj 248.000 6470.000 13.953 67.815 1.578 1.592 0.015