Sunday, December 29, 2013

SharePoint 2013 Distributed Cache Roundup and Dev VM Turbo Boost

Mike Marnocha, Technology Director, CMS & Web Platforms

I recently had issues with the Distributed Cache in SharePoint 2013 and wanted to share some information on this topic to help others that may be lost in an App Fabric nightmare. At the end of this post we will use the information we learned to build a script to turbo boost your development VM.


App Fabric 1.1 is a Windows Server technology that essentially lets you have a large pool of memory to use as a cache that is combining memory from multiple servers. Distributed Cache Service is a customized version of Windows App Fabric deployed in SharePoint 2013.

Here is a good introduction to the Distributed Cache -

For more Architecture and Configuration take a look at this -

The Setup

Here is a great trick to play on your SharePoint administrator if you want to make them angry. Tell them you think there is a problem with the Distributed Cache in the farm and they should check the cache with this PowerShell command: Get-CacheHost

They will receive an error message like this and begin to panic:

Get-CacheHost : ErrorCode<ERRPS013>:SubStatus<ES0001>:Error: No valid cluster settings were provided with Use-CacheCluster.

Ok, before your administrator or you start restarting services and trying to fix this, here is why you get the error. Chances are nothing is wrong, you just want to run this command prior to Get-CacheHost: Use-CacheCluster

Use-CacheCluster tells PowerShell to get the configuration or settings for your Cache Cluster so that subsequent commands know what to look for. If you run the Get-CacheHost command following Use-CacheCluster you should see something like this:

PS C:\Users\administrator.DEV> Get-CacheHost

HostName : CachePort    Service Name            Service Status Version Info

--------------------    ------------            -------------- ------------ AppFabricCachingService UP             3 [3,3][1,3]

Common Issues

The SharePoint Health Analyzer can be the first sign that you might have an issue with Distributed Cache. If you are having issues during installation, here are a few common things to look at:

  1. Installation Account permission or Group Policy settings restricting access to file system or registry. Use a tool like Process Monitor to see errors. Specifically in one environment I had to modify permissions on the file C:\Program Files\AppFabric 1.1 for Windows Server\ DistributedCacheService.exe.config
  2. Firewalls may be blocking communication between the servers to access the cache. One quick fix if using Windows Firewall would be the following command:
    • Set-NetFireWallRule -DisplayName "File and Printer Sharing (Echo Request - ICMPv4-In)" -Enabled True
  3. Network Connection settings could be causing communication issues between servers. I’ve seen posts on this where dns settings were different on the network adapter causing communication issues. Make sure servers are configured properly.
  4. Previous versions of App Fabric can cause issues. SharePoint requires version 1.1 and as part of pre-requisite you should uninstall 1.0 if it existed. Also stay away from custom code using the same cluster as SharePoint as that is not supported.
  5. Running the cache on servers running other non-recommended services such as Excel Services, Search, or Project. Per this article you should not run these on the same servers that are part of the cluster -
  6. Stopping the Distributed Cache on a single server can lead to issues. To remove a server from the cluster you would run the following commands on the server you want to remove:
    • Stop-SPDistributedCacheServiceInstance –Graceful
    • Remove-SPDistributedCacheServiceInstance
  7. Utilizing dynamic memory on VMs is not supported.

Here is a good article on some helpful commands to be aware of -

Here is a 5 minute cheat sheet on Distributed Cache -

VM Turbo Boost

Ok, now to the fun part boosting performance of your VM. You now know how to manage and configure your Distributed Cache and start doing development or testing on a development virtual machine. After a while your server starts to get slow and you notice your memory is low and CPU is high likely because it is switching context between all of these powerful services in SharePoint 2013. The top 4 consumers of your memory and processor are: SQL Server, IIS (w3wp.exe), Search (noderunner.exe), and Distributed Cache Service.

If you run this script it will restart each of these, free up memory and clean out processing that is no longer needed. Open PowerShell as an administrator when you run this, I’d recommend saving to a TurboBoost.ps1 file that you can easily access when needed:

   2:  if((Get-PSSnapin Microsoft.Sharepoint.Powershell -ErrorAction SilentlyContinue) -eq $null)
   3:  {
   4:      Add-PSSnapin Microsoft.SharePoint.Powershell;
   5:  }
   7:  #Restart IIS process
   8:  iisreset
  10:  #Restart Timer and Search Services
  11:  Restart-Service -displayname "SharePoint Timer Service"
  12:  Restart-Service -displayname "SharePoint Server Search 15"
  13:  Restart-Service -displayname "SharePoint Search Host Controller"
  15:  #Stop the Distributed Cachce
  16:  Stop-SPDistributedCacheServiceInstance -Graceful
  17:  # Start the Distributed Cache service by using Windows PowerShell            
  18:  $InstanceName = "SPDistributedCacheService Name=AppFabricCachingService";            
  19:  $serviceInstance = Get-SPServiceInstance | ? {($_.service.tostring()) -eq $instanceName -and ($ -eq $env:computername}            
  20:  $serviceInstance.Provision(); 
  22:  #Check to see that Cache is up and running
  23:  Use-CacheCluster
  24:  Get-CacheHost
  26:  #Restart SQL Server Agent and Database - assumes your database is default instance, modify as needed
  27:  net stop SQLSERVERAGENT
  28:  net stop  MSSQLSERVER
  29:  net start  MSSQLSERVER
  30:  net start SQLSERVERAGENT

The script should work on your local virtual machine, Azure, Cloudshare, or internally hosted solution. The search restart takes a few minutes and you will have to go to your websites or run a warm up script for the first time before you reap the turbo boost benefits. Schedule it to run periodically or as needed as you start to see performance issues.