Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot Embedded Tomcat Performance

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?

like image 274
Peter Jerald Avatar asked Oct 29 '16 14:10

Peter Jerald


People also ask

Can we use embedded Tomcat in spring boot for production?

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.

What is the advantage of having an embedded Tomcat server?

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.

Does Tomcat spring boot embedded container?

The Spring Boot starters ( spring-boot-starter-web in particular) use Tomcat as an embedded container by default.

What is embedded Tomcat in spring boot?

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.


1 Answers

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

like image 145
Peter Jerald Avatar answered Sep 18 '22 13:09

Peter Jerald