Tomcat set Best Thread Count summary

Source: Internet
Author: User
Tags jboss

Optimal number of threads :

In the case of performance profiling, the QPS will rise at first as the number of users increases, and when a certain threshold is reached, the number of users to increase the QPS does not increase or increase significantly, while the response time of the request increases significantly. This threshold is considered to be the optimal number of threads.

Why to find the best number of threads

1. Excessive threads only cause more memory overhead and more CPU overhead, but it does not help to raise the QPS

2. After finding the optimal number of threads through simple setup, can make the web system more stable, get the highest, most stable QPS output

Get the best number of threads:

1, through the user slowly increase performance pressure measurement, observe QPS, response time

2, according to the formula calculation: server-side optimal number of threads = ((thread waiting time + thread CPU time)/thread CPU Time) * Number of CPUs

3, single-User pressure measurement, look at the CPU consumption, and then directly multiplied by the percentage, then the pressure test, the general value of the vicinity should be the best number of threads.

Key factors that affect the optimal number of threads:

1. IO

2. CPU

By formula: server-side best Thread count = ((thread wait + thread CPU time)/thread CPU Time) * Number of CPUs

Generally it is IO and CPU. IO more expensive applications its CPU thread waiting time will be longer, so the number of threads can be more open, instead of the number of threads less, in fact, there are two extreme, pure IO applications, such as proxy, the number of threads can be open to very large (it is too large to consider the cost of thread switching), This application is basically the back end (such as the proxy is the agent search) of the QPS can have how many, proxy.

The other is CPU-intensive computing, which typically only drives the number of threads to the CPU. But it is not that the application of the QPS is not high, often this application of the QPS can be very high.

The relationship between the QPS and the number of threads

1, before the optimal number of threads, the QPS and threads are mutually incremental relationship, the number of threads to the best thread, the QPS flat, not rising, or even slightly down, while the corresponding time continues to rise.

2. The higher the number of threads supported by the same system (the more the optimal number of threads rather than the number of threads configured), the higher the QPS

The relationship between QPS and response time

1, for the general web system, the response time generally has CPU execution time +io wait time composition

2, the CPU execution time is reduced, to the QPS has the substantial ascension, the IO time reduces, to the QPS ascension is not obvious. If you want to significantly improve the QPS, optimize the system by focusing on optimizing CPU consumption.

Optimal number of threads and JVM heap memory relationships:

All of these are based on performance bottlenecks in the CPU, and for Java applications There is also a factor of full GC, we want to ensure that in the optimal number of threads, there will be no frequent full GC

According to the formula: (Small GC interval/rt) * (Number of concurrent threads * tHM) <=young compute the number of concurrent threads if the < optimal number of threads can cause the full GC to be more frequent, the situation seems to be very small on the web system. But it can be simulated.

So when we set up the JBoss thread, we can set it up with the number of threads calculated by the memory formula, get the best number of threads by pressing and calculating, and then set the number of threads.

To set the number of threads:

Best thread Count < True set Number of threads < number of memory limit threads

For example, by measuring the optimal number of threads for a system is 10, and then the number of threads calculated through memory is 20, it is possible to set the number of threads for JBoss to 15, if 10 is set directly, as the system itself is subject to changes in some dependent systems, For example, the system depends on some IO response time will be suddenly extended, due to the number of threads or 10, in fact, this time the best number of threads has become 13, because we set a dead 10, the result is to cause the QPS down, but if more than 20, it will cause the full GC very frequent, In turn affects the decline of the QPS.

JBoss Number of threads setting:

For JBoss, the number of threads to be set depends on the type of thread connection used, such as HTTP, AJP, etc.

The settings for HTTP and AJP are exactly the same, very simple:

Take AJP, for example, to find Server.xml or tomcat-server.xml:

The default number of threads is 200

<connector port= "8009" address= "${jboss.bind.address}" connectiontimeout= "15000" protocol= "AJP/1.3 " maxthreads="minsparethreads=" "maxsparethreads=" maxpostsize= "512000" acceptcount= "buffersize=" 16384 "Emptysessionpath=" false "enablelookups=" false "redirectport=" 8443 "usebodyencodingforuri=" true "/>

The default number of threads is changed to 20, and the corresponding minimum number of idle threads and the maximum number of idle threads are adjusted as well:

<connector port= "8009" address= "${jboss.bind.address}" connectiontimeout= "15000" protocol= "AJP/1.3 " maxthreads= "minsparethreads=" "maxsparethreads=" "maxpostsize=" 512000 "acceptcount=" "buffersize=" 16384 "Emptysessionpath=" false "enablelookups=" false "redirectport=" 8443 "usebodyencodingforuri=" true "/>

Tomcat set Best Thread Count summary

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.