Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I find out what's taking my WAR so long to deploy on Tomcat?

I have a web application which often takes an inordinate amount of time to deploy on Tomcat. My suspicion is that there's a database connection somewhere that's waiting until a timeout, but that's just a guess and I want to find out for sure what's causing the hold up so I can remedy the issue. Can anyone suggest a way I can go about doing this? Should I profile Tomcat when it's loading the WAR and look there for clues? If so is there a tutorial somewhere that's good for a beginner?

In case this matters my web application uses Spring and Hibernate. I've been told by a colleague that perhaps these are causing the slow down in that they are so huge that somewhere a class loader is choking on the sheer number of classes it needs to load.

Also I see this when I stop Tomcat or hot deploy the WAR to an already running Tomcat:

Jun 1, 2012 6:03:33 PM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
SEVERE: The web application [/nacem-rest] registered the JDBC driver [oracle.jdbc.OracleDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
Jun 1, 2012 6:03:34 PM org.apache.catalina.startup.HostConfig deployWAR

Perhaps this is part of the problem? Redeploying my web application almost always requires a restart of Tomcat as well, and I've always assumed that the above mentioned JDBC driver issue was to blame, but maybe it also has something to do with the sluggish start time as well?

like image 678
James Adams Avatar asked Jun 01 '12 21:06

James Adams


People also ask

How do I deploy a WAR file to Tomcat?

A WAR file can be deployed to Tomcat by copying its contents over to its webapps directory and accessing it via the WAR’s output. WAR files can be deployed via Tomcat’s webapps directory by copying and pasting them. Start by downloading your application built on Tomcat on your machine and using it to deploy.

Where are Tomcat project files stored after deployment?

After deploying our WAR file, Tomcat unpacks it and stores all project files in the webapps directory in a new directory named after the project. 3.

What is Tomcat and how do I use it?

It provides a management dashboard from which you can deploy a new web application, or undeploy an existing one without having to restart the container. This is especially useful in production environments. In this article, we will do a quick overview of Tomcat and then cover various approaches to deploying a WAR file.

How do I deploy a WAR file from local machine?

From the opening page, scroll downwards until you see the "Deploy"-part of the page, where you can click "browse" to select a WAR file to deploy from your local machine. After you've selected the file, click deploy. After a while the manager should inform you that the application has been deployed (and if everything went well, started).


2 Answers

You can use a profiler, but it is a bit of an overkill. Instead just make few thread dumps while the application loads. You can use jstack or jvisualvm, plenty of resources over the net describing how to do this. Basically you need a PID of your Tomcat (see: jps).

If you find it hard to analyse the thread dump - add it to your question. Typically it's pretty easy to find a bottleneck. Typical problems:

  • the application tries to fetch some resource from the Internet like XML schema
  • a lot of classes to scan on the CLASSPATH
  • excessive GC (enable verbose gc logging just in case)
  • not enough memory (swapping, see iostat/iotop)
like image 156
Tomasz Nurkiewicz Avatar answered Oct 22 '22 20:10

Tomasz Nurkiewicz


the first I would look is how the CPU or RAM usage of tomcat perform during your application startup.

If you see a lot of CPU activity and RAM increase, then it's probably loading a lot of stuff, like a lot of classes, or performing some kind of huge pre-allocation or similar. In that case thread dumps can help you a lot, but also "lsof" (if your tomcat is running on an *nix environment) to see what files it is currently working on.

However, if you see it simply sitting there, then it is probably waiting on some kind of connection.

One cause may be a DB connection, as you supposed. The DB is usually fast to answer, and a failed attempt to connect to a DB is usually clearly logged somewhere, but still it could be.

Another, less known, cause may be some XML validation. It is not uncommon for a web application to load some XML data, and it is not uncommon to use a validating parser to load that XML. The validating parser needs a schema or DTD to validate, and the URL for the schema/DTD file is often included in the XML. So, some parsers will try to load the schema file from internet to validate the XML, and that could take a lot of time being an internet connection. Moreover, some parsers will fail silently and simply not validate the XML, probably after a rather long timeout. Sorry for being vague on "some parsers" etc.. but if XML loading is done by libraries used inside your webapp, they could use the JVM XML parser, any possible version of Xerces, any possible version for JDOM etc... and even worst different libraries may be using different parsers.

However, if it is a connection problem, it's easier to see it using "netstat -anlp | grep java" (in your tomcat is on a *nix environment, otherwise it should be "netstat -ano" on windows), and looking for what outgoing connection your tomcat is trying to make. There you can see DB connections and also outgoing (usually http) connections searching for schemes or other stuff.

like image 38
Simone Gianni Avatar answered Oct 22 '22 19:10

Simone Gianni