标签:space jmap base loader lan 配置文件 star 功能 with
优化Tomcat分为四个方面:
1、优化配置
2、优化内存
3、优化并发
4、优化缓存
===================================================================================================
一、配置优化
旧的配置:
参考网络对服务器做过如下配置
1 <Connector port="9027" 2 3 protocol="HTTP/1.1" 4 5 maxHttpHeaderSize="8192" 6 7 maxThreads="1000" 8 9 minSpareThreads="25" 10 11 maxSpareThreads="75" 12 13 enableLookups="false" 14 15 compression="on" 16 17 compressionMinSize="2048" 18 19 compressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain" 20 21 connectionTimeout="20000" 22 23 URIEncoding="utf-8" 24 25 acceptCount="200" 26 27 redirectPort="8443" 28 29 disableUploadTimeout="true" />
后来发现在访问量达到3 百万多的时候出现性能瓶颈
更改后的配置:
1 <Connector port="9027" 2 3 protocol="HTTP/1.1" 4 5 maxHttpHeaderSize="8192" 6 7 maxThreads="1000" 8 9 minSpareThreads="100" 10 11 maxSpareThreads="1000" 12 13 minProcessors="100" 14 15 maxProcessors="1000" 16 17 enableLookups="false" 18 19 compression="on" 20 21 compressionMinSize="2048" 22 23 compressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain" 24 25 connectionTimeout="20000" 26 27 URIEncoding="utf-8" 28 29 acceptCount="1000" 30 31 redirectPort="8443" 32 33 disableUploadTimeout="true"/>
二、内存优化
Tomcat内存优化主要是对 tomcat 启动参数优化,我们可以在 tomcat 的启动脚本 catalina.sh 中设置 java_OPTS 参数。
JAVA_OPTS 参数说明:
-server 启用jdk 的 server 版;
-Xms Java虚拟机初始化时的最小内存;
-Xmx java虚拟机可使用的最大内存;
-XX: PermSize 内存永久保留区域
-XX:MaxPermSize 内存最大永久保留区域
服务器参数配置
1 [root@tomcat ~]# vim /usr/local/tomcat/bin/catalina.sh 2 3 ······ 4 5 234 #JAVA_OPTS="$JAVA_OPTS -Dorg.apache.catalina.security.SecurityListener.UMASK=`umask`" 6 7 将这行修改为 8 9 JAVA_OPTS=" -Xms1024m -Xmx2048m -XX:PermSize=256M -XX:MaxNewSize=256m -XX:MaxPermSize=256m"
配置完成后可重启Tomcat ,通过以下命令进行查看配置是否生效:
首先查看Tomcat 进程号:
1 [root@tomcat ~]# ps aux | grep :8080 2 root 9438 0.0 0.0 103324 884 pts/0 S+ 16:38 0:00 grep :8080 3 4 [root@localhost2 bin]# ps aux | grep java 5 root 1552 25.9 8.3 4065032 159156 pts/0 Sl 00:44 0:05 /usr/local/java/bin/java -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Xms1024m -Xmx2048m -XX:PermSize=256M -XX:MaxNewSize=256m -XX:MaxPermSize=256m -Djava.endorsed.dirs=/usr/local/tomcat/endorsed -classpath /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat -Dcatalina.home=/usr/local/tomcat -Djava.io.tmpdir=/usr/local/tomcat/temp org.apache.catalina.startup.Bootstrap start 6 7 [root@localhost2 bin]# jmap -heap 1552 8 Attaching to process ID 1552, please wait... 9 Debugger attached successfully. 10 Server compiler detected. 11 JVM version is 24.65-b04 12 13 using thread-local object allocation. 14 Parallel GC with 4 thread(s) 15 16 Heap Configuration: 17 MinHeapFreeRatio = 0 18 MaxHeapFreeRatio = 100 19 MaxHeapSize = 2147483648 (2048.0MB) 20 NewSize = 1310720 (1.25MB) 21 MaxNewSize = 268435456 (256.0MB) 22 OldSize = 5439488 (5.1875MB) 23 NewRatio = 2 24 SurvivorRatio = 8 25 PermSize = 268435456 (256.0MB) 26 MaxPermSize = 268435456 (256.0MB) 27 G1HeapRegionSize = 0 (0.0MB) 28 29 Heap Usage: 30 PS Young Generation 31 Eden Space: 32 capacity = 201326592 (192.0MB) 33 used = 124955872 (119.16720581054688MB) 34 free = 76370720 (72.83279418945312MB) 35 62.0662530263265% used 36 From Space: 37 capacity = 33554432 (32.0MB) 38 used = 0 (0.0MB) 39 free = 33554432 (32.0MB) 40 0.0% used 41 To Space: 42 capacity = 33554432 (32.0MB) 43 used = 0 (0.0MB) 44 free = 33554432 (32.0MB) 45 0.0% used 46 PS Old Generation 47 capacity = 805306368 (768.0MB) 48 used = 0 (0.0MB) 49 free = 805306368 (768.0MB) 50 0.0% used 51 PS Perm Generation 52 capacity = 268435456 (256.0MB) 53 used = 14604864 (13.92828369140625MB) 54 free = 253830592 (242.07171630859375MB) 55 5.440735816955566% used 56 57 8958 interned Strings occupying 742584 bytes.
我们可以看到MaxHeapSize 等参数已经生效。
三、并发优化
1.Tomcat连接相关参数
在Tomcat 配置文件 server.xml 中的
1 <Connector port="9027" 2 3 protocol="HTTP/1.1" 4 5 maxHttpHeaderSize="8192" 6 7 minProcessors="100" 8 9 maxProcessors="1000" 10 11 acceptCount="1000" 12 13 redirectPort="8443" 14 15 disableUploadTimeout="true"/>
2.调整连接器connector的并发处理能力
1>参数说明
maxThreads 客户请求最大线程数
minSpareThreads Tomcat初始化时创建的 socket 线程数
maxSpareThreads Tomcat连接器的最大空闲 socket 线程数
enableLookups 若设为true, 则支持域名解析,可把 ip 地址解析为主机名
redirectPort 在需要基于安全通道的场合,把客户请求转发到基于SSL 的 redirectPort 端口
acceptAccount 监听端口队列最大数,满了之后客户请求会被拒绝(不能小于maxSpareThreads )
connectionTimeout 连接超时
minProcessors 服务器创建时的最小处理线程数
maxProcessors 服务器同时最大处理线程数
URIEncoding URL统一编码
2>Tomcat中的配置示例
1 <Connector port="9027" 2 3 protocol="HTTP/1.1" 4 5 maxHttpHeaderSize="8192" 6 7 maxThreads="1000" 8 9 minSpareThreads="100" 10 11 maxSpareThreads="1000" 12 13 minProcessors="100" 14 15 maxProcessors="1000" 16 17 enableLookups="false" 18 19 URIEncoding="utf-8" 20 21 acceptCount="1000" 22 23 redirectPort="8443" 24 25 disableUploadTimeout="true"/>
四、缓存优化
1>参数说明
c ompression 打开压缩功能
compressionMinSize 启用压缩的输出内容大小,这里面默认为2KB
compressableMimeType 压缩类型
connectionTimeout 定义建立客户连接超时的时间. 如果为 -1, 表示不限制建立客户连接的时间
2>Tomcat中的配置示例
1 <Connector port="9027" 2 3 protocol="HTTP/1.1" 4 5 maxHttpHeaderSize="8192" 6 7 maxThreads="1000" 8 9 minSpareThreads="100" 10 11 maxSpareThreads="1000" 12 13 minProcessors="100" 14 15 maxProcessors="1000" 16 17 enableLookups="false" 18 19 compression="on" 20 21 compressionMinSize="2048" 22 23 compressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain" 24 25 connectionTimeout="20000" 26 27 URIEncoding="utf-8" 28 29 acceptCount="1000" 30 31 redirectPort="8443" 32 33 disableUploadTimeout="true"/>
标签:space jmap base loader lan 配置文件 star 功能 with
原文地址:http://www.cnblogs.com/LuckWJL/p/7095300.html