Alachisoft NCache 3.8

Using sessions in geographically separated web farms

NCache provides ability to manage ASP.NET session state across multiple web farms. This improves high availability and fault tolerance by allowing web farms to spread across multiple geographic regions. To achieve this, NCache provides Location Affinity feature for sessions.

To understand Location Affinity feature for sessions, consider the following scenario. Suppose that you have created multiple clustered caches, one for each geographical location. Each clustered cache has its own set of clients as a web farm. These clients will add, insert, and get sessions mostly from their own clustered cache. However, some of the times, a user might be sent to the web farm of another geographical location. Now, NCache allows that user to still be able to access the same session, based on the original session id.

This is further explained with the help of following diagram:

This figure demonstrates the following ASP.NET session state scenario:

  1. A client makes a request that passes through the Global Load Balancer.
  2. Global Load Balancer passes the request to a Local Load Balancer based on current system load. Suppose, the session request is passed to Local Load Balancer 1.
  3. The Local Load Balancer1 in turn passes the request to a server within a web farm based on system load. Suppose request is passed to Web Server1. Once the request reaches Web Server1, CustomSessionIDManager adds a unique prefix for this ASP.NET session. 
  4. After the server establishes the ASP.NET session, current session state is saved in primary cache for this web farm, in this case Replicated Cache1.
  5. When Global Load Balancer routes the same client to Web Farm2, web server analyzes the session prefix. With the help of this prefix it fetches the session from Clustered Cache1 even though it belongs to Web Farm1.

Note: This optimization is possible only in .Net 2.0 and later versions where a CustomSessionIDManager can add sid-prefix to session id. This sid-prefix helps in directing client to the cache holding the session.

To use Location Affinity, you will need to specify one 'primary' and one or more 'secondary' caches for each web farm in web.config. The primary cache will be used for all local traffic and all secondary caches will be used when a user goes to different geography.

Enable Location Affinity for SessionStoreProvider

  1. Add following section in web.config.


      <section name = "ncache" type = "Alachisoft.NCache.Web.SessionStateManagement.NCacheSection,

    Alachisoft.NCache.SessionStateManagement, Version=3.8.X.X, Culture=neutral, PublicKeyToken=CFF5926ED6A53769"/>





        <primaryCache id = "London_Cache" sid-prefix = "LDC"/>

        <secondaryCache id = "NewYork_Cache " sid-prefix = "NYC"/>

        <secondaryCache id = "Tokyo_Cache" sid-prefix = "TKC"/>



    • Replace "X.X" of the "Version" with the actual version of NCache you have.
    • The sid-prefix is a unique identifier that is appended by custom session-ID manager in the beginning of session-ID. sid-prefix length must be equal to 4.

  2. Enable custom session-ID manager using the sessionIDManagerType attribute of the sessionState element in web.config.

    <sessionState cookieless = "false" regenerateExpiredSessionId = "true" mode = "Custom" customProvider = "NCacheSessionProvider" timeout = "60" sessionIDManagerType = "Alachisoft.NCache.Web.SessionStateManagement.CustomSessionIdManager,                           Alachisoft.NCache.SessionStateManagement">


         <add  name = "NCacheSessionProvider" type = "Alachisoft.NCache.Web.SessionState.NSessionStoreProvider"

           sessionAppId = "1234" cacheName = "myCache" writeExceptionsToEventLog = "false" asyncSession = "false"

           enableLogs = "false"/>   




    • When Location Affinity is enabled, "CacheName" specified in <providers> section of web.config will be ignored.
    • Cookieless sessions are not supported.

See Also

Using Session State Module | Using Session State Store Provider