<?xml version='1.0' encoding='utf-8'?> <Server port="8005" shutdown="SHUTDOWN"> <Listener className="org.apache.catalina.startup.VersionLoggerListener" /> <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" /> <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html --> <Listener className="org.apache.catalina.core.JasperListener" /> <!-- 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" /> <GlobalNamingResources> <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> <Service name="Catalina"> <!-- <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />--> <!-- Define an AJP 1.3 Connector on port 8080 --> <!-- maxThreads 請求處理線程的最大數量。默認值是200(Tomcat7和8都是的)。 如果該Connector綁定了Executor,這個值會被忽略,因為該Connector將使用綁定的Executor,而不是內置的線程池來執行任務--> <!-- acceptCount accept隊列的長度;當accept隊列中連接的個數達到acceptCount時,隊列滿,進來的請求一律被拒絕。默認值是100--> <!-- connectionTimeout Tomcat在任意時刻接收和處理的最大連接數。當Tomcat接收的連接數達到maxConnections時, Acceptor線程不會讀取accept隊列中的連接;這時accept隊列中的線程會一直阻塞着, 直到Tomcat接收的連接數小於maxConnections。如果設置為-1,則連接數不受限制。--> <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" maxThreads="600" minSpareThreads="100" maxSpareThreads="500" acceptCount="700" connectionTimeout="20000"/> <Engine name="Catalina" defaultHost="localhost"> <Realm className="org.apache.catalina.realm.LockOutRealm"> <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/> </Realm> <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log." suffix=".txt" pattern="%h %l %u %t "%r" %s %b" /> </Host> </Engine> </Service> </Server>
http://tomcat.apache.org/ 我們點擊左側導航欄中“Documentation”下的Tomcat 7.0,進入到這個鏈接中:http://tomcat.apache.org/tomcat-7.0-doc/index.html ,詳細的信息我們不用都看,在左側導航欄中有一個鏈接Configuration,我們點進去之后,再點擊其左側導航欄中connector一項的HTTP,就進入到HTTP連接數及其他相關屬性的設置頁面了。在這里(http://tomcat.apache.org/tomcat-7.0-doc/config/http.html)我們可以看到,在Connector的屬性配置中,壓根就沒有maxProcessors等的設置選項。其中這句話已經介紹得很清楚:
If more simultaneous requests are received than can be handled by the currently available request processing threads, additional threads will be created up to the configured maximum (the value of the maxThreads
attribute). If still more simultaneous requests are received, they are stacked up inside the server socket created by the Connector, up to the configured maximum (the value of the acceptCount
attribute).
所以我們需要設置的是maxThreads和acceptCount這兩個值:
其中,maxThreads的介紹如下:
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. If an executor is associated with this connector, this attribute is ignored as the connector will execute tasks using the executor rather than an internal thread pool.
而acceptCount的介紹為:
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 will be refused. The default value is 100.