07/10/2010 Leave a comment
Microsoft Distributed Cache “Velocity” provides a highly scalable in-memory application cache for all kinds of data. By using cache, your application performance can improve significantly by avoiding unnecessary calls to the data source. You know for sharepoint farms caching and session management is one of challenging issue. Sharepoint farms have many servers as application servers, web front end (WFE) servers etc. And using Network load balancing (NLB) services for efficiency. By default your caches are server specfic and you can not use cached data by other WFE servers except which one of them has cached the data.
Velocity offers a custom state provider for your ASP.NET Web applications. This lets Web applications spread objects across the cache cluster, providing scalability. Due to the nature of “Velocity,” objects that you put in must be serializable.
Alternatively you can use SQL Server for SessionState but this solution has some disadvantages.For example performance and high availability are the key points.
- InProc – Fastest, but the more session data, the more memory is consumed on the web server, and that can affect performance.
- StateServer – When storing data of basic types (e.g. string, integer, etc), in one test environment it’s 15% slower than InProc. However, the cost of serialization/deserialization can affect performance if you’re storing lots of objects. You have to do performance testing for your own scenario.
- SQLServer – When storing data of basic types (e.g. string, integer, etc), in one test environment it’s 25% slower than InProc. Same warning about serialization as in StateServer.
You can also use 3rd party distributed caches that Memcached , ScaleOut, NCache,SharedCache some options .
Some advantages of Velocity:
- Scalebility: Velocity provides a cache cluster with multiple hosts and spread cache data between hosts.You can add more servers to the cache cluster.
- High Availablity:The high availability feature in Microsoft project code named “Velocity” supports continuous availability of your cached data by storing copies of that data on separate cache hosts. When you have high availability enabled on a multi-server cluster, your application can still retrieve its cached data if a cache server fails
- Cache Notifications:Microsoft project code named “Velocity” offers cache notifications that allow your applications to receive asynchronous notifications when a variety of cache operations occur on the cache cluster. Cache notifications also provide automatic invalidation of locally cached objects
- Concurrency Models :To help your application deal with concurrency issues, “Velocity” supports optimistic and pessimistic concurrency models
- SessionState Provider: you can share sessions across multiple sites. You can now host your application in multiple sites and have users visit one location to another without losing their sessions.
About Performance of Velocity :
MSDN Magazine Article about Velocity says “Simply put, if accessing the cache is not faster than accessing your database, there is no need to have it. Having said that, what should you expect in terms of performance from a good distributed cache?
1)Copy Client DLL’s to your bin directory
< localCache isEnabled=”true” sync=”TTLBased” ttlValue=”300″ / >
<host name=”bugrapostaci” cacheHostName=”DistributedCacheService” cachePort=”22233″ / >
Into SafeControls tag:
<SafeControl Assembly=”CacheBaseLibrary, Version=188.8.131.52, Culture=neutral, PublicKeyToken=89845dcd8080cc91″ Namespace=”Microsoft.Data.Caching” TypeName=”*” Safe=”True” SafeAgainstScript=”False” / >
<SafeControl Assembly=”ClientLibrary, Version=184.108.40.206, Culture=neutral, PublicKeyToken=89845dcd8080cc91″ Namespace=”Microsoft.Data.Caching” TypeName=”*” Safe=”True” SafeAgainstScript=”False” / >
My Code for sample webpart:
public partial class DistributedCacheClientUserControl : UserControl
protected void Page_Load(object sender, EventArgs e)
DataCacheServerEndpoint servers = new DataCacheServerEndpoint;
////specify cache host(s)
servers = new DataCacheServerEndpoint(“BUGRAPOSTACI”,
//specify cache client configuration
= new DataCacheFactory(servers, true, false);
//get cache client for default cache
DataCache dCache = mycacheFactory.GetDefaultCache();
string cacheContent = dCache.Get(“TestKey”) as string;
Response.Write(“VALUE = “ + cacheContent);
Important :When installing Velocity If your religional settings is different from “en-xx” some language specific characters can be problematic .In my case because of turkish char “i” and “ı” i got exception “url not found” and unable to start cache cluster. I solved this problem with change my religional settings of computer to english and reinstalled velocity .
Important:Velocity client dll’s needs Custom Access Policy configuration when using bin directory copy-paste deployment. I suggest that you should change your “trust” option in your web.config to “Full” instead of using default value of “WSS_Minimal”.
<trust level=”Full” />
Download Microsoft Distributed Cache:
End of article .)