Couple of thoughts while reviving the experience I had with ASP.NET cache, Memcached and Varnish. Memcached and Varnish are the two different caching mechanisms and cannot be compared with each other, though their ultimate goal is to decrease the response time taken by the server to cater the received request.
Following is some insight in their capabilities:
Varnish is a server that runs as a reverse proxy in front of the real webserver (apache, nginx, etc.) and it stores the response of the server separately in memory and could decide to serve it for a subsequent request without passing the request to the backend (the webserver in this context), so simply it's like HTML caching. Varnish saves your dynamic web server from CPU load by making you generate pages less frequently (and lightens the DB load a bit as well). It is focused on HTTP acceleration and it works for unauthenticated traffic, via cookie.
Memcached is distributed caching mechanism to cache data which means that if I have a cluster of servers accessing the cache, all of them are essentially reading from and writing to the same cache. Once an entry is placed in the cache all machines in the cluster can retrieve the same cached item. Invalidating an entry in the cache invalidates it for everyone. It saves DB from doing a lot of read work. Memcached will cache authenticated traffic.
Comparing .NET cache with Memcached, the disadvantage is that accessing a memcached cache requires inter-process/network communication, which will have a small performance penalty over the .Net caches which are in-process. Memcached works as an external process/service, which means that you need to install/run that service in your environment. Again the .Net caches don't need this step as they are hosted in-process. In case of distributed environment, however, out of process caching solution like Memcached is far scalable than in process one like ASP.NET cache.
Note: Generally, websites do deploy both Varnish and Memcached. Varnish, to speed up delivery of its cache hits, and when there is a cache miss the application server might have access to some data in Memcached which will be available to the application faster than what the database is capable of.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.