Tomcat configuration: Memory - Heap and PermGen

Author: Dean Hutchinson, Quality Assurance Analyst, OpenText

Memory- Heap and PermGen

After searching for answers on where to set memory options for the JVM, specifically for AppWorks on Tomcat, I found that the best place to put them is in a file called “setenv.sh”, under the tomcat/bin directory.

The two memory specific options that most commonly affects AppWorks has to do with Heap and PermGen size. If you‘ve followed the installation guide, these settings have already been taken care of. However, should you be experiencing any tomcat server issues, a quick check of the catalina.out log file should reveal the source of the problem.

For errors pertaining to “heap”, we will be tweaking the “-Xmx” setting.

Some notes on this now…

  • The default heap size is typically 64MB.
  • This setting is of the form -Xmx(memorysize). i.e. -Xmx2048m sets the max heap size to 2048 megabytes.
  • 32 bit JVM is limited to approximately 1.8GB on Windows and 2GB on Linux.
  • Performance recommendation is to set the initial heap size equal (-Xms) to the max heap size.

For errors pertaining to “PermGen”, normally logged as “java.lang.OutOfMemory:PermGen space”, we will be tweaking the “-XX:MaxPermSize” setting.

Some notes on this…

  • There is a difference in defining the heap parameter vs the PermGen parameter in that the PermGen parameter uses an equal sign for setting the value. i.e. -XX:MaxPermSize=256m” sets the size to 256 megabytes.
  • The 2 most common values that have brought success have been either 256m or 512m.

Take a look at the sample setenv.sh file below. Along with the memory options defined above, there are several other parameters that can be changed for server performance and stability.

Complete credit for this goes to Terrance A. Snyder - http://www.terranceasnyder.com.

#! /bin/sh # ================================================================== # ______ __ _____ # /_ __/___ ____ ___ _________ _/ /_ /__ / # / / / __ \/ __ `__ \/ ___/ __ `/ __/ / / # / / / /_/ / / / / / / /__/ /_/ / /_ / / #/_/ \____/_/ /_/ /_/\___/\__,_/\__/ /_/ # Multi-instance Apache Tomcat installation with a focus # on best-practices as defined by Apache, SpringSource, and MuleSoft # and enterprise use with large-scale deployments. # Credits: # Google -> Couldn‘t survive without it # Stackoverflow.com -> Community support # SpringSource -> Specifically best-practices and seminars (Expert Series) # Based On: # http://www.springsource.com/files/uploads/tomcat/tomcatx-performance-tuning.pdf # http://www.springsource.com/files/u1/PerformanceTuningApacheTomcat-Part2.pdf # http://www.springsource.com/files/uploads/tomcat/tomcatx-large-scale-deployments.pdf # Created By: Terrance A. Snyder # URL: http://www.terranceasnyder.com, http://shutupandcode.net # Best Practice Documentation: # http://terranceasnyder.com/2011/05/tomcat-best-practices/ # Looking for the latest version? # github @ https://github.com/terrancesnyder # ================================================================== export JAVA_HOME="/usr/java/latest" # discourage address map swapping by setting Xms and Xmx to the same value # http://confluence.atlassian.com/display/DOC/Garbage+Collector+Performance+Issues export CATALINA_OPTS="$CATALINA_OPTS -Xms2048m" export CATALINA_OPTS="$CATALINA_OPTS -Xmx4096m" # Increase maximum perm size for web base applications to 4x the default amount # http://wiki.apache.org/tomcat/FAQ/Memoryhttp://wiki.apache.org/tomcat/FAQ/Memory export CATALINA_OPTS="$CATALINA_OPTS -XX:MaxPermSize=256m" # Reset the default stack size for threads to a lower value (by 1/10th original) # By default this can be anywhere between 512k -> 1024k depending on x32 or x64 # bit Java version. # http://www.springsource.com/files/uploads/tomcat/tomcatx-large-scale-deployments.pdf # http://www.oracle.com/technetwork/java/hotspotfaq-138619.html # Note - JDK 7 on RHEL needs minimum -Xss256k #export CATALINA_OPTS="$CATALINA_OPTS -Xss192k" # Oracle Java as default, uses the serial garbage collector on the # Full Tenured heap. The Young space is collected in parallel, but the # Tenured is not. This means that at a time of load if a full collection # event occurs, since the event is a ‘stop-the-world‘ serial event then # all application threads other than the garbage collector thread are # taken off the CPU. This can have severe consequences if requests continue # to accrue during these ‘outage‘ periods. (specifically webservices, webapps) # [Also enables adaptive sizing automatically] export CATALINA_OPTS="$CATALINA_OPTS -XX:+UseParallelGC" # This is interpreted as a hint to the garbage collector that pause times # of <nnn> milliseconds or less are desired. The garbage collector will # adjust the Java heap size and other garbage collection related parameters # in an attempt to keep garbage collection pauses shorter than <nnn> milliseconds. # http://java.sun.com/docs/hotspot/gc5.0/ergo5.html export CATALINA_OPTS="$CATALINA_OPTS -XX:MaxGCPauseMillis=1500" # A hint to the virtual machine that it.s desirable that not more than: # 1 / (1 + GCTimeRation) of the application execution time be spent in # the garbage collector. # http://themindstorms.wordpress.com/2009/01/21/advanced-jvm-tuning-for-low-pause/ export CATALINA_OPTS="$CATALINA_OPTS -XX:GCTimeRatio=9" # The hotspot server JVM has specific code-path optimizations # which yield an approximate 10% gain over the client version. export CATALINA_OPTS="$CATALINA_OPTS -server" # Disable remote (distributed) garbage collection by Java clients # and remove ability for applications to call explicit GC collection export CATALINA_OPTS="$CATALINA_OPTS -XX:+DisableExplicitGC" # Uncomment to enable jconsole remote connection management. # export CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote  # -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=9011  # -Dcom.sun.management.jmxremote.local.only=false  # -Dcom.sun.management.jmxremote.authenticate=false" # Check for application specific parameters at startup if [ -r "$CATALINA_BASE/bin/appenv.sh" ]; then . "$CATALINA_BASE/bin/appenv.sh" fi echo "Using CATALINA_OPTS:" for arg in $CATALINA_OPTS do echo ">> " $arg done echo "" echo "Using JAVA_OPTS:" for arg in $JAVA_OPTS do echo ">> " $arg done echo "_______________________________________________" echo ""

Top of page

时间: 2024-08-27 02:21:13

Tomcat configuration: Memory - Heap and PermGen的相关文章

InnoDB: The InnoDB memory heap is disabled报错记录

报错记录: [[email protected] ~]# cat /data/3307/data/localhost.localdomain.err  150509 21:21:27 mysqld_safe Starting mysqld daemon with databases from /data/3307/data 150509 21:21:27 InnoDB: The InnoDB memory heap is disabled 150509 21:21:27 InnoDB: Mute

windows系统bat方式启动tomcat出现java.lang.OutOfmemoryError:PermGen Space 错误

1.问题情景: 在部署项目时,将两个应用部署到同一个tomcat下,通过startup.bat启动服务时,控制台出现出现java.lang.OutOfmemoryError:PermGen Space 错误服务器环境:    系统版本:windows server 2008 r2    安装内存:64GB    处理器:8核(具体型号记不得了) 2.解决方法: PermGen Space:全称是Permanent Generation Space,是指内存的永久保存区域,这块内存主要是被JVM存

tomcat服务器java.lang.OutOfMemoryError: PermGen space

一挂就报内存溢出 下面是TOMCAT日志 JAVA程序是没有报错, Nov 24, 2009 4:07:02 PM org.apache.catalina.core.ApplicationDispatcher invoke SEVERE: Servlet.service() for servlet jsp threw exception java.lang.OutOfMemoryError: PermGen space Nov 24, 2009 4:07:02 PM org.apache.cat

Tomcat报java.lang.OutOfMemoryError: PermGen space错误

java.lang.OutOfMemoryError: PermGen space解决方案 : -Xms512m -Xmx1024m -XX:MaxPermSize=256m

Tomcat – java.lang.OutOfMemoryError: PermGen space Cause and Solution

Read more: http://javarevisited.blogspot.com/2012/01/tomcat-javalangoutofmemoryerror-permgen.html#ixzz3QDWa3Zqi Tomcat web server often suffers from java.lang.OutOfMemoryError: PermGen space whenever you deploy and undeploy your web application coupl

java heap space, PermGen space 错误 使用jvisualvm监测设置合理值

使用myeclipse启动tomcat 报java heap space ,PermGen space 错误,分别为 heap内存不足,PermGen内存不足需加大 tomcat启动项参数 Xmx 和 XX:MaxPermSizePermGen是指内存的永久保存区域,它用于存放class和 method 对象,以及String 对象(sun原文:permanent generation is the area of the heap where class and method objects

tomcat 安装

来自:http://www.davidghedini.com/pg/entry/install_tomcat_7_on_centos Install Tomcat 7 on CentOS, RHEL, or Fedora This post will cover installing and basic configuration of Tomcat 7 on CentOS 5.x. or CentOS 6.x Tomcat 7 implements the JavaServer Pages 2

http://wiki.apache.org/tomcat/HowTo

http://wiki.apache.org/tomcat/HowTo Contents Meta How do I add a question to this page? How do I contribute to Tomcat's documentation? Installation How do I set up and run Tomcat on Macintosh OS X? How do I set up and run Tomcat on Solaris 10? How do

DTrace to Troubleshoot Java Native Memory Problems

How to Use DTrace to Troubleshoot Java Native Memory Problems on Oracle Solaris 11 Hands-On Labs of the System Admin and Developer Community of OTN by Wang Yu, Vincent Liu, and Gary Wang This lab will introduce the basic concepts of DTrace and provid