Skip to content

Instantly share code, notes, and snippets.

@hardyoyo
Last active August 9, 2020 05:56
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hardyoyo/8664b2171d26adcf7b7e to your computer and use it in GitHub Desktop.
Save hardyoyo/8664b2171d26adcf7b7e to your computer and use it in GitHub Desktop.
Tomcat7 setenv.sh
cat /usr/local/tomcat7/bin/setenv.sh
#! /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
# ==================================================================
# set a CATALINA_PID so RHEL knows how to keep track of this beast
export CATALINA_PID="$CATALINA_HOME/work/catalina.pid"
# 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 -Xmx1536M"
#export CATALINA_OPTS="$CATALINA_OPTS -Xms256M" #old setting 2015-10-19
#export CATALINA_OPTS="$CATALINA_OPTS -Xms956M" #new setting, from watching YourKit a while
export CATALINA_OPTS="$CATALINA_OPTS -Xms1200M" #new setting, from watching YourKit a bit more
# 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=192M"
export CATALINA_OPTS="$CATALINA_OPTS -XX:PermSize=96M"
# 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
#export CATALINA_OPTS="$CATALINA_OPTS -Xss192k"
export CATALINA_OPTS="$CATALINA_OPTS -Xss228k"
# 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"
export CATALINA_OPTS="$CATALINA_OPTS -XX:+UseG1GC"
# suggestion from http://stackoverflow.com/questions/5839359/java-lang-outofmemoryerror-gc-overhead-limit-exceeded
# and here https://plumbr.eu/outofmemoryerror/gc-overhead-limit-exceeded
# though, really, we ought to figure out where the DSpace memory leak is a some point...
export CATALINA_OPTS="$CATALINA_OPTS -XX:-UseGCOverheadLimit"
# 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"
export CATALINA_OPTS="$CATALINA_OPTS -XX:MaxGCPauseMillis=250"
# 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"
# more tweaks for Solr performance optimization, from
# http://wiki.apache.org/solr/ShawnHeisey
export CATALINA_OPTS="$CATALINA_OPTS -XX:+PerfDisableSharedMem"
export CATALINA_OPTS="$CATALINA_OPTS -XX:+ParallelRefProcEnabled"
export CATALINA_OPTS="$CATALINA_OPTS -XX:G1HeapRegionSize=8m"
export CATALINA_OPTS="$CATALINA_OPTS -XX:InitiatingHeapOccupancyPercent=75"
export CATALINA_OPTS="$CATALINA_OPTS -XX:+UseLargePages"
export CATALINA_OPTS="$CATALINA_OPTS -XX:+AggressiveOpts"
# a minor Solr tweak
export JAVA_OPTS="$JAVA_OPTS -Dsolr.autoSoftCommit.maxTime=1000"
# 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"
# turn on the remote memory thing so LambaProbe can work
#export CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9001 -Dcom.sun.management.jmxremote.password.file=/usr/local/tomcat7/conf/jmxremote.password -Dcom.sun.management.jmxremote.access.file=/usr/local/tomcat7/conf/jmxremote.access -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=true"
export CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote"
# turn on the Yourkit profiler
export CATALINA_OPTS="$CATALINA_OPTS -agentpath:/usr/local/yourkit/bin/linux-x86-64/libyjpagent.so=delay=10000"
# dump the heap on Out of Memory errors, for further analysis (do not use this in production)
export CATALINA_OPTS="$CATALINA_OPTS -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/log/tomcat7/heapdumps"
#load up the lib folder, to enable Apr
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CATALINA_HOME/lib
# 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 ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment