tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kitching Simon <Simon.Kitch...@orange.ch>
Subject RE: limit threads per servlet in Tomcat
Date Fri, 08 Dec 2000 16:33:28 GMT
Hi,

I think this answer is to a slightly different 
question than the one that was asked...

The config example below limits the number of
threads handling client requests to 3. However,
any further clients that connect *wait* for an
earlier request to finish (freeing the thread).

The original question asked if a *new object*
could be spawned if the number of concurrent
requests exceeded a certain limit.

Now that I think of it, perhaps Jay's question
is a result of a minor misunderstanding about
tomcat's threads. Just in case, here's a brief
summary of thread-pools in tomcat.

A common misunderstanding is to think that
each servlet implements "runnable", and it is
the servlet's thread(s) that waits for a URL 
specifying itself. This won't work because
(a) a web application can have hundreds of
servlets in it. Allowing (for example) 20 threads
*per servlet* just won't work.
(b) a request can pass through multiple servlets
(via forward or include commands).

Instead, Tomcat creates threads to handle 
incoming requests. When a client connects, the 
thread gets assigned to that client, and runs 
*whatever* servlets need to be run to satisfy the 
request.

In summary, the solution is to use the example
as given below. This way, tomcat is configured 
to handle a certain number of requests in parallel,
no matter what servlets are to be executed. The 
upper bound on the number of threads ensures
that there is an upper bound on the resources
required by tomcat (at least thread-related resources).

There is only ever one instance of each servlet,
and this is all there needs to be, no matter how
many threads are configured in the thread pool.

Cheers,

Simon

> -----Original Message-----
> From:	Clifford.Okoro@ladbrokes.co.uk [SMTP:Clifford.Okoro@ladbrokes.co.uk]
> Sent:	Friday, December 08, 2000 5:18 PM
> To:	tomcat-user@jakarta.apache.org
> Subject:	Re: limit threads per servlet in Tomcat
> 
> 
> 
> Oh yes there is a way to set it. In the server.xml file. Like this
> 
>         <Connector className="org.apache.tomcat.service.PoolTcpConnector">
>             <Parameter name="handler"
> value="org.apache.tomcat.service.connector.Ajp12ConnectionHandler"/>
>             <Parameter name="port" value="8007"/>
>             <Parameter
>                 name="max_threads"
>                 value="3"/>
>             <Parameter
>                 name="max_spare_threads"
>                 value="2"/>
>             <Parameter
>                 name="min_spare_threads"
>                 value="1" />
>         </Connector>
> 
> Just find the Connector entry corresponding to the one above and go for
> it. The
> nodes that youll need are the 'thread' named nodes.
> 
> Yes, it'll hit your performance (esp OutOfmemory) if you don't allocate
> enough
> for the possible threads so take care.
> 
> Clifford
> 
> 
> 
> 
> 
> 
> 
> "J Y" <jy_home@hotmail.com> on 12/08/2000 03:35:09 PM
> 
> 
> Please respond to tomcat-user@jakarta.apache.org
>  
> 
>  
> 
>  
> 
> 
> 
>                                                               
>                                                               
>                                                               
>  To:      tomcat-user@jakarta.apache.org                      
>                                                               
>  cc:      (bcc: Clifford Okoro/Harrow/Ladbrokes)              
>                                                               
>                                                               
>                                                               
>  Subject: limit threads per servlet in Tomcat                 
>                                                               
> 
> 
> 
> 
> 
> 
> 
> Hi
> 
> I wish to setup Tomcat to limit threads per servlet, say 20 threads to
> execute in one servlet concurrently. the 21th request would cause the
> Tomecat engine to generate a new servlet instance.
> 
> Is there a way to do it. any comment appriciated.
> 
> Also, what's the performance concerns. is that possible to create a pool
> of
> servelts?
> 
> Thanks
> 
> Jay
> __________________________________________________________________________
> ___________
> 
> Get more from the Web.  FREE MSN Explorer download :
> http://explorer.msn.com
> 
> 
> 
> 
> ______________________________________________________________________
> 
> 
>    This communication and any files transmitted with it are confidential
> and
>    intended solely for the use of the individual or entity to whom they
> are
>    addressed. If you have received it in error please notify the sender or
>    postmaster@ladbrokes.co.uk or telephone +44 (0)20 8868 8899. The
> unauthorised
>    use, disclosure, copying or alteration of this message is forbidden.
>    Ladbrokes Limited will not be liable for direct, special, indirect or
>    consequential damage as a result of any virus being passed on, or
> arising
>    from alteration of the contents of this message by a third party.
> Please note
>    that in replying to this mail, you are granting the right for that
> reply to
>    be forwarded to any other individual and to be read by a surrogate in
> the
>    event that the intended recipient is out of the office or is no longer
>    employed by the company.
>    Any views expressed by an individual within this message do not
> necessarily
>    reflect the views of the firm.
> 
> 

Mime
View raw message