Friday, 25 October 2019

SharePoint Distributed Cache

Distributed Cache Service in SharePoint 2013

What is Distributed Cache in SharePoint 2013:  The SharePoint Distributed Cache service is an additional caching mechanism introduced in SharePoint 2013 to support beyond the options that already exist (such as Object Cache, BLOB Cache, and Page Output Cache) from the earlier versions of SharePoint. Distributed cache enables to quickly retrieve data without any dependency on SQL databases, as everything is stored in memory.  The Distributed Cache service provides caching services for several features in SharePoint Server 2013. Some of the features that use the Distributed Cache service include:   
  • News feed 
  • Authentication 
  • OneNote client access 
  • Security Trimming 
  • Page load performance 
How to Install SharePoint Distributed Cache?  The good news is: You don't have to do anything to get distributed cache service features! When you install SharePoint 2013, distributed cache gets installed and configured automatically! The Distributed Cache service is built on Windows Server AppFabric, which is a required component for SharePoint 2013 and is installed as part of the SharePoint 2013 prerequisite installer.  Distributed Cache service - Hosts - Cluster and Modes: Any server in the farm running the Distributed Cache service is known as a cache host. A cache cluster is the group of all cache hosts in a SharePoint Server 2013 farm. A cache host joins a cache cluster when a new application server running the Distributed Cache service is added to the farm. When using a cache cluster, the Distributed Cache spans all application servers and creates one cache in the server farm. Distributed Cache service can be deployed in two modes:   
  • Dedicated mode 
  • Collocated mode. 
When running in dedicated mode, the Distributed Cache service is started and all other services are stopped on the server. In collocated mode, the Distributed Cache service is running along with other services on the server. For large-scale production use, the recommendation is to have dedicated servers hosting your cache.  If you have over 10000 users, you should look into a dedicated server (dedicated mode) Distributed Cache.   Should I Start Distributed Cache Service in All Servers of the Farm? The Distributed Cache is started and run on all WFE and APP servers by default. Running distributed cache on an already overtaxed server, such as SQL Server, Search services, Excel Services, or Project Services, negates any benefit you may garner out of distributed cache. As per Microsoft: When the Distributed Cache service runs on a server together with other services and the server's memory resources near 95% utilization, the Distributed Cache will start throttling requests. This means that the Distributed Cache service will no longer accept read and write requests until the server utilization reduces to approximately 70% utilization    If your farm is having four or more servers, starting distributed cache service in all servers results performance degrade, as per this Technet article https://technet.microsoft.com/en-us/library/jj891124.aspx  Get Distributed Cache Cluster-Servers: Use this cmdlets to retrieve current cache setup:   
1 
2 
Use-CacheCluster 
Get-CacheHost 
This gets you the cache hosts, their ports, service status and version info.  How to Add Distributed Cache on a new server: You can add a server to distributed cache host by running the cmdlet:   
1 
Add-SPDistributedCacheServiceInstance 
Verify the distributed cache Service:   
  • Go to: Central Administration >> Services on server >> Pick the relevant server >> Check Distributed cache service must be in Started state. 
  • Open Windows Services console (services.msc) > Locate "AppFabric Caching service">> Make sure its Started. 

Memory Allocation for Distributed Cache: A minimum of 8 GB and maximum of 16 GB can be allocated to the Cache. On a server that has more than 16 GB of total physical memory, allocate a maximum of 16 GB of memory to the Distributed Cache service. By default, the Distributed memory allocation size defaults to a value of 10 percent of total physical memory when SharePoint Server 2013 installs. You can change the memory allocation with the Update-SPDistributedCacheSize cmdlet. This allocation significantly affects the performance of the Distributed Cache service. Ensure that the memory allocation assigned to the Distributed Cache service is the same on all servers that are running the Distributed Cache service  How to Stop or Restart Distributed Cache Service: The Distributed Cache service can be stopped via the Central Administration. To stop (not remove) the Distributed Cache service by using Central Administration: 
In Central Administration, click Application Management. In Service Applications 
  • Click Manage Services on Server. On the Services on Server page, locate the Distributed Cache service.  
  • If the Distributed Cache service is started and you want to stop the service, under Action, click Stop or restart. 
Firewall configuration considerations 
The Distributed Cache service uses the following communication ports:   
  • 22233 
  • 22234 
  • 22235 
  • 22236  

Cache Port The cache port is used for transmitting data between the cache hosts and your cache-enabled application. The default is 22233. 

Cluster Port The cache hosts use the cluster port to communicate availability to each of their neighbors in the cluster. The default is 22234. 

Arbitration Port If a cache host fails, the arbitration port is used to make certain that the cache host is unavailable. The default is 22235. 

Replication Port The replication port is used to move data between hosts in the cache cluster. This supports features such as high availability and load balancing. The default is 22236. 

How to Remove Distributed Cache Service: To remove distributed Cache service from the server, use PowerShell. Going to Services on Server from SharePoint Central Administration site and clicking "Stop" next to distributed just stops the service but doesn't remove it from the cache cluster. You have to actually remove the service from the servers instead of stopping it to remove it! Use this PowerShell cmdlet:When you remove a server from the cache cluster, you must first perform a graceful shutdown on the server that you want to remove. This graceful shutdown transfers all cached data on the server to other servers within the cache cluster.   
1 
2 
Stop-SPDistributedCacheServiceInstance -Graceful 
Remove-SPDistributedCacheServiceInstance 
Run this cmdlet on server(s) that doesn't need to run the Distributed Cache service. This simply removes the current server from cache host and Services on Server for the selected server! Removing the Distributed cache service instance and this will stop the app fabric caching service in service.msc, as well.  
  
Network Connectivity 

If you plan to have more than one Cache Host, the first server added should be configured to allow inbound ICMPv4 traffic. If you are using Windows Firewall, you can enable this in PowerShell with the Set-NetFirewallRule cmdlet. The name of the rule is “File and Printer SharePoint (Echo request – ICMPv4-In)”. Notice also that it doesn’t take a Boolean ($true), but rather the string “True” as an argument to the -Enabled parameter. Don’t forget to Import-Module NetSecurity first, though! 

Starting and Stopping the Service 

Once the Distributed Cache service instance is started on any server in your farm, it will become part of your Cache Cluster. 
The right way to start the service is with the
 Add-SPDistributedCacheServiceInstance PowerShell cmdlet. 

You run this on a SharePoint server you would like to add to your Cache Cluster, which makes the current server a Cache Host. Simply stopping the service instance would cause the contents of the cache on that server to go missing, degrading performance.  

If you need to remove a server from the Cache Cluster, the safe way to do this is first to use 
Stop-SPDistributedCacheServiceInstance with the –Graceful parameter. 
This transfers any cached data to another server, and can therefore take some time to perform. Afterwards you can safely run
Remove-SPDistributedCacheServiceInstance to make the current server a non-Cache Host. 

No comments:

Post a Comment