On Memcached
For some reason, I have not heard much about Memcached in the .Net circles, which is a shame. Memcached is a distributed memory caching system, which makes it very interesting for ASP.Net applications in web farms scenarios (but not just), since the ASP.Net cache is local cache, and can go out of sync with the other caches on the
The basic idea is that a Memcached server is listening on a port, and you set and get data from it. So far, it is not very exciting, but the nice part is that there everything is in memory, and that you can use multiply Memcached server to increase the cache size indefinitely very cheaply. Because everything is done in memory, and the server is carefully designed to hold no locks, the performance is really impressive.
An interesting scenario is to take couple hundreds of megabytes from each computer in the organization, and use that to fuel the cache size for the servers. Memcached has automatic failover support, so you can just ignore Memcached server going offline for a period of time, and it is very low on CPU usage.
I intended to write a bit more about it, but I found this article, that explains how it works, and it even have some pretty pictures, so it is pretty useless for me to try. :-)
A couple of interesting points Memcached:
- It runs out of process, so it is not affected by IIS Reset, restarting the application, etc. This is very important if you rely on a cache for good performance, and especially if you application startup loads big amounts of data. This is very important in development, since we can safely skip this initialization step when we are developing.
- Memcached can cache any byte stream, which means that in .Net, it can hold any serialized object
- It is one of the options for NHibernate's caching, and the recommended one for use in web farms. This make it very attractive to me, since I can flip a switch and start using it, without touching my code.
- Make sure that you set it up in a way that makes maping highly unlikely (in other words, if you put it on a 1Gb machine, don't tell it to cache 2Gb), there is no point in paging in a caching server.
- Using Memcached can significantly reduce your database load, turning it into a mostly write store.
- Many people seem to be using Memcached as a fast storage engine for interesting data that shouldn't be persisted. Caching calculation, behavioral patterns, etc.
I'll just add that Memcached servers exists for unix and windows, and there are client APIs for just about anything, including .Net.
Comments
Comment preview