技术开发 频道

Apache HTTP Server和Tomcat的性能优化

  PermSize和MaxPermSize指明虚拟机为java永久生成对象(Permanate generation)如,class对象、方法对象这些可反射(reflective)对象分配内存限制,这些内存不包括在Heap(堆内存)区之中。

  -XX:PermSize=512MB 最小尺寸,初始分配。

  -XX:MaxPermSize=512MB 最大允许分配尺寸,按需分配。

  在Tomcat安装目录下的bin/catalina.sh文件下添加。

  JAVA_OPTS="-Xmx2048M -Xms1024M -XX:PermSize=512M -XX:MaxPermSize=512M"; 设置了初始堆大小为2014M,最大值为2048M。永久保存区域初始大小512M,最大允许分配尺寸512内存。

  2、禁用DNS查询

  Set to true if you want calls to request.getRemoteHost() to perform DNS lookups in order to return the actual host name of the remote client. Set to false to skip the DNS lookup and return the IP address in String form instead (thereby improving performance). By default, DNS lookups are enabled.

  Server.xml中的Connector 节点中进行设置:修改server.xml文件中的enableLookups参数值为false。

  3、调整线程数

  Server.xml中的Connector 节点中进行设置如下:

  minProcessors 服务器启动时创建的处理请求的线程数。

  maxProcessors 最大可以创建的处理请求的线程数。

  maxThreads:这个值表示Tomcat可创建的最大的线程数。 默认为200;If not specified, this attribute is set to 200。

  acceptCount :指定当所有可以使用的处理请求的线程数都被使用时,可以放到处理队列中的请求数,超过这个数的请求将不予处理。The default value is 100

  connnectionTimeout 网络连接超时,单位:毫秒。设置为0表示永不超时,这样设置有隐患的。通常可设置为30000毫秒。

  minSpareThreads Tomcat初始化时创建的线程数。 If not specified, the default of 10 is used.

  maxSpareThreads 一旦创建的线程超过这个值,Tomcat就会关闭不再需要的socket线程。 (tomcat5以后已删除)

<Connector port="80" maxThreads="150" minSpareThreads="25" enableLookups="false" redirectPort="8443" acceptCount="100" debug="0" connectionTimeout="20000" disableUploadTimeout="true"/>

  总 结:

  首先要争取使得操作系统以及网络资源达到最优,并且最好使用高版本的JDK。对于有大量静态页面的系统,采用Apache集成Tomcat的方式,把静态页面交由Apache处理,动态部分交由Tomcat处理,能极大解放Tomcat的处理能力。通过Apache和Tomcat负载提供稳定高并发的性能需求。同时需要对Tomcat自身进行优化,包括增大内存、调节并发线程数等。

0
相关文章