Tomcat: what happens when number of connections exceeds number of threads?

Viewed 3317

According to this link, the properties server.tomcat.max-connections and server.tomcat.max-threads determine the max number of connections and max number of threads in the application.

I have two questions:

  1. What happens if at a given moment number of connections exceed number of threads? What will happen to the connections that did not get a thread?

  2. What happens if the server has to serve more requests that server.tomcat.max-connections? Will it just ignore the requests that arrived after number of threads connections has reached its maximum value?

1 Answers

What happens if at a given moment number of connections exceed number of threads? What will happen to the connections that did not get a thread?

They will wait for a worker thread to become available.

Tomcat uses an "accept queue" to hold connections between accepting them and passing them off to a worker thread. The Tomcat config parameter that controls this is:

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.

(Source https://tomcat.apache.org/tomcat-8.0-doc/config/http.html)


What happens if the server has to serve more requests than server.tomcat.max-connections? Will it just ignore the requests that arrived after number of threads connections has reached its maximum value?

According to the above, the connections will be accepted up to the queue limit, and then refused. I take it to mean that the client will get a TCP/IP level "Connection Refused".

(It is not entirely clear what happens to a queued request if the client times it out and closes the TCP/IP connection from the client end.)

Related