设为首页 收藏本站
查看: 382|回复: 0

[经验分享] tomcat jvm优化设置

[复制链接]

尚未签到

发表于 2017-1-21 09:04:11 | 显示全部楼层 |阅读模式
  tomcat实例CATALINA_BASE/bin下的setenv.sh文件中设置
  export CATALINA_OPTS="$CATALINA_OPTS -Xms1024m"
  export CATALINA_OPTS="$CATALINA_OPTS -Xmx1024m"
  export CATALINA_OPTS="$CATALINA_OPTS -Xmn128m"
  export CATALINA_OPTS="$CATALINA_OPTS -XX:PermSize=128m"
  export CATALINA_OPTS="$CATALINA_OPTS -XX:MaxPermSize=128m"
  export CATALINA_OPTS="$CATALINA_OPTS -server"
  export CATALINA_OPTS="$CATALINA_OPTS -Dfile.encoding=UTF8"
  export CATALINA_OPTS="$CATALINA_OPTS -Djava.awt.headless=true"
  echo "Using CATALINA_OPTS:$CATALINA_OPTS"
tomcat服务器端jvm优化设置
可以在对应tomcat实例CATALINA_BASE/bin下的setenv.sh文件中设置,如果没有该文件先创建该脚本文件
然后在其中设置jvm的优化参数。
http://doc.cloveretl.com/documentation/UserGuide/index.jsp?topic=/com.cloveretl.server.docs/docs/tomcat.html
如:



  • It is strongly recommended you change default limits for the heap and perm gen memory spaces.
    See section the section called “Memory Settings” for details.
    You can set the minimum and maximum memory heap size by adjusting the "Xms" and "Xmx" JVM parameters. You can set JVM parameters for Tomcat by setting the environment variable JAVA_OPTS in the [TOMCAT_HOME]/bin/setenv.sh file (if it does not exist, you may create it).
    Create setenv file:
    Unix-like systems: [tomcat]/bin/setenv.sh

    export CATALINA_OPTS="$CATALINA_OPTS -XX:MaxPermSize=512m -Xms128m -Xmx1024m"
    export CATALINA_OPTS="$CATALINA_OPTS -Dderby.system.home=$CATALINA_HOME/temp -server"
    echo "Using CATALINA_OPTS: $CATALINA_OPTS"

    Windows systems: [tomcat]/bin/setenv.bat

    set "CATALINA_OPTS=%CATALINA_OPTS% -XX:MaxPermSize=512m -Xms128m -Xmx1024m"
    set "CATALINA_OPTS=%CATALINA_OPTS% -Dderby.system.home=%CATALINA_HOME%/temp -server"
    echo "Using CATALINA_OPTS: %CATALINA_OPTS%"

     
    As visible in the settings above, there is also switch -server. For performance reasons, it is recommended to run the container in the "server" mode.


示例2:
https://gist.github.com/terrancesnyder/986029

#! /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

 

# ==================================================================

 

# 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 -Xms64m"


export CATALINA_OPTS="$CATALINA_OPTS -Xmx512m"


 

# 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

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"


 

# 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 ""

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-331384-1-1.html 上篇帖子: tomcat配置https详述(SSL) 下篇帖子: Tomcat部署web应用
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表