zoukankan      html  css  js  c++  java
  • Tomcat

    How to Change JVM Heap Setting (-Xms -Xmx) of Tomcat – Configure setenv.sh file – Run catalina.sh

    Apache Tomcat is widely used Web Container in the world. Very big companies run on Apache Tomcat now a days. There are quite a few other alternatives like IBM WebSphere, Geronimo, IIS, etc. but Tomcat is my favorite one too.

    It’s very critical for us to configure all correct parameters while running your application in Production environment or even in development env.

    In this tutorial we will go over steps on how to configure -Xms, -Xmx and -XX:PermSizevalue for Tomcat server. Let’s first understand few terms.

    -Xmx

    Specifies the maximum size, in bytes, of the memory allocation pool. This value must a multiple of 1024 greater than 2MB. Append the letter k or K to indicate kilobytes, or m or M to indicate megabytes. The default value is 64MB. The upper limit for this value will be approximately 4000m on Solaris 7 and Solaris 8 SPARC platforms and 2000m on Solaris 2.6 and x86 platforms, minus overhead amounts. So, in simple words, you are saying Java to use Maximum of 1024 MB from available memory.

    NOTE: there is NO SPACE between -Xmx and 1024m

    -Xmn

    It’s a size of the heap for the young generation.

    -XX:PermSize

    It’s used to set size for Permanent Generation. It is where class files are kept.

    Another must readChange -Xmx value of Tomcat in Eclipse IDE

    Let’s get started:

    Below are the simple steps to change -Xmx / -Xms values or other JVM parameters if you are running Tomcat from command prompt.

    Step-1

    Download Apache Tomcat.

    Step-2

    Go to Apache Tomcat /bin directory.

    [webapp@merch-monkeylbin]$ cat setenv.sh
    export CATALINA_OPTS="$CATALINA_OPTS -Xms1024m"
    export CATALINA_OPTS="$CATALINA_OPTS -Xmx2048m"

    Step-4

    1. Go to command prompt.
    2. Go to <Tomcat Directory>/bin directory
    3. Execute command: ./catalina.sh run

    Step-5

    Monitor logfile and you should see your Tomcat started with all your specified parameters in setenv.sh file.

    28-Mar-2019 12:02:02.248 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dorg.apache.catalina.security.SecurityListener.UMASK=0022
    28-Mar-2019 12:02:02.248 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Xms1024m
    28-Mar-2019 12:02:02.248 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Xmx20248m

    Command for Windows Environment:

    You need to create setenv.bat file with below content:

    set "JAVA_OPTS=%JAVA_OPTS% -Xms1024m -Xmx2048m -server"
    

    and run Tomcat with catalina.bat

     
    关闭localhost_access_log日志
    修改在tomcat的安装目录conf文件夹下server.xml里配置,将AccessLogValve注释掉:

    优化:

    [webapp@merch-monkey conf]$ diff server.xml /mnt/server.xml
    58c58
    < maxThreads="700" minSpareThreads="15"/>
    ---
    > maxThreads="150" minSpareThreads="4"/>
    116c116
    < <!--<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />-->
    ---
    > <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
    160,161c160
    <
    < <!-- <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
    ---
    > <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
    163c162
    < pattern="%h %l %u %t &quot;%r&quot; %s %b" /> -->
    ---
    > pattern="%h %l %u %t &quot;%r&quot; %s %b" />

  • 相关阅读:
    C if语句判断年龄
    C 计算时间差
    C 计算身高
    JRebel激活破解完美解决方式
    Maven optional和scope
    判断当前时间是否在某个时间段内
    给定时间加上几个小时
    RabbitMQ学习笔记
    浏览器、服务器会话
    Maven核心知识点梳理
  • 原文地址:https://www.cnblogs.com/xiewenming/p/10617621.html
Copyright © 2011-2022 走看看