!Note: This post is written as of the SharePoint 2016 Release Candidate. Pre-release software is subject to change prior to release. I will update this post once SharePoint 2016 hits RTM or the related information has changed!
In this post I’ll walk through the steps to enable background garbage collection for AppFabric 1.1 which is used by the SharePoint 2016 Distributed Cache service. I also provide a sample PowerShell script to automate the change. Skip down to the Solution section for specific changes and a script to automate implementing the change.
Background
The change that I describe is not a new one. It was first introduced during SharePoint 2013’s lifecycle when Microsoft AppFabric 1.1 Cumulative Update 3 (CU3) was released. CU3 allowed for a non-blocking garbage collection to take place but in order to take advantage of this capability an administrator needed to update a Distributed Cache configuration file (described below in the Solution section). Later Microsoft AppFabric cumulative updates also require this same change to the configuration file.
Fast forward to SharePoint 2016 which continues to use Microsoft AppFabric 1.1 for the Distributed Cache service. As of the release candidate (RC) SharePoint 2016 ships with Microsoft AppFabric 1.1 Cumulative Update 7. Since this cumulative update builds upon CU3 it also requires the same configuration file change to enable background garbage collection.
Problem
Depending on server configuration, hardware, workloads being run, and more factors a SharePoint farm may or may not experience any issues with the Distributed Cache service if the background garbage collection change has not been applied. In my lab environment I simulated load (10-50 requests / sec) against the SharePoint Newsfeed. After a few minutes I began to experience issues with Newsfeed posts not appearing and eventually the Distributed Cache service instances crashed on the two servers hosting that service. A restart of the AppFabric service allowed the Distributed Cache to recover and function normally again.
Solution
The configuration change to allow for background garbage collection in Microsoft AppFabric 1.1 is outlined in Cumulative Update 3. An administrator who has access to the SharePoint server(s) hosting the Distributed Cache service will need to perform the following actions.
- Upgrade the Distributed Cache servers to the .NET Framework 4.5 (as of the publishing of this blog .Net 4.5 is no longer supported and .Net 4.5.2 will need to be installed.)
- Install the cumulative update package (already installed for SharePoint 2016 Release Candidate).
- Enable the fix by adding / updating the following setting in the DistributedCacheService.exe.config file:
<appSettings><add key="backgroundGC" value="true"/></appSettings>
- Restart the AppFabric Caching service for the update to take effect.
Note: By default, the DistributedCacheService.exe.config file is located under the following directory:
”%ProgramFiles%AppFabric 1.1 for Windows Server” where %ProgramFiles% is the folder where Windows Program Files are installed.
While it is possible to modify this file by hand it is preferred to automate this process especially when multiple servers need to be updated. The below script leverages the System.Configuration.ConfigurationManager class to make the necessary changes on an individual server running the Distributed Cache service.
Note: This script must be run from each server running the Distributed Cache service. For an automated way to run on all Distributed Cache servers in a SharePoint farm see the PowerShell snippet following this script.
THIS SAMPLE CODE AND ANY RELATED INFORMATION ARE PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
Download link:
https://gallery.technet.microsoft.com/SharePoint-update-7816fa74
[system.reflection.assembly]::LoadWithPartialName(“System.Configuration”) | Out-Null # intentionally leave off the trailing “.config” as OpenExeConfiguration will auto-append that $configFilePath = “$env:ProgramFilesAppFabric 1.1 for Windows ServerDistributedCacheService.exe” $appFabricConfig = [System.Configuration.ConfigurationManager]::OpenExeConfiguration($configFilePath) # if backgroundGC setting does not exist add it, else check if value is “false” and change to “true” if($appFabricConfig.AppSettings.Settings.AllKeys -notcontains “backgroundGC”) { $appFabricConfig.AppSettings.Settings.Add(“backgroundGC”, “true”) } elseif ($appFabricConfig.AppSettings.Settings[“backgroundGC”].Value -eq “false”) { $appFabricConfig.AppSettings.Settings[“backgroundGC”].Value = “true” } # save changes to config file $appFabricConfig.Save()
Optionally the following snippet can be run from any machine in a SharePoint farm that has the SharePoint commandlets available. This will identify each Distributed Cache server and remotely run the previous script to implement the Distributed Cache configuration change.
Note: Update $UpdateDistributedCacheScriptPath with the path of the above script. Also ensure that PowerShell remoting is enabled and the account running the script has access to the target machines.
$UpdateDistributedCacheScriptPath = “C:ScriptsUpdateDistributedCacheBackgroundGCSetting.ps1” $serversRunningDistributedCache = Get-SPServiceInstance | where typename -eq “Distributed Cache” | select server | %{$_.Server.ToString().Split(‘=’)[1]} foreach($server in $serversRunningDistributedCache) { Write-Verbose “Modifying config file on server: $server” Invoke-Command -FilePath $UpdateDistributedCacheScriptPath -ComputerName $server Write-Verbose “Script completed on server: $server” }
Conclusion
In this post I walked through the update required to enable background garbage collection in Microsoft AppFabric 1.1 Cumulative Update 3 and higher. This configuration change is required for SharePoint 2013 or SharePoint 2016 (as of Release Candidate). I also provided a script for automating the process of implementing this configuration change. I’m told a future update may automatically apply this change for SharePoint 2016. If and when that change is released I’ll update this post to reflect that change.
-Frog Out