Adjust Cache Size of the SharePoint 2013 Distributed Cache Service Part III – Using Set-Update-SPDistributedCacheSize Command

Note: This article is part of series of articles showcasing different approaches & variations to adjust cache size of the SharePoint 2013 Distributed Cache service using PowerShell commands – Set-AFCacheHostConfiguration and Update-SPDistributedCacheSize.

This is 3nd and last article in this series and provides step by step guide for SharePoint Admins to configure Distributed Cache size using Set-Update-SPDistributedCacheSize command and high level guidance on why and when you should use this command.

Previous Article in this series –

Use Cases

  • If you have servers in your distributed cache cluster with same RAM allocated to physical or virtual machine. Additionally, all the cache hosts in cluster are active.

Pros

  • This is SharePoint cmdlet and preferred approach by Microsoft. Additionally, Microsoft do recommend that you must ensure memory allocation assigned to the Distributed Cache service is the same on all servers that are running the Distributed Cache service. It’s just unfortunate, this may not be applicable in real world scenarios and you may have servers with different physical or virtual RAM on the farm.

Cons

  • Sets all cache hosts to the same size
  • Must require same physical or virtual RAM allocated all the cache hosts to function correctly

Syntax

Set-Update-SPDistributedCacheSize – Reconfigures the allocation of memory that is dedicated to the Distributed Cache service. Use this cmdlet to allocate memory to the Distributed cache service. This cmdlet is part of SharePoint 2013 powershell cmdlets. CacheSizeInMB is required parameter. Notice that there is no parameter to specify server name. This cmdlet applies same cache size to all the cache hosts in the cache cluster.

Update-SPDistributedCacheSize [-CacheSizeInMB] <UInt32> [-AssignmentCollection <SPAssignmentCollection>]

Scenario

I have a multi-server farm with 2 WFEs (Niks-SP13-Web1, Niks-SP13-Web2) and 2 App Servers (Niks-SP13-App1, Niks-SP13-App2). When I have installed SharePoint 2013 on all servers in farm, it started Distributed Cache by default on all the servers. I have stopped and removed Distributed Cache service on all Application servers by running Stop-SPDistributedCacheServiceInstance -Graceful and Remove-SPDistributedCacheServiceInstance command. The reason for removing application servers from Distributed Cache cluster is we want to manage Distributed Cache memory using Update-SPDistributedCacheSize, which unfortunately treats all the servers in the cluster same and sets same memory regardless cache host is active or inactive.

Having removed Distributed Cache service on all Application servers, these servers won’t be part of Cache cluster and we will lose ability to manage Distributed Cache from the Application Servers using PowerShell. Please note that you can still use Update-SPDistributedCacheSize, if Distributed Cache is stopped (not removed) on application servers like 2nd article in this series. Unfortunately Update-SPDistributedCacheSize doesn’t allow different cache sizes for each host  & apply same Cache size to all inactive cache hosts, which wouldn’t be best practice. That’s the reason, if you are planning to use Update-SPDistributedCacheSize, my preference would be remove the cache host from cache cluster instead of stopping the Distributed Cache service on cache host.

In my environment, Initially I had allocated 4 GB RAM to 2 WFEs virtual machines and 5 GB RAM to 2 App Servers virtual machines during SharePoint installation. During default Distributed Cache configuration, SharePoint has allocated 205 MB (5% of 4 GB) to the Distributed Cache running on WFE servers. As I have mentioned earlier, I have removed Distributed Cache on application servers using Remove-SPDistributedCacheServiceInstance cmdlet. After a while, I have reallocated RAM to my virtual machines with 3 GB RAM to 2 WFEs servers and 4 GB RAM to 2 App Servers. Because of underlying Virtual machine RAM changes, I need to reallocate Distributed Cache size to all WFE servers.

Here are the commands I have used to stop the Distributed Cache service gracefully and remove the server from the Cache cluster.

1_DS_Update-SPDistributedCacheSize

Here is how my SharePoint farm looks like prior to attempting to change Distributed Cache Size.

0_DS_Update-SPDistributedCacheSize
Step by Step Guide to change Distributed Cache Size

  • To Adjust Memory allocation of Distributed Cache on Web Front End Servers, log in to the Web Front End Server using SP_Install account. Please note that you can’t manage Distributed Cache from application server like 2nd article because application server aren’t part of the Cache Cluster.
  • Open the Windows PowerShell or SharePoint PowerShell Management Window as an Administrator.
  • Set the context of your PowerShell session to a particular cache cluster. Note that you must run this command before using any other Cache Administration commands in PowerShell

Use-CacheCluster

  • Retrieve the initial cache information by running this command from one of the cache host. This will allow us to view number of Cache hosts in Cache cluster, active Cache hosts in Cache cluster, and current memory allocated to Cache hosts. If you have never adjusted Cache size after your SharePoint installation, default memory allocated to Distributed Cache host should be 5% of initial RAM of server.

Get-CacheHost
Get-AFCacheHostConfiguration -ComputerName Niks-SP13-Web1.niks.local -cacheport 22233
Get-AFCacheHostConfiguration -ComputerName Niks-SP13-Web2.niks.local -cacheport 22233

In my case, I have 2 web front end servers running as part of Cache Cluster.

2_DS_Update-SPDistributedCacheSize

When I installed SharePoint on these servers, I had allocated 4 GB RAM to the web front end server virtual machines. Since default memory allocation for Distributed Cache is 5%, you may notice that Distributed Cache size for web front end server is 205 MB (5% of 4 GB)

3_DS_Update-SPDistributedCacheSize

  • Manually Stop Distributed Cache Service on all WFEs from the Services on Server Page in Central Admin. Alternatively, you can login to all WFE servers and run following command to stop the Distributed Cache from the WFE servers. Please note that you must run this command from all the WFE servers and ensure Distributed Cache is stopped on all the servers in the farm.

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

I have manually stopped Distributed Cache service on both web front servers from Services on Server page on Central Admin. Notice that Distributed Cache is no longer showing up on the Servers in Farm page in Central Admin.

3_DS_et-AFCacheHost

  • Update Cache Size on all WFEs by running this command from one of the cache host using Update-SPDistributedCacheSize. As you may notice, it doesn’t require server name as parameter, it would set same Cache Size on all cache host on the farm including application servers if they are part of Cache cluster.

In my sample test case, I have readjusted & decreased total RAM allocated to my virtual machines – 3 GB RAM to each web front end servers. In this step, since our WFE have 3GB RAM allocated, we will allocate Maximum 1 GB (1024 MB) to Distributed Cache. Cache size should be half of maximum Distributed Cache allocated memory. In our case, it will be 512 MB.

Update-SPDistributedCacheSize -CacheSizeInMB 512

5_DS_Update-SPDistributedCacheSize

  • Manually Start Distributed Cache Service on all WFEs from the Services on Server Page in Central Admin. Alternatively, you can login to all WFE servers and run following command to start the Distributed Cache from the WFE servers. Please note that you must run this command from all the WFE servers and ensure Distributed Cache is started on all the servers in the farm

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

I have manually started Distributed Cache service on both web front servers from Services on Server page on Central Admin. Notice that Distributed Cache shows up on the Servers in Farm page in Central Admin.

5_DS_et-AFCacheHost

  • Verify your final Cache Cluster configuration, memory allocation to each servers in the farm running following command.  Please notice that since we ran Update-SPDistributedCacheSize command, all the cache hosts in the cluster will have same 512 MB memory allocated.

Get-CacheHost
Get-AFCacheHostConfiguration -ComputerName Niks-SP13-Web1.niks.local -cacheport 22233
Get-AFCacheHostConfiguration -ComputerName Niks-SP13-Web2.niks.local -cacheport 22233

7_DS_Update-SPDistributedCacheSize

Hopefully this step by step guide will show you approach to change Distributed Cache size on your SharePoint 2013 farm. Good luck!!!!

Advertisements
This entry was posted in Distributed Cache, SP2013 Admin. Bookmark the permalink.

Leave a Reply

Please log in using one of these methods to post your comment:

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