Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tomcat - maxThreads vs maxConnections

Tags:

java

tomcat

In Tomcat server.xml what is maxThreads versus maxConnections

I understand that maxConnections is the number of connections open to the server

And maxThreads is the maximum number of request processing threads

But how the two configuration parameters working together, obviously you will not set maxConnections to 1000 and maxThreads to 10

What is the relationship between the two configuration parameters?

<Connector      port="8443"      protocol="org.apache.coyote.http11.Http11Protocol"     maxThreads="250"      SSLEnabled="true"      scheme="https" secure="true"     clientAuth="false"      sslProtocol="TLS"      connectiontimeout="20000" /> 
like image 695
JavaSheriff Avatar asked Jul 10 '14 14:07

JavaSheriff


People also ask

What is maxThreads in Tomcat?

By default, Tomcat sets maxThreads to 200, which represents the maximum number of threads allowed to run at any given time. You can also specify values for the following parameters: minSpareThreads : the minimum number of threads that should be running at all times.

What is maxThreads?

1 : the top of a mast. 2a : the printed matter in a newspaper or periodical that gives the title and details of ownership, advertising rates, and subscription rates. b : the name of a publication (such as a newspaper) displayed on the top of the first page.

What are the two types of connectors used in Tomcat?

There are two basic Connector types available in Tomcat - HTTP and AJP.

How many concurrent connections can Tomcat handle?

The default installation of Tomcat sets the maximum number of HTTP servicing threads at 200. Effectively, this means that the system can handle a maximum of 200 simultaneous HTTP requests.


2 Answers

Tomcat can work in 2 modes:

  • BIO – blocking I/O (one thread per connection)
  • NIO – non-blocking I/O (many more connections than threads)

Tomcat 7 is BIO by default, although consensus seems to be "don't use Bio because Nio is better in every way". You set this using the protocol parameter in the server.xml file.

  • BIO will be HTTP/1.1 or org.apache.coyote.http11.Http11Protocol
  • NIO will be org.apache.coyote.http11.Http11NioProtocol

If you're using BIO then I believe they should be more or less the same.

If you're using NIO then actually "maxConnections=1000" and "maxThreads=10" might even be reasonable. The defaults are maxConnections=10,000 and maxThreads=200. With NIO, each thread can serve any number of connections, switching back and forth but retaining the connection so you don't need to do all the usual handshaking which is especially time-consuming with HTTPS but even an issue with HTTP. You can adjust the "keepAlive" parameter to keep connections around for longer and this should speed everything up.

like image 152
Tim Cooper Avatar answered Oct 03 '22 04:10

Tim Cooper


From Tomcat documentation, For blocking I/O (BIO), the default value of maxConnections is the value of maxThreads unless Executor (thread pool) is used in which case, the value of 'maxThreads' from Executor will be used instead. For Non-blocking IO, it doesn't seem to be dependent on maxThreads.

like image 22
Swapnil Avatar answered Oct 03 '22 02:10

Swapnil