Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring boot project publish to production environment choose war(standalone tomcat) or jar(embedded tomcat)?

Tags:

spring-boot

Latest project I used Spring boot, and prepare to deploy to production environment, I want to know which way to run application have better performance or have the same performance?

  1. generate a war package and put it in a stand-alone tomcat
  2. generate a jar package and use embedded tomcat

In addition, when publish to production environment if should to remove devtools dependency.

like image 626
zhuguowei Avatar asked Dec 18 '22 22:12

zhuguowei


1 Answers

This is a broad question. The answer is it depends on your requirements.

Personally, I prefer standalone applications with Spring Boot today. One app, one JVM. It gives you more flexibility and reliability in regard to deployments and runtime behaviour. Spring Boot 1.3.0.RELEASE comes with init scripts which allows you to run your Spring Boot application as a daemon on a Linux server. For instance, you can integrate rpm-maven-plugin into your build pipeline in order to package and publish your application as a RPM for deployment or you can dockerize your application easily.

With a classic deployment into a servlet container like Tomcat you will be facing various memory leaks after redeployment for example with logging frameworks, badly managed thread local objects, JDBC drivers and a lot more. Either you spend time to fix all of those memory leaks inside your application and frameworks you use or just restart servlet container after a deployment. Running your application as a standalone version, you don't care about those memory leaks because you are forced to restart in order to bring you new version up.

In the past, several webapps ran inside one servlet container. This could lead to performance degradation for all webapps because every webapp has its own memory, cpu and GC characteristics which may interfere with each other. Further more, resources like thread pools were shared among all webapps.

In fact, a standalone application is not save from performance degradation due to high load on the server but it does not interfere with others in respect to memory utilization or GC. Keep in mind that performance or GC tuning is much more simpler if you can focus on the characteristics of just one application. It gets complicated as soon as you'll need to find common denominator for several webapps in one servlet container.

In the end, your decision may depend on your work environment. If you are building an application in a corporation where software is running and maintained by operations, it is more likely that you are forced to build a war. If you have the freedom to choose your deployment target, then I recommend a standalone application.


In order to remove devtools from a production build

you can use set the excludeDevtools build property to completely remove the JAR. The property is supported with both the Maven and Gradle plugins.

See Spring Boot documentation.

like image 106
ksokol Avatar answered Jun 01 '23 17:06

ksokol