首页 > 技术文章 > tomcat配置Gzip压缩 server.xml

MuZi0627 2018-09-18 17:05 原文

 <Connector port="52200" protocol="HTTP/1.1" 
               connectionTimeout="20000" 
               maxThreads="999" minSpareThreads="20"
               maxSpareThreads="999"
               maxProcessors="1024"
               minProcessors="10"
               acceptCount="1024" 
               debug="0"
               emptySessionPath="true" 
               enableLookups="false"
               redirectPort="8443" />

 

还可配置Executor,如下:

<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
maxThreads="3000" 
minSpareThreads="5"
maxIdleTime="60000"        
/>

maxThreads :客户请求最大线程数
minSpareThreads - 最小空闲线程数,Tomcat初始化时创建的线程数
maxSpareThreads - 最多空闲连接数,一旦创建的线程超过这个值,Tomcat就会关闭不再需要的socket线程
maxIdleTime="60000":最大空闲时间,60秒内未使用则连接被丢弃。若为0则永不丢弃。单位毫秒.

<Connector executor="tomcatThreadPool"
               port="52200" protocol="HTTP/1.1"
               URIEncoding="UTF-8" enableLookups="false" disableUploadTimeout="true"
        connectionTimeout="20000" keepAliveTimeout="15000" maxKeepAliveRequests="1000"
               compression="on" compressionMinSize="4096"
               compressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain" 
        redirectPort="8443"/>

connectionTimeout - 网络连接超时,单位:毫秒。设置为0表示永不超时,这样设置有隐患的。通常可设置为30000毫秒。
keepAliveTimeout - 长连接最大保持时间(毫秒)。此处为15秒
maxKeepAliveRequests - 最大长连接个数(1表示禁用,-1表示不限制个数,默认100个。一般设置在100~200之间)
compression:如果开启gzip服务,则为on,默认关闭
compressionMinSize="4096":对小于该配置大小的文件不进行压缩(单位:B,也就是4K)。注该属性自Tomcat7中有效
compressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain" (这是默认值,指定需要压缩的请求文档类型)


其他参数
enableLookups:若设为true, 则支持域名解析,可把 ip 地址解析为主机名
redirectPort:在需要基于安全通道的场合,把客户请求转发到基于SSL 的 redirectPort 端口
acceptAccount:监听端口队列最大数,满了之后客户请求会被拒绝(不能小于maxSpareThreads)
connectionTimeout - 网络连接超时,单位:毫秒。设置为0表示永不超时,这样设置有隐患的。通常可设置为30000毫秒。
keepAliveTimeout - 长连接最大保持时间(毫秒)。此处为15秒。
maxKeepAliveRequests - 最大长连接个数(1表示禁用,-1表示不限制个数,默认100个。一般设置在100~200之间) the maximum number of HTTP requests that can be held in the pipeline until the connection is closed by the server. Setting this attribute to 1 disables HTTP/1.0 keep-alive, as well as HTTP/1.1 keep-alive and pipelining. Setting this to -1 allows an unlimited number of pipelined or keep-alive HTTP requests. If not specified, this attribute is set to 100.
maxHttpHeaderSize - http请求头信息的最大程度,超过此长度的部分不予处理。一般8K。
URIEncoding - 指定Tomcat容器的URL编码格式。
acceptCount - 指定当所有可以使用的处理请求的线程数都被使用时,可以放到处理队列中的请求数,超过这个数的请求将不予处理,默认为10个。defines the maximum queue length for incoming connection requests when all possible request processing threads are in use. Any requests received when the queue is full are refused. The default value is 10.
disableUploadTimeout - 上传时是否使用超时机制
enableLookups - 是否反查域名,取值为:true或false。为了提高处理能力,应设置为false
bufferSize - defines the size (in bytes) of the buffer to be provided for input streams created by this connector. By default, buffers of 2048 bytes are provided.
maxSpareThreads - 做多空闲连接数,一旦创建的线程超过这个值,Tomcat就会关闭不再需要的socket线程 the maximum number of unused request processing threads that are allowed to exist until the thread pool starts stopping the unnecessary threads. The default value is 50.
maxThreads - 最多同时处理的连接数,Tomcat使用线程来处理接收的每个请求。这个值表示Tomcat可创建的最大的线程数。。 the maximum number of request processing threads to be created by this Connector, which therefore determines the maximum number of simultaneous requests that can be handled. If not specified, this attribute is set to 200.
minSpareThreads - 最小空闲线程数,Tomcat初始化时创建的线程数 the number of request processing threads that are created when this Connector is first started. The connector will also make sure it has the specified number of idle processing threads available. This attribute should be set to a value smaller than that set for maxThreads. The default value is 4.
minProcessors - 最小空闲连接线程数,用于提高系统处理性能,默认值为10。(用于Tomcat4中)
maxProcessors - 最大连接线程数,即:并发处理的最大请求数,默认值为75。(用于Tomcat4中)

 

推荐阅读