Since we are mostly using Tomcat as App Container, it's making tough environment when deploying a patch or existing application without restarting tomcat server (Hot deployments) due to reaching the PermGen size due to memory leaks. Hence most of the cases we have to increase PermGen size more than required to deployed applications and it's wasting of memory in the system.
There is a solution for them to release PermGen size and let it clean by GC in JVM at hot deployment.
Step 01: Include below dependency to pom.xml
<dependency>
<groupId>se.jiderhamn.classloa der-leak-prevention</groupId>
<artifactId>classloader-leak-p revention-servlet</artifactId> <version>2.2.0</version>
</dependency>
<groupId>se.jiderhamn.classloa
<artifactId>classloader-leak-p
</dependency>
Step 02: Add listener to web.xml
<listener> <listener-class>se.jiderhamn.c lassloader.leak.prevention.Cla ssLoaderLeakPreventorListener< /listener-class></listener>
Visit here for more details : https://github.com/mjiderhamn/ classloader-leak-prevention
Step 03: Provide below JRE options to enable markSweep GC when starting tomcat. (into catalina.sh or setenv.sh)
export CATALINA_OPTS="-XX:+CMSClassUn loadingEnabled -XX:+CMSPermGenSweepingEnabled -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode"
OR
export CATALINA_OPTS="-XX:+CMSClassUn loadingEnabled -XX:+CMSPermGenSweepingEnabled -XX:+UseParallelOldGC"
Note: Do several hot deployments (just touch the web.xml) and monitor the behaviour by using jconsole or jvisualvm.
Issues: I found the issue there still getting PermGen size not cleaning by GC when using Hibernate second level cache.
Comments
Post a Comment