Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tomcat 5 cluster

Status
Not open for further replies.

Bluebanshee01

Technical User
Aug 13, 2003
22
US
Hi all,
I am trying to set up a tomcat5 cluster at least that is what I think I need to do. I want to move away from apache. So I have set up my vhosts and everything works fine. I login and hit a few pages on this peticular site and then I need to submit some information so I go to the submit page it is the redirected to be secure HTTPS and it blows up. Here is the problem I have two web servers running behind a altion hardware load blancer. At the time the page gets redirected the altion thinks it is a new session and sometimes sends traffic to the other webserver. This is my problem. How can I make tomcat keep the session on the same machine that the request came in on throughout the entire time until I logout? That is why I thought I need to cluster. Maybe I don't I really don't know. I believe I need to make tomcat be something like stateful connections.

HELP!!!!


Thanks

Dave
 
This is a common problem, which has a few possible solutions :

1) Make sure that your hardware load balancer keeps a certain IP/client on one machine (most have this ability).

2) Use Tomcat clustering to share session info between your clustered machines.

3) Write your code in such a way that it is session independant - ie never ever use the "session" objects.



--------------------------------------------------
Free Database Connection Pooling Software
 
Excellent thank you. In answer to question #1 it does keep the ip address that the users will alwayse hit. Can you tell me or direct me as to how to set up tomcat clustering correctly? Correct parameters/settings etc..

Thanks again.
 
Never done tomcat clustering, but I understand it is fairly easy.

Here is the how-to :
Bear in mind that all session objects you use must implement java.io.Serializable because Tomcat will serialize the objects between machines.

I would also go as light as possible for session objects - use them sparingly because I imagine there will be a fair IO hit on using clustering - make sure you load test your webapp thoroughly before releasing to live - and also make sure you start tomcat's JVM with a LOT of RAM.

--------------------------------------------------
Free Database Connection Pooling Software
 
I have 4 GB ram in each server. I did see that link but didn't find it very useful. I was just hoping that there was something else. Do you know if there is a setting somewhere in tomcat that you can set for session persistance? I do believe I may have the clustering working I just wanted to find out if I have it set up properly.

Thanks again for your help.
 
Having 4GB of RAM on the machine does NOT mean that Tomcat has 4GB of RAM available to it - the default JVM startup RAM value is 16Mb. Read this thread : thread877-1038796

As I said before, I've never used Tomcat clustering ... so I guess its google time :)

--------------------------------------------------
Free Database Connection Pooling Software
 
Thanks for the insight and the article on memory.

I will go with that. I did confirm with our developersw that we are not using java.io.Serializable. So I will get them to change that and see if it helps. I guess thet even though I have the cluster running, since we don't have java.io.Serializable set then the session info really insn't getting replicated.

THanks again
 
I need to ask one more question. If I have clustering set up correctly what should I expect? I am under the impression that I should see the same session information on all replicated nodes, session id etc.. is this correct?
 
I guess so.

You can test it by doing this :

Hit "a.jsp" on server A, which sets a simple session variable such as a String to "Hello A" or something like that.

Then go to server B, hit "b.jsp" which sees if the session var set in "a.jsp" on server A was actually set.

--------------------------------------------------
Free Database Connection Pooling Software
 
First of all I want to tell you thank you for all the help. Do you know if the mcast address the 228.0.0.4 the cluster services or whatever you decide to use if it actually has to be a real (ping able) address or is it just an address that the cluster services set?

Thanks again
 
Different question. I have these two machines. With tomcat cluster enabled. With session replication does it only replicate http to http and https to https. In other words when I look on one server and I have a url with a session then when I click a secure (https) page on that same site it jumps to the other server. Should I see the same session information on the machine that it jumped to now that is is https?

Thanks
 
Whether the protocol is http or https, the session info should be the same, and also be replicated between the two servers - use the "a.jsp" and "b.jsp" scenerio I suggested before to test that replication is occuring correctly.

--------------------------------------------------
Free Database Connection Pooling Software
 
Cool thanks. I guess I haven't got it yet. I still don't see anything being replicated. I can see however that in the logs that each tomcat does see the other. It does say that the member is added. Do you have any other suggestions or places to go? I am pulling out my hair.

Thank for everything though.
 
Sorry fella, as I said before, I've never actually tried replication myself !

--------------------------------------------------
Free Database Connection Pooling Software
 
sedj,
Would you by chance have or could you give me the two jsp scripts you suggested to make sure this replication is working? I am still struggling with this. I am not sure if what I have is compatible with replication. I want something that is so I can start ruling out pieces.

THanks

Dave
 
Code:
<!-- a.jsp - execute this on Server A -->
<%
 session.setAttribute("aVar", "Session var set on server A");
%>

<html>
<body>
Set var under name "aVar" on Server A
</body>
</html>
<!-- end a.jsp -->


Code:
<!-- b.jsp - execute this on Server B -->
<%
 String aVar = session.getAttribute("aVar");
%>

<html>
<body>
The value that should have been set in the session on server B is : <b> <%= aVar %> </b>
<br>
If that was null, then session replication is not working.
</body>
</html>
<!-- end b.jsp -->

Make sure you run a.jsp on Server A, then in the SAME browser, go to server B, and run b.jsp.



--------------------------------------------------
Free Database Connection Pooling Software
 
Thank You
I don't want to sound retarded but how do I go to the other machine to run b.jsp in the same browser? I am using Internet Explorer.

THanks Again

Dave
 
Sorry I am also getting this when I run b.jsp..

An error occurred at line: 2 in the jsp file: /b.jsp
Generated servlet error:
Type mismatch: cannot convert from Object to String

Thanks again.
 
Change :
String aVar = session.getAttribute("aVar");
to :

String aVar = (String)session.getAttribute("aVar");

I take it that you have two machines on two separate IP addresses. So prepare a webapp build containing a.jsp and b.jsp.

Then deploy it to tomcat. Lets say the context is "test".

Then (for example) go to first :


then go to :


--------------------------------------------------
Free Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top