How does Tomcat distribute servlet/JSP processing to the 20+ Java processes it creates?

Alessandro A. Garbagnati

[How does Tomcat distribute servlet/JSP processing to the 20+ Java processes it creates? Is each client request serviced by a different Java process? If Tomcat received 100 simultaneous servlet requests, would it need to create 100 Java processes to handle them?]

Theoretically yes, Tomcat will try to optimize the requests to handle as much simultaneous requests it can.

[N.B.: Under Linux, each Java Thread appears in the process list (ps) as a separate process. This is because native Linux threads are implemented as lightweight processes. However, there is still only one Java process space -- the memory/CPU reported by each thread is actually shared among all threads. -A]

Yes, the number of threads can be controlled for each connector in the server configuration file (normally server.xml). This is an extract from the Tomcat User Guide:

[...] the (default) pool behaviour instructed by it is:

Upper bound for concurrency of 50 threads.
When the pool has more then 25 threads standing idle it will start to kill them.
The pool will start 10 threads on creation, and it will try to keep 10 vacant threads (as long as the upper bound is kept).

The default configuration is suitable for medium load sites with an average of 10-40 concurrent requests. If your site differs you should modify this configuration (for example reduce the upper limit). Configuring the pool can be done through the <Connector> element in server.xml as demonstrated in the next fragment:

        <Connector className="org.apache.tomcat.service.PoolTcpConnector">
                value="5" />
As can be seen the pool has 3 configuration parameters:

max_threads - defines the upper bound to the for the concurrency, the pool will not create more then this number of threads.
max_spare_threads - defines the maximum number of threads that the pool will keep idle. If the number of idle threads passes the value of max_spare_threads the pool will kill these threads.
min_spare_threads - the pool will try to make sure that at any time there is at least this number of idle threads waiting for new requests to arrive. min_spare_threads must be bigger then 0.

You should use the above parameters to adjust the pool behavior to your needs.[...]

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact