Web application Performance Test-tomcat 7 number of connections and number of threads configured

Source: Internet
Author: User

Transferred from: Http://www.jianshu.com/p/8445645b3aff

Introduction

This is a time of stress testing for Java Web applications, and the deployment container is Tomcat 7. During the period of learning a lot of scattered knowledge points, timely carding summary, build a good and easy to understand the knowledge structure to organize them, for forgetting.
For Web application developers, we are concerned about the number of requests that the app can process simultaneously, and the response time. The application itself and the Web container in which it runs are two very important factors.
For Tomcat, each incoming request requires a thread until the request ends. If more requests come in at the same time than the currently available request processing threads, the additional threads are created until the maximum number of threads configured (the MaxThreads property value) is reached. If more requests are still received at the same time, these late-processing requests accumulate in the server socket created by connector until the maximum configuration value (Acceptcount property value) is reached. At this point, any requests that come back will receive connection refused errors until there are resources available to process them.

Analyze, comb, organize

What we are concerned about is the number of requests that Tomcat can handle simultaneously and the response time of the request, apparently the MaxThreads and Acceptcount attributes of the connector element have a direct effect on it. Regardless of the Acceptcount value, MaxThreads directly determines the number of requests that can actually be processed concurrently. Regardless of the MaxThreads, Acceptcount determines how many requests can wait to be processed. However, whether a request can be processed immediately or in a waiting area, Tomcat will need to accept the request first (that is, accept the client's connection request and establish the socket channel), then the number of connections that Tomcat can make (the MaxConnections attribute value) Also affects the number of requests that can be processed concurrently.
We can think of Tomcat as a hospital, you come to the hospital hall registered doctor, if they accept, it is equivalent to the client and server to establish a socket connection. Then you come to the appropriate department, each doctor in the department has a consulting room, which is equivalent to processing the request of the thread; If all the clinics have patients, the department's dispatching nurses will let you wait in the Department hall, until they inform you to the number of consultation room, if you have a free doctor, you can immediately visit.
Some patients to the hospital is very hasty, the results of his turn to register or a doctor, he still in the bag to look for cases and health insurance card, if more than the nurses or doctors can withstand the waiting time, they will let patients go to the side to find, first service inferior. This situation is similar to the ConnectionTimeout attribute of the connector element. A time-out exception is thrown if the current connector (Connector) waits for a specified time after the connection is accepted, but still does not receive the request URI line.

Knowledge Point Collection

The configuration reference documentation for Tomcat 7 has been described in detail for the relevant properties, which are gathered here:

Protocol

Sets the protocol to handle incoming traffic. The default value is http/1.1 which uses an auto-switching mechanism to select either a blocking Java based connector or a N apr/native based connector. If the PATH (Windows) or Ld_library_path (on most UNIX systems) environment variables contain the Tomcat native LIBRARY, t He apr/native Connector would be used. If The native library cannot be found, the blocking Java based connector would be used. Note that the Apr/native connector have different settings for HTTPS than the Java connectors.
To use a explicit protocol rather than rely on the auto-switching mechanism described above, the following values may Used:
org.apache.coyote.http11.http11protocol-blocking Java Connector
Org.apache.coyote.http11.http11nioprotocol-non Blocking Java Connector
Org.apache.coyote.http11.http11aprprotocol-the apr/native connector.

Custom implementations may also is used.
Take a look at our Connector Comparison chart. The configuration for both Java connectors are identical, for HTTP and HTTPS.
For more information on the APR connector and APR specific SSL settings visit the APR documentation

MaxThreads

The maximum number of request processing threads to being created by this Connector, which therefore determines the maximum n Umber of simultaneous requests that can be handled. If not specified, this attribute is set to 200. If an executor are associated with this connector, this attribute is ignored as the connector would execute tasks using the Executor rather than an internal thread pool.

Acceptcount

The maximum queue length for incoming connection requests if all possible request processing threads is in use. Any requests received if the queue is full would be refused. The default value is 100.

MaxConnections

The maximum number of connections that the server would accept and process at any given time.When this number has been reached, the server would accept, but not process, one further connection. This additional connection is blocked until the number of connections being processed falls below maxconnections at which Point the server would start accepting and processing new connections again. Note that once the limit have been reached, the operating system may still accept connections based on the Acceptcount sett Ing.The default value varies by connector type. For BIO The default was the value of MaxThreads unless an Executor was used in which case the default would be the value of M Axthreads from the executor. For NIO, the default is 10000. For apr/native, the default is 8192.
Note that for apr/native on Windows, the configured value'll be reduced to the highest multiple of 1024x768 that's less tha n or equal to MaxConnections. This is the done for performance reasons.
If set to a value of of-1, the MaxConnections feature is disabled and connections be not counted.

ConnectionTimeout

The number of milliseconds this Connector would wait, after accepting a connection, for the request U RIline to is presented. Use a value of-1 to indicate no (i.e. infinite) timeout. The default value is 60000 (i.e. seconds), but note, the standard Server.xml, the ships with Tomcat sets this to 200 (i.e. seconds). Unless disableuploadtimeout is set to False, this timeout would also be used when reading the request body (if any ).

Further analysis

Tomcat's HTTP Connector has three types: BIO, NiO, Apr. As you can see from the attribute descriptions above, the same properties may have different default values and different processing strategies for different connector implementations, so before you adjust the configuration, you need to figure out the difference between the various implementations and what kind of connector the current deployment container is using.
Consult the Tomcat 7 HTTP connector configuration Document Connector comparison section to learn about the differences between the various connector implementations.
How do you know what connector implementation the container is using? After you start Tomcat, access the server Status Page and see the following information to know what connector is being used:

My OS is windows, so Tomcat uses APR connector by default. On Linux, the Bio Connector is used by default. Compared with NIO, Bio has a low performance. Insert the following configuration fragment in <tomcat_home>/conf/server.xml:

<Connector port="8080" protocol="HTTP/1.1"               connectionTimeout="20000"               redirectPort="8443" />

Modified to:

<Connector port="8080" protocol="org.apache.coyote.http11.Http11NioProtocol"               connectionTimeout="20000"               redirectPort="8443" />

You can switch the HTTP connector to NIO. For more details, refer to modifying Tomcat connector run mode to optimize Tomcat run performance

Web application Performance Test-tomcat 7 number of connections and number of threads configured

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.