High CPU Utilization by Security Token Service on SharePoint Server 2013

Issue

You have a high CPU utilization, in my case it was almost 100% for several hours, and mostly consumed by the Security Token Service (STS). The issue will show up after installing June 2016 CU for SharePoint 2013, or any subsequent CU until March 2017 CU.

Restarting IIS will resolve the issue temporarily, but it will show up again shortly. Checking the SharePoint ULS logs will show events as shown below:

 

 xx/xx/xxxx xx:xx:xx.xx w3wp.exe (0x34F0) 0x47C4 SharePoint Foundation Database 4ohp High Enumerating all sites in SPWebApplication Name=Contoso Site. 

xx/xx/xxxx xx:xx:xx.xx w3wp.exe (0x0448) 0x066C SharePoint Foundation Database 4ohq Medium Site Enumeration Stack:    at Microsoft.SharePoint.SPBaseCollection.GetEnumerator()     at Microsoft.Office.Server.Search.Administration.UrlMapper.GetNewCacheEntry(Pair`2 properties)     at Microsoft.Office.Server.Search.Administration.UrlMapper.GetUrlMapping(QueryProperties properties, Boolean useCache, UrlZoneOverride urlZoneOverride)     at Microsoft.Office.Server.Search.Administration.SearchServiceApplicationProxy.<>c__DisplayClass6.<UpdateQueryProperties>b__4(Object x)     at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)     at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()     at System.Threading.ThreadPoolWorkQueue.Dispatch()

 

Cause

Analyzing this issue shows that the Security Token Service was heavily consumed by receiving so many requests while SharePoint was enumerating all the sites in the farm, and in my case we had so many sites.

 

Solution

The issue was fixed in March 2017 CU for SharePoint Server 2013.

 

Note: this fix is only for this issue, and is not supposed to resolve any other performance or high CPU issue you have in your SharePoint farm.