1 如何優(yōu)化Tomcat

目錄

Tomcat目錄

Tomcat優(yōu)化方向

配置項(xiàng)的刪除

WEB-INF/web.xml

conf/web.xml

server.xml

配置項(xiàng)參數(shù)優(yōu)化

jvm參數(shù)優(yōu)化

sever.xml中的配置參數(shù)優(yōu)化

Tomcat內(nèi)存優(yōu)化

JAVA_OPTS參數(shù)說明

服務(wù)器參數(shù)配置

Tomcat并發(fā)優(yōu)化

1.Tomcat連接相關(guān)參數(shù)

2.調(diào)整連接器connector的并發(fā)處理能力

Tomcat緩存優(yōu)化

1>參數(shù)說明

2>Tomcat中的配置示例


Tomcat目錄

(1)bin:主要用來(lái)存放命令,.bat是windows下,.sh是Linux下
(2)conf:主要用來(lái)存放tomcat的一些配置文件
(3)lib:存放tomcat依賴的一些jar包
(4)logs:存放tomcat在運(yùn)行時(shí)產(chǎn)生的日志文件
(5)temp:存放運(yùn)行時(shí)產(chǎn)生的臨時(shí)文件
(6)webapps:存放應(yīng)用程序
(7)work:存放tomcat運(yùn)行時(shí)編譯后的文件,比如JSP編譯后的文件

Tomcat優(yōu)化方向

tomcat優(yōu)化可以有幾個(gè)方向:配置項(xiàng)的刪除,配置參數(shù)的修改,jdk參數(shù)修改、Tomcat內(nèi)存優(yōu)化、Tomcat并發(fā)優(yōu)化、Tomcat緩存優(yōu)化

配置項(xiàng)的刪除

tomcat涉及的配置文件有三種

web項(xiàng)目中自帶的WEB-INF/web.xml,
tomcat自帶的conf/web.xml以及conf/server.xml文件。
因?yàn)檫@些xml文件都會(huì)被tomcat解析,所以優(yōu)化方向是將這三類文件中不必要的配置刪除。

tomcat在啟動(dòng)時(shí),會(huì)將web項(xiàng)目中WEB-INF/web.xml和自己的conf/web.xml進(jìn)行合并,然后在ContextConfig類下的configureContext()統(tǒng)一解析這些內(nèi)容:

private void configureContext(WebXml webxml) {
    ...
    for (Entry<String, String> entry : webxml.getContextParams().entrySet()) {
        context.addParameter(entry.getKey(), entry.getValue());
    }
    for (ContextEjb ejbRef : webxml.getEjbRefs().values()) {
        context.getNamingResources().addEjb(ejbRef);
    }
    for (ContextEnvironment environment : webxml.getEnvEntries().values()) {
        context.getNamingResources().addEnvironment(environment);
    }
    for (ErrorPage errorPage : webxml.getErrorPages().values()) {
        context.addErrorPage(errorPage); // 解析錯(cuò)誤頁(yè)面
    }
for (FilterDef filter : webxml.getFilters().values()) {
// 解析過濾器標(biāo)簽
        if (filter.getAsyncSupported() == null) {
            filter.setAsyncSupported("false");
        }
        context.addFilterDef(filter);
    }
    ...
}

WEB-INF/web.xml

這個(gè)只能是在項(xiàng)目中不需要的配置不要放進(jìn)去,有過期的配置要及時(shí)刪除,減少tomcat的解析成本。

conf/web.xml

DefaultServlet

這是一個(gè)處理靜態(tài)文件的servlet,如果項(xiàng)目中不需要tomcat進(jìn)行靜態(tài)文件的處理,可以將其刪掉。

<!-- The default servlet for all web applications, that serves static     -->
  <!-- resources.  It processes all requests that are not mapped to other   -->
  <!-- servlets with servlet mappings (defined either here or in your own   -->
  <!-- web.xml file).   -->
    <servlet>
        <servlet-name>default</servlet-name>
        <servlet-class>org.apache.catalina.servlets.DefaultServlet
</servlet-class>
        <init-param>
            <param-name>debug</param-name>
            <param-value>0</param-value>
        </init-param>
        <init-param>
            <param-name>listings</param-name>
            <param-value>false</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

JspServlet

這個(gè)servlet是用來(lái)編譯和執(zhí)行jsp文件的,如果項(xiàng)目中沒有jsp文件,可以將其刪掉。

 <!-- The JSP page compiler and execution servlet, which is the mechanism  -->
  <!-- used by Tomcat to support JSP pages.  Traditionally, this servlet    -->
  <!-- is mapped to the URL pattern "*.jsp".      -->
    <servlet>
        <servlet-name>jsp</servlet-name>
        <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
        <init-param>
            <param-name>fork</param-name>
            <param-value>false</param-value>
        </init-param>
        <init-param>
            <param-name>xpoweredBy</param-name>
            <param-value>false</param-value>
        </init-param>
        <load-on-startup>3</load-on-startup>
    </servlet>

jsp映射

項(xiàng)目中沒有jsp,關(guān)于jsp下面的映射也可以刪除:

 <!-- The mappings for the JSP servlet -->
    <servlet-mapping>
        <servlet-name>jsp</servlet-name>
        <url-pattern>*.jsp</url-pattern>
        <url-pattern>*.jspx</url-pattern>
    </servlet-mapping>

mime類型映射

文件中提供的mime類型非常多,如果有確定項(xiàng)目中不會(huì)涉及到的類型,可以刪除其映射配置。

 <!-- ===================== Default MIME Type Mappings =================== -->
  <!-- When serving static resources, Tomcat will automatically generate    -->
  <!-- a "Content-Type" header based on the resource's filename extension,  -->
  <!-- based on these mappings.  Additional mappings can be added here (to  -->
  <!-- apply to all web applications), or in your own application's web.xml -->
  <!-- deployment descriptor.                                               -->
  <!-- Note: Extensions are always matched in a case-insensitive manner.    -->
    ...
    <mime-mapping>
        <extension>jpg</extension>
        <mime-type>image/jpeg</mime-type>
    </mime-mapping>
    <mime-mapping>
        <extension>jpgm</extension>
        <mime-type>video/jpm</mime-type>
    </mime-mapping>
    <mime-mapping>
        <extension>jpgv</extension>
        <mime-type>video/jpeg</mime-type>
    </mime-mapping>
    <mime-mapping>
        <extension>jpm</extension>
        <mime-type>video/jpm</mime-type>
    </mime-mapping>
    <mime-mapping>
        <extension>jsf</extension>
        <mime-type>text/plain</mime-type>
    </mime-mapping>
    <mime-mapping>
        <extension>json</extension>
        <mime-type>application/json</mime-type>
    </mime-mapping>
    ...

歡迎頁(yè)配置

如果不需要展示tomcat的歡迎頁(yè),可以將其刪掉。

 <!-- ==================== Default Welcome File List ===================== -->
  <!-- When a request URI refers to a directory, the default servlet looks  -->
  <!-- for a "welcome file" within that directory and, if present, to the   -->
  <!-- corresponding resource URI for display.                              -->
  <!-- If no welcome files are present, the default servlet either serves a -->
  <!-- directory listing (see default servlet configuration on how to       -->
  <!-- customize) or returns a 404 status, depending on the value of the    -->
  <!-- listings setting.                                                    -->
  <!--                                                                      -->
  <!-- If you define welcome files in your own application's web.xml        -->
  <!-- deployment descriptor, that list *replaces* the list configured      -->
  <!-- here, so be sure to include any of the default values that you wish  -->
  <!-- to use within your application.                                       -->

    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

server.xml

Listener

下面是tomcat8.5版本提供的默認(rèn)listener列表:

<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
<!-- Security listener. Documentation at /docs/config/listeners.html
<Listener className="org.apache.catalina.security.SecurityListener" />
-->
<!--APR library loader. Documentation at /docs/apr.html -->
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<!-- Prevent memory leaks due to use of particular java/javax APIs-->
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />

VersionLoggerListener

作用是在Tomcat初始化時(shí),打印一下Tomcat相關(guān)的版本信息以及操作系統(tǒng)和jdk環(huán)境信息,可以刪掉。

AprLifecycleListener

Tomcat啟動(dòng)時(shí),檢查APR庫(kù),如果存在則加載,這個(gè)配置僅當(dāng)connector的protocol設(shè)置為AJP/1.3時(shí)有用,如果非AJP/1.3,可以刪除。

JreMemoryLeakPreventionListener

Java運(yùn)行環(huán)境可能導(dǎo)致某些已知位置的內(nèi)存泄漏或文件鎖定,
JreMemoryLeakPreventionListener提供這些情況的解決方案。

GlobalResourcesLifecycleListener

作用于全局資源,通過該監(jiān)聽器,初始化標(biāo)簽中定義的全局JNDI資源;
如果沒有該監(jiān)聽器,定義的全局資源都不能使用。
如果不使用GlobalNamingResources定義全局資源,可以刪除。

ThreadLocalLeakPreventionListener

Web應(yīng)用因thread-local導(dǎo)致的內(nèi)存泄露而要停止時(shí),該監(jiān)聽器會(huì)觸發(fā)線程池中線程的更新。
只有當(dāng)Web應(yīng)用(即Context元素)的renewThreadsWhenStoppingContext屬性設(shè)置為true時(shí),該監(jiān)聽器才有效。
官方文檔對(duì)renewThreadsWhenStoppingContext配置的解釋為:

If true, when this context is stopped, Tomcat renews all the threads from the thread pool that was used to serve this context.
This also requires that the ThreadLocalLeakPreventionListener be configured in server.xml and that the threadRenewalDelay property of the Executor be >=0.
If not specified, the default value of true will be used.

GlobalNamingResources

GlobalNamingResources可以定義全局資源,可以看出,這個(gè)tomcat的默認(rèn)配置是通過讀取$TOMCAT_HOME/ conf/tomcat-users.xml實(shí)現(xiàn)的。
tomcat-user.xml用于定義tomcat管理頁(yè)面相關(guān)配置,如果不登錄管理界面可以刪掉。

 <GlobalNamingResources>
    <!-- Editable user database that can also be used by
         UserDatabaseRealm to authenticate users
    -->
    <Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
              description="User database that can be updated and saved"
              factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
              pathname="conf/tomcat-users.xml" />
  </GlobalNamingResources>

Connector

官網(wǎng)中對(duì)于這個(gè)connector有如下描述:
The AJP Connector element represents a Connector component that communicates with a web connector via the AJP protocol. This is used for cases where you wish to invisibly integrate Tomcat into an existing (or new) Apache installation, and you want Apache to handle the static content contained in the web application, and/or utilize Apache's SSL processing.
可知當(dāng)tomcat需要集成到Apache服務(wù)器時(shí)才使用這個(gè)connector,現(xiàn)在一般都用Nginx代替Apache,所以不使用Apache的話這個(gè)也可以刪掉。

tomcat默認(rèn)配置包含如下connector:
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

Realm

Realm,可以把它理解成“域”;
Realm提供了一種用戶密碼與web應(yīng)用的映射關(guān)系,從而達(dá)到角色安全管理的作用,tomcat默認(rèn)的這個(gè)realm是和name為UserDatabase的資源綁定的,而該資源在Server元素中使用GlobalNamingResources配置。如果不需要可以刪掉。

<Realm className="org.apache.catalina.realm.LockOutRealm">
<!-- This Realm uses the UserDatabase configured in the global JNDI
     resources under the key "UserDatabase".  Any edits
     that are performed against this UserDatabase are immediately
     available for use by the Realm.  -->
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
       resourceName="UserDatabase"/>
</Realm>

Valve

Valve的意思是“閥門”,不同的Valve有不同的特性,Valve的配置中AccessLogValve的作用是記錄其所在容器處理的所有請(qǐng)求,默認(rèn)配置中的Valve放在Host下,便可以記錄該Host處理的所有請(qǐng)求。
AccessLogValve記錄的日志就是訪問日志,每天的請(qǐng)求會(huì)寫到一個(gè)日志文件里?,F(xiàn)在一般記錄Nginx訪問日志,這個(gè)也可以刪除。

<!-- Access log processes all example.
     Documentation at: /docs/config/valve.html
     Note: The pattern used is equivalent to using pattern="common" -->
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
       prefix="localhost_access_log" suffix=".txt"
       pattern="%h %l %u %t &quot;%r&quot; %s %b" />

配置項(xiàng)參數(shù)優(yōu)化

jvm參數(shù)優(yōu)化

tomcat是用Java寫的,就要運(yùn)行在jvm上,垃圾處理方式等都要遵循jvm的方式。
tomcat中設(shè)置jvm參數(shù)在 catalina.sh(Linux)和catalina.bat(windows)中,以JAVA_OPTS變量存儲(chǔ)。以catalina.sh為例:

JAVA_OPTS="-Dfile.encoding=UTF8"
JAVA_OPTS="$JAVA_OPTS $JSSE_OPTS"

可以在該變量中添加jvm參數(shù),達(dá)到減少gc次數(shù)等目標(biāo),例如根據(jù)tomcat所在服務(wù)器修改jvm內(nèi)存大小等。

sever.xml中的配置參數(shù)優(yōu)化

參數(shù)優(yōu)化主要是優(yōu)化sever.xml中的配置參數(shù),示例server.xml如下:

<?xml version='1.0' encoding='utf-8'?>

<Server port="8005" shutdown="SHUTDOWN">
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />

  <Service name="Catalina">
    <Connector port="8002" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8444" />
    <Engine name="Catalina" defaultHost="wggl">
      <Host name="wggl" appBase="wggl" unpackWARs="true" autoDeploy="false">
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="wggl_accesslog" suffix=".txt" pattern="%h %l %u %t &quot;%r&quot; %s %b" />
        <Context docBase="ROOT" path="/" reloadable="false"  sessionCookieName="wggl"/>
      </Host>
    </Engine>
  </Service>
  <Service name="Catalina">
    <Connector port="8003" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8444" />
    <Engine name="Catalina" defaultHost="jxkh">
      <Host name="jxkh" appBase="jxkh" unpackWARs="true" autoDeploy="false">
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="jxkh_accesslog" suffix=".txt" pattern="%h %l %u %t &quot;%r&quot; %s %b" />
        <Context docBase="ROOT" path="/" reloadable="false"  sessionCookieName="jxkh"/>
      </Host>
    </Engine>
  </Service>
</Server>

server

port:指定一個(gè)端口,這個(gè)端口負(fù)責(zé)監(jiān)聽關(guān)閉tomcat的請(qǐng)求。
shutdown:指定向端口發(fā)送的命令字符串。
sever配置沒什么可優(yōu)化的。

service

name:指定service的名字。
service配置沒什么可優(yōu)化的。

Connector

port:指定服務(wù)器端要?jiǎng)?chuàng)建的端口號(hào),并在這個(gè)端口監(jiān)聽來(lái)自客戶端的請(qǐng)求
minProcessors:服務(wù)器啟動(dòng)時(shí)創(chuàng)建的處理請(qǐng)求的線程數(shù)
maxProcessors:最大可以創(chuàng)建的處理請(qǐng)求的線程數(shù)
enableLookups:如果為true,則可以通過調(diào)用request.getRemoteHost()進(jìn)行DNS查詢來(lái)得到遠(yuǎn)程客戶端的實(shí)際主機(jī)名,若為false則不進(jìn)行DNS查詢,而是返回其ip地址
redirectPort:指定服務(wù)器正在處理http請(qǐng)求時(shí)收到了一個(gè)SSL傳輸請(qǐng)求后重定向的端口號(hào)
acceptCount:指定當(dāng)所有可以使用的處理請(qǐng)求的線程數(shù)都被使用時(shí),可以放到處理隊(duì)列中的請(qǐng)求數(shù),超過這個(gè)數(shù)的請(qǐng)求將不予處理
maxConnections:達(dá)到這個(gè)值之后,將繼續(xù)接受連接,但是不處理,能繼續(xù)接受多少根據(jù)acceptCount的值
minSpareThreads:最小空閑線程數(shù)
connectionTimeout:指定超時(shí)的時(shí)間數(shù)(以毫秒為單位)
官網(wǎng)8.5版本connector使用連接類型如下:

org.apache.coyote.ajp.AjpNioProtocol - non blocking Java NIO connector.
org.apache.coyote.ajp.AjpNio2Protocol - non blocking Java NIO2 connector.
org.apache.coyote.ajp.AjpAprProtocol - the APR/native connector.

查看Connector源碼:

public void setProtocol(String protocol) {
    ...
    if ("HTTP/1.1".equals(protocol) || protocol == null) {
        if (aprConnector) {
           setProtocolHandlerClassName("org.apache.coyote.http11.Http11AprProtocol");
        } else {
            setProtocolHandlerClassName("org.apache.coyote.http11.Http11NioProtocol");
        }
    } else if ("AJP/1.3".equals(protocol)) {
        if (aprConnector) {
            setProtocolHandlerClassName("org.apache.coyote.ajp.AjpAprProtocol");
        } else {
            setProtocolHandlerClassName("org.apache.coyote.ajp.AjpNioProtocol");
        }
    } else {
        setProtocolHandlerClassName(protocol);
    }
}

可知默認(rèn)協(xié)議使用的是Http11NioProtocol,即NIO方式。
tomcat默認(rèn)連接池有限制,可以為connector配置自己的連接池,例如:

<Connector executor="tomcatThreadPool"
port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />

<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
maxThreads="1000" minSpareThreads="4"/>

在連接池中可以根據(jù)項(xiàng)目自定義最大線程數(shù)量。

Engine

name:屬性用于日志和錯(cuò)誤信息,在整個(gè)Server中應(yīng)該唯一
defaultHost:defaultHost屬性指定了默認(rèn)的host名稱,當(dāng)發(fā)往本機(jī)的請(qǐng)求指定的host名稱不存在時(shí),一律使用defaultHost指定的host進(jìn)行處理;因此defaultHost的值,必須與Engine中的一個(gè)Host組件的name屬性值匹配
沒什么可優(yōu)化的。

host

name:指定虛擬主機(jī)的主機(jī)名,一個(gè)Engine中有且僅有一個(gè)Host組件的name屬性與Engine組件的defaultHost屬性相匹配;
注:一般情況下,主機(jī)名需要是在DNS服務(wù)器中注冊(cè)的網(wǎng)絡(luò)名,但是Engine指定的defaultHost不需要

appBase:應(yīng)用程序基本目錄,即存放應(yīng)用程序的目錄

unpackWARs:指定了是否將war文件解壓,如果為true,則通過解壓后的目錄運(yùn)行該Web應(yīng)用;如果為false,則直接使用WAR文件運(yùn)行Web應(yīng)用

autoDeploy:是否自動(dòng)部署,Tomcat運(yùn)行期間會(huì)用一個(gè)線程定時(shí)檢查,如果有新的web工程會(huì)自動(dòng)部署。
autoDeploy生產(chǎn)環(huán)境之下可以改成false,減少tomcat的負(fù)擔(dān)。
autoDeploy有需要注意的點(diǎn),如果為true,拷貝war到webapp下面,tomcat自動(dòng)解壓并部署。但是停掉tomcat拷貝新的war包過去,tomcat不會(huì)解壓新包并后覆蓋舊目錄,因?yàn)閠omcat直接使用了之前解壓過的目錄。官網(wǎng)有描述:
If you redeploy an updated WAR file, be sure to delete the expanded directory when restarting Tomcat, so that the updated WAR file will be re-expanded (note that the auto deployer, if enabled, will automatically expand the updated WAR file once the previously expanded directory is removed).

Context

docBase:代表應(yīng)用程序或war文件存放的路徑,這個(gè)可以自由指定,例如d:/study

path:

表示此web應(yīng)用程序的url的前綴,這樣請(qǐng)求的url為http://localhost:8080/path/**

reloadable:如果為true,則tomcat會(huì)自動(dòng)檢測(cè)應(yīng)用程序的/WEB-INF/lib和/WEB-INF/classes目錄的變化,自動(dòng)裝載新的應(yīng)用程序,可以在不重起tomcat的情況下改變應(yīng)用程序

生產(chǎn)環(huán)境中可以把reloadable設(shè)置為false。

Realm

className:指定Realm使用的類名,此類必須實(shí)現(xiàn)org.apache.catalina.Realm接口
沒什么可優(yōu)化的

Valve

className:規(guī)定了Valve的類型;例如tomcat默認(rèn)的是AccessLogValve。
directory:指定日志存儲(chǔ)的位置,默認(rèn)日志存儲(chǔ)在TOMCAT_HOME/logs目錄下。 prefix:指定了日志文件的前綴。 suffix:指定了日志文件的后綴。通過directory、prefix和suffix的配置,在TOMCAT_HOME/logs目錄下,可以看到如下所示的日志文件。
沒什么可優(yōu)化的。

Tomcat內(nèi)存優(yōu)化

Tomcat內(nèi)存優(yōu)化主要是對(duì) tomcat 啟動(dòng)參數(shù)優(yōu)化,我們可以在 tomcat 的啟動(dòng)腳本 catalina.sh 中設(shè)置 java_OPTS 參數(shù)。

JAVA_OPTS參數(shù)說明

-server 啟用jdk 的 server 版;
-Xms java虛擬機(jī)初始化時(shí)的最小內(nèi)存;
-Xmx java虛擬機(jī)可使用的最大內(nèi)存;
-XX: PermSize 內(nèi)存永久保留區(qū)域
-XX:MaxPermSize 內(nèi)存最大永久保留區(qū)域

服務(wù)器參數(shù)配置

現(xiàn)公司服務(wù)器內(nèi)存一般都可以加到最大2G ,所以可以采取以下配置:
  JAVA_OPTS=’-Xms1024m -Xmx2048m -XX: PermSize=256M -XX:MaxNewSize=256m -XX:MaxPermSize=256m’

配置完成后可重啟Tomcat ,通過以下命令進(jìn)行查看配置是否生效:
  首先查看Tomcat 進(jìn)程號(hào):sudo lsof -i:9027

我們可以看到Tomcat 進(jìn)程號(hào)是 12222 。
  查看是否配置生效:sudo jmap – heap 12222
  我們可以看到MaxHeapSize 等參數(shù)已經(jīng)生效。

Tomcat并發(fā)優(yōu)化

1.Tomcat連接相關(guān)參數(shù)

在Tomcat 配置文件 server.xml 中的
  <Connector port="9027"
  protocol="HTTP/1.1"
  maxHttpHeaderSize="8192"
  minProcessors="100"
  maxProcessors="1000"
  acceptCount="1000"
  redirectPort="8443"
  disableUploadTimeout="true"/>

2.調(diào)整連接器connector的并發(fā)處理能力

1>參數(shù)說明

maxThreads 客戶請(qǐng)求最大線程數(shù)
minSpareThreads Tomcat初始化時(shí)創(chuàng)建的 socket 線程數(shù)
maxSpareThreads Tomcat連接器的最大空閑 socket 線程數(shù)
enableLookups 若設(shè)為true, 則支持域名解析,可把 ip 地址解析為主機(jī)名
redirectPort 在需要基于安全通道的場(chǎng)合,把客戶請(qǐng)求轉(zhuǎn)發(fā)到基于SSL 的 redirectPort 端口
acceptAccount 監(jiān)聽端口隊(duì)列最大數(shù),滿了之后客戶請(qǐng)求會(huì)被拒絕(不能小于maxSpareThreads )
connectionTimeout 連接超時(shí)
minProcessors 服務(wù)器創(chuàng)建時(shí)的最小處理線程數(shù)
maxProcessors 服務(wù)器同時(shí)最大處理線程數(shù)
URIEncoding URL統(tǒng)一編碼

2>Tomcat中的配置示例

<Connector port="9027"
  protocol="HTTP/1.1"
  maxHttpHeaderSize="8192"
  maxThreads="1000"
  minSpareThreads="100"
  maxSpareThreads="1000"
  minProcessors="100"
  maxProcessors="1000"
  enableLookups="false"
  URIEncoding="utf-8"
  acceptCount="1000"
  redirectPort="8443"
  disableUploadTimeout="true"/>

Tomcat緩存優(yōu)化

1>參數(shù)說明

compression 打開壓縮功能
compressionMinSize 啟用壓縮的輸出內(nèi)容大小,這里面默認(rèn)為2KB
compressableMimeType 壓縮類型
connectionTimeout 定義建立客戶連接超時(shí)的時(shí)間. 如果為 -1, 表示不限制建立客戶連接的時(shí)間

2>Tomcat中的配置示例

<Connector port="9027"
  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"/>

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容