Good learning Java programmers to share practical route Tomcat performance optimization, preface, due to the different hardware configurations lead to a default tomcat configuration can not achieve the best performance, we need to lead to adjustments to the corresponding configuration of tomcat.
T omcat memory optimization
Configuration: JAVA_OPTS = '- Xms1024m -Xmx2048m -XX: PermSize = 256M -XX: MaxNewSize = 256m -XX: MaxPermSize = 256m'
The above configuration information in the following figure tomcat catalina.sh shown:
Parameter Description:
-server jdk enable the server version;
-Xms java virtual machine when the minimum memory initialization;
-Xmx maximum memory java virtual machine can be used;
-XX: PermSize memory permanently reserved area
-XX: MaxPermSize maximum memory permanently reserved area
Depending on the hardware configuration parameters can be adjusted size, large memory, cpu multiple audit may be too large for the corresponding parameter settings, whereas small set appropriately.
T omcat concurrent optimization
Concurrent optimization in the main configuration file server.xml in conf. Configuration code is as follows:
<Connector port="8080"
protocol="HTTP/1.1"
maxHttpHeaderSize="8192"
minProcessors="100"
maxProcessors="1000"
acceptCount="1000"
redirectPort="8443"
disableUploadTimeout="true"/>
Parameter Description
maxThreads customer requests maximum number of threads
Number of socket threads created during initialization of minSpareThreads Tomcat
maxSpareThreads Tomcat连接器的最大空闲 socket 线程数
enableLookups 若设为true, 则支持域名解析,可把 ip 地址解析为主机名
redirectPort 在需要基于安全通道的场合,把客户请求转发到基于SSL 的 redirectPort 端口
acceptAccount 监听端口队列最大数,满了之后客户请求会被拒绝(不能小于maxSpareThreads )
connectionTimeout 连接超时
minProcessors 服务器创建时的最小处理线程数
maxProcessors 服务器同时最大处理线程数
URIEncoding URL统一编码
效果图如下:
Tomcat缓存优化
缓存优化主要在conf中server.xml文件中配置。配置代码如下:
<Connector port="8080"
protocol="HTTP/1.1"
maxHttpHeaderSize="8192"
maxThreads="1000"
minSpareThreads="100"
maxSpareThreads="1000"
minProcessors="100"
maxProcessors="1000"
enableLookups="false"
compression="on"
compressionMinSize="2048"
compressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain"
connectionTimeout="20000"
URIEncoding="utf-8"
acceptCount="1000"
redirectPort="8443"
disableUploadTimeout="true"/>
参数说明
maxThreads 客户请求最大线程数
minSpareThreads Tomcat初始化时创建的 socket 线程数
maxSpareThreads Tomcat连接器的最大空闲 socket 线程数
enableLookups 若设为true, 则支持域名解析,可把 ip 地址解析为主机名
redirectPort 在需要基于安全通道的场合,把客户请求转发到基于SSL 的 redirectPort 端口
acceptAccount 监听端口队列最大数,满了之后客户请求会被拒绝(不能小于maxSpareThreads )
connectionTimeout 连接超时
minProcessors 服务器创建时的最小处理线程数
maxProcessors 服务器同时最大处理线程数
URIEncoding URL统一编码
compression 打开压缩功能
compressionMinSize 启用压缩的输出内容大小,这里面默认为2KB
compressableMimeType 压缩类型
connectionTimeout 定义建立客户连接超时的时间. 如果为 -1, 表示不限制建立客户连接的时间
效果图如下:
总结
配置了内存、并发、缓存优化后,同配置硬件设备可提高多倍有效访问率。