I am developing Microservices API for my application. I started with Spring Boot application. I created two artifacts - "business code with embedded tomcat" and "business code without embedded tomcat".
When I compare the performance results, I can see that the "non-embedded tomcat" (i.e. executing on standalone tomcat) gives good output because of native execution.
So basically what is the difference between the embedded tomcat and the standalone tomcat regarding implementation?
How the performance varies between two executions?
Yes. It's the same tomcat, but in library form. So you are responsible for configuration and other things that the standalone tomcat provides. Also you don't have to use tomcat.
Embedded Tomcat offers a way to package Java web applications that is consistent with a microservices-based approach to software development. It also makes it easier to distribute Java web applications through Docker containers and manage them through a container orchestration service, such as Kubernetes or OpenShift.
The Spring Boot starters ( spring-boot-starter-web in particular) use Tomcat as an embedded container by default.
Embedded tomcat means in runtime inside your JVM Spring boot starts a server with the dependencies in your jar. So all the problems of pushing the war to tomcat folder and restarting are eliminated. Build your jar using Spring boot plugin.
I found out actual root cause of this issue.
APR (Apache Portable Runtime) plays important role in tomcat thread execution.
By Default, embedded tomcat executes NIO. NIO and BIO are Java based executions whereas APR is native execution. When we compare performance of NIO and APR, APR is pretty much faster.
In fact all the Linux based tomcat bundles are shipped with APR libs under the tomcat lib folder.
After I enabled APR in embedded tomcat (i.e. Spring Boot) performance execution was same compared to standalone tomcat.
http://tomcat.apache.org/tomcat-7.0-doc/apr.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With