Sudhagar Sachin
Sudhagar Sachin

Reputation: 565

Blocking vs Non blocking main thread in tomcat

Normally in tomcat, a thread will be running and when a request comes in,it will assign the responsibility of servicing the request to a thread from thread pool.

Does it matter if that main thread is blocking or non blocking in terms of scalability?

Upvotes: 1

Views: 4512

Answers (2)

jontro
jontro

Reputation: 10628

When an incoming request is processed in tomcat it will assign the connection to a thread from its thread pool.

What matters here is to run the thread as fast as possible. You typically run blocking io calls in this thread, for file io, db and so on.

You need to adjust the size of this thread pool apropriatley to handle your expected traffic.

Esentially when using the Java EE servlet spec you are forced into handling your requests in a one thread per incoming connection manner.

There are a few non blocking frameworks out there. Check out http://www.playframework.org/ and Jetty ( Jetty nonblocking by default? )

Upvotes: 1

Ramesh PVK
Ramesh PVK

Reputation: 15446

Non Blocking IO has the following advantages:

  • Highly Scalable : Because no-more you require one thread per client. It can effectively support more number of clients.
  • High Keep Alive : Blocking IO requires to block until the keepalive time for the next request. Non-Blocking being notification model, it can support high keepalive times.
  • Better Performance on High Load : Because in blocking IO has one thread per connection, it requires n threads for n connections. As the value n increases, the performance degrades because more thread context switching.

Upvotes: 2

Related Questions