ONJava.com -- Clustering and Load Balancing 2.1

来源:百度文库 编辑:神马文学网 时间:2024/04/27 23:24:57


Sign In/My Account |View Cart
ArticlesWeblogsBooksCoursesShort CutsPodcasts
‘);//]]>
‘);//]]>
 
ListenPrintDiscussSubscribe to ONJavaWhat are those green links?
Clustering and Load Balancing in Tomcat 5, Part 2
Pages:1, 2
Sample Code
The sample code used in this article is provided astomcatclustering.zip. After installing Tomcat server instances (you need four of them), extract the contents of the zip file to the tomcat directories. The sample code provided uses RoundRobinRule as the load-balancing policy. If you want to use the random redirect policy, modify the rules.xml file located in "tomcat50/webapps/balancer/WEB-INF/config" directory. Just comment-out the rule elements for RoundRobinRule and uncomment rule elements specifying RandomRedirectRule. Also, if you want to use two instances in the cluster instead of three, comment out the third rule and change maxServerInstances attribute to 2 (instead of 3).
‘);//]]>',1)">
Note: I removed all other web applications (jsp-examples, etc.) that were included in the Tomcat installation, keeping only the balancer and the sample web applications.
HTTP Request Flow
The web request flow in the sample cluster environment is as follows:
Launch the startup page (http://localhost:8080/balancer/testLB.jsp). JSP redirects the request to balancer filter (URL: http://localhost:8080/balancer/LoadBalancer). The Tomcat server working as Load Balancer (TC-LB) intercepts the web request and redirects to the next available cluster member (TC01, TC02, or TC03) based on load-balancing algorithm specified in the configuration file. The JSP script sessiondata.jsp (located in "clusterapp" web application) in the selected cluster member is called. If the session is modified the session listener methods in ClusterAppSessionListener are called to log the session modification events. sessiondata.jsp displays the session details (such as session id, last access time, etc.) on the web browser. Randomly stop one or two cluster nodes (by calling "stop.tomcat5x" target in Ant script). Repeat steps 1 through 7 to see if the requests fail over to one of the available cluster members. Also, check if the session information is copied to the cluster members without losing any data.
Figure 3 shows the web request flow represented in a Sequence diagram.

Figure 3. Cluster application sequence diagram (click on the screenshot to open a full-size view).
Cluster Configuration
A sample web application called "clusterapp" was created to run in the cluster. All the instances have the same directory structure and contents to optimize session replication.
Since Tomcat server instances in the cluster use IP Multicast to transmit sessions, we need to make sure that IP multicast is enabled on the machine where the cluster is set up. To verify this, you can run the sample Java program MulticastNode provided in the bookTomcat: The Definitive Guide or refer to thesample tutorial available on JavaSoft web site on how to write multicast server and client programs.
When a cluster node is started the other members in the cluster show a log message on the server console that a member has been added to the cluster. Similarly, when a cluster node goes down, the remaining members display a log message on the console that a member has disappeared from the cluster. Figure 4 shows the log messages displayed on Tomcat console when a cluster node is removed from the cluster or a new member is added to the cluster.

Figure 4. Log messages when a member is added or removed from cluster
Follow the steps below to enable clustering and session replication in Tomcat server:
All session attributes must implement the java.io.Serializable interface.
Uncomment the Cluster element in server.xml file. The attributes useDirtyFlag and replicationMode in the Cluster element are used to optimize frequency and the session replication mechanism.
Enable ReplicationValve by uncommenting Valve element in server.xml. The ReplicationValve is used to intercept the HTTP request and replicate the session data among the cluster members if the session has been modified by the web client. The Valve element has a "filter" attribute that can be used to filter out requests that could not modify the session (such as HTML pages and image files).
Since all three Tomcat instances are running on the same machine, the tcpListenPort attribute is set to be unique for each Tomcat instance. It is important to know that the attributes starting with mcastXXX (mcastAddr, mcastPort, mcastFrequency, and mcastDropTime) are for the cluster membership IP multicast ping and those starting with tcpXXX (tcpThreadCount, tcpListenAddress, tcpListenPort, and tcpSelectorTimeout) are for TCP session replication ("Clustering configuration parameters" table below shows the configuration of different settings in the Tomcat server instances to enable clustering).
The web.xml meta file (located in clusterapp\WEB-INF directory) should have element. In order to replicate session state for a specific web application, the distributable element needs to be defined for that application. This means if you have more than one web application that need session replication, then you need to add distributable in all those web applications‘ web.xml files. The Tomcat clustering chapter in the bookTomcat: The Definitive Guide provides a very good explanation on this topic.
Table 2. Clustering configuration parameters
Configuration Parameter Instance 1 Instance 2 Instance 3 Instance 4
Instance Type Load Balancer Cluster Node 1 Cluster Node 2 Cluster Node 3
Code name TC-LB TC01 TC02 TC03
Home Directory c:/web/tomcat50 c:/web/tomcat51 c:/web/tomcat52 c:/web/tomcat53
Server Port 8005 9005 10005 11005
Connector 8080 9080 10080 11080
Coyote/JK2 AJP Connector 8009 9009 10009 11009
Cluster mcastAddr 228.0.0.4 228.0.0.4 228.0.0.4 228.0.0.4
Cluster mcastPort 45564 45564 45564 45564
tcpListenAddress 127.0.0.1 127.0.0.1 127.0.0.1 127.0.0.1
Cluster tcpListenPort 4000 4001 4002 4003
Note: Since all the cluster members are running on the same physical machine they use the same IP address (127.0.0.1).
If you are not using the Ant script to start and stop Tomcat instances, do not set up the CATALINA_HOME environment variable on your computer. If this variable is set, all instances will try to use the same directory (specified in CATALINA_HOME variable) to start Tomcat instances. As a result, only the first instance will successfully start and the other instances will crash with a bind exception message saying that the port is already in use: "java.net.BindException: Address already in use: JVM_Bind:8080".
Related Reading
Java Performance Tuning
ByJack燬hirazi
Table of Contents
Index
Sample Chapter
Read Online--Safari Search this book on Safari:  
Only This Book All of Safari
Code Fragments only
Load Balancer setup
I wrote two simple, custom load-balancing rules extending the rules API to redirect incoming web requests (RoundRobinRule and RandomRedirect). These rules are based on load-balancing algorithms such as round robin and random redirect. You can write similar custom load balancing rules based on other factors like weight based and last access time, etc. The Tomcat load balancer provides a sample parameter-based load balancing rule. It redirects web requests to different URLs depending on the parameter specified in the HTTP request.
Leave the cluster and valve elements in server.xml (in TC-LB instance) commented out since we are not using this Tomcat instance as a cluster member.
Testing Setup
Session Persistence Testing
In session persistence testing, the main objective is to verify that session data is not lost when a cluster member crashes in the middle of a web request. The JSP sessiondata.jsp was used to display the session details. This script also provides HTML text fields to add/modify/remove the session attributes. After adding couple of attributes to HTTP session, I randomly stopped the cluster nodes and check the session data on the available cluster members.
Load Testing
The objective of load testing is to study the custom load balancing algorithms and see how effectively the web requests are distributed to the nodes in the cluster especially when one or more of the nodes go down. JMeter load testing tool was used to simulate multiple concurrent web users.
Steps to test load balancing in the cluster setup:
Start the load balancer and cluster instances of Tomcat server. Launch the startup JSP script (testLB.jsp). Simulate the server crash by manually stopping one or more containers at random intervals. Check the load distribution pattern. Repeat steps 1 through 4 for 100 times.
All log messages were directed to a text file called tomcat_cluster.log (located in tomcat50/webapps/balancer directory). The response times for all the web objects shown in the sequence diagram (Figure 2) were logged using Log4J messages. The elapsed times (in milliseconds) were collected and tabulated into a matrix as shown in Table 3. I followed a similar instrumentation methodology described inDesigning Performance Testing Metrics into Distributed J2EE Apps in collecting the response times during the tests.
The following tables show the elapsed times in load testing (using RoundRobinRule) and load distribution percentages (using RandomRedirectRule) respectively.
Table 3. Elapsed times for load testing
# Scenario testLB.jsp
(ms) RoundRobinRule
(ms) sessiondata.jsp
(ms) Total
(ms)
1 All three server instances running 54 76 12 142
2 Two server instances running (TC02 was stopped) 55 531 14 600
3 Only one server instance running
(TC01 and TC02 were stopped) 56 1900 11 1967
Note: All elapsed times are average values based on a load of 100 concurrent users.
Table 4. Load distribution when using random LB policy
# Scenario TC01 (%) TC02 (%) TC03 (%)
1 All three server instances running 30 46 24
2 Two server instances running (TC02 was stopped) 56 0 44
Note: Load distribution percentages are based on a load of 100 concurrent users.
Conclusion
In session persistence testing, after adding session attributes one of the cluster nodes was brought down and it was verified that the session attributes were not lost due to the server outage. The session details logged in the text file were used to study the details of session attributes.
In load testing, when one or two server instances were stopped and only one Tomcat instance was running, the response times took longer compared to when all three instances were available. When the stopped instances were restarted, the load balancer automatically found that the server is again available to take the requests and redirected the next web request, which significantly improved the response times.
The mechanism I used to find if a cluster member is available (using ServerUtil) is not the fastest way to do this. More sophisticated and robust fail-over techniques should be used in real world scenarios.
One of the limitations of the proposed cluster setup is that it only provides a single load balancer. What happens if the Tomcat instance acting as load balancer goes down? There is no way to forward the requests to any of the cluster members and the result is a so-called Single Point of Failure (SPoF). One solution to this problem is to have a second Tomcat instance as the standby load balancer to take over if the primary load balancer crashes. Typical HA options involve having two load balancers to prevent SPoF situations.
In the sample cluster setup, all Tomcat instances (including load balancer) were configured to run on the same computer. A better design is to run a load balancer instance on a separate machine from the cluster members. Also, we should limit two cluster nodes per machine to take advantage of horizontal scaling method and to improve cluster performance.
HTTP session replication is an expensive operation for a J2EE web application server. The implications of session management in a clustered J2EE environment should be considered during the analysis and design phases of a project rather than waiting until the web application is implemented in the production environment. The application code must be designed keeping the cluster environment in mind. If the clustering implications are not considered at the design phase, the code may need to be completely rewritten to make it work in the cluster setup, which could be a very expensive effort.
If a web application supports any kind of object caching mechanism, then caching of objects in a cluster environment should be considered at the initial stages of the application development. This is very important because keeping cached data in all the cluster nodes in sync is critical for providing accurate and up-to-date business data to web users. Another important consideration is clearing the expired session data in a cluster.
Once the J2EE cluster has been successfully set up and is running, its management and maintenance will become very important to provide the benefits of scalability and high availability. With many nodes (members) in a cluster, maintenance revolves around keeping the cluster running and pushing out application changes to all cluster nodes. One way to provide these services is to implement a monitoring service that periodically checks the server availability and notifies if any of the nodes in the cluster become unavailable. This service should check the nodes at regular intervals detecting failed nodes and removing them from the active cluster node list so no requests go to those nodes. It should include, as changes and updates occur, the ability to update and synchronize all servers in the cluster. Since all requests to a web application must pass through the load-balancing system, the system can determine the number of active sessions, the number of active sessions connected in any instance, response times, peak load times, the number of sessions during peak load, the number of sessions during minimum load, and more. All this audit information can be used to fine-tune the entire system for optimal performance. Reports showing all these metrics should be generated on a regular basis to assess the effectiveness of load-balancing policies and cluster nodes.
Currently, all the configuration required to set up the cluster and load balancer is done manually by manipulating the configuration files (server.xml and rules.xml). It would be very helpful if the Jakarta group were to provide a web-based cluster administration GUI tool to perform the configuration changes needed to manage the clustering and load-balancing setup.
Resources
Tomcat 5 Home PageClustering Home Page on Tomcat siteLoad Balancer Home Page on Tomcat siteTomcat: The Definitive Guide by Jason Brittain and Ian F. DarwinJava Performance Tuning, 2nd Edition by Jack Shiraji Creating Highly Available and Scalable Applications Using J2EE, The Middleware Company, EJB Essentials Training Class Material
Srini Penchikala is an information systems subject matter expert at Flagstar Bank.
Return toONJava.com.

Has Tomcat‘s clustering support delivered on its promises?
You must belogged in to the O‘Reilly Network to post a talkback.


Showing messages 1 through 26 of 26.
Seems Failover is not working for me .
2007-02-13 23:32:16  vsubram2 [Reply |View]
I have followed the article and created and configured the Load Balancer and the Cluster Instances .
could see the memebrship establishment ,replication member added messages in the cluster instances cmd pmpt windows .
also able to see the recieve session messages in other instances of the cluster domain whenever a session.set,add,removeAttribute is called in one of the instances of the cluster .
failover,sessionreplication is not happening ..
http://localhost:10080/clusterapp/sessiondata.jsp is the page i am working on .i have added two session attributes and it is listed ,i manually crash the 10080 ie)cluster2 instance and i continue to add attributes in the same page http://localhost:10080/clusterapp/sessiondata.jsp?method=addAttr...browser is saying page canot be found .
will the loadbalancer not working properly?means it is load balancers duty to redirect the request to the available instance or not .
please help asap .I need to make use of this sample in my real working application .
suggestion required on tomcat clustering with Https
2006-03-16 06:22:18  abuthalha [Reply |View]
Hi
I have been trying to implement tomcat clusetering with tomcat5.x and facing it as difficult with Https.
If you anyone has come accross a solution for this plz reply to my mail
abu_thalha@rediffmail.com
I cant install 4TC
2005-07-07 20:18:13  jaimeca馻s [Reply |View]
Hello
I have a problem installing the second TC instance, I get this error: "the tomcat5 service cannot be installed. check your permissions", I‘m not able to ignore this. What can I do?
thanks
4 Tomcat Servers
2005-04-22 13:48:05  j2eeman [Reply |View]
Nice article for me to get start up with Tomcat clustering. I have a question regarding the number of server to be set up on my machine. In your article "After installing Tomcat server instances (you need four of them), extract the contents of the zip file to the tomcat directories"
so, does this mean, I need to install tomcat in 4 places.
Can you pls clarify.
Thanks,
Raghu
4 Tomcat Servers
2006-10-25 23:07:05  suhaib [Reply |View]
Hi
I am new to Tomcat and infact new to this domain. I am trying to set up 4 Tomcat servers in a cluster and one of them will act as load balancer. (This one does both load balacing and server the requests). Moreover, I need a way to design a load balancing scheme where I can dynamically balance the load among all the available servers. (Balanced load in contrast to random or round robin which does work this way). Moreover any of the server can go down and comes up but not the load balancer one which always stays up.
I have read a couple of articles but none seems to answer my questions as no one really explains the things in the server.xml and rules.xml. I have no clue to what these are and how these are manil]pulated to get the desires results. ( Java sucks full time and it seems that it does not have any direcion so far, I am a C programmer).
I will highly appreciate if someone can tell me what needs to be modified in the server.xml and rules.xml or other file to get this work done.
Moreover WHAT is these lines in server.xml (the first server LOAD BALANCER in this article) doing:
debug="0"
saveOnRestart="true">
directory="E:\web\tomcat50\work" />

These lines are not in the other servers servers.xml files nor in my server.xml file
I am using tomcat 5.5:
Finally what does this means:
"extract the contents of the zip file to the tomcat directories."Do we have to overwrite all the files in the tomecat folder with these folders. Do I need "ServerUtil" class or other rule classes in tomcat 5.5.
This is my server.xml file




debug="0"/>
debug="0"/>








factory
org.apache.catalina.users.MemoryUserDatabaseFactory


pathname
conf/tomcat-users.xml







port="8180" maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="true" acceptCount="10" debug="0"
connectionTimeout="20000" useURIValidationHack="false" />

port="8009" maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="true" acceptCount="10" debug="0"
connectionTimeout="20000" useURIValidationHack="false"
protocolHandlerClassName="org.apache.jk.server.JkCoyoteHandler"/>





debug="0" resourceName="UserDatabase"/>

unpackWARs="true" autoDeploy="true">


managerClassName="org.apache.catalina.cluster.session.DeltaManager"
expireSessionsOnShutdown="false"
useDirtyFlag="true"
notifyListenersOnReplication="true">
className="org.apache.catalina.cluster.mcast.McastService"
mcastAddr="228.0.0.4"
mcastPort="45564"
mcastFrequency="500"
mcastDropTime="3000"/>
className="org.apache.catalina.cluster.tcp.ReplicationListener"
tcpListenAddress="auto"
tcpListenPort="4001"
tcpSelectorTimeout="100"
tcpThreadCount="6"/>
className="org.apache.catalina.cluster.tcp.ReplicationTransmitter"
replicationMode="pooled"
autoConnect="true"
maxPoolSocketLimit="10"
keepAliveTimeout="-1"
keepAliveMaxRequestCount="10000"
waitForAck="true"/>
filter=".*\.gif;.*\.js;.*\.jpg;.*\.png;.*\.htm;.*\.html;.*\.css;.*\.txt;"
primaryIndicator="true"/>



tempDir="/tmp/war-temp/"
deployDir="/tmp/war-deploy/"
watchDir="/tmp/war-listen/"
watchEnabled="false"/>












4 Tomcat Servers
2005-04-24 18:36:28  srinip [Reply |View]
Hi,
Since the cluster setup used in this article uses 3 TC nodes in the cluster and another TC for load balancing the web requests, you will need a total of 4 Tomcat instances running on a single machine. Or you can only run 2 nodes in the cluster and install 3 TC instances to get the clustering up and running.
-Srini
4 Tomcat Servers
2005-05-12 13:27:42  vqt [Reply |View]
I have able to setup the load balancer and the three nodes to run on a single server per you article. Your article also alludes that it is possible to setup the node to run on different servers.
I was wondering what changes would I need to make in order to set up tomcat nodes to run on different machines and be able to communicate with the load balancer. It sounded like you would need to make a configuration changes to set this up.
I appreciate any suggestions you have on this...
Thanks!
Not able to locate BalancerFilter
2005-03-03 22:10:40  Falgun [Reply |View]
hi there
i am not able to locate BalancerFilter.java or BalancerFilter.class.
can anyone tell me that how do i forward(redirect) request object, which has userID and password as its parameter to servlet running on some other host.
i tried using following code in LoadBalancerServlet
getServletContext().getRequestDispatcher("http://172.16.25.54:8080/MyServlets/MainServlet").forward(request, response);
but it thorws following exception
java.lang.RuntimeException url does not start with ‘/‘
please help
thanks
Falgun
thanks in advance
Falgun
Not able to locate BalancerFilter
2005-07-20 02:02:00  IDunno [Reply |View]
You can see BalancerFilter in Tomcat sources :
/jakarta-tomcat-catalina/webapps/balancer/WEB-INF/classes/org/apache/webapp/balancer/BalancerFilter.java
Here is the source :
/*
* Copyright 2000,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.webapp.balancer;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* The balancer filter redirects incoming requests
* based on what rules they match. The rules
* are configurable via an XML document whose URL
* is specified as an init-param to this filter.
*
* @author Yoav Shapira
*/
public class BalancerFilter implements Filter {
/**
* The rules this filter consults.
*/
private RuleChain ruleChain;
/**
* The servlet context.
*/
private ServletContext context;
/**
* Returns the rule chain.
*
* @return The rule chain
*/
protected RuleChain getRuleChain() {
return ruleChain;
}
/**
* Initialize this filter.
*
* @param filterConfig The filter config
* @throws ServletException If an error occurs
*/
public void init(FilterConfig filterConfig) throws ServletException {
context = filterConfig.getServletContext();
String configUrlParam = filterConfig.getInitParameter("configUrl");
if (configUrlParam == null) {
throw new ServletException("configUrl is required.");
}
try {
InputStream input = context.getResourceAsStream(configUrlParam);
RulesParser parser = new RulesParser(input);
ruleChain = parser.getResult();
context.log(
getClass().getName() + ": init(): ruleChain: " + ruleChain);
} catch (Exception e) {
throw new ServletException(e);
}
}
/**
* Filter the incoming request.
* Consults the rule chain to see if
* any rules match this request, and if
* so redirects. Otherwise simply
* let request through.
*
* @param request The request
* @param response The response
* @param chain The filter chain
* @throws IOException If an error occurs
* @throws ServletException If an error occurs
*/
public void doFilter(
ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
if (response.isCommitted()) {
context.log(
getClass().getName()
+ ": doFilter(): not inspecting committed response.");
chain.doFilter(request, response);
} else if (!(request instanceof HttpServletRequest)) {
context.log(
getClass().getName()
+ ": doFilter(): not inspecting non-Http request.");
chain.doFilter(request, response);
} else {
HttpServletRequest hreq = (HttpServletRequest) request;
HttpServletResponse hres = (HttpServletResponse) response;
URL redirectUrl = getRuleChain().evaluate(hreq);
if (redirectUrl != null) {
String encoded =
hres.encodeRedirectURL(redirectUrl.toString());
context.log(
getClass().getName()
+ ": doFilter(): redirecting request for "
+ hreq.getRequestURL().toString() + " to " + encoded);
hres.sendRedirect(encoded);
} else {
chain.doFilter(request, response);
}
}
}
/**
* Destroy this filter.
*/
public void destroy() {
context = null;
ruleChain = null;
}
}
// End of file: BalanceFilter.java
Not able to locate BalancerFilter
2005-12-19 20:59:27  minil [Reply |View]
Hi,
where to place the BalancerFilter.java file in Web-inf directory. Its urgent. can u plz reply back immediatly.
Thanks in advance.
(transparent) load balancing with tomcat 5.5 ?
2004-12-03 00:19:23  MarcR [Reply |View]
Thank you for your really nice article!
Unfortunately the description works for 5.0 only, it seems that they changed the load balancing stuff a little bit in the current tomcat 5.5. Maybe anyone could give me a hint how to migrate load-
balancing to 5.5.
The second thing is that I believe sendRedirect is not the best solution. In my opinion load balancers should work transparently to users. Is there a good way to pipe the whole content through
the tomcat-lb?
The cluster members are communicating, but...
2004-11-24 12:07:21  steveb209 [Reply |View]
Hello,
I tried the example and can see from the console output that the balancer and cluster members acknowledge each other when starting up and terminating, but I cannot get the balancer to forward requests on to the cluster. Has anyone else seen something like this?
The cluster members are communicating, but...
2007-03-02 13:37:52  Ethiraj [Reply |View]
Hi,
I have read the article. i understood the concepts.but in practical i cant understand.
Here how do we specify the application server in same cluster.
for example if 3 servers are clustered together.for that where we have to specify these 3 servers are in single cluster.
can you explain what is tomcat instance. how do we create . in single machine lot of tomcat instance means it represent different applications or same application deployed in differet directory.
could you please clear these doubts
Clustering And LoadBalancing
2004-11-07 08:45:42  armedace [Reply |View]
Indeed, an excellently written article on the related topic. The code is superbly written, and does executes well.
Now, based upon the artilce i was trying to load-shed a sample request from a simple webpage. But the problem here is that the information provided at the webpage is not reaching a servlet at one of the clustered node server.
Let me explain, there is a web page which asks a simple username through a textbox and then redirects it to a servlet through the LoadBalancer provided by you. But what happens at the servlet end is the username information never reaches.
Pardon me to say that I am new to this topic, so any sort of help will indeed help out.
Thanks...
Clustering And LoadBalancing
2004-11-10 16:59:48  armedace [Reply |View]
Sorry people, it was my fault and now I have figured that out. The respective article is so well written that it hardly needs any challenge.
All the credit goes to Mr.Srini.
The example works well on both kinds of clusters. So if anyoen needs kinda help, i wont mind.
Thanks again to Mr.Srini.
Clustering And LoadBalancing
2007-02-13 23:29:07  vsubram2 [Reply |View]
I have followed the article and created and configured the Load Balancer and the Cluster Instances .
could see the memebrship establishment ,replication member added messages in the cluster instances cmd pmpt windows .
also able to see the recieve session messages in other instances of the cluster domain whenever a session.set,add,removeAttribute is called in one of the instances of the cluster .
failover,sessionreplication is not happening ..
http://localhost:10080/clusterapp/sessiondata.jsp is the page i am working on .i have added two session attributes and it is listed ,i manually crash the 10080 ie)cluster2 instance and i continue to add attributes in the same page http://localhost:10080/clusterapp/sessiondata.jsp?method=addAttr...browser is saying page canot be found .
will the loadbalancer not working properly?means it is load balancers duty to redirect the request to the available instance or not .
please help asap .I need to make use of this sample in my real working application .
How to hide the cluster implementation?
2004-11-01 07:32:22  puneetk [Reply |View]
This is certainly a very good working example for introduction to clustering using tomcat.
However one of the questions still remains unanswered about how to hide this implementation from end users. From emd-user‘s perse, they get to know that there is redirecting from the URL.
Is it the standard behaviour in other containers as well?
How can it be made transparent to end users?
High Availability
2004-10-20 06:32:21  MyOReilly [Reply |View]
Hi,
I am new to clustering,I enjoyed the article ,It is an excellent article and works fine ,but what about the high availability
I think not every request routed through the TC-LB, only the first request routed through TC-LB. After that the corresponding server is reponding for the request.what will happen if the server which responded for the reqquest goes off .
Ramesh
Load Balacer fail-over
2004-09-17 12:20:57  blauf [Reply |View]
I enjoyed the articles on Tomcat clustering/load balancing as I‘m new to Tomcat and have a need to define an architecture to support several web applications running on Tomcat.
My question relates to the load balancer node: Is there a way to define a "primary" load balancer and a "secondary" load balancer. The idea being that only the "primary" load balancer would truley do load balancing and the "secondary" load balancer is only there in case the primary node were to fail?
Any thoughts on this?
Thanks,
-B
Fail over utility, Load balancing with URL redirecting
2004-08-20 10:53:23  yogesh_prajapati [Reply |View]
This is very good article and provide a solid base to start using Tomcat 5.0 for clustering and load balancing. As it was pointed out in this article that the default balancer (bundled with Tomcat 5.0) does not handle fail over. I tried using your utility class, it works but it throws error and need some improvements. I may probably come up with improvements. Let me know where and how to publish the improved fail over.
Anther point I wanted to bring up is that URL redirecting is not really transparent to end client (web browser), what if the load balancer is redirecting response (with encoded URL) to some other server (on LAN) that is not exposed to external network, how will it work. I am confused....any idea ?
Fail over utility, Load balancing with URL redirecting
2004-08-22 12:37:36  srinip [Reply |View]
Hi,
Thanks for the feedback on Clustering and Load Balancing article.
Can you e-mail me the error message you are getting when using ServerUtil class. I have the configuration working on my home PC and am curious to see what kind of error message the load balance is throwing in your configuration.
Also, regarding URL redirecting it should work by redirecting the Http request to the available cluster member (this is a simple forward to the new URL). This should work with any URL (internal server or external). Let me know what‘s the server configuration you are using in your web application.
-Srini
Fail over utility, Load balancing with URL redirecting
2004-08-23 17:02:36  yogesh_prajapati [Reply |View]
As such your server util class works fine but it always starts and stops MCastService as many times as no of rules configured in rules.xml. This process is repeated for ever single incoming request. I am not sure if this is a good approach to be adopted. During start/stop of this temporary McastService there are warnings generated on other tomcat instancess running "clusterapp", I have sent the stack trace to you via email.
About Redirection: I had a look into Tomcat BalanceFilter code it uses response.sendRedirect(..) method. There should be provision for more than just redirect. (I know this is something beyond the scope of what you have done) As I understand from the real application needs , this should not be (and can not be) a simple forward to new URL because of two reasons:
1. Size limitation on URL rewriting. What if your request has a number of parameters size of which spans over beyond the limit of data your URL could carry. I am talking about simple URL size limit in HTTP GET Vs HTTP POST secenarios.
2. Redirecting to local internal server (where actual Tomcat server running) changes the URL on client web browser (in this case to local internal address as hardcoded in rules.xml) and hence not acceptable. I think there should exactly the same mechanism between Tomcat Worker and actual Tomcat Server as it has been between Apache and Tomcat to for request forwarding transparently.
ideas.....?????
Fail over utility, Load balancing with URL redirecting
2006-03-17 06:36:55  ipolak [Reply |View]
I had the same problem, so i created my own BalancerFilter class.
On the point where the BalancerPortal class uses a hres.sendRedirect(encoded);
I implement the following strategy:
A) determine new URL (most of the time simple substring replacement)
B) get content of that URL (using e.g. apache‘s org.apache.commons.HttpClient)
note special treatment is necessary to handle POST requests, parameters need to be copied, but not all the request headers (since there is a length attribute which might give problems).
C) write content on the reponse outputstream of the doFilter parameter.
Note that in my current setup there is no security for the other nodes, but this could be implemented using htaccess rules by restricting clients to the ip of the balancer app.
I think the neatest approach would be to be able to specify a Strategy object using the xml configuration of the balancer so you can plug-in your own strategy class for handling a request.
Maybe I‘ll rewrite my solution in such a way.
First I must now make sure that all my sessions are Serializable....:)
Session replication requirements
2004-04-16 13:19:50  jeffhuff [Reply |View]
I think in WebLogic, in order to get it to replicate your Serializable session object to the other clustered servers, you have to set the attribute back into the session if you modify it.
Session session = request.getSession(false);
Map items = (Map)session.getAttribute("items");
items.put("new", new String("new"));
won‘t do it, you have to
session.setAttribute("items", items);
This seems to be the only way that the session would know that something changed.
Are there any good patterns to ensure that developers don‘t forget to set it back into the session instead of relying on modifying the reference?
Thanks for the article.
Clustering and Load Balancing in Tomcat 5
2004-04-15 18:43:34  srmarreddy [Reply |View]
Very informative article on Clustering with Tomcat.Iam trying to setup a tomcat cluster for my website and this is going to be a big help for that. Many thanks to Srini Penchikola.
Clustering and Load Balancing in Tomcat 5
2004-09-24 02:29:59  ndh13X [Reply |View]
any one can help me st up the cluster
i am new here
‘);//]]>
Search ONJava

Tagged Articles
Post to del.icio.us
This article has been tagged:
tomcat
java
web
tomcat
Articles that share the tag tomcat:
How to Publish Multiple Websites Using a Single Tomcat Web Application (41 tags)
Database Connection Pooling with Tomcat (34 tags)
Top Ten Tomcat Configuration Tips (32 tags)
Clustering and Load Balancing in Tomcat 5, Part 1 (10 tags)
Configuring Tomcat and Apache With JK 1.2 (10 tags)
View All
java
Articles that share the tag java:
Profiling Your Applications with Eclipse Callisto (113 tags)
Configuration Management in Java EE Applications Using Subversion (49 tags)
Wiring Your Web Application with Open Source Java (44 tags)
Internals of Java Class Loading (43 tags)
POJO Application Frameworks: Spring Vs. EJB 3.0 (43 tags)
View All
web
Articles that share the tag web:
Very Dynamic Web Interfaces (362 tags)
Rolling with Ruby on Rails (230 tags)
Ajax on Rails (183 tags)
What Is Web 2.0 (145 tags)
How to Create a REST Protocol (103 tags)
View All
Sponsored Resources
Inside Lightroom
Related to this Article
Checking Java Programs
byIan F. Darwin
March 2007
$9.99 USD
SQL Injection Defenses
byMartin Nystrom
March 2007
$9.99 USD

‘);//]]>
Sponsored by:
‘);//]]>
 

Contact Us |Advertise with Us |Privacy Policy |Press Center |Jobs
Copyright © 2000-2006 O‘Reilly Media, Inc. All Rights Reserved.
All trademarks and registered trademarks appearing on the O‘Reilly Network are the property of their respective owners.
For problems or assistance with this site, emailhelp@oreillynet.com