Rohan Dodeja
Rohan Dodeja

Reputation: 306

What are acceptCount, maxConnections and maxThreads in Tomcat HTTP connector configuration?

This is the configuration I'm using

 <Connector port="8080"
            protocol="HTTP/1.1"
            connectionTimeout="20000"
            redirectPort="8443"
            acceptCount="1000"
            maxConnections="500" />

I have read the doc but can't able to understand, please explain with an example if possible, and what is relationship between them.

Upvotes: 15

Views: 34337

Answers (2)

StackzOfZtuff
StackzOfZtuff

Reputation: 3102

Note: Tomcat documentation has changed since brad's answer in 2016. So rather than bulk edit his post, I've added an updated version below. I've added some formatting and line breaks for emphasis.

Excerpt from Introduction section of Apache Tomcat 9 Configuration Reference (with added line breaks for readability):

Note: The first sentence is

Each incoming, non-asynchronous request requires a thread for the duration of that request.

But I'm not sure what this sentence means and if applies anymore to Tomcat 8.5.0 and later. So I'm not quite sure if this section is correct anymore. Since the completely synchronous "BIO" connector was thrown out of Tomcat 8.5.0 and later versions. So does that mean that there is no such thing as a "non-asynchronous request" in Tomcat 8.5.0 and later anymore? There is a comparison table with both BIO and the other connectors. But ALL of them are listed as Blocking in some sections. So they have Non-Blocking in some sections but not in others. Only poor BIO has Blocking everywhere. -- I've read this writeup (archived here) but I didn't really get my answer there either.

Anyway: Here's the section itself:

Each incoming, non-asynchronous request requires a thread for the duration of that request. If more simultaneous requests are received than can be handled by the currently available request processing threads, additional threads will be created up to the configured maximum (the value of the maxThreads attribute).

If still more simultaneous requests are received, Tomcat will accept new connections until the current number of connections reaches maxConnections. Connections are queued inside the server socket created by the Connector until a thread becomes available to process the connection.

Once maxConnections has been reached the operating system will queue further connections. The size of the operating system provided connection queue may be controlled by the acceptCount attribute. If the operating system queue fills, further connection requests may be refused or may time out.

Excerpt from Attributes section:

  • redirectPort: If this Connector is supporting non-SSL requests, and a request is received for which a matching <security-constraint> requires SSL transport, Catalina will automatically redirect the request to the port number specified here.

  • maxConnections: The maximum number of connections that the server will accept and process at any given time. When this number has been reached, the server will accept, but not process, one further connection. This additional connection be blocked until the number of connections being processed falls below maxConnections at which point the server will start accepting and processing new connections again. Note that once the limit has been reached, the operating system may still accept connections based on the acceptCount setting. The default value is 8192.

    For NIO/NIO2 only, setting the value to -1, will disable the maxConnections feature and connections will not be counted.

  • acceptCount: The maximum length of the operating system provided queue for incoming connection requests when maxConnections has been reached. The operating system may ignore this setting and use a different size for the queue. When this queue is full, the operating system may actively refuse additional connections or those connections may time out. The default value is 100.

  • connectionTimeout: The number of milliseconds this Connector will wait, after accepting a connection, for the request URI line to be presented. Use a value of -1 to indicate no (i.e. infinite) timeout.

    The default value is 60000 (i.e. 60 seconds) but note that the standard server.xml that ships with Tomcat sets this to 20000 (i.e. 20 seconds). Unless disableUploadTimeout is set to false, this timeout will also be used when reading the request body (if any).

Upvotes: 1

brad
brad

Reputation: 1013

  • acceptCount -- The maximum queue length for incoming connection requests when all possible request processing threads are in use. Any requests received when the queue is full will be refused. The default value is 100.

  • redirectPort -- if this Connector is supporting non-SSL requests, and a request is received for which a matching <security-constraint> requires SSL transport, Catalina will automatically redirect the request to the port number specified here.

  • maxConnections -- The maximum number of connections that the server will accept and process at any given time. When this number has been reached, the server will accept, but not process, one further connection.

  • connectionTimeout -- The number of milliseconds this Connector will wait, after accepting a connection, for the request URI line to be presented

acceptCount is like the line waiting to get into a popular nightclub that is full. (maxConnections) when some people leave maxConnections goes down allowing more people to connect from the acceptCount waiting list. The connection timeout is simply how long it will wait for the request. So you can either make the line longer (acceptCount) or make the nightclub larger (maxConnections)

Redirect port is how/where it handles a redirect due to a security restraint.

Upvotes: 62

Related Questions