`

Tomcat优化

阅读更多

1.JVM内存配置

修改/bin/catalina.bat

set _EXECJAVA=%_RUNJAVA%
set MAINCLASS=org.apache.catalina.startup.Bootstrap
set ACTION=start
set SECURITY_POLICY_FILE=
set DEBUG_OPTS=
set JPDA=
set JAVA_OPS=-Xms64m -Xmx128m 

其中,-Xms:初始值,-Xmx:最大值,-Xmn:最小值

 

 2.Tomcat线程池的配置

修改/conf/server.xml,去掉以下代码的注释

 <!--
    <Executor name="tomcatThreadPool" namePrefix="catalina-exec-" 
        maxThreads="150" minSpareThreads="4"/>
    -->

其中,

name
The name used to reference this pool in other places in server.xml. The name is required and must be unique.
这个是线程池的名字,必须唯一,后面的配置里有用.
namePrefix
(String) The name prefix for each thread created by the executor. The thread name for an individual thread will be namePrefix+threadNumber
线程的名字前缀,用来标记线程名字的,这样每个线程就用这个前缀加上线程编号了,比如
catalina-exec-1
catalina-exec-2

maxThreads
(int) The max number of active threads in this pool, default is 200
允许的最大线程池里的线程数量,默认是200,大的并发应该设置的高一些,反正只是限制而已,不占用资源

minSpareThreads
(int) The minimum number of threads always kept alive, default is 25
最小的保持活跃的线程数量,默认是25.这个要根据负载情况自行调整了。太小了就影响反应速度,太大了白白占用资源。

maxIdleTime
(int) The number of milliseconds before an idle thread shutsdown, unless the number of active threads are less or equal to minSpareThreads. Default value is 60000(1 minute)
超过最小活跃线程数量的线程,如果空闲时间超过这个设置后,会被关别。默认是1分钟。

threadPriority
(int) The thread priority for threads in the executor, the default is Thread.NORM_PRIORITY
线程的等级。默认是Thread.NORM_PRIORITY

 

去掉以下代码的注释

 <!-- A "Connector" using the shared thread pool-->
   
    <Connector executor="tomcatThreadPool"
               port="8080" protocol="HTTP/1.1" 
               connectionTimeout="20000" 
               redirectPort="8443" />

 注意,一旦使用了线程池,则其它的线程属性,比如 maxThreads等将被忽略

分享到:
评论
3 楼 xiaoping8411 2011-11-19  
    <Connector port="8080" maxHttpHeaderSize="8192"
               maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
               enableLookups="false" redirectPort="8443" acceptCount="100"
               connectionTimeout="20000" disableUploadTimeout="true" />
您好,我想问问你这种配置和我这里的配置有区别吗?
2 楼 javaEE_dev 2009-11-29  
<div class="quote_title">lectery 写道</div>
<div class="quote_div">
<p>1.JVM内存配置</p>
<p>修改/bin/catalina.bat</p>
<pre name="code" class="xml">set _EXECJAVA=%_RUNJAVA%
set MAINCLASS=org.apache.catalina.startup.Bootstrap
set ACTION=start
set SECURITY_POLICY_FILE=
set DEBUG_OPTS=
set JPDA=
set JAVA_OPS=-Xms64m -Xmx128m
</pre>
<p>其中<span style="font-size: xx-small;">,</span><span style="font-size: small;"><span style="font-size: x-small;">-Xms:初始值,-Xmx:最大值,-Xmn:最小值</span></span></p>
<p> </p>
<p> 2.Tomcat线程池的配置</p>
<p>修改/conf/server.xml,去掉以下代码的注释</p>
<pre name="code" class="xml"> &lt;!--
    &lt;Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
        maxThreads="150" minSpareThreads="4"/&gt;
    --&gt;
</pre>
<p>其中,</p>
<p>name <br>The name used to reference this pool in other places in server.xml. The name is required and must be unique. <br>这个是线程池的名字,必须唯一,后面的配置里有用.<br>namePrefix <br>(String) The name prefix for each thread created by the executor. The thread name for an individual thread will be namePrefix+threadNumber <br>线程的名字前缀,用来标记线程名字的,这样每个线程就用这个前缀加上线程编号了,比如 <br>catalina-exec-1 <br>catalina-exec-2 <br><br>maxThreads <br>(int) The max number of active threads in this pool, default is 200 <br>允许的最大线程池里的线程数量,默认是200,大的并发应该设置的高一些,反正只是限制而已,不占用资源 <br><br>minSpareThreads <br>(int) The minimum number of threads always kept alive, default is 25 <br>最小的保持活跃的线程数量,默认是25.这个要根据负载情况自行调整了。太小了就影响反应速度,太大了白白占用资源。 <br><br>maxIdleTime <br>(int) The number of milliseconds before an idle thread shutsdown, unless the number of active threads are less or equal to minSpareThreads. Default value is 60000(1 minute) <br>超过最小活跃线程数量的线程,如果空闲时间超过这个设置后,会被关别。默认是1分钟。 <br><br>threadPriority <br>(int) The thread priority for threads in the executor, the default is Thread.NORM_PRIORITY <br>线程的等级。默认是Thread.NORM_PRIORITY </p>
<p> </p>
<p>去掉以下代码的注释</p>
<pre name="code" class="xml"> &lt;!-- A "Connector" using the shared thread pool--&gt;
  
    &lt;Connector executor="tomcatThreadPool"
               port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" /&gt;
</pre>
<p> 注意,一旦使用了线程池,则其它的线程属性,比如 maxThreads等将被忽略</p>
</div>
<p> </p>
1 楼 mercyblitz 2009-11-17  
还有采用NIO的方法,静态编译JSP等等

相关推荐

Global site tag (gtag.js) - Google Analytics