Thank you Rainer, it make me clear! And thank you for your creatation of worker.domain directive :)
Rainer Jung-3 wrote: > > On 05.01.2010 09:44, LiuYan 刘研 wrote: >> >> I'm currently learning Tomcat clustering these days. >> >> I setup 4 Tomcat-6.0.22 instances in Windows XP: server1, server2, >> server3, >> server4 >> cluster1: server1& server2 (228.0.0.4:45564) >> cluster2: server3& server4 (228.0.0.4:45566) >> >> Apache/2.2.14(win32) is the frontend. mod_jk-1.2.28 is the connector >> between >> Apache and Tomcats. >> >> Start tomcats, start apache, then I visit >> http://localhost/tomcatClusterTest/session-test.jsp 4 times, then I saw >> each >> tomcat server got a request. >> >> What I expected is: server1 should get request #1,#3. server2 should get >> request #2,#4. server3 and server4 should get no request because they are >> another cluster and so they do not have the session which is created at >> server1. >> >> I read the comments of "Bug 32317 - Making mod_jk replication aware >> (Clustering Support)" from here >> https://issues.apache.org/bugzilla/show_bug.cgi?id=32317 >> I saw the following comment in bug description: >> ------------------------------------------------------------------------------- >> - without stickyness to decide to which workers an existing session >> is >> allowed to be balanced (all workers with the same domain as the worker >> given >> in >> the session id) > > No, in the current implementation domains are only used if the lb worker > is configured to use sticky sessions (default). > >> ------------------------------------------------------------------------------- >> The comment is what I expected, but the test result is unexpected: >> server3& >> server4 which belongs another domain/cluster are picked. >> >> Is it a bug or I misunderand the meaning of the comment above? >> >> >> workers.properties: >> #------------------------------------------------------------------------------- >> worker.list=LoadBalancer >> >> worker.LoadBalancer.type=lb >> worker.LoadBalancer.balance_workers=server1,server2,server3,server4 >> worker.LoadBalancer.sticky_session=false > > Use sticky sessions. Even when doing cluster session replication, > stickyness is usually better. Cluster+sticky only relies on the correct > replication if a node breaks. > >> worker.server1.host=localhost >> worker.server1.port=8109 >> worker.server1.type=ajp13 >> worker.server1.lbfactor=1 >> worker.server1.domain=cluster1 >> >> worker.server2.host=localhost >> worker.server2.port=8209 >> worker.server2.type=ajp13 >> worker.server2.lbfactor=1 >> worker.server2.domain=cluster1 >> >> worker.server3.host=localhost >> worker.server3.port=8309 >> worker.server3.type=ajp13 >> worker.server3.lbfactor=1 >> worker.server3.domain=cluster2 >> >> worker.server4.host=localhost >> worker.server4.port=8409 >> worker.server4.type=ajp13 >> worker.server4.lbfactor=1 >> worker.server4.domain=cluster2 >> #------------------------------------------------------------------------------- >> >> httpd.conf >> #------------------------------------------------------------------------------- >> JkMount /tomcatClusterTest/* LoadBalancer >> #... >> #------------------------------------------------------------------------------- >> >> session-test.jsp >> ------------------------------------------------------------------------------- >> <%@ page contentType='text/html' pageEncoding='GBK' %> >> <pre style='font-size: 12px;'> >> <% >> String sUserName=(String)session.getAttribute ("username"); >> Integer oRequestCounter=(Integer)session.getAttribute ("request >> counter"); >> int iRequestCounter = oRequestCounter!=null ? oRequestCounter.intValue() >> : >> 0; >> iRequestCounter ++; >> session.setAttribute ("request counter", >> Integer.valueOf(iRequestCounter)); >> >> java.sql.Timestamp oSessionCreatedTime = new >> java.sql.Timestamp(session.getCreationTime()); >> java.sql.Timestamp oSessionLastAccessedTime = new >> java.sql.Timestamp(session.getLastAccessedTime()); >> String sSessionID = session.getId (); >> >> java.sql.Timestamp currentTimestamp=new >> java.sql.Timestamp(System.currentTimeMillis()); >> String sInfo = >> "-------------------------------------------\n" + >> "Request: # " +iRequestCounter + "\n" + >> " Time: " + currentTimestamp + "\n" + >> "Session:\n" + >> " ID " + sSessionID + "\n" + >> " Created " + oSessionCreatedTime + "\n" + >> " Accessed " + oSessionLastAccessedTime + "\n" + >> " Attribute: username = " + sUserName + "\n" + >> " Attribute: request counter = " + session.getAttribute ("request >> counter") + "\n" + >> "" >> ; >> System.out.println (sInfo); >> out.println (sInfo); >> >> if (sUserName==null) >> { >> session.setAttribute ("username", "MyName "+new >> java.sql.Time(System.currentTimeMillis())); >> } >> %> >> </pre> >> ------------------------------------------------------------------------------- >> >> >> My test result: >> server1: >> ------------------------------------------- >> Request: # 1 >> Time: 2010-01-05 16:01:10.687 >> Session: >> ID 7E5BAD3313EF518C189B1237E7475D74.server1 >> Created 2010-01-05 16:01:10.687 >> Accessed 2010-01-05 16:01:10.687 >> Attribute: username = null >> Attribute: request counter = 1 >> >> server2: >> ------------------------------------------- >> Request: # 2 >> Time: 2010-01-05 16:01:12.828 >> Session: >> ID 7E5BAD3313EF518C189B1237E7475D74.server2 >> Created 2010-01-05 16:01:10.687 >> Accessed 2010-01-05 16:01:10.687 >> Attribute: username = MyName 16:01:10 >> Attribute: request counter = 2 >> >> server3: >> ------------------------------------------- >> Request: # 1 >> Time: 2010-01-05 16:01:14.343 >> Session: >> ID 46F2C9DA30599FF835358D50682E7583.server >> Created 2010-01-05 16:01:14.343 >> Accessed 2010-01-05 16:01:14.343 >> Attribute: username = null >> Attribute: request counter = 1 >> >> server4: >> ------------------------------------------- >> Request: # 2 >> Time: 2010-01-05 16:01:15.0 >> Session: >> ID 46F2C9DA30599FF835358D50682E7583.server4 >> Created 2010-01-05 16:01:14.343 >> Accessed 2010-01-05 16:01:14.359 >> Attribute: username = MyName 16:01:14 >> Attribute: request counter = 2 > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org > For additional commands, e-mail: users-h...@tomcat.apache.org > > > -- View this message in context: http://old.nabble.com/mod_jk%3A-The-worker-pick-order-scope-when-sticky_session%3Dfalse-and-clusters-are-grouped-by-worker.domain-tp27025276p27092159.html Sent from the Tomcat - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org