Facade Pattern - Controller Load
I was just pondering about the predicament of a Controller Servlet in a facade pattern.
Say, Iam following the conventional MVC architecture with just one controller servlet. Every request that is submitted must go through this servlet only. For example, http://mysite.com/Controller?action=register and http://mysite.com/Controller?action=login
Even Jakarta Struts this stuff.
My Question is, in a heavy traffic scenario, how can this single object of the Controller can handle such a heavy load and how can it manage to spawn so many threads and maintain them.
How does everybody feel about this.
-Harish.
[646 byte] By [
kulkhsuna] at [2007-9-27 11:55:14]

> I was just pondering about the predicament of a
> Controller Servlet in a facade pattern.
>
> Say, Iam following the conventional MVC architecture
> with just one controller servlet. Every request that
> is submitted must go through this servlet only. For
> example, http://mysite.com/Controller?action=register
> and http://mysite.com/Controller?action=login
> Even Jakarta Struts this stuff.
>
> My Question is, in a heavy traffic scenario, how can
> this single object of the Controller can handle such a
> heavy load and how can it manage to spawn so many
> threads and maintain them.
>
This depends on a lot of disperate issues, the type/nature of the system, Resources Consumed, Server Hardware, Server OS, Container (AppServer) choice.
Hello.
When you use a servlet to manage all of your requests you are using the "Front Controller" patern in fact.
A servlet can manage concurrence because of multithreading. This means that every time a servlet receives a request, start a new thread to process it and so be available for receiving new requests.
When you need a servlet will not be available to manage various sessions at the same time you can declare that implements the SingleThreadModel
interface.
The load balancing mechanism is implemented by the provider of the J2EE container and is not part of the J2EE specification.
I hope this can help you, and thank you for some duke dollars :-)
Naaaaaaaaah! Ur answer is not convincing. U r telling the same thing that everybody knows. I am interesting in knowing if anyone has come across any kind of performance hassles or VM errors because of overburdening the single instance of front servlet. Has anyone done any optomization and profiling analysis in such scenario.
Duke$ would be definitely awarded if someone could answer my question based on their past experience in such a scenario, rather than mere concept.
..........but I certainly honour ur sincere attempt in answering my Q.
The very short answer: session scope. User login with a session and the session information manages the information and requests for a user. The question then is how do sessions scale. Please see your servlet container documentation for details
No of request that can be handled can be set by using the Server Admin.I have used this technique in many application without any issues.
Do not think of that one instance of the controller as something that does work. Think of it as one copy of instructions on how to do work. The threads are actual workers that use those instructions to perform the tasks. The container will probably have a pool of threads (workers) which are used to satisfy all of the requests. When the request maps to your controller servlet, the work that is performed by one of these threads is the work that is described in the controller code.
I hope that helped. Now, things are a little more complicated than that since this instance is not only instructions on how to do work, but can possibly contain shared resources and state needed to do such work. In that case, the workers (threads) that are preforming instructions specified in the instance will clash over those resources.
> My Question is, in a heavy traffic scenario, how can
> this single object of the Controller can handle such a
> heavy load and how can it manage to spawn so many
It is not a single object that handles the load, its a new object for every client, unless you implicitly configure it to run in a SingleThread model. Performance would then depend on the app server that you're using as well as the hardware that its running on. The more memory and processor power you have, the better the performance. Another thing that can improve performance and response time is clustering the app server so that requests are handled over multiple servers, rather than a single one.
Regards,
Dimitar
> Naaaaaaaaah! Ur answer is not convincing.
<i>rotnacogeid</i> is correct.
> I am interesting
> in knowing if anyone has come across any kind of
> performance hassles or VM errors because of
> overburdening the single instance of front servlet.
It is not a single *Instance*. The Application Server creates as instances of Servlets & threads as needed. You can this of this as something akin to this.
HttpServlet instance = (HttpServlet) new Controller() ;
...
It is possible to overburden this system but you would be overburdening the Application Server not your Servlet. The throughput drops off there are several tools out there to
http://www.google.co.uk/search?hl=en&lr=&ie=UTF-8&oe=UTF-8&q=java+servlet+load+testing&spell=1
> Has anyone done any optomization and profiling
> analysis in such scenario.
Yes my team use Grinder http://grinder.sourceforge.net/
> Duke$ would be definitely awarded if someone could
> answer my question based on their past experience in
> such a scenario, rather than mere concept.
