10 Replies Latest reply on Jul 19, 2017 3:23 PM by leaqui

    Configuring sticky session attribute name

    leaqui

      Hi, is it possible to configure the sticky session attribute name?

       

      I need to use a name different to JSESSIONID.

       

      I´ve tried:

       

      ProxyPass / balancer://xxxxx/ stickysession=TESTSESSIONID|testsessionid

       

      ProxyPassReverse / balancer://xxxxx/ stickysession=TESTSESSIONID|testsessionid

       

      but didn't work.

       

      Thanks in advance.

       

      Leandro

        • 1. Re: Configuring sticky session attribute name
          jfclere

          How are the balancer members defined?

          • 2. Re: Configuring sticky session attribute name
            leaqui

            Thanks for replying Jean.

             

            We use system properties:

            modcluster.balancer.name = xxxxx

            modcluster.proxy.list = balancer.ip:port

            • 3. Re: Configuring sticky session attribute name
              jfclere

              try:

              modcluster.balancer.StickySessionCookie = xxxx

              • 4. Re: Configuring sticky session attribute name
                leaqui

                It didn't work Jean.

                 

                Is it possible to configure, at balancer, a cookie name for session id different than what is used in the back-end server?

                 

                What I want to do is to manage the sticky session duration. So when a client doesn't make requests for a period of time, next request could go to a different server than the original, without losing its session.

                 

                We have a distributable application that keeps a reference to logged user in the web session. But at login time, the web session replication isn't enough fast as requests that follow the login request. So, if, for those requests, the balancer choose a node that doesn't have been replicated yet, the user wouldn't be in session and an error occur.

                 

                The solution I found is using a cookie A at backend Server, a cookie B at balancer and manage both cookies at client. A the beginning I set B=A, but when there isn't activity for a period of time, I clear B so that balancer could choose another server.

                 

                Few months ago I´ve made a question load balancing - Sticky session duration - Stack Overflow and posted this solution but I couldn't make it work.

                 

                Is [MODCLUSTER-477] Broken design: session cookie name should be specified on the Context level instead of the Engine level… related to this?

                 

                Thanks in advance

                • 5. Re: Configuring sticky session attribute name
                  jfclere

                  Is it possible to configure, at balancer, a cookie name for session id different than what is used in the back-end server?

                   

                  I don't understand what you want to achieve with that...

                   

                  balancers aren't storing sessions nor session information so they can't know when a session is expired.

                   

                  MODCLUSTER-477 isn't related to your problem.

                  • 6. Re: Configuring sticky session attribute name
                    leaqui

                    I want to achieve a better load balance between back-end servers.

                     

                    Imagine 2 servers (X, Y) and 6 clients (A, B, C ,D ,E, F) configured with sticky session.

                    At the beginning, A, C and E start sessions with X and B, D and F start sessions with Y.

                    Later A, C and E end their sessions.

                    The result is a system that is not well balanced, because Y has 3 active sessions and X doesn't have any.

                     

                    Some of our sessions are heavy weight and last for 8 hours, so this problem gets bigger.

                    • 7. Re: Configuring sticky session attribute name
                      leaqui

                      jfclere, am I wrong if I conclude that it's impossible to configure, at balancer, a cookie name for session id different than what is used in the back-end server?

                      • 8. Re: Configuring sticky session attribute name
                        pferraro

                        leaqui What you are looking for is a mechanism for the servers to rebalance the sessions such that work is redistributed following a change to your server topology, and yet session stickiness is preserved.  I am not sure what you hope to achieve by changing the cookie name, but, in general, load balancers do not have any knowledge of where a given session is located.  This is, however, typically supported by your application server itself.  WildFly's distributed session manager supports this, for one.

                        • 9. Re: Configuring sticky session attribute name
                          leaqui

                          Thanks pferraro for answering.

                          Paul Ferraro escribió:

                           

                          leaqui What you are looking for is a mechanism for the servers to rebalance the sessions such that work is redistributed following a change to your server topology, and yet session stickiness is preserved.

                          Server topology is not changed. What has changed is number of clients connected to Server X, making the cluster to be unbalanced in a "standard" sticky session scenario.

                           

                          I am not sure what you hope to achieve by changing the cookie name, but, in general, load balancers do not have any knowledge of where a given session is located. This is, however, typically supported by your application server itself.

                          What I am looking for is a better load balance after the scenario of 2 servers and 6 clients I mentioned before.

                          A way to achieve this is implementing a duration for the sticky session. So after a period of time the cluster could be balanced again.

                          The way I found to implement sticky session duration, is that the balancer looks to another cookie (MYSESSIONID, different from JSESSIONID) so when the period of time spent, the client can clear MYSESSIONID cookie, so the balancer must assign a server following metrics configured, re-balancing the cluster.

                           

                          WildFly's distributed session manager supports this, for one.

                          I am using JBoss AS 7, does Wildfly implement some mechanism for re-balance the cluster?

                           

                          Again, thanks for your time, Paul

                          • 10. Re: Configuring sticky session attribute name
                            leaqui

                            Finally I´ve found a way to configure the session cookie name, but I´ve needed to make some minor changes in mod_cluster-container-jbossweb.

                            I've created a JBossWebEngine subclass:

                            package org.jboss.modcluster.container.jbossweb;

                             

                            import org.apache.catalina.Engine;

                            import org.jboss.modcluster.container.Server;

                            import org.jboss.modcluster.container.catalina.CatalinaFactoryRegistry;

                             

                            public class CustomJBossWebEngine extends JBossWebEngine {

                             

                              private static final String CUSTOM_SESSION_COOKIE_NAME_ATT = "org.jboss.modcluster.container.jbossweb.customSessionCookieName";

                             

                              private static final String CUSTOM_SESSION_PARAMETER_NAME_ATT = "org.jboss.modcluster.container.jbossweb.customSessionParameterName";

                             

                              private String sessionCookieName;

                             

                              private String sessionParameterName;

                             

                              public CustomJBossWebEngine(CatalinaFactoryRegistry registry, Engine engine, Server server) {

                                super(registry, engine, server);

                              }

                             

                              @Override

                              public String getSessionCookieName() {

                                if (this.sessionCookieName == null) {

                                  this.sessionCookieName = System.getProperty(CUSTOM_SESSION_COOKIE_NAME_ATT,

                                      super.getSessionCookieName());

                                }

                                return this.sessionCookieName;

                              }

                             

                              @Override

                              public String getSessionParameterName() {

                                if (this.sessionParameterName == null) {

                                  this.sessionParameterName = System.getProperty(CUSTOM_SESSION_PARAMETER_NAME_ATT,

                                      super.getSessionParameterName());

                                }

                                return this.sessionParameterName;

                              }

                            }

                             

                            And an EngineFactory implementation:

                            package org.jboss.modcluster.container.jbossweb;

                             

                            import org.jboss.modcluster.container.Engine;

                            import org.jboss.modcluster.container.Server;

                            import org.jboss.modcluster.container.catalina.CatalinaFactoryRegistry;

                            import org.jboss.modcluster.container.catalina.EngineFactory;

                             

                            public class CustomJBossWebEngineFactory implements EngineFactory {

                             

                              @Override

                              public Engine createEngine(CatalinaFactoryRegistry registry, org.apache.catalina.Engine engine,

                                  Server server) {

                                return new CustomJBossWebEngine(registry, engine, server);

                              }

                            }

                             

                            And modified the /META-INF/services/org.jboss.modcluster.container.catalina.EngineFactory file:

                            org.jboss.modcluster.container.jbossweb.CustomJBossWebEngineFactory

                             

                            And specified the system properties:

                            org.jboss.modcluster.container.jbossweb.customSessionCookieName=TESTID

                            org.jboss.modcluster.container.jbossweb.customSessionParameterName=testid

                             

                            It would be nice if you could add this to mod_cluster.