I. Concept of server thread
Generally, servers need to withstand high traffic and can respond to requests from different users at the same time. In the server, threads are used to process each request received. If the number of threads can be managed reasonably, the server can better maintain in harsh environments with high stability and robustness.
Each web server management thread mainly uses the following parameters:
Minimum number of threads: the minimum number of threads guaranteed by the server;
Maximum number of threads: the maximum number of tasks that the server can process concurrently. When this number is exceeded, the request will enter the wait and wait for an idle thread;
Maximum waiting time: The number of server threads exceeds the maximum number of threads, and the waiting request is entered. When the maximum waiting time is exceeded, the server will reject the request and return connection refused.
II. How to set the number of server threads
General server operations include two aspects: calculation (mainly consuming CPU) and waiting (IO, database, etc.). The most important parameter is the "maximum number of threads":
In the first extreme case, if our operation is pure calculation, then the main limitation of the system response time is the computing power of the CPU. At this time, the maximum number of threads should be set as small as possible to reduce the number of threads competing for the CPU at the same time , can improve the calculation efficiency and improve the overall processing capacity of the system.
In the second extreme case, if our operation is pure IO or database, then the main limitation of response time is waiting for external resources. At this time, the maximum number of threads should be set as large as possible, so as to increase the number of simultaneous processing requests. Thereby improving the overall processing capacity of the system. In this case, because Tomcat handles a relatively large amount of requests at the same time, you need to pay attention to Tomcat's virtual machine memory settings and Linux's open file limit.
In real applications, our operations will include the above two types (calculation, waiting), so the configuration of the maximum number of threads does not have an optimal value, and it must be configured according to the specific situation.
The best approach is: on the basis of continuous testing, continuous adjustment and optimization can get the most reasonable configuration.
Index:
View and modify the number of concurrent Tomcat