Tomcat maximum number of threads, maximum number of queues appropriate

Source: Internet
Author: User

The connector configuration for Tomcat is as follows

<</span>ConnectorPort= "8080"Protocol= "http/1.1"
ConnectionTimeout= "20000"
Redirectport= "8443"
MaxThreads= "$"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 the maximum, the number of requests queued is accepted, and the default value is $

&NBSP;

how these two values work, see the following three scenarios

Case 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 point the number of threads that Tomcat started has reached Maxthreads,tomcat will put this request into the waiting queue, waiting for the idle thread.

Case 3: Accept a request, at which point the number of threads that Tomcat started has reached MaxThreads, and the number of requests waiting in the queue has reached Acceptcount, At this point Tomcat rejects this request directly and returns connection refused

maxthreads How to configure

General server operations include volume aspects: 1 compute (CPU consumed primarily), 2 waits (IO, database, etc.)

The first extreme case, if our operation is purely computational, so the main limitation of system response time is the CPU's computing power, 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 calculation efficiency, improve the overall processing capacity of the system.

The second extreme situation, If our operation is purely IO or database, then the main limitation of response time becomes waiting for external resources, when maxthreads should be as large as possible, in order to improve the number of simultaneous processing of requests, So as to improve 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 was having a problem with the test, maxthreads I set a larger example of 3000, when the number of threads in a service is large to a certain extent, is usually in the early 2000, The response time for a single request increases sharply, and the

Baffled why this is why, looking around for answers without fruit, and finally I summarize the reason may be the time consumed by the CPU thread switchover is increasing as the number of threads increases,

cpu spend most of the time switching directly over these 2000 + threads, and of course the CPU has no time to process our programs.

has always 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 CPU cores < threads count, the CPU needs to switch back and forth between multiple threads to ensure that each thread gets CPU time, which is what we call concurrent execution.

So the configuration of MaxThreads is definitely not as big as the better.

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

The best thing is: on the basis of continuous testing, constantly adjust, optimize, to get the most reasonable configuration.

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

if the setting is smaller, The accepted request can be guaranteed to be faster, but the exceeded request may be rejected directly

if set to a larger, There may be a large number of requests that are timed out, because the processing power of our system is certain.

remarks:

The best settings refer to Http://blog.sina.com.cn/s/blog_4080505a01016o3d.html

Tomcat maximum number of threads, maximum number of queues appropriate

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.