I. Problem description
When a user accesses a report, the server uses a thread to process report calculations.
If the number of visitors is too large and the amount of report calculations is large, there will be a lot of people competing for server CPU threads at the same time. The server's responsiveness will be weakened, so we need to reasonably control the number of server threads.
II. Solution
1. Setting method
We can control the number of threads by modifying the configuration of the Tomcat server.
Open the %Tomcat_HOME%/conf/server.xml document and find the column of <Connector port="8080"....>.
Add the corresponding parameter to control the number of threads after Connector port = "8080". The control parameters are as follows:
Parameter | Meaning | Default Value |
---|---|---|
maxThreads | The maximum number of threads started by Tomcat, that is, the number of tasks processed at the same time | 200 |
acceptCount | When the number of threads started by Tomcat reaches the maximum, the number of requests queued is accepted | 100 |
To adjust Tomcat's default maximum number of connections, you can increase the values of these two attributes, and make acceptCount greater than or equal to maxThreads. After the setting is completed, the following is as follows:
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" acceptCount="500" maxThreads="400" />
2. Precautions
The maximum number of connections allowed by the web server is also restricted by the kernel parameter settings of the operating system. Usually, it is about 2000 for Windows and 1000 for Linux.
The number of connections here cannot directly give the best configuration. It needs to be adjusted and tested continuously according to your actual situation to achieve the most reasonable configuration.