0

I have a Tomcat7 server running and it crashes and shows sometimes a memory warning that there is not enough Heap Space.

What do I have to do here?

My server has 4GB RAM, 4CPU and runs on ubuntu 12.04 LTS 64-Bit

I am new with Tomcat so I will be thankful for help.

I want to use tomcat in production here is what I have changed:

web.xml

<servlet>
    <servlet-name>jsp</servlet-name>
    <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
    <init-param>
        <param-name>fork</param-name>
        <param-value>false</param-value>
    </init-param>
    <init-param>
        <param-name>xpoweredBy</param-name>
        <param-value>false</param-value>
    </init-param>
    <init-param>
        <param-name>development</param-name>
        <param-value>false</param-value>
    </init-param>
    <init-param>
        <param-name>reloading</param-name>
        <param-value>false</param-value>
    </init-param>
    <init-param>
        <param-name>genStringAsCharArray</param-name>
        <param-value>true</param-value>
    </init-param>
    <init-param>
        <param-name>modificationTestInterval</param-name>
        <param-value>40</param-value>
    </init-param>
    <init-param>
        <param-name>trimSpaces</param-name>
        <param-value>true</param-value>
    </init-param>       
    <load-on-startup>3</load-on-startup>
</servlet>

server.xml

<Connector port="8080" 
            protocol="org.apache.coyote.http11.Http11AprProtocol" 
            connectionTimeout="3000"
            redirectPort="8443"                 
            URIEncoding="UTF-8"
            maxPostSize="0"
            maxThreads="100"            
            enableLookups="false"
            disableUploadTimeout="false"
            maxKeepAliveRequests="-1"
            useBodyEncodingForURI="true"
            compression="on"
            compressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain" 
            />

setenv.sh

export LD_LIBRARY_PATH='$LD_LIBRARY_PATH:/usr/local/apr/lib'

CATALINA_OPTS="
-server 
-Xss1G 
-Xms2G 
-Xmx2G 
-XX:+UseConcMarkSweepGC 
-XX:NewSize=1G 
-XX:+UseParNewGC

-Djava.awt.headless=true 
-Dfile.encoding=UTF-8
-XX:MaxNewSize=1G
-XX:PermSize=1G 
-XX:MaxPermSize=1G
-XX:+DisableExplicitGC


-XX:SurvivorRatio=128 
-XX:MaxTenuringThreshold=0 
-XX:+UseTLAB 
-XX:+CMSClassUnloadingEnabled 
-XX:+CMSIncrementalMode 
-XX:-UseGCOverheadLimit 
-XX:+ExplicitGCInvokesConcurrent 

-Dorg.apache.jasper.runtime.JspFactoryImpl.USE_POOL=true 
-Dcom.sun.management.jmxremote 
-Dcom.sun.management.jmxremote.port=8999 
-Dcom.sun.management.jmxremote.ssl=false 
-Dcom.sun.management.jmxremote.authenticate=true 
-Djava.rmi.server.hostname=localhost
-Dcom.sun.management.jmxremote.password.file=/home/grails/apache-tomcat/conf/jmxremote.password 
-Dcom.sun.management.jmxremote.access.file=/home/grails/apache-tomcat/conf/jmxremote.access";
export CATALINA_OPTS;
1
  • "a memory warning that there is not enough Heap Space" Increase the Heap?
    – HTTP500
    Aug 16, 2013 at 14:53

1 Answer 1

0

Generate a heap dump when your application crashes, and run it through a tool like Eclipse's Memory Analysis Tool (MAT). I believe you can generate a heap dump from JConsole as well.

You can generate a heap dump using a tool like jmap, but consult your JRE's documentation for exact flags. An example usage to generate a heapdump.bin file (can be any name of your choosing) would be:

jmap -dump:format=b,file=/path/to/heapdump.bin <pid>

pid is the process id of the Java process running your app.

Open this file in MAT, to see memory usage of your application.

Also, start looking at your garbage collection logs. To enable those, see the "GC Logging Options" here: http://blog.ragozin.info/2011/09/hotspot-jvm-garbage-collection-options.html

HTH.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .