I have a simple application that I create, using JSP/Servlet. The application consists of a single page, where a person enters some infomation and submits it, I need to show the submitted information another page.
I have 1000 users and all the users log on to the application at the same time.
Will the server load 1000 instances of the servlet for each user or will it have only 1 addressing all the users? I am a bit confused on this?
I need to decide which server I need to deploy this application to. Can I use tomcat to deploy this application to? Do I need to consider clustering for this simple application?
Now I could assume that this servlet is thread-safe. So multiple users can use the same instane of the servlet.
Firstly - yes, there will be only one instance of your servlet catering to all 100 user requests. However, there will be 100 threads representing each of the requests. So you will have to be careful about shared data. To be on the safe side, avoid using or be extra careful about any data that you define as a member/class variable.
Secondly - Tomcat can handle a load of 100 concurrent users without any fuss. I don't think you really need to bother about clustering, or for that matter load-balancing for a user load like that. The upper limit of the user load is subject to the kind of data structures you're using, and the hardware capabilities of your setup.
Joined: Oct 22, 2009
Well 100 users sounds fine, what about 1000 users, what is your views?
Also what will happen if my application is synchronized? How many instances will the container create for 1000 users? Will it be a unique instance for each user?
Joined: Feb 22, 2005
Now, why would you think that making your application 'synchronized' will have anything to do with the number of servlet instances that get created? I'm sorry to break it to you, but synchronized or not, even then there will be ONLY one servlet instance for any number of user requests. Making your app synchronized will only help in keeping the threads [for every request] from interfering with each others data.
As for the number of users, you've got to realise that Tomcat as a server is capable of handling a really large number of parallel requests. I'm quite sure that the number is much >> 1000 concurrent requests. The exact number I am not sure of. However, if your application processes a really large amount of data for every request, then you can witness an awful response time even for 10 concurrent users.
Joined: Oct 22, 2009
Sorry to go into Java basics but as far as I know there are 2 things when you talk about threads, a Servlet being Thread Safe, which means even if multiple users try to use same servlet there wont be any clashes for each of these users.
Now if I make my servlet implement SessionSyncronization it means that I am forcing a single user to use a Servlet at a time, in this case wont the 1000 users get a serial access to the 1 instance of the servlet? This will slow down the response, should the container not create multiple instance of the Servlet to cater to all these request then?
Please pardon me if I am worng but this is what I expected the Container to do.
OK I have read over a couple of forums and I accept that my understanding is wrong. I will read what tomcat does and get back to you.
Here are a few links that I can share with you too just FYI, which kind of proves me wrong!