6 Replies Latest reply on Jun 26, 2003 7:40 AM by ged

    Load balancing and Clustering Http Sessions

    amontesinos

      Hi all,

      I have been trying to get JBoss/Clustering up and running for several days now. The problem I am finding is that once a http session is updated within a single node, it is not always distributed to the other nodes.

      Here is the quick sceanrio:

      1) User navigates to a page, page request is sent to first node in cluster. Since this is the first visit, new session variable "counter" is created: 1

      2) User clicks button on page that posts to same page, the load balancer kicks in and sends request to second node in cluster, it picks up the other node's session and this time since the session counter exists, it increments: 2

      3) Again user clicks on button, and again load balancer round-robins back to first node, however session counter is not updated, it remains 2.

      4) But posting once more to the second node and the counter is updated: 3

      It seemes as though the second node was notified that a new session was created in the first step, however at step 2 the change in the session variable was not notified back to the first node...

      I can see in the log files that each node is notified via the DistributedState components.

      Here's my config:
      - JBoss 3.2.1 + Tomcat
      - WinXP / Win2K nodes
      - Mod_JK load balancing

      Any help would be great...

        • 1. Re: Load balancing and Clustering Http Sessions
          dcartier

          I seem to recall that the existing Session clustering only distributes the state on the addition or removal of objects, not changes in the objects themselves. So it is not aware of any chages to the objects outside of the session, once the object has been added.

          Try making sure that you create a new object based on the incremented counter and see if adding it under the same key causes the session to be distributed properly.

          Dennis

          • 2. Re: Load balancing and Clustering Http Sessions
            buckman1

            This is one way I was looking to implement clustering into Jetty way back when I was going to try to help them with it. It is pretty impossible to watch objects change that are in the session. However, because each servlet container can implement the setAttribute(), removeAttribute() and getAttribute() calls, they inject code that can replicate the object being added (or removed) in their implementation. Thus, what you need to do is every time you change any object, any ref in an object, etc that is in the HttpSession, you need to re-add it to the session. Simply doing session.setAttribute(key, value) will do the trick, or so it should.

            One thing I did with my own MVC framework a while back was institute this in the code. Every time an "action" came in, at the END of the call before the request went back I automatically re-added every javabean that was used by the request. I did not do this for any other objects, as there is know way for my framework to know what objects a servlet may use. But, if the framework was used correctly, all session objects were JavaBeans anyway and thus would automatically enforce state replication IF the container that the framework was being used in supported that manner of replication.

            • 3. Re: Load balancing and Clustering Http Sessions
              amontesinos

              Thanks all for you help...

              I tried as you suggested with the same result. Do you know where I might look for extending the session clustering to add my desired behaviour?

              • 4. Re: Load balancing and Clustering Http Sessions
                buckman1

                I don't quite understand what you mean? Extending the clustering session?

                • 5. Re: Load balancing and Clustering Http Sessions
                  amontesinos

                  Sorry for not being clear, but yes is there any way to do this or am I stuck?

                  • 6. Re: Load balancing and Clustering Http Sessions
                    ged

                    Hello.
                    I saw this topic and thought that it fit quite nicely with the problems I'm having. My setup is the following:

                    Comp 1:
                    RH 9, JBoss 3.2.1, J2ee 1.4_beta2
                    Comp 2:
                    Win2k, JBoss 3.2.1, J2ee 1.4_beta2

                    Now, what I want to do is to set the whole thing up so that it will support load balancing. Clustering works but when I set the tag on the windows computer it can't do anything. It stops working. On the linux computer on the other hand, it works fine until I try to login, then it complains about that attributes need to be serializable. But I can't even login on the windows computer except if I remove the <dist..> tag.

                    I have also set this up with apache and mod_jk v1.2.3 and it almost works. It forwards me to my windows box but well, as described, can't login from there.

                    Hope you have any good suggestions.
                    Regards,
                    Ged