Adjust Cache Size of the SharePoint 2013 Distributed Cache Service Part II – Using Set-AFCacheHostConfiguration 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 2nd article in this series and provides step by step guide for SharePoint Admins to configure Distributed Cache size using Set-AFCacheHostConfiguration command and high level guidance on why and when you should use this command.

Use Cases

  • If you have servers in your distributed cache cluster with different RAM allocated to physical or virtual machine and Set-Update-SPDistributedCacheSize may not be viable option to allocate same RAM on inadequate servers.
  • If you have application servers running as inactive cache host part of cache cluster for Distributed Cache administrative purpose and you would like to avoid resizing or adjusting default cache size on inactive cache hosts.

Pros

  • You can specify different cache sizes for each host
  • Works great where you have different physical or virtual RAM allocated to the cache hosts

Cons

  • This is not SharePoint cmdlet and may not gain any respect from hardcore seasoned SharePoint professional. Additionally, keep an eye on future SharePoint service packs where it may dependent on future version of Microsoft AppFabric version which may have different cmdlets. e.g. Microsoft AppFabric 1.0 for Windows Server had Set-CacheHostConfig and Microsoft AppFabric 1.1 for Windows Server has Set-AFCacheHostConfiguration to change memory cache information. Since Set-Update-SPDistributedCacheSize is SharePoint wrapper for AppFabric cmdlet, it’s safe to assume Set-Update-SPDistributedCacheSize would work for future service packs.

Syntax

Set-AFCacheHostConfiguration – Updates the configuration settings for a Cache host to the specified values. This cmdlet is part of Microsoft AppFabric 1.1 for Windows Server caching powershell cmdlets. Only CachePort and ComputerName is required field. Notice this command would not only allow you to adjust Cachesize but allows you to adjust advanced settings like lead host, high watermark, and low watermark settings.

Set-AFCacheHostConfiguration [-ComputerName] <String> [-CachePort] <Int32> [-ArbitrationPort <Int32> ] [-CacheSize <Int64> ] [-ClusterPort <Int32> ] [-HighWatermark <Int32> ] [-IsLeadHost <String> ] [-LowWatermark <Int32> ] [-RefreshNow] [-ReplicationPort <Int32> ] [ <CommonParameters>]

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 Distributed Cache service on all Application servers from Services on Server page on central admin. Having stopped Distributed Cache service on all Application servers, these servers would be part of Cache cluster and allows us to manage Distributed Cache from the Application Servers using PowerShell. If your server isn’t part of Cache Cluster, you can’t login to the server and run Distributed Cache commands to adjust the memory allocation.

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 stopped Distributed Cache on application servers from Services on Server Page on central admin. 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 is how my SharePoint farm looks like prior to attempting to change Distributed Cache Size.

0_DS_et-AFCacheHost

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 Application Server hosting Central Admin using SP_Install account
  • 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
Get-AFCacheHostConfiguration -ComputerName Niks-SP13-App1.niks.local -cacheport 22233
Get-AFCacheHostConfiguration -ComputerName Niks-SP13-App2.niks.local -cacheport 22233

In my case, I have 2 web front end & 2 application servers running as part of Cache Cluster. You may notice only that Distributed Cache is running only on web front servers but application servers are still part of Cache cluster.

1_DS_et-AFCacheHost

When I installed SharePoint on these servers, I had allocated 4 GB RAM to the web front end server virtual machines & 5 GB RAM to the application 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) and application server is 256 MB (5% of 5 GB)

2_DS_et-AFCacheHost

  • 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 (e.g. application server hosting central admin) using Use Set-AFCacheHostConfiguration. As I said earliar, beauty of this command is it allows us to configure Cache Size for specific Server.

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 & 4 GB to each application 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. We won’t adjust Distributed Cache size on any application servers.

Set-AFCacheHostConfiguration -ComputerName Niks-SP13-Web1.niks.local -cacheport 22233 -cachesize 512
Set-AFCacheHostConfiguration -ComputerName Niks-SP13-Web2.niks.local -cacheport 22233 -cachesize 512

4_DS_et-AFCacheHost

  • 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 Set-AFCacheHostConfiguration command, all the WFE servers should have newly adjusted 8GB memory allocated and all the application & search servers have only intiial 5% memory allocated. Since Distributed Cache is not running on application & search servers, memory allocated to Distributed Cache is never used but it would allow you to run Distributed Cache PowerShell commands from Central Admin Server.

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

As you may notice, Distributed Cache on web server has been increased from 205MB to desired 500 MB but application server cache size stayed default value.

6_DS_et-AFCacheHost

Hopefully this step by step guide will show you approach to change Distributed Cache size on your SharePoint 2013 farm. Stay tuned to learn how to change Distributed Cache size using Microsoft’s preferred approach in my next article!!!!

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

2 Responses to Adjust Cache Size of the SharePoint 2013 Distributed Cache Service Part II – Using Set-AFCacheHostConfiguration Command

  1. Some of the article you mention yourself say you shouldn’t stop the cache instance by Stop-SPServiceInstance or by stopping the instance using Services on Server. Instead use Stop-SPDistributedCacheServiceInstance -Graceful on the individual cache host server, set size and use Start-SPDistributedCacheServiceInstance to start it again. Do it one of the time to avoid evicting your cache as this can cause data loss on social feeds (this is the one good argument I see in using Set-AFCacheHostConfiguration over Update-SPDistributedCacheSize)

    • Nik Patel says:

      That’s actually a great way to manage distributed cache. I agree with your observation and might be best way to manage distributed cache. I am yet to be happy with both options as you can see from pros and cons but leaning towrds Set-AFCacheHostConfiguration even though it’s not SharePoint PowerShell cmdlet. I am in the process of writing fully automated distributed cache script to manage cache size for multi-server farm environment which I can run from one of the DS cache host. Having lots of difficulties running DS commands from remote servers. I am going to employ your tip in that script to see if we can gracefully stop and start while changing distributed cache fully automated way without loosing any cached contents.

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