You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Herman Schultz <he...@gmail.com> on 2007/05/25 19:42:35 UTC

How can I limit the number of thread that tomcat spawn for my servlet

Hi,

My understanding is tomcat will spawn a thread for each request to my
servlet.
How can I limit the number of thread that tomcat spawn for my servlet
simultaneously?

And let say if I limit the simulateous thread for my servlet to 10, what
happens to the 11th request? Will it get dropped? Or Will it get queued?

Thank you.

Re: How can I limit the number of thread that tomcat spawn for my servlet

Posted by Bill Barker <wb...@wilshire.com>.
"Herman Schultz" <he...@gmail.com> wrote in message 
news:5dd1639d0705251042q243a5e54yc6663e2f3229ffed@mail.gmail.com...
> Hi,
>
> My understanding is tomcat will spawn a thread for each request to my
> servlet.
> How can I limit the number of thread that tomcat spawn for my servlet
> simultaneously?
>
> And let say if I limit the simulateous thread for my servlet to 10, what
> happens to the 11th request? Will it get dropped? Or Will it get queued?
>

TC 6 has the SemaphoreValve 
(http://tomcat.apache.org/tomcat-6.0-doc/api/org/apache/catalina/valves/SemaphoreValve.html) 
that you could sub-class to do mostly what you want (or for TC 5 under Java 
5, grab the source and modify it).  It doesn't prevent the number of theads 
that Tomcat spawns, but it limits the number that are executing through it 
at any given time (out-of-the-box, it would be the number of threads 
accessing the Context, but you can sub-class it and override the 
controlConcurrency method to make it finer grained).  You could also look 
at the code, and do the same thing in a Filter.  In this case, the 11th 
request will get queued, at least until the browser gets tired of waiting 
for it :).

As Chris has already said, you can only limit the number of threads spawned 
at the <Connector> level.

> Thank you.
> 




---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: How can I limit the number of thread that tomcat spawn for my servlet

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Herman,

Herman Schultz wrote:
> My understanding is tomcat will spawn a thread for each request to my
> servlet.

I think you might be misinterpreting this part of the spec. It just says
that each request will be handled by a separate thread. That doesn't
mean that a thread will be created for each request. Most app servers
will use thread pools and re-use threads since they are relatively heavy
to just create and discard all the time.

> How can I limit the number of thread that tomcat spawn for my servlet
> simultaneously?

Tomcat's connector specifies the number of threads that will be created
for request handling. Check out the documentation for the Tomcat connectors:

HTTP: http://tomcat.apache.org/tomcat-5.5-doc/config/http.html
AJP:  http://tomcat.apache.org/tomcat-5.5-doc/config/ajp.html

(Note that these are for TC 5.5, so if you are using a different
version, you should use the documentation appropriate for that version).

Specifically, look for settings including the word "thread", as well as
the "backlog" setting. Actually, it's worth reading the whole thing.

> And let say if I limit the simulaneous thread for my servlet to 10, what
> happens to the 11th request? Will it get dropped? Or Will it get queued?

That depends on other settings (such as "backlog"). The links above
should explain everything.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGVzhm9CaO5/Lv0PARAg1IAKC/WUCTjImVABuLokG2NISNypudYQCgl595
ahSYbdx7XAHe27TCPtGaqo4=
=iBTq
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org