Thursday, November 14, 2013

Web Session Clustering - No Session Left Behind

Clustering and failing-over web sessions is certainly not a new topic, but time proves that this topic never gets old either.  No e-commerce site wants to loose any customers in case of a server crash. The old approach of sticky sessions does not seem to do the trick anymore, as it often causes uneven load distribution across cluster with certain servers being overloaded while others being almost idle.

Web session clustering provides freedom of load balancing user sessions to any app server without losing intermediate user session data. Why? Because underneath it takes advantage of in-memory distributed caching technology which ensures that user sessions are available in memory regardless of which server is hit. With this approach fault tolerance comes automatically - if a server crashes, simply go to another server and your session will still be available. All of this happens transparently to user who simply continues to browse and add items to the shopping cart as if nothing happened.

As an example, diagram below illustrates how web session clustering works in GridGain:


With GridGain In-Memory Database technology (IMDB) web sessions will be either replicated to all servers or partitioned across the cluster, where every cluster node will serve as a primary node for a particular web session. In case of partitioned strategy, it is possible to configure any number of backup copies within the cluster to ensure fault tolerance. All sessions will be eagerly removed from cache whenever they expire in the app server to free up memory space for others.

Configuration is as easy as adding a few lines into your web.xml file, like so:
    ...
 
    
    
        
            org.gridgain.grid.cache.websession.GridWebSessionServletContextListener
        
    
    
    
    
        GridGainConfigurationFilePath
        /examples/config/spring-cache.xml
    
    
    
    
        GridGainWebSessionsCacheName
        session-cache
    

    ...

Once configured, simply bring up as many instances of your favorite app server and web sessions will be automatically clustered and cached in memory.

5 comments:

  1. Very interesting. Am I right to say that this eliminates the need to cluster application server? Or this will only work with clusterred servers?

    ReplyDelete
  2. Yes, app server clustering is not needed. GridGain will cluster the web sessions using its own clustering.

    ReplyDelete
  3. can u give an example in j2ee

    ReplyDelete
  4. You can find more thorough documentation here:
    http://atlassian.gridgain.com/wiki/display/GID/Web+Sessions+Caching

    ReplyDelete
  5. Can't seem to access the link there...
    in gridgain 6.0.3 is the listener class


    org.gridgain.grid.startup.servlet.GridServletContextListenerStartup



    tried it with the one stated in the blog, which didn't exist. Just want to verify that this is the write functionality.

    ReplyDelete