tomcat性能优化

<span style="font-size:12px;">&nbsp; </span>



<b><span style="font-family:宋体;">一、操作系统调优<span> </span></span></b>

对于操作系统优化来说,是尽可能的增大可使用的内存容量、提高CPU的频率,保证文件系统的读写速率等。经过压力测试验证,在并发连接很多的情况下,CPU的处理能力越强,系统运行速度越快。

<span style="font-family:宋体;">【适用场景】任何项目。<span> </span></span>



<span style="font-family:宋体;"></span>



<b><span style="font-family:宋体;">二、<span>Java</span>虚拟机调优<span> </span></span></b>

应该选择SUNJVM,在满足项目需要的前提下,尽量选用版本较高的JVM,一般来说高版本产品在速度和效率上比低版本会有改进。

<span style="font-family:宋体;">JDK1.4</span><span style="font-family:宋体;">比<span>JDK1.3</span>性能提高了近<span>10%-20%</span>,<span>JDK1.5</span>比<span>JDK1.4</span>性能提高<span>25%-75%</span>。<span> </span></span>



<span style="font-family:宋体;">因此对性能要求较高的情况推荐使用<span> JDK1.6</span>。<span> </span></span>



<span style="font-family:宋体;">【适用场景】任何项目。<span></span></span>



<span style="font-family:宋体;"><span>&nbsp;</span></span>



<b><span style="font-family:宋体;">三、<span>Apache</span>集成<span>Tomcat </span></span></b>

Web服务器专门处理HTTP请求,应用服务器是通过很多协议为应用提供商业逻辑。虽然Tomcat也可以作web服务器,但其处理静态html的速度比不上Apache,且其作为web服务器的功能远不如Apache,因此把ApacheTomcat集成起来,将htmlJsp的功能部分进行明确分工,让Tomcat只处理Jsp部分,其他的由ApacheIISweb服务器去处理,由此大大提高Tomcat的运行效率。

<span style="font-family:宋体;">如果一个项目中大量使用了静态页面、大量的图片等,并有有较大的访问量,推荐使用<span>Apache</span>集成<span>Tomcat</span>的方式来提高系统的整体性能。<span> </span></span>



<span style="font-family:宋体;">Apache</span><span style="font-family:宋体;">和<span>Tomcat</span>的整合有三种方式,分别是<span>JK</span>、<span>http_proxy</span>和<span>ajp_proxy.</span>其中<span>JK</span>方式是最常见的方式,<span>JK</span>本身有两个版本分别是<span>1</span>和<span>2</span>,目前<span>1</span>最新版本是<span>1.2.8</span>,而版本<span>2</span>早已经废弃了。<span>http_proxy</span>是利用<span>Apache</span>自带的<span>mod_proxy</span>模块使用代理技术来连接<span>Tomcat</span>。<span>Ajp_proxy</span>连接方式其实跟<span>http_proxy</span>方式一样,都是由<span>mod_proxy</span>所提供的功能。只需要把配置中的<span> http://</span>换成<span>ajp://,</span>同时连接的是<span>Tomcat</span>的<span>AJP Connector</span>所在的端口。<span> </span></span>



<span style="font-family:宋体;">相对于<span>JK</span>的连接方式,后两种在配置上比较简单的,灵活性方面也一点都不逊色。但就稳定性而言不像<span>JK</span>这样久经考验,所以建议采用<span>JK</span>的连接方式。<span> </span></span>



<span style="font-family:宋体;">Apache+JK+Tomcat</span><span style="font-family:宋体;">配置:<span> </span></span>



<span style="font-family:宋体;">使用到的两个配置文件分别是:<span>httpd.conf</span>和<span>mod_jk.conf</span>。其中<span>httpd.conf</span>是<span>Apache</span>服务器的配置文件,用来加载<span>JK</span>模块以及指定<span>JK</span>配置文件信息。<span>mod_jk.conf</span>是到<span>Tomcat</span>服务器的连接定义文件。<span> </span></span>



<span style="font-family:宋体;">【部署步骤】<span> </span></span>



<span style="font-family:宋体;">1.</span><span style="font-family:宋体;">安装<span>Apache</span>服务器<span> </span></span>



<span style="font-family:宋体;">2.</span><span style="font-family:宋体;">部署<span>Tomcat </span></span>



<span style="font-family:宋体;">3.</span><span style="font-family:宋体;">将<span>mod_jk.so</span>拷贝到<span>modules</span>目录下面<span> </span></span>



<span style="font-family:宋体;">4.</span><span style="font-family:宋体;">修改<span>httpd.conf</span>和<span>mod_jk.conf </span></span>



<span style="font-family:宋体;">【适用场景】大量使用静态页面的应用系统。<span></span></span>



<span style="color:#e56600;">注:此处建议使用nginx集成tomcat,因为本文的内容来自于网络上七零八落的拼接,很多东西都比较老了。nginx在处理静态页面上的能力比apache还要强,而jsp</span><span style="color:#e56600;">动态页面的处理可以通过http_proxy交给tomat来处理。</span>



<span style="font-family:宋体;"><span>&nbsp;</span></span>



<b><span style="font-family:宋体;">四、<span>Apache</span>和<span>Tomcat</span>集群<span> </span></span></b>

对于并发要求很高的系统,我们需要采取负载均衡的方式来分担Tomcat服务器的压力。负载均衡实现大概有四种:第一是通过DNS,但只能简单的实现轮流分配,不能处理故障;第二是基于MS IIS,windows 2003 server本身就带了负载均衡服务;第三是硬件方式,通过交换机功能或专门的负载均衡设备来实现;第四种是软件的方式,通过一台负载均衡服务器进行,上面安装软件。使用Apache Httpd Server做负载均衡器,Tomcat集群节点使用Tomcat就可以做到上述第四种方式,这种方式比较灵活,成本相对比较低,另外一个很大的优点就是可以根据应用情况和服务器的情况做一些灵活的配置。所以推荐使用Apache+Tomcat集群来实现负载均衡。

<span style="font-family:宋体;">采用<span>Tomcat</span>集群可以最大程度的发挥服务器的性能,可以在配置较高的服务器上部署多个<span>Tomcat</span>,也可以在多台服务器上分别部署<span> Tomcat</span>,<span>Apache</span>和<span>Tomcat</span>整合的方式还是<span>JK</span>方式。经过验证,系统对大用户量使用的响应方面,<span>Apache+3Tomccat</span>集群<span>> Apache+2Tomcat</span>集群<span> > Apache</span>集成<span>Tomcat > </span>单个<span>Tomcat</span>。并且采用<span>Apache+</span>多<span>Tomcat</span>集群的部署方式时,如果一个<span>Tomcat</span>出现宕机,系统可以继续使用,所以在硬件系统性能足够优越的情况下,需要尽量发挥软件的性能,可以采用增加<span>Tomcat</span>集群的方式。<span> </span></span>



<span style="font-family:宋体;">Apache+Tomcat</span><span style="font-family:宋体;">集群的方式使用到得配置文件有<span>httpd.conf</span>、<span>mod_jk.conf</span>、<span>workers.properties</span>。其中<span> mod_jk.conf</span>是对<span>JK</span>信息的配置,包括<span>JK</span>的路径等,<span>workers.properties</span>配置文件是对<span>Tomcat</span>服务器的连接定义文件。<span> </span></span>



<span style="font-family:宋体;">Apache</span><span style="font-family:宋体;">需要调整运行参数,这样才能构建一个适合相应网络环境的<span>web</span>服务。其中可进行的优化配置如下:<span> </span></span>



<span style="font-family:宋体;">1. </span><span style="font-family:宋体;">设置<span>MPM</span>(<span>Multi Processing Modules</span>多道处理模块)。<span>ThreadPerChild,</span>这个参数用于设置每个进程的线程数,在<span>Windows</span>环境下默认值是<span>64</span>,最大值是<span> 1920</span>,建议设置为<span>100-500</span>之间,服务器性能高的话值大一些,反之小一些。<span>MaxRequestPerChild</span>表示每个子进程能够处理的最大请求数。这个参数的值更大程度上取决于服务器的内存,如果内存比较大的话可以设置为很大的参数,否则设置一个较小的值,建议值是<span>3000. </span></span>



<span style="font-family:宋体;">2. </span><span style="font-family:宋体;">关闭<span>DNS</span>和名字解析 <span> HostnameLookups off </span></span>



<span style="font-family:宋体;">3. </span><span style="font-family:宋体;">打开<span>UseCanonicalName</span>模块<span> UseCanonicalName on </span></span>



<span style="font-family:宋体;">4. </span><span style="font-family:宋体;">关闭多余模块 一般来说,不需要加载的模块有,<span>mod_include.so</span>、<span>mod_autoindex.so</span>、<span>mod_access.so</span>、<span>mod_auth.so. </span></span>



<span style="font-family:宋体;">5. </span><span style="font-family:宋体;">打开<span>KeepAlive</span>支持<span> </span></span>



<span style="font-family:宋体;">KeepAlive on, KeepAliveTimeout 15 MaxKeepAliveRequests 1000 </span>



<span style="font-family:宋体;">   根据实际经验,通过<span>Apache</span>和<span>Tomcat</span>集群的方式提高系统性能的效果十分明显,这种方式可以最大化的利用硬件资源,通过多个<span>Tomcat</span>的处理来分担单<span>Tomcat</span>时的压力。<span> </span></span>



<span style="font-family:宋体;">【部署步骤】<span> </span></span>



<span style="font-family:宋体;">1.</span><span style="font-family:宋体;">安装<span>Apache</span>服务器<span> </span></span>



<span style="font-family:宋体;">2.</span><span style="font-family:宋体;">部署<span>Tomcat</span>集群,即多个相同的<span>Tomcat</span>。<span> </span></span>



<span style="font-family:宋体;">3.</span><span style="font-family:宋体;">将<span>mod_jk.so</span>拷贝到<span>modules</span>目录下面<span> </span></span>



<span style="font-family:宋体;">4.</span><span style="font-family:宋体;">修改<span>httpd.conf</span>、<span>mod_jk.conf</span>和<span>workers.properties </span></span>



<span style="font-family:宋体;">【适用场景】并发用户量及在线使用用户数量比较高的系统。<span></span></span>



<span style="font-family:宋体;color:#e56600;"><span style="color:#e56600;">&nbsp;</span></span><span style="color:#e56600;"> 注:此处也建议使用nginx+keepalived做为高性能和高可用性方案。</span>



&nbsp;



<b><span style="font-family:宋体;">五、<span>Tomcat</span>自身优化<span> </span></span></b>



<span style="font-family:宋体;">1. JVM</span><span style="font-family:宋体;">参数调优:<span>-Xms<size> </span>表示<span>JVM</span>初始化堆的大小,<span>-Xmx<size></span>表示<span>JVM</span>堆的最大值。这两个值的大小一般根据需要进行设置。当应用程序需要的内存超出堆的最大值时虚拟机就会提示内存溢出,并且导致应用服务崩溃。因此一般建议堆的最大值设置为可用内存的最大值的<span>80%</span>。在<span>catalina.bat</span>中,设置<span> JAVA_OPTS='-Xms256m -Xmx512m'</span>,表示初始化内存为<span>256MB</span>,可以使用的最大内存为<span>512MB</span>。<span>tomcat </span>的<span>jvm</span>建议调整到<span>1024M </span>即在<span>tomcat/bin/catalina.bat</span>文件头部添加<span></span></span>



<span style="font-family:宋体;">set JAVA_OPTS=-Xms512m -Xmx1024m </span><span style="font-family:宋体;">默认<span>tomcat </span>最大为<span>64M</span></span>



<span style="font-family:宋体;">2. </span><span style="font-family:宋体;">禁用<span>DNS</span>查询<span> </span></span>



<span style="font-family:宋体;">当<span>web</span>应用程序向要记录客户端的信息时,它也会记录客户端的<span>IP</span>地址或者通过域名服务器查找机器名转换为<span>IP</span>地址。<span>DNS</span>查询需要占用网络,并且包括可能从很多很远的服务器或者不起作用的服务器上去获取对应的<span>IP</span>的过程,这样会消耗一定的时间。为了消除<span>DNS</span>查询对性能的影响我们可以关闭<span>DNS</span>查询,方式是修改<span>server.xml</span>文件中的<span>enableLookups</span>参数值:<span> </span></span>



<span style="font-family:宋体;">Tomcat4 </span>



<span style="font-family:宋体;"></span>



<span style="font-family:宋体;"><Connector className="org.apache.coyote.tomcat4.CoyoteConnector" port="80" minProcessors="5" maxProcessors="75" enableLookups="false" redirectPort="8443" acceptCount="100" debug="0" connectionTimeout="20000" useURIValidationHack="false" disableUploadTimeout="true" /> </span>



<span style="font-family:宋体;"></span>



<span style="font-family:宋体;">Tomcat5 </span>



<span style="font-family:宋体;"></span>



<span style="font-family:宋体;"><Connector port="80" maxThreads="150" minSpareThreads="25" maxSpareThreads="75" enableLookups="false" redirectPort="8443" acceptCount="100" debug="0" connectionTimeout="20000" disableUploadTimeout="true"/> </span>



<span style="font-family:宋体;">3. </span><span style="font-family:宋体;">调整线程数<span> </span></span>



<span style="font-family:宋体;">通过应用程序的连接器(<span>Connector</span>)进行性能控制的的参数是创建的处理请求的线程数。<span>Tomcat</span>使用线程池加速响应速度来处理请求。在<span>Java </span>中线程是程序运行时的路径,是在一个程序中与其它控制线程无关的、能够独立运行的代码段。它们共享相同的地址空间。多线程帮助程序员写出<span>CPU</span>最大利用率的高效程序,使空闲时间保持最低,从而接受更多的请求。<span> </span></span>



<span style="font-family:宋体;"></span>



<span style="font-family:宋体;">调整<span>tomcat</span>的<span>server.xml </span>其中的参数配置,例<span></span></span>



<span style="font-family:宋体;"><Connector port=</span><span style="font-family:宋体;">”<span>8080</span>″<span> maxHttpHeaderSize=</span>”<span>8192</span>″<span></span></span>



<span style="font-family:宋体;">maxThreads=</span><span style="font-family:宋体;">”<span>150</span>″<span> minSpareThreads=</span>”<span>25</span>″<span> maxSpareThreads=</span>”<span>75</span>″<span></span></span>



<span style="font-family:宋体;">enableLookups=</span><span style="font-family:宋体;">”<span>false</span>”<span> redirectPort=</span>”<span>8443</span>″<span> acceptCount=</span>”<span>100</span>″<span></span></span>



<span style="font-family:宋体;">connectionTimeout=</span><span style="font-family:宋体;">”<span>20000</span>″<span></span></span>



<span style="font-family:宋体;">disableUploadTimeout=”true” URIEncoding=”GBK” /></span>



<span style="font-family:宋体;"></span>



<span style="font-family:宋体;">将其中的<span>maxThreads=</span>”<span>150</span>″ 修改为<span>maxThreads=</span>”<span>1500</span>″ ,即可以最大承载<span>1500</span>个并发事务。一个用户基本上请求一次服务需要二个线程进行支持(一个是<span>request,</span>一个是<span>response</span>)。这样<span>IGRP</span>就可以承载最高<span>750</span>个用户的完全并发。<span>maxThreads</span>默认<span>tomcat</span>配置为<span>200</span>个。不要遗漏<span>URIEncoding=</span>”<span>GBK</span>”,能使页面<span>url</span>传递中文参数时保证正确。<span></span></span>



<span style="font-family:宋体;"> <span><span>&nbsp; </span>Tomcat4</span>中可以通过修改<span>minProcessors</span>和<span>maxProcessors</span>的值来控制线程数。这些值在安装后就已经设定为默认值并且是足够使用的,但是随着站点的扩容而改大这些值。<span>minProcessors</span>服务器启动时创建的处理请求的线程数应该足够处理一个小量的负载。也就是说,如果一天内每秒仅发生<span>5</span>次单击事件,并且每个请求任务处理需要<span>1</span>秒钟,那么预先设置线程数为<span>5</span>就足够了。但在你的站点访问量较大时就需要设置更大的线程数,指定为参数<span>maxProcessors</span>的值。<span>maxProcessors</span>的值也是有上限的,应防止流量不可控制(或者恶意的服务攻击),从而导致超出了虚拟机使用内存的大小。如果要加大并发连接数,应同时加大这两个参数。<span>web server</span>允许的最大连接数还受制于操作系统的内核参数设置,通常<span>Windows</span>是<span>2000</span>个左右,<span>Linux</span>是<span>1000</span>个左右。<span> </span></span>



<span style="font-family:宋体;">  <span><span>&nbsp; </span></span>在<span>Tomcat5</span>对这些参数进行了调整,请看下面属性:<span> </span></span>



<span style="font-family:宋体;">maxThreads</span><span style="font-family:宋体;"> <span><span>&nbsp; </span>Tomcat</span>使用线程来处理接收的每个请求。这个值表示<span>Tomcat</span>可创建的最大的线程数。<span> </span></span>



<span style="font-family:宋体;">acceptCount</span><span style="font-family:宋体;"> <span><span>&nbsp; </span></span>指定当所有可以使用的处理请求的线程数都被使用时,可以放到处理队列中的请求数,超过这个数的请求将不予处理。<span> </span></span>



<span style="font-family:宋体;">connnectionTimeout</span><span style="font-family:宋体;"> <span><span>&nbsp; </span></span>网络连接超时,单位:毫秒。设置为<span>0</span>表示永不超时,这样设置有隐患的。通常可设置为<span>30000</span>毫秒。<span> </span></span>



<span style="font-family:宋体;">minSpareThreads</span><span style="font-family:宋体;"> <span><span>&nbsp; </span>Tomcat</span>初始化时创建的线程数。<span> </span></span>



<span style="font-family:宋体;"></span>



<span style="font-family:宋体;">maxSpareThreads</span><span style="font-family:宋体;">   一旦创建的线程超过这个值,<span>Tomcat</span>就会关闭不再需要的<span>socket</span>线程。<span> </span></span>



<span style="font-family:宋体;"></span>



<span style="font-family:宋体;">   最好的方式是多设置几次并且进行测试,观察响应时间和内存使用情况。在不同的机器、操作系统或虚拟机组合的情况下可能会不同,而且并不是所有人的<span>web</span>站点的流量都是一样的,因此没有一刀切的方案来确定线程数的值。<span> </span></span>



<span style="font-family:宋体;"></span>



<b><span style="font-family:宋体;">六、<span>APR</span>库使用<span> </span></span></b>



<span style="font-family:宋体;">Tomcat</span><span style="font-family:宋体;">中使用<span>APR</span>库,其实就是在<span>Tomcat</span>中使用<span>JNI</span>的方式来读取文件以及进行网络传输。可以大大提升<span>Tomcat</span>对静态文件的处理性能,同时如果你使用了<span>HTTPS</span>方式传输的话,也可以提升<span>SSL</span>的处理性能。<span> </span></span>



<span style="font-family:宋体;">一般在<span>Windows</span>下,可以直接下载编译好的二进制版本的<span>dll</span>库文件来使<span>Tomcat</span>启用<span>APR</span>,一般建议拷贝库文件<span>tcnative-1.dll</span>到<span> Tomcat</span>的<span>bin</span>目录下。而在<span>Linux</span>下,可以直接解压和安装<span>bin</span>目录下的<span>tomcat_native.tar.gz</span>文件,编译之前要确保<span>apr </span>库已经安装。<span> </span></span>



<span style="font-family:宋体;">怎么才能判断<span>Tomcat</span>是否已经启用了<span>APR</span>库呢?方法是通过看<span>Tomcat</span>的启动日志:<span> </span></span>



<span style="font-family:宋体;">如果没有启用<span>APR</span>,则启动日志一般有这么一条:<span> </span></span>



<span style="font-family:宋体;">org.apache.coyote.http11.Http11Protocol start </span>



<span style="font-family:宋体;">如果启用了<span>APR</span>,则这条日志就会变成:<span> </span></span>



<span style="font-family:宋体;">org.apache.coyote.http11.Http11AprProtocol start </span>



<span style="font-family:宋体;">tcnative-1.dll </span><span style="font-family:宋体;">下载地址:<span>http://tomcat.heanet.ie/native/ </span></span>



<span style="font-family:宋体;"></span>



<b><span style="font-family:宋体;">七、使用<span>tomcat</span>自带的<span>dbcp</span>数据库链接池</span></b><span style="font-family:宋体;"></span>



<span style="font-family:宋体;"></span>



<span style="font-family:宋体;">tomcat5.0</span><span style="font-family:宋体;">配置如下<span></span></span>



<span style="font-family:宋体;">先修改<span>server.xml,</span>增加如下内容,在<span> <GlobalNamingResources></span>标签里增加<span></span></span>



<span style="font-family:宋体;"><Resource name=”CarmotDS” type=”javax.sql.DataSource”/></span>



<span style="font-family:宋体;"><ResourceParams name=”CarmotDS”></span>



<span style="font-family:宋体;"><parameter></span>



<span style="font-family:宋体;"><name>factory</name></span>



<span style="font-family:宋体;"><value>org.apache.commons.dbcp.BasicDataSourceFactory</value></span>



<span style="font-family:宋体;"></parameter></span>



<span style="font-family:宋体;"><parameter></span>



<span style="font-family:宋体;"><name>url</name></span>



<span style="font-family:宋体;"><value>jdbc:oracle:thin:@192.168.1.12:1521:igrp</value></span>



<span style="font-family:宋体;"></parameter></span>



<span style="font-family:宋体;"><parameter></span>



<span style="font-family:宋体;"><name>password</name></span>



<span style="font-family:宋体;"><value>carmot</value></span>



<span style="font-family:宋体;"></parameter></span>



<span style="font-family:宋体;"><parameter></span>



<span style="font-family:宋体;"><name>maxActive</name></span>



<span style="font-family:宋体;"><value>500</value></span>



<span style="font-family:宋体;"></parameter></span>



<span style="font-family:宋体;"><parameter></span>



<span style="font-family:宋体;"><name>maxWait</name></span>



<span style="font-family:宋体;"><value>9000</value></span>



<span style="font-family:宋体;"></parameter></span>



<span style="font-family:宋体;"><parameter></span>



<span style="font-family:宋体;"><name>driverClassName</name></span>



<span style="font-family:宋体;"><value>oracle.jdbc.driver.OracleDriver</value></span>



<span style="font-family:宋体;"></parameter></span>



<span style="font-family:宋体;"><parameter></span>



<span style="font-family:宋体;"><name>username</name></span>



<span style="font-family:宋体;"><value>carmot_ystest</value></span>



<span style="font-family:宋体;"></parameter></span>



<span style="font-family:宋体;"><parameter></span>



<span style="font-family:宋体;"><name>maxIdle</name></span>



<span style="font-family:宋体;"><value>20</value></span>



<span style="font-family:宋体;"></parameter></span>



<span style="font-family:宋体;"></ResourceParams></span>



<span style="font-family:宋体;"></span>

maxActive 是最大激活连接数,这里取值为500,表示同时最多有500个数据库连接。maxIdle是最大的空闲连接数,这里取值为20,表示即使没有数据库连接时依然可以保持20空闲的连接,而不被清除,随时处于待命状态。MaxWait是最大等待秒钟数,这里取值-1,表示无限等待,直到超时为止,也可取值 9000,表示9秒后超时。

<span style="font-family:宋体;"></span>



<span style="font-family:宋体;">修改<span>confweb.xml,</span>增加如下内容<span></span></span>



<span style="font-family:宋体;"><resource-ref></span>



<span style="font-family:宋体;"> <span><description>DB Connection</description></span></span>



<span style="font-family:宋体;"> <span><res-ref-name>CarmotDS</res-ref-name></span></span>



<span style="font-family:宋体;"> <span><res-type>javax.sql.DataSource</res-type></span></span>



<span style="font-family:宋体;"> <span><res-auth>Container</res-auth></span></span>



<span style="font-family:宋体;"></resource-ref></span>



<span style="font-family:宋体;"></span>

然后修改 confCatalinalocalhostROOT.xml,context标签里增加如下内容:

<span style="font-family:宋体;"><ResourceLink global=”CarmotDS” name=”CarmotDS” type=”javax.sql.DataSource”/></span>



<span style="font-family:宋体;"></span>

Tomcat 5.5以上版本可以直接修改confCatalinalocalhostROOT.xml,context标签里增加如下内容:

<span style="font-family:宋体;"></span>



<span style="font-family:宋体;"><Resource name=” CarmotDS ” auth=”Container” type=”javax.sql.DataSource”</span>



<span style="font-family:宋体;">maxActive=</span><span style="font-family:宋体;">”<span>500</span>″<span> maxIdle=</span>”<span>20</span>″<span> maxWait=</span>”<span>9000</span>″<span></span></span>



<span style="font-family:宋体;">driverClassName=”oracle.jdbc.driver.OracleDriver”</span>



<span style="font-family:宋体;">username=”carmot_ystest” password=”carmot”</span>



<span style="font-family:宋体;">url=”jdbc:oracle:thin:@192.168.1.12:1521:igrp”</span>



<span style="font-family:宋体;">defaultAutoCommit=”true” removeAbandoned=”true”</span>



<span style="font-family:宋体;">removeAbandonedTimeout=</span><span style="font-family:宋体;">”<span>60</span>″<span> logAbandoned=</span>”<span>true</span>”<span>/></span></span>



<span style="font-family:宋体;">removeAbandonedTimeout=60,</span><span style="font-family:宋体;">表示<span>60</span>秒没有使用连接会自己回收资源<span>.</span></span>



<span style="font-family:宋体;">修改<span>global-config.xml</span></span>



<span style="font-family:宋体;"><datasource>java:comp/env/CarmotDS</datasource></span>



<span style="font-family:宋体;"></span>



<b><span style="font-family:宋体;">八、<span>admin/manager</span>的安全设置<span></span></span></b>



<span style="font-family:宋体;">配置文件<span>conf/ tomcat-users.xml</span></span>



<span style="font-family:宋体;">修改如下内容:<span></span></span>



<span style="font-family:宋体;"><role rolename=”manager”/></span>



<span style="font-family:宋体;"><role rolename=”admin”/></span>



<span style="font-family:宋体;"><user username=”admin” password=”admin” roles=”admin,manager”/></span>



<span style="font-family:宋体;">上面的密码设置项记得设为一个复杂的密码,或者干脆删除<span>admin/manager</span>目录<span></span></span>



<b><span style="font-family:SimSun;color:black;font-size:12px;">tomcat</span></b><b><span style="font-family:SimSun;color:black;font-size:12px;">中如何禁止列目录下的文件</span></b><span style="font-family:'Verdana','sans-serif';color:black;"><br />

{tomcat_home}/conf/web.xml中,把listings参数设置成false即可,如下:



listings
false


<span style="font-family:宋体;"></span>



<b><span style="font-family:宋体;">九、日志调整<span></span></span></b>



<span style="font-family:宋体;"></span>



<span style="font-family:宋体;"><Logger className=”org.apache.catalina.logger.FileLogger” prefix=”localhost_log.” suffix=”.txt” timestamp=”true”/></span>



<span style="font-family:宋体;"><Valve className=”org.apache.catalina.valves.AccessLogValve” directory=”logs” prefix=”access_log.” suffix=”.log” pattern=”combined” fileDateFormat=”yyyy-MM-dd” resolveHosts=”false”/></span>



<span style="font-family:宋体;">  调优综述<span> </span></span>



<span style="font-family:宋体;">  <span><span>&nbsp; </span></span>根据以上分析,如果想要<span>Tomcat</span>达到最优的效果,首先要争取使得操作系统以及网络资源达到最优,并且最好使用高版本的<span>JDK</span>。对于有大量静态页面的系统,采用<span>Apache</span>集成<span>Tomcat</span>的方式,把静态页面交由<span>Apache</span>处理,动态部分交由<span>Tomcat</span>处理,能极大解放<span>Tomcat</span>的处理能力。使用<span> ARP</span>库也能极大的提高<span>Tomcat</span>对静态文件的处理能力。对于并发要求较高的系统,采用<span>Apache</span>加<span>Tomcat</span>集群的方式,将负载分别分担到多个<span> Tomcat</span>上,能很大的提高系统的性能,充分利用硬件资源。同时需要对<span>Tomcat</span>自身进行优化,包括增大内存、调节并发线程数等。<span></span></span>



<span style="font-family:宋体;"></span>



<span style="font-family:宋体;"></span>



<span style="font-family:宋体;"><span style="font-family:Tahoma;"></span></span>

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注