现在的位置: 首页 > 综合 > 正文

NCache

2013年12月08日 ⁄ 综合 ⁄ 共 7163字 ⁄ 字号 评论关闭

How NCache Resolves ASP.NET Cache Limitations

ASP.NET provides a Cache class within the Application scope to let you cache frequently used application data and reduce expensive trips to the database. However, ASP.NET Cache is an in-process and stand-alone cache and therefore has many limitations and problems.

NCache on the other hand provides an in-memory distributed cache that has none of the limitations of ASP.NET Cache. NCache supports, in-process, out-process, and remote cache access in addition to providing cache distribution through clustering and caching topologies.

ASP.NET Cache Deployment Limitations

Since ASP.NET Cache is always in-process, it creates many limitations and problems. None of these problems occur if you use NCache in your ASP.NET application. Here is a list of problems and limitations.

  • Data Integrity Problem in Web Gardens: A web garden is configured on a web server by specifying multiple worker processes for an application pool. However, in this situation, ASP.NET creates multiple isolated instances of the Cache class, one for each worker process. And, the Cache in each worker process is not synchronized with other worker processes thereby creating data integrity problem.
  • Data Loss with Worker Process Recycling: ASP.NET always runs in worker processes (whether single or multiple processes) and these worker processes recycle by default. Once a process recycles, the entire Cache is lost because it was within this process. This can lead to serious problems if you don't have a backup storage of the cached data. At the minimum, it is a performance issue because you now have to reload the entire cache.
  • Cache Size Limitation: An in-process Cache is limited by how much a single process can store. Most ASP.NET applications these days run on 32-bit platforms and therefore there is a 2GB or 3GB memory size limit which has to be shared between the Cache and your ASP.NET application. Although on a 64-bit platform this limit goes away, process recycling becomes an even more serious performance issue since the cache is now much larger and has to be reloaded at runtime.
  • Single Point of Failure: The entire Cache is stored on a single server and therefore is lost if this server goes down for any reason.
  • Data Integrity Problem in Web Farms: A web farm consists of multiple web servers connected together through a load balancer. The load balancer routes user requests to all web servers thereby distributing the load evenly. In a web farm configuration, each web server creates its own isolated copies of ASP.NET Cache that is not synchronized with other web servers. This creates data integrity problems.
  • Scalability Problem in Web Farms: The ideal way to distribute load evenly in a web farm is for the load balancer to send each request to the most appropriate web server based on the load on all web servers. However, since ASP.NET Cache is stand-alone and in-process, the load balancer has to send the request to the same web server where the user was originally serviced. This severely limits scalability because you end up with situations where some of the servers are extremely overloaded and slow while others are free and adding more servers doesn't increase the total processing throughput.

ASP.NET Cache SqlCacheDependency Limitations

ASP.NET allows you to use the SqlCacheDependency class to create a cache item dependency on a table or row in a database. When a change occurs in that table or specific row, the item in the cache that has this dependency is invalidated and removed from the cache. With SQL Server 2000, you can only create a table level dependency but SQL Server 2005 allows you to also create a row level dependency.

Although, SqlCacheDependency tries to address the severe scalability limitations in ASP.NET Cache mentioned above, it is unable to completely resolve these problems. Here are the problems associated with SqlCacheDependency:

  • Performance Issue: The whole idea behind the cache is to reduce expensive database trips. However, SqlCacheDependency is stored in the database and therefore causes major performance degradation. Every time your ASP.NET application adds, updates, or removes anything from the cache, the same information is updated once in the application database and secondly in the SqlCacheDependency database. It is then propagated from the databases to all the other Cache instances, whether in a web garden or in a web farm configuration. This makes cache updates extremely slow.
  • Scalability Issue: Database server is not able to scale out as your server farm grows. You may be able to build an active-active cluster of your database but even this cannot grow beyond 2-3 database servers without giving major performance degradation. In addition, this type of a configuration is extremely expensive. Hence, as your server farm grows, if you're using SqlCacheDependency, you'll see a major drop in performance.

How NCache Addresses These Limitations?

NCache is an in-memory distributed cache and resolves all the limitations of ASP.NET Cache mentioned above. Here is how NCache addresses these limitations:

  • No Data Integrity Problem in Web Gardens: NCache allows you to store you cache out-of-process. This means that even in web gardens, all the different worker processes share a common cache and hence there is no data integrity problem.
  • No Data Loss with Worker Process Recycling: Out-of-process cache storage also resolves the data loss problem when a worker process recycles.
  • No Cache Size Limitation: NCache allows you to keep cache out-of-process, remotely, or distributed. This allows you to grow the cache size as much as you want. Keeping the cache on a separate server means there is no memory competition with your ASP.NET application. And, distributing the cache on multiple servers through partitioning means you grow cache storage capacity as you add more cache servers. Finally, a 64-bit platform for cache allows you a lot of cache storage space.
  • No Single Point of Failure: NCache provides replication of the cache so there is no single point of failure. You can choose Mirrored, Replicated, or Partition-Replica cache topologies for this.
  • No Data Integrity Problem in Web Farms: NCache allows you to keep the cache on a remote cache server and also distribute it on multiple cache servers. This means there is no data integrity in a web farm because all web servers are accessing a common cache remotely.
  • No Scalability Problem in Web Farms: Most importantly, a cache cluster grows flawlessly as your server farm grows. Various caching topologies allow you to grow the cache cluster without any problems.

ASP.NET Cache Feature Comparison with NCache

ASP.NET Cache does not provide a lot of very important caching features that are required for scalability. Below is a brief list of feature comparison of ASP.NET Cache with NCache:

Feature Comparison 
Feature ASP.NET Cache NCache
Data Expirations
Absolute Time Expirations True True
Idle Time Expirations True True
Cache Dependency
File Based Dependency True True
Key Based Dependency True True
Key based across caches   True
Database Synchronization
SqlDependency (SQL Server 2005) True True
Row based Polling DbDependency (OLEDB)   True
Other Object Caching Features
Asynchronous Operations (Add, Insert, Remove)   True
Bulk Operations (Get, Add, Insert, Remove)   True
Read-Through, Write-Through, Write-Behind   True
Object Query Language (OQL)   True
Data Groups   True
Compact Serialization   True
Cache Dependencies
File Based Dependency   True
Key Based Dependency   True
Multi-cache Key Dependency   True
Caching Topologies
Max Cache Size   True
Local Cache   True
Replicated Cache   True
Mirrored Cache   True
Partitioned Cache   True
Partitioned Cache with Replicas   True
Client Cache   True
Dynamic Clustering
Local .NET Clients (InProc & OutProc)   True
Remote .NET Clients   True
Local Java Clients (OutProc)   True
Remote Java Clients   True
Add or Remove Cache Servers at Runtime   True
Event Notifications on Cluster Changes   True
Event Notifications
For Selected Cached Items (on Update/Remove)   True
For any Add/Update/Remove/ClearCache Operation   True
Client Initiated Custom Event Notification   True
Evictions
Max Cache Size   True
Least Recently Used (LRU) Eviction   True
Least Frequently Used (LFU) Eviction   True
Priority Eviction   True
Do Not Evict Option (for Sessions)   True
Distributed ASP.NET Session State Storage
Managed .NET Memory True True
GUI Based Administration
GUI based Remote Cluster Administration   True
PerfMon based Cluster Monitoring   True
InProc Cache Instance Monitoring   True
Command-line tools   True
GUI Based Monitoring
GUI Based Remote Cluster Monitoring (WMI Based)   True
WMI Monitoring Data and Events

抱歉!评论已关闭.