Troubleshooting Distributed Cache in SharePoint Server 2013

The Distributed Cache plays an important role in SharePoint Server 2013 as it’s a key component for performance and caching. Distributed Cache is not a SharePoint service, it’s a standalone service called AppFabric 1.1 for Windows Server. SharePoint Server 2013 requires Windows Server App Fabric and the App Fabric 1.1 CU 1 (KB 2671763) to be installed .It takes care and improves the performance of the following features in SharePoint Server 2013:

  • Authentication
  • Newsfeeds
  • OneNote client access
  • Security Trimming
  • Page load performance

It’s always quite comfortable to manage Distributed Cache in SharePoint Server 2013 using PowerShell and the same applies while troubleshooting it also .This articles discusses on the useful PowerShell commands that can be used to troubleshoot Distributed Cache service in SharePoint Server 2013.

                     Command                    Explanation
                  Use-CacheCluster This is used to enable cache administration via PowerShell.
                  Get-CacheHost This would get you the list of every server in the cluster as well as the state of the service on that server.
      Get-CacheHostConfig <HostName> <Port> This would give you the general configuration details about a specific host in the cache cluster. All Windows Server AppFabric cache hosts use TCP/IP to communicate with each other and support the cache cluster. The SharePoint distributed cache is an AppFabric cache behind the scenes and  it uses the default AppFabric ports for server to server communication. These ports should be allowed through your firewalls for the cacheservice  to function correctly.
           Get-CacheAllowedClientAccounts This would tell which accounts/groups have rights to connect to the cache cluster as clients. This seems to be the standard configuration in SharePoint 2013.
                   Get-Cache Gets a listing of all the default caches in the farm. All caches have the Id (Guid) of the farm appended to the name.
       Get-CacheConfig <CacheName> Gives you the details about a specific cache instance
         Restart-CacheCluster This will restart the distributed cache service on all servers in the cluster and it will also clear the contents of the cache.
  Stop-SPDistributedCacheServiceInstance -Graceful This will stop the distributed cache service on an individual machine. The Graceful parameter will allow the cache service to migrate cached items to another host in the cluster.
 Remove-SPDistributedCacheServiceInstance Removes a cache host from the cluster. The best practice is to stop the cache service before you remove it.
  Add-SPDistributedCacheServiceInstance This command will add the cache host back to the cluster. If there is more than one host in the cluster, it will take a few minutes for the service to start and for any cached items to be synchronized to the new host.
   Get-CacheClusterHealth  Returns health statistics for all of the named caches in the cache cluster.
    Clear-CacheLogging  This command is used to disable all logging for the current admin
    Get-CacheStatistics Gives the statistics for a Cache or for a Cache Host.
     Start-CacheHost This would start the Caching Service on the specified cache host. If no cache hosts are up in the cache cluster, use the Start-CacheCluster command instead
     Stop-CacheCluster Stops the Caching Services on all cache hosts in the cluster.
    Stop-CacheHost Stops the specified cache host service.
   Test-CacheConfigAvailability Tests the connection with the cache cluster configuration store. This command will throw an exception if the connection fails.

In addition to the commands listed above there are couple of other things which you’re supposed to know while troubleshooting Distributed Cache Service/App Fabric.

  1. Query AppFabric for Caching Servers/Statuses :

To get the list of servers that AppFabric thinks there should in the cluster run “Get-CacheHost” (use “Use-CacheCluster” if necessary). This command gives us the list of the servers and also their availability status as far as AppFabric’s concerned.

  1. Query SharePoint for Caching Servers/Statuses :

To do the same for SharePoint, run:

Get-SPServiceInstance | ? {($_.service.tostring()) -eq “SPDistributedCacheService Name=AppFabricCachingService”} | select Server, Status

This will give you the same kind of data but from SharePoint perspective.  Make sure all the servers show the status as “Online” but more importantly that both SP & AF have the same names between them. If you see “cacheHostInfo is null” somewhere then it’s quite likely there’s a mismatch here.

What if one or more App Fabric Service Instance is disabled?

Run the below mentioned PowerShell command …..

Get-SPServiceInstance | ? {($_.service.tostring()) -eq “SPDistributedCacheService Name=AppFabricCachingService”} | select Server, Status

If any status shows as “disabled” then we have a problem and in that case please perform the below mentioned steps:

  1. Remove the service-instance (see above).
  2. Try re-adding it with Add-SPDistributedCacheServiceInstance
  3. Verify the new service-instance is “online”.

If for some reason Add-SPDistributedCacheServiceInstance doesn’t give you a healthy endpoint, try running Remove-SPDistributedCacheServiceInstance then Add-SPDistributedCacheServiceInstance on the server in question. If you still can’t get a healthy endpoint then it needs some serious consideration.

 

Command to Stop and Start the Distributed Cache service:

To start the Distributed Cache service by using Windows PowerShell:

At the Windows PowerShell command prompt, run the following command:

$instanceName =”SPDistributedCacheService Name=AppFabricCachingService”

$serviceInstance = Get-SPServiceInstance | ? {($_.service.tostring()) -eq $instanceName -and ($_.server.name) -eq $env:computername}

$serviceInstance.Provision()

To stop the Distributed Cache service by using Windows PowerShell :

At the Windows PowerShell command prompt, run the following command:

$instanceName =”SPDistributedCacheService Name=AppFabricCachingService”

$serviceInstance = Get-SPServiceInstance | ? {($_.service.tostring()) -eq $instanceName -and ($_.server.name) -eq $env:computername}

$serviceInstance.Unprovision()

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s