Tomcat MaxThreads, Acceptcount (maximum number of threads, maximum number of queues)

Source: Internet
Author: User

Reprint: http://blog.sina.com.cn/s/blog_605f5b4f01012ljj.html

The connector configuration for Tomcat is as follows

<connector port= "8080" protocol= "http/1.1" connectiontimeout= "20000" redirectport= "8443" maxThreads= "800" Acceptcount= "/>"
The last two parameters have the following meanings:

maxthreads: The maximum number of threads that Tomcat will start, that is, the number of simultaneous tasks, with a default value of 200

Acceptcount: When the number of threads started by Tomcat reaches maximum, the number of requests queued is accepted, the default value is 100

How these two values work, see the following three scenarios

Scenario 1: Accept a request when the number of threads that Tomcat started does not arrive maxthreads,tomcat will start a thread to process the request.

Case 2: Accept a request, at which time the number of threads that Tomcat started has reached Maxthreads,tomcat will put this request into the waiting queue, waiting for the idle thread.

Scenario 3: When a request is accepted, the number of threads that Tomcat started has reached MaxThreads, and the number of requests waiting in the queue has reached Acceptcount, and Tomcat rejects the request directly, returning connection refused

MaxThreads How to configure

General server operations include volume aspects: 1 calculation (mainly CPU consumption), 2 waits (IO, database, etc.)

In the first extreme case, if our operation is purely computational, then the main limitation of the system response time is the CPU computing ability, at this time maxthreads should be set as small as possible, reduce the number of threads competing for CPU at the same time, can improve the computational efficiency, Improve the overall processing capacity of the system.

In the second extreme case, if our operation is purely IO or database, then the main limitation of response time becomes waiting for external resources, when the maxthreads should be set as large as possible, so as to improve the number of simultaneous processing requests, thus improving the overall processing capacity of the system. in this case, because Tomcat is processing more requests at the same time, you need to focus on Tomcat's virtual machine memory settings and Linux open file restrictions.

I encountered a problem in the test,maxthreads I set the relatively large, such as 3000, when the number of threads of service is large to a certain extent, usually in the early 2000, the response time of a single request will increase sharply,

Best of all, this is why, looking around for the answer is not the result, I conclude that the reason may be that the CPU thread switching time consumption as the number of threads increases more and more large,

The CPU uses most of the time to switch directly over the 2000 + threads, and of course the CPU has no time to process our programs.

Previously it has been simple to think multithreading = high efficiency. In fact, multithreading itself does not improve CPU efficiency, but too many threads will reduce CPU efficiency.

When the number of CPU cores < threads, the CPU needs to switch back and forth on multiple threads directly to ensure that each thread gets CPU time, which is what we usually call concurrent execution.

So the maxthreads configuration is definitely not as big as the better.

In real-world applications, our operations will contain the above two types (calculation, wait), so the MaxThreads configuration does not have an optimal value, it must be configured according to the specific situation.

The best practice is: on the basis of continuous testing, continuous adjustment, optimization, to get the most reasonable configuration

acceptcount configuration , I generally set the same size as maxthreads, this value should be mainly based on the application's access peaks and averages to weigh the configuration.

If set to a smaller size, you can guarantee that the accepted request will be faster, but the exceeding request may be rejected directly

If the set is large, there may be a large number of request timeouts, because the processing power of our system is certain.

Tomcat MaxThreads, Acceptcount (maximum number of threads, maximum number of queues)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.