We've noticed in our that SOAP web-services seem to run faster when run as
spring-boot:run
as opposed to packaging up the JAR as we do for deployment and running
java -jar mySpringApp.jar
The speed up is in the order of 2-3x so obviously we would like this for our live environment.
To validate that this wasn't something in our app I've tried this with the sample app from the spring guide
git source https://github.com/spring-guides/gs-soap-service.git
Testing this with JMeter shows the same sort of speed up. I've tested this on both Windows 7 Java 1.8.0_31 and Ubuntu 14.04 platforms with 1.8.0_45-b14.
This only seems to be the case for soap services, simple html doesn't show any significant difference in performance. Any idea what could be causing this?
I tested this and it appears that the application spends a significant amount of time in the following two code paths:
and
The interesting lines are
and
What this means is that for every request, the SAAJ implementation in the JRE requests a new
TransformerFactory
and a newDocumentBuilderFactory
. These factories are located using the JDK 1.3 service provider discovery mechanism, which involves searching for certain resources underMETA-INF/services
. The performance of that search is very sensitive to the characteristics of the class loaders from which these resources are looked up. That is why you see a difference betweenmvn spring-boot:run
and using an executable JAR. In particular, the executable JAR contains embedded JARs and looking up resources from these embedded JARs is expensive. Formvn spring-boot:run
this is not the case, which explains why it is faster.Since this is ultimately a problem with the SAAJ implementation, one solution is to use Apache Axiom instead. To do this with the sample application from the spring guide, simply add the following code to
WebServiceConfig
:You also need to add the following dependency: