Alachisoft.com
Extremely Scalable ASP.NET Session Storage

Extremely Scalable ASP.NET Session Storage

Remove performance bottlenecks and scale up your .NET applications to extreme transaction processing (XTP). NCache provides multiple powerful mechanisms for boosting .NET application performance and scalability.

Distributed ASP.NET Session State Cache

Built on the distributed caching core, this module provides an extremely scalable ASP.NET Session State storage for apps running in a server farm with a load balancer.

  • Remove session storage bottlenecks and scale up ASP.NET
  • Faster & more scalable than StateServer & SQLServer
  • Highly reliable thru session replication
  • Software appliance (No code change required)

Distributed In-Memory Object Cache

Distributed cache, the core engine of NCache, is extremely fast and scalable. Cache both static and transactional application data and reduce expensive database trips. NCache synchronizes cache updates across multiple servers.

  • Scale up with Mirrored, Replicated, Partitioned, and Client Cache topologies
  • Software appliance for Caching Application Block
  • Software appliance for NHibernate

Drawbacks of Regular ASP.NET Session State in Server Farms

Although adding web servers to the farm is a great way to scale up ASP.NET applications, one thing that does not scale well is ASP.NET Session State itself. Following are some of its drawbacks:

  1. Loss of session data if using InProc, StateServer, or SqlServer mode without clustering.
  2. Slow performance if you store session data in SQL Server.
  3. Not scalable if using InProc or StateServer modes and expensive scalability thru SQL Server.
  4. Single point of failure if you're using InProc, StateServer, or SqlServer without clustering.
  5. Expensive high availability if using SqlServer mode due to cost of SQL Server clustering.
  6. Maintenance downtime difficult if using InProc or StateServer mode.

Benefits of NCache Distributed ASP.NET Sessions in Server Farms

NCache lets you transform your regular ASP.NET sessions into distributed sessions without any code change. You follow a few simple steps and your existing ASP.NET applications can suddenly benefit from powerful distributed sessions. Below are some of the benefits of using distributed sessions:

  1. No loss of session data: You can replicate your session data to multiple nodes and avoid any loss of data if a web server crashes.
  2. High performance: Keep your session data close-by (either InProc or local OutProc) on all web servers for an extremely fast performance. Even keeping a separate distributed caching-tier for session data is much faster than accessing SQL Server.
  3. Highly scalable: You have a rich set of clustering topologies (replicated, partitioned, and client nodes) that allow you to scale up to 100's of web servers in your farm without compromising on performance.
  4. No single point of failure: Clustering the session allows you to eliminate all single points of failures from your environment. This makes your application highly available.
  5. Low cost high availability: Instead of buying expensive SQL Server clustering, you can cluster sessions on your web servers without the need for any additional expensive hardware.
  6. Easy maintenance downtime: Clustering means that data is not only on one server. This allows you to schedule down time for your servers without any problem.
  7. 100% Native .NET: NCache is a 100% native .NET product. This means that you can expect us to stay on top of all additions and changes to .NET as compared to a non-.NET solution.
  8. Share sessions across multiple geographical sites: NCache lets you share sessions across multiple geographical sites. You can now host your application in multiple sites and have users go from one location to another without losing their sessions.

How Does It Work?

Using NCache Distributed Sessions is very simple. You have two options for incorporating session clustering into your application. Two require no code change and the third requires minor code change. Here they are:

1. Use HttpModule for ASP.NET 1.1 (no code change)

NCache provides an HttpModule for ASP.NET 1.1. This HttpModule intercepts all Http Requests and Responses and synchronizes the regular SessionState with NCache. This allows you to incorporate session clustering without any code change to your ASP.NET application.

Use HttpModule for ASP.NET 1.1

Incorporating NCache HttpModule into your ASP.NET is a simple three-step process as described below. Read Using NCache for ASP.NET Sessions for more details.

  1. Install NCache on each web server. Make sure you configure cache server properly for multiple network cards. See online help for details.
  2. Define a distributed cache: Use NCache Manager (a graphical tool) to define a distributed cache that is appropriate for you. For small web farms, use Replicated Cache. And, for larger web farms, use Partition-Replica caching topology. 2-node web farms should keep cache on web servers but larger web farms should use a separate caching tier of 2 or more cache servers. Make sure you test the distributed cache to ensure it is properly working. See details in online help.
  3. Modify web.config file to add the HttpModule information and the name of the cache you've just created. NCache provides a sample project called guessgamehttpmodule that demonstrates how to use HttpModule option for sessions. Here is a sample web.config:
       <appSettings>
              <add key="CacheName" value="myReplicatedCache"/>
       </appSettings>
            <httpModules>
            <add name="NCacheWebSessionState"
                 type="Alachisoft.NCache.Web.SessionState.NSessionStateModule,
                 Alachisoft.NCache.SessionState, Version=3.2.1.0, Culture=neutral,
                 PublicKeyToken=cff5926ed6a53769"/>
            </httpModules>

Please note "Version=3.2.1.0" should match the NCache version you have downloaded. Once you do this, you're ASP.NET application is ready to start using distributed sessions.

2. Use SessionState Provider in ASP.NET 2.0 (no code change)

SessionState Provider in ASP.NET 2.0

For ASP.NET 2.0, NCache also provides a custom SessionState Provider that synchronizes your regular ASP.NET Session with NCache. This allows you to use session clustering without any code change. Just like the HttpModule option, this is also a simple three-step process as described below. You can also read Using NCache for ASP.NET Sessions for more details.

  1. Install NCache on each web server. Make sure you configure cache server properly for multiple network cards. See online help for details.
  2. Define a distributed cache: Use NCache Manager (a graphical tool) to define a distributed cache that is appropriate for you. For small web farms, use Replicated Cache. And, for larger web farms, use Partition-Replica caching topology. 2-node web farms should keep cache on web servers but larger web farms should use a separate caching tier of 2 or more cache servers. Make sure you test the distributed cache to ensure it is properly working. See details in online help.
  3. Modify web.config file: to add the SessionState Provider information and the name of the cache you've just created. NCache provides a sample project called guessgamesessionstoreprovider that demonstrates how to use SessionState Provider option for sessions.
    <assemblies>
         <add assembly="Alachisoft.NCache.SessionStoreProvider,
                       Version=3.2.1.0, Culture=neutral,
                       PublicKeyToken=CFF5926ED6A53769"/>
    </assemblies>

      <sessionState cookieless="false" regenerateExpiredSessionId="true"
	   mode="Custom"
                    customProvider="NCacheSessionProvider" timeout="1">
            <providers>
                  <add name="NCacheSessionProvider"
                        type="Alachisoft.NCache.Web.SessionState.
						NSessionStoreProvider"
                        cacheName="myreplicatedcache" 
						writeExceptionsToEventLog="false"
                        AsyncSession="false"/>
            </providers>
      </sessionState>

Please note that Version=3.2.1.0 should match the specific NCache version you've downloaded. Once you do this, you're ASP.NET application is ready to start using distributed sessions.

Multiple Geographical Sites Sharing Sessions

If you have an ASP.NET application that hosted in multiple geographical locations and you want your users to be bounced from one location to another without losing sessions, you can do that with NCache. In order to do that you need to follow these simple steps. You can also read Using NCache for ASP.NET Sessions for more details.

  1. Define a separate distributed cache for each location: You must define a separate replicated or partition-replica cache for each location.
  2. Modify web.config file for each location: In addition to other web.config changes mentioned above, you must also specify the following in each location.
	<configSections>
		<section name="ncache"
			type="Alachisoft.NCache.Web.SessionStateManagement.NCacheSection,
				  Alachisoft.NCache.SessionStateManagement, Version=3.2.1.0,
				  Culture=neutral, PublicKeyToken=CFF5926ED6A53769"/>
	</configSections>

	<ncache>
		<sessionLocation>
			<primaryCache id="londonReplicatedCache" sid-prefix="lndr"/>
			<secondaryCache id="newyorkReplicatedCache" sid-prefix="nykr"/>
			<secondaryCache id="tokyoReplicatedCache" sid-prefix="tkyr"/>
		</sessionLocation>
	</ncache>

Please make sure that Version=3.2.1.0 matches the specific version of NCache you have downloaded. For more details on this, please see online help.