How to Use Locking in a Distributed Cache for Data Consistency?

Businesses today are developing high traffic ASP.NET web applications that serve tens of thousands of concurrent users. To handle this type of load, multiple application servers are deployed in a load balanced environment. In such a highly concurrent environment, multiple users often try to access and modify the same data and trigger a race condition. A race condition is when two or more users try to access and change the same shared data at the same time but end up doing it in the wrong order. This leads to high risk of loosing data integrity and consistency. This is where distributed lock mechanism comes in very handy to achieve data consistency.

Continue reading

Posted in Distributed Cache | Tagged | Leave a comment

How is a .NET Distributed Cache Superior to Key Value Store?

ASP.NET web applications, .NET web services applications, and other .NET server applications need to handle extreme transaction loads without slowing down. And, although their application tier scales linearly, the data storage and database tier does not scale and therefore becomes a bottleneck. As a result, the entire application cannot scale.

Originally, simple in-memory distributed key-value stores like Memcached and later Redis were introduced on Unix/Linux platforms to help resolve this scalability problem. They quickly became quite popular mainly because they provided linear scalability just like the application tiers and removed the database bottleneck.

Continue reading

Posted in Cache dependency, CLR procedures, Distributed Cache, LINQ Query, Uncategorized | Leave a comment

NCache Celebrating 10 Years of Success

ncache-10-years

A Look Back and Our Future Vision

The Launch

With enthusiasm and stars in our eyes, NCache was launched in July 2005. And wow have we all come a long way since then!  We’ve grown up with the .NET community and its adoption of caching solutions.  Back then, caching was pretty new for .NET.  I remember we wrote articles, created slideware, went to shows, meetups and prospects everywhere educating developers and managers about the benefits of caching, how to architect it and what it can do for the enterprise.  At the time, .NET itself was not used as much in high transaction, high traffic applications as it is today. But it took hold.

Continue reading

Posted in News | Leave a comment

Microsoft Ends AppFabric Support, NCache Keeps on Going!

Update: Microsoft has extended the AppFabric support to April 11th 2017. The extension is only applicable for AppFabric 1.1 and not for 1.0. For more information check out their blog post.

April 2nd 2016 (April 11th 2017) is proving to be an important date for Alachisoft’s product NCache. This is the date when Microsoft ends AppFabric support – essentially withdrawing the product from the market. See details on Microsoft AppFabric 1.1 for Windows Server Ends Support 4/2/2016

AppFabric was Microsoft’s answer to .NET industry’s need for an in-memory distributed cache to provide performance and scalability boost for .NET server applications. But, first it was late to the party with AppFabric 1.0 released in June 2010 (five years after NCache). And, second, it struggled to provide the features and functionalities considered de rigueur for in-memory distributed caches. Eventually, Microsoft decided to pull the plug on a product that essentially provided less features than other .NET caching solutions like NCache.

Read AppFabric vs NCache comparison and see for yourself how much AppFabric lacked in features and capabilities.

Continue reading

Posted in ASP .NET performance, ASP.NET Cache, Distributed Cache | Tagged , | 1 Comment

In-Memory NoSQL – Improve .NET App Scalability

Modern day .NET applications must be well equipped to cope with the scalability demands being put on them due to the explosion of ASP.NET web applications reaching millions of users, WCF web services applications handling Internet of Things (IoT) devices, and Big Data analytics applications processing huge amounts of data. Scalability here means to maintain the same high performance under extremely heavy loads that you see with no load.

The architectures of these .NET applications are very scalable because you can add more app servers as you need higher transaction loads. But, the problem is with data storage, especially relational databases like SQL Server and Oracle, and mainframe. Basically, data storage is unable to scale in the same manner as the application tier.

Continue reading

Posted in NoSQL In-memory Datastore | Tagged , , , , | Leave a comment

How .NET Cache Improves Performance and Scalability?

Some of the very basic needs for .NET applications to stay competitive in today’s market are to be extremely responsive and scalable. The bottleneck in the way of achieving these benchmarks is your relational database.

This is a two fold bottleneck, first the reads from disk are very inefficient and time consuming. Secondly, you cannot scale out the database tier by adding more database servers. Whereas if you have a .NET distributed cache, it provides fast data access because it is in-memory and it can also scale linearly the same way your application tier does.

NCache is a .NET distributed cache that provides performance and scalability for your applications. It comes with a rich set of features including but not limited to cache elasticity, high availability, data replication, seamless integration with existing technologies and ease of management. Lets just focus on performance and scalability, as identified in the beginning. These are two fundamental metrics needed by .NET applications to survive in today’s world. Let’s see how NCache is positioned to cater for both.

NCache gets its performance edge over relational database because it keeps its data in memory and not on the disk. The performance boost over relational databases is ten times or higher depending on your hardware and .NET cache positioning in the network. For example if you deploy NCache as a local in-proc cache in your environment, the data access becomes lightning fast.

And the way NCache provides scalability is by allowing you to add more cache servers when your transaction load grows. So, if you see that your application getting overwhelmed by transaction load, just add a new cache server at run-time. You don’t even have to stop your application for this. With this new cache server added, you have the ability to serve more requests and all of this happens transparent to the user. Now, that’s what I mean by scalability.

ncache-architecture

 

There are a number of caching topologies that NCache offers to choose from depending on your specific need. The caching topology defines how your data is stored and the way individual cache servers in the cluster interact with one another. For example, Partitioned Cache, Partition-Replica Cache, Replicated Cache, and Mirrored Cache are the caching topologies.

If your primary concern with your .NET cache is scalability and not reliability you can use the ‘Partitioned Cache’ topology. On the other hand, if your primary focus is to get reliability and not scalability you should go for the ‘Replicated Cache’ topology. The ‘Partition-Replica Cache’ is the combination of both of these and gives you the best of both worlds. It provides you with reliability and scalability at the same time with some trade offs.

I would like to conclude by saying that if you want your application to be at par with the growing needs of performance and scalability, .NET distributed cache is the way to go.

Posted in .NET 4.0 Cache, ASP.NET Cache, Distributed Cache | Tagged , , | Leave a comment

Couchbase Alternatives Open Source Distributed Cache

The database tier based on traditional RDBMS has proven to be the biggest bottleneck in the way of achieving competitive response times for applications. This has forced the application vendors to look for alternatives that can provide improved performance. One such alternative is storing data in a distributed cache.

From the available cache technologies you need to pick one that answers most if not all of the major questions asked in this domain. Going forward I will be comparing two products in this arena, Couchbase and NCache – Open Source Distributed Cache.

1 – ASP.NET Sessions

ASP.NET Session State caching has come a long way starting from keeping the session information in-memory on the Web server (default), to having it on a State server, to storing it on a SQL server. All of these have one limitation in common and that is the Single Point of Failure. Session state is lost if any of the following happens: Web server goes down, the State server goes down or the SQL server goes down.

To answer all these concerns NCache provides a solution by saving session state in its Open Source Distributed Cache. Since it’s distributed there is no single point of failure. Despite its importance Couchbase does not support saving ASP.NET sessions.

2 – ASP.NET View State

ASP.NET uses View State to store pages, controls and custom values between multiple HTTP requests. In some cases where we have complex controls on a page e.g. Data Grid Control, the string representing the View State grows very large. In such a case you would be using extra bandwidth to pass this string back and forth without any real benefit, in addition you are opening up a loop hole with regards to security.

What are the ways to address these issues ? All we need to have is a distributed cache that can store the View State text and pass back an identifier that can be used to retrieve our View State from the store. NCache provides this exact functionality in form of ASP.NET View State Caching whereas Couchbase does not.

3 – Memcached Smart Wrapper

NCache provides support to integrate with Memcached in a transparent way using Memcached integration.

Let me just say a few words about Memcached, it is a popular distributed cache that is being used in the market but offers very basic caching features. It does not provide any support for high availability, data replication, cache elasticity, and ease of management.

Couchbase does not provide any such integration, so to be able to adapt to Couchbase for someone using Memcached there is only one way; Rewrite your code from scratch!

4 – Security & Encryption

One of the fundamental requirements of applications needing fast response times is that the data be secured. This makes security and encryption must haves for providers of distributed caching.

NCache is well equipped to provide support for both of these features in a comprehensive manner, Couchbase on the other hand fails to provide support for data encryption and active directory/ LDAP authentication. Read more on NCache encryption here.

5 – Read-through & Write-through

Read-through means that your application always asks the cache for data and the cache gets it from your data source if it doesn’t have it and caches this data for future accesses. This simplifies your application code greatly because cache API is very simple to use in comparison to the database.

Similarly write-through allows your application to write to the cache and the cache then writes the same data to the database either synchronously or asynchronously. Both these features facilitate you to have the cache as your enterprise data store and have all applications read from it and write to it.

NCache provides full support for both Read-through and Write-through but Couchbase fails to do so and hence lags behind NCache here as well. More on Read-through & Write through.

Further Reading

For feature by feature comparison of Couchbase with NCache please take a look at the following link:

Couchbase vs. NCache

Posted in Distributed Cache, Open Source Distributed Cache, Product Comparison | Tagged , , , | Leave a comment

AppFabric Alternatives Open Source Distributed Cache

Looking for Appfabric Alternatives?

Today’s applications need to scale and handle extreme data loads due to explosion of web technologies and Internet of Things. The biggest bottleneck in the way of achieving this is the data tier with relational databases. The need of the hour is to be able to make this data available to applications in a faster and more efficient way.

You can achieve this by using distributed caching of data that facilitates faster response times. There are a few big names in this domain with less than competitive products, e.g. Microsoft with their AppFabric caching product. In contrast to this NCache is an Open Source Distributed Cache that offers cutting edge technology and features.

An interesting point to note here is that Microsoft is no longer pushing AppFabric in their flagship cloud environment called Microsoft Azure. Instead, they’re recommending another Open Source cache called Redis (read NCache vs Redis Comparsion). Why Microsoft chose to do so will become clearer as you read this article.

Appfabric Alternative

In the next few paragraphs, I’m taking a somewhat detailed look at some of the core differences between NCache and AppFabric.

1 – High Availability of Cache (Peer to Peer Architecture)

A distributed cache runs in your production environment and as part of your application deployment. Therefore, you should treat it just like a database when it comes to high availability requirements.

Any distributed cache that does not provide a peer to peer architecture for the cache cluster becomes very limiting. AppFabric does not provide such a clustering architecture and therefore is not as flexible as NCache for providing high availability. NCache provides a truly peer to peer clustering.

2 – Synchronization with Data Sources

A very core requirement of caching data is to keep it from getting stale. In plain simple words this means that the cache needs to refresh its data every time there is an update or remove operation in the master database. NCache provides a very strong mechanism to do this called “Data Synchronization” through three types of dependencies:

  •           SqlDependency (SQL Server 2005-2012 events)
  •           OracleDependency (Oracle events)
  •           Db Dependency (polling for OLEDB databases)

This is a feature that AppFabric lacks even though it is core to a powerful distributed cache.

3 – WAN Replication

As the name suggests, WAN replication deals with the availability of data in geographically dispersed data centers. NCache provides powerful WAN replication capability for its distributed cache in the following data center configurations:

  •        Active – Passive
  •        Active – Active

The first case is applicable to the situation where you want to have one data center to handle all user requests i.e. Active data center. And at the same time have a backup data center for disaster recovery, i.e. Passive data center. All the data operations on the active data center are replicated to the passive data center asynchronously. So that if the active DC goes down the passive will become active and start serving user requests.

The second case is applicable to the situation where you want to have two active data centers serving users in their nearby geographical area. Since both DCs are active, data would be getting replicated in both directions. So that if a need arises to reroute all traffic to one data center, in case one of the DCs is overwhelmed or goes down, it can be done without any data integrity issues.

AppFabric fails to provide this very much needed functionality at all levels.

4 – Search Cache with SQL

The real power of a cache lies in the fact that once it has the data, it should be made easily searchable and accessible. NCache comes with very handy tools to accomplish this task. Here they are:

  •        Object Query Language (OQL)
  •        Group-by for Queries
  •        Delete Statement in Queries
  •        LINQ Queries

AppFabric does not provide any of this and hence lacks behind NCache on this avenue as well.

5 – Memcached Smart Wrapper

NCache provides the ability to integrate with Memcached in a seamless way using Memcached integration.

For those of you not familiar with Memcached, it is a popular distributed cache that is being used in the market but offers very basic caching features. Does not provide any support for high availability, data replication, cache elasticity, and ease of management.

AppFabric does not provide any such integration, so to be able to adapt to AppFabric for someone using MemCached there is only one way; Rewrite your code from scratch!

6 – Cache Size Management – Priority Evictions

To be able to use memory available to the cache efficiently we have the concept of evictions. Simply put it means to remove relatively old data from the cache so that we may have space for newer items. There are a number of algorithms that NCache employs to carry out this important task, such as:

  •        Least Recently Used (LRU) Evictions
  •        Least Frequently Used (LFU) Evictions
  •        Priority Evictions
  •        Do Not Evict Option

Each of these options has its own advantages and disadvantages over others, with one being most suitable for a particular use case. AppFabric only supports LRU evictions; this is a big limitation as some scenarios might demand to keep older data and to evict using some other matrix.

Further Reading

For feature by feature comparison of NCache with AppFabric please take a look at the following link: AppFabric vs NCache

Also read: Step-by-Step Appfabric Migration

Posted in Distributed caching, Open Source Distributed Cache, Product Comparison | Tagged , , , | 1 Comment

Redis Alternatives Open Source Distributed Cache

Redis is an in-memory key value store developed in C/C++ with clients for various programming languages like .NET, Java and C. Redis has features to tackle critical issues but falls short in some fundamental aspects. NCache – a .NET distributed caching solution on the other hand when compared with Redis answers all these concerns effectively and also provides additional features that are absent in Redis making it an ideal replacement.

The demand for high speed data access along with its integrity and fault tolerance is ever increasing in the contemporary application arena. Traditional disk based RDBMS systems have failed to answer these concerns in a comprehensive manner. This paved way for in-memory data solutions that cover all the bases listed above.

Here’s why you want to use NCache as an alternative to Redis.

1 – WAN Replication

First and the foremost Redis has no support for WAN replication of the cached data. The need for this feature becomes indispensable when your application is deployed in multiple data centers across the country or world. NCache provides powerful WAN replication capability for its distributed cache in the following data center configurations:

  •        Active – Passive
  •        Active – Active

The first situation is suitable when you have an active data center and a disaster recovery backup data center. The backup data center only becomes active if the active one goes down. And, for this to be possible, the distributed cache must be replicated to the passive data center so it is available when the data center becomes active.

The second situation is applicable where you have two active data centers serving geographically dispersed users so as to improve their access time. And, you want the ability to either reroute some of the traffic from one data center to another in case of overflow. Or, one of the data centers goes down and you want to route all its traffic to the other one.

In this second case, you need the distributed cache updates from both data centers to be replicated to the other ones and also handle conflict situations. This is the capability that NCache provides which Redis does not support.

2 – Security & Encryption

Many of the applications needing a distributed cache are dealing with sensitive and highly confidential data. Therefore, security and encryption are two areas that hold fundamental importance when talking about data storage and retrieval.

Redis is lacking support for both of these neither authentication nor encryption. NCache in contrast provides support for authentication and authorization through Active Directory / LDAP. NCache also provides very strong encryption options to encrypt the stored data. Here they are:

  •        3DES
  •        AES-128
  •        AES-192
  •        AES-256

Read more on NCache encryption here.

3 – Read-through & Write-through

Read-through and write-through are familiar concepts in the domain of distributed caching. But for people starting to get familiarized with caching it won’t hurt to give a brief definition for these.

Read-through means that your application always asks the cache for data and the cache gets it from your data source if it doesn’t have it. So, this simplifies your application code greatly because cache API is very simple to use in comparison to database.

Similarly write-through allows your application to write to the cache and the cache then writes the same data to the database either synchronously or asynchronously.

Both these features allow you to designate the distributed cache as your enterprise data store and have all applications read from it and write to it. And, the cache then deals with the database. This results in the cache always being synchronized with your database.

Despite its importance Redis lacks this feature but NCache covers it in length and breadth.

4 – Cache Administration

The effectiveness of distributed cache also depends on your ability to administer and monitor it through user friendly GUI tools. In this regard, Redis does not provide any GUI tools for its cache administration or monitoring. The only things available to you are the command line tools.

On the other hand, NCache provides powerful GUI based tools like NCache Manager and NCache Monitor for cache administration and monitoring. Some people however prefer to use command line tools because you can use them in scripts for automation. In this regard, NCache also provides all the cache administration through command line tools.

5 – ASP.NET View State Caching

View State is a powerful mechanism that ASP employs to store pages, controls and custom values between multiple HTTP requests across client and the server. This View State is passed in form of an encrypted text which becomes very large in cases involving forms with lot of controls, Data Grid control, or some other complex controls. This raises two concerns:

  •        Security risk
  •        Bandwidth usage

Both of these concerns will be answered if we have a distributed cache that can store the View State text and passes back an identifier that can be used to retrieve our View State from the store. NCache provides this exact functionality in the form of ASP.NET View State Caching whereas Redis does not.

6 – Memcached Smart Wrapper

Memcached is a popular distributed cache that is being used by a host of applications to benefit from the performance boost being discussed herein. It however has a number of limitations in the areas of high availability, data replication, cache elasticity, and ease of management.

The easiest way to address these issues for the customers using Memcached is to use NCache’s Memcached integration, such that the users can plug-in NCache to their existing Memcached applications without any code change. The users only need to change their application configuration files to take advantage of NCache’s distributed caching system.

Redis does not provide any such integration and hence falls behind on this as well.

Further Reading

For feature by feature comparison of NCache with Redis please take a look at the following link:

Redis vs. NCache

Posted in Open Source Distributed Cache, Product Comparison | Tagged , , , , , | 2 Comments

ASP.NET View State Caching in Microsoft Azure for Better Performance

ASP.NET View State is a client side state management mechanism, which is used to save page and control values. ASP.NET View State is a hidden field on the page as an encoded Base64 string. It is sent to client as part of every response and is returned to the server by the client as part of a post back.

<input id="__VIEWSTATE" type="hidden"
name="__VIEWSTATE" value="wEPDwUJNzg0MDMxMDA1D2QWAmYPZBYCZg9kFgQ
CQ9kFgICBQ9kFgJmD2QWAgIBDxYCHhNQcm2aW91c0NvbnRyb2xNb2RlCymIAU1pY3
Jvc29mdC5TaGFyZVBvaW50LldlYkNvbnRyb2xzLlNQQ29udHJbE1vZGUsIE1pY3Jv
29mdC5TaGFyZVBvaW50LCBWZXJzaW9uPTEyLjAuMC4wLCBDdWx0dXJlPW5ldXRyWw
sIFB1YmxpY0tleVRva2VuPTcxZTliY2UxMTFlOTQyOWMBZAIDD2QWDgIBD2QWBgUm
Z19lMzI3YTQwMF83ZDA1XzRlMjJfODM3Y19kOWQ1ZTc2YmY1M2IPD2RkZAUmZ18yN
DQ3NmI4YV8xY2FlXzRmYTVfOTkxNl8xYjIyZGYwNmMzZTQPZBYCZg8PZBYCHgVjbG
DQWBgUmZ19lMzI3YTQwMF83ZDA1XzRlMjJfODM3Y19kOWQ1ZTc2YmY1M2IPD2...."/>

Problems with ASP.NET View State in Microsoft Azure

ASP.NET View State is a very important feature for applications deployed as web/worker roles in Microsoft Azure Cache. But, View state comes with some issues that you need to understand and resolve in order to take full benefit from it.

First of all, ASP.NET View State becomes very large especially when your Microsoft Azure ASP.NET application has a lot of heavy controls on its pages. This results in heavy view state payload which travels back and forth between browser and your application on each request. Heavy view state payload slows down performance and also results in extra bandwidth consumption especially when an average ASP.NET View State ends up in 100’s of kilobytes and when millions of such requests are processed within your Microsoft Azure application.

ASP.NET View State is also a security risk when sending confidential data as part of view state to client. This data is vulnerable to attacks and can be tampered with by an attacker, which is a serious security threat.

Solution to ASP.NET View State Problems

You can resolve ASP.NET View State issues in Microsoft Azure applications by storing the actual ASP.NET View State on the server side in a distributed cache and never send it back to browser along with request payload.

NCache for Azure is an extremely fast and scalable distributed cache for Microsoft Azure. It allows you to store actual ASP.NET View State in Distributed Cache on server side and instead send a small token as view state to the client in a request payload. This dramatically reduces the request payload size. View State token is then used on the server side to find the right ASP.NET View State in NCache for Azure Distributed Cache on post backs. A smaller payload resolves issues related to performance and bandwidth utilization because you are not dealing with huge view state anymore on each request in your Microsoft Azure Application. Moreover, View State stored on the server side in NCache for Azure distributed cache is never exposed to clients so it addresses the above mentioned security concerns.

Here is an example of a token being used in place of ASP.NET View State with NCache for Azure ASP.NET View State provider:

<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE"
value="cf8c8d3927ad4c1a84dsadfgsdsfdsda7f891bb89185" />

Using NCache for Azure ASP.NET View State Caching

Step 1: Create an app.browser file in App_browsers directory. Plug in page adapters in the app.browser file as follows:

   File: App_browsersapp.browser 

<browser refID="Default">
    <controlAdapters>
        <adapter controlType="System.Web.UI.Page"
            adapterType="Alachisoft.NCache.Adapters.PageAdapter" />
    </controlAdapters>
</browser>

Step 2: Add the following assembly reference in compilation section of web.config file.

   File: web.config

<compilation defaultLanguage="c#" debug="true" targetFramework="4.0">
    <assemblies>
        <add assembly="Alachisoft.NCache.Adapters, Version=1.0.0.0,
            Culture=neutral, PublicKeyToken=CFF5926ED6A53769"/>
    </assemblies>
</compilation>

Step 3: Register NCache for Azure config section in your web.config file.

   File: web.config

<configSections>
    <sectionGroup name="ncContentOptimization">
        <section name="settings"
            type="Alachisoft.NCache.ContentOptimization.Configurations.ContentSettings"
            allowLocation="true" allowDefinition="Everywhere"/>
    </sectionGroup>
</configSections>

Step 4: Specify settings for your config section in web.config file (that was registered above). These settings control NCache for Azure ASP.NET View State Caching features.

   File: web.config

<ncContentOptimization>
    <settings viewstateThreshold="12" enableViewstateCaching="true"
        enableTrace="false" groupedViewStateWithSessions="false"
        <cacheSettings cacheName="myCache"
             maxViewStatesPerSession="3">
        <expirationtype="Absolute" duration="1"/>
        </cacheSettings>
    </settings>
</ncContentOptimization>

Conclusion

NCache for Azure provides a no code change option for your Microsoft Azure applications to store ASP.NET View State on the server side in a Distributed Cache. NCache for Azure ASP.NET View State provider optimizes performance by reducing request payload and bandwidth consumption while addressing security issues related to client side View State.

Download NCache Open Source and run it on Microsoft Azure.

Posted in ASP .NET performance, ASP.Net, ASP.NET View State, Distributed Cache, Microsoft Azure | 2 Comments