Reputation: 1442
I have a Tomcat 7 with a few applications installed, for now it's usual to upload new versions of the applications pretty fast: so I pack the war and undeploy the existing one and deploy the new war or redeploy an existing application, The problem comes few weeks later when I see that the memory is almost full in order to prevent some unexpected outofmemory exceptions that makes our customers without service
Do I have to restart time to time Tomcat? ¿Is that normal? Is there a pragmatic solution for zero Tomcat restarts?
Please only expert answers
UPDATE: This library can really help to avoid permgem issues and classloader leaks: https://github.com/mjiderhamn/classloader-leak-prevention, But remember that it's your responsability to not having leaks, there's no silver bullet. Visual VM can really help detecting classloader leaks.
Upvotes: 0
Views: 1350
Reputation: 1
You need add the VM arguments in the eclipse with minimum and maximum length. In eclipse goto window--> preferences-->click on Java-->click on installed JREs. then double click on jre record add the vm arguments as -Xms768m -Xmx1024m.
Upvotes: 0
Reputation: 3325
The pragmatic solution for zero Tomcat restarts is coding applications that does not leak memory. It's that easy - Tomcat it not likely to leak that memory on it's own ;) In other words: As long as your application is leaking memory restarting is unavoidable. You can tune memory settings, but you're just postponing the inevitable. Tomcat7 can detect some memory leaks (and even remedy some simple ones) - this feature is exposed through the Tomcat Manager if you install that. It does not, however, help you point our where the leak is.
Speaking from recent experience I had an app that did not seem to leak during normal operation, but had a PermGen leak - this means I do not really see the leak until I try to do what you're doing - hot deploy. I could only do a few deploys before filling the PermGen as Tomcat was unable to unload the old instance of the classes... There may be better explanations of PermGen leak on the web, but a quick google gave me this: http://cdivilly.wordpress.com/2012/04/23/permgen-memory-leak/
If, however, your application crashes after running for some time it is likely that is has a proper memory leak. You can tune heap sizes and garbage collection settings in an attempt to remedy/work around this, but it may very well be that the only real fix is to track down the leak, fix the code and build a version that does not leak. ...but unless you can ensure every release will be leak-free you need a strategy for restarting your service. If you don't do it during release, look into doing it off peak hours. If you have a cluster you can look into setting up Tomcat with memcached for session replication so as to not disrupt users when restarting a node in the cluster. You can also look into setting up monit, god, runit, upstart, systemd etc. for automatic restart of failed services...
Upvotes: 1