• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

one servlet container per server or per JVM?

 
Caly LeeAnn
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is one servlet container per server or per JVM?

I think it's one servlet container per server. What do you think?
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What should stop me from hosting two containers working on different ports with two different instances of the JVM (one for each container) on one server ?
 
Sunil Kumar Jakkaraju
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

What should stop me from hosting two containers working on different ports with two different instances of the JVM (one for each container) on one server ?


John, how can we accomplish that? Is it by enabling clustering in the web server. So if I want to call a servlet MyServlet on that server, how does the server choose what container on what JVM will respond?
 
Jeroen T Wenting
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nothing is stopping you from running multiple servlet containers side by side on the same server (hardware).
Each has its own webserver built in to serve the generated content.

Whether you can plug multiple servlet containers into a single Apache (for example) instance is another question, and one to which I don't know the answer.
 
Dan Howard
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John, how can we accomplish that? Is it by enabling clustering in the web server. So if I want to call a servlet MyServlet on that server, how does the server choose what container on what JVM will respond?


I'm not John, but I'll try to answer anyway.

For Tomcat, you can simply install a second instance and then modify server.xml and change the port number. Look for the Connector port setting. Server.xml would be in the conf folder under where you installed Tomcat.

At the servlet level servlets don't choose where to respond. They're simply doing a request/response on that single connection. In other words, at the application level there's no need to think about this.

For a servlet container what clustering does is replicate the users session object on each web server. Say you had 4 web servers and you set up clustering using Tomcat's built-in clustering. What happens is that in your code whenever you set an attribute on the session object it gets serialized and sent to each web server. So each web server has a copy of that session object. In the event a web server goes down the load balancer (another piece of this puzzle) will redirect the request to another web server. Since that second web server has a copy of the session object the user won't notice any problem. The request will hit the new server and the session will be there already.

Load balancing is the other part of this. Usually you can have a software load balancer (Apache can be used for this) or a hardware load balancer.
All the load balance basically does is see if a particar web server can repond to the request. If the web server it's trying to talk to is not responding then it redirects to another web server.

Hope this helps.
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For a servlet container what clustering does is replicate the users session object on each web server.


I found a tomcat article about this. Have a look if you have time. I dont know how to configure these clusters. It would be interesting to learn though.

http://tomcat.apache.org/tomcat-5.5-doc/cluster-howto.html
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A Servlet will run with one instance on each JVM.

In a clustered environment, many JVMs work on either the same machine (vertical scaling) or on separate machines(horizontal scaling) to provide load balancing and failover support. A client request may be sent to any JVM participating in this workload management scheme, although the idea of 'sticky sessions' still remains.

Since a client can potentially have their request handled by any JVM, the Servlet being invoked must be running on each JVM participating in the cluster.

-Cameron McKenzie
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic