views:

393

answers:

3

I'm using Teamcity to run CI which works great, apart from one thing: when my webapp is deployed to the web container (Tomcat 5.5) after a few times Tomcat runs out of memory. This is something that you see in development as well, but it's not such a huge problem since then you can restart manually any way - with CI it's all automatic which makes it really annoying.

I tried to setup Teamcity so that it restarts Tomcat every deploy, but then I ran into another problem - the Tomcat start script just hangs when called from ant (ie it starts Tomcat just fine, but then doesn't go any further in the build-process).

Anyone out there with a similar Teamcity-Tomcat setup?

A: 

It's an issue with tomcat, the classloader and the classes are not being garbage collected properly. Every time you reload the webapp context, more copies of these classes are loaded, and as these are stored in the permanent heap generation, it will eventually run out of memory.

You can increase the PermGen size on tomcat startup, this will only allow you to re-deloy more times with out running out of memory, it's not really a fix but you can increase the number of deploys until you'll have to restart.

Mark Robinson
A: 

We had exactly the same issue, and as Mark Robinson points out, it's to do with classes not getting garbage collected.

The particular issue we had was lots of static stuff getting loaded: log4j, spring contexts stuffed in static globals, and other class libraries that created static instances or singletons.

It was possible to trace down a lot of these using a profiler, and then explicitly deal with resource cleanup in the servlet's destroy() method. Although this didn't totally solve the problem, it did relieve some of it.

In the end we added an additional pair of ant targets to stop and start Tomcat, and wrapped the build process in these. YMMV.

Dan Vinton
A: 

I am facing the same problem. I have created stop and start targets in the ant script. The Tomcat gets stopped, and build gets created correctly and then tomcat also starts but the start thread seems to hang. Has any body found a solution for this. Please let me know. Thanks, Gagan Suri

Gagan