-----------------------------
Please read the FAQ!
<http://java.apache.org/faq/>
-----------------------------

Frederic Bellier wrote:

> -----------------------------
> Please read the FAQ!
> <http://java.apache.org/faq/>
> -----------------------------
>
> Hello ,
>
> I am having a unique servlet generating all my web site. This servlet gets
> its information from my database to know what to do with a request.
>
> Because JVM can not handle a lot of threads on this servlet I need a way to
> load balance the request between multiple instance of this servlets. I still
> want it to be multithreaded so I thought of having an instance of it in
> every zone and load balance between this zones.
> Do you think that will work for me?
>

Why doesn't your JVM handle lots of threads?  If you do not declare your
servlet to implement SingleThreadModel, Apache JServ will have as many threads
as you need active in the servlet at the same time (how many threads is
ultimately limited by the security.maxConnections setting in jserv.properties,
which defaults to 50).  Even if you do use SingleThreadModel, you can create a
pool of instances (default size is 5, but it is configurable) to still support
multiple simultaneous requests.

Remember, also, that a particular user is only occupying a thread from the time
they submit a request until the time the servlet completes the generated page.
While the user is browsing through the response page, the resources of the
server are available to meet the needs of other users.  So, in order to run out
of thread capacity you have to have 50 users simultaneously submitting a
request -- and if that's not enough, just increase the thread limit (you might
also have to modify your OS kernel to increase the number of threads allowed
per process, but I think the default for Linux is either 256 or 1024).

Load balancing with Apache JServ is certainly feasible, but my guess is that it
would just slow things down unless you ran the JVMs on different servers.  It
will also require substantially more memory to support the same number of
simultaneous requests across load balanced JVMs instead of a single one.

>
> Another solution would be to have another servlet handling all the requests
> from the web server and forward them to different servlets. But the problem
> then is that Apache do not do servlet chaining so this first servlet will
> suffer from the same issue of having to many threads open at the same time.
> Is it possible to forward a request from one servlet to another having the
> first servlet thread dying even before the second respond to the web server
> directly?

With Apache JServ, this is not possible because it only implements the 2.0
API.  With later versions, you will be able to use a
RequestDispatcher.forward() call to forward a request.

But I think you are missing a key point -- servlets are already multithreaded,
and you have to work at it (use "implements SingleThreadModel" or do something
foolish like declaring your doGet() and doPost() methods to be synchronized) to
make them single threaded.

>
> If this was possible then I could use the first one to manage a pool of
> instance of the other servlet by counting the number of threads from all
> these instances.
>
> Please respond to me directly if possible.
>
> Kind regards.
>
> Frederic
> Mobile: +31 (0) 655102855
> Phone: +31 (0) 207788211
>

Craig McClanahan




--
--------------------------------------------------------------
Please read the FAQ! <http://java.apache.org/faq/>
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Archives and Other:  <http://java.apache.org/main/mail.html>
Problems?:           [EMAIL PROTECTED]

Reply via email to