Version 1612 (8.2.0.749) (DB 8.2.0.749) on-premises
Our On-Premise CRM instance will occasionally spike to 100% constant CPU usage, usually around once a day. CRM still responds, but incredibly slowly. 100% CPU usage continues until the IIS App Pool is restarted or iisreset.
I've dumped the IIS process into a DMP file and DebugDiag reveals that there are multiple threads stuck FindEntry/TryGetValue within a .NET Dictionary. From the stack trace this appears to be accessed in parallel as part of the 'MultiEntitySearchService' which I suspect causes some sort of infinite loop caused by concurrent read/writes into the dictionary across multiple threads, causing the 100% CPU usage. See here for a further explanation of this issue: https://blogs.msdn.microsoft.com/tess/2009/12/21/high-cpu-in-net-app-using-a-static-generic-dictionary/ - the stack trace of my DMP files exhibit the classic symptoms of this problem. A quick decompilation of reveals a potential source of the problem within Microsoft.Crm.CrmCache.AggregateCacheCount.
As a workaround, is there a way to disable the parallel processing of Multi Entity search?
Sample stack trace below:
mscorlib_ni!System.Collections.Generic.Dictionary`2[[System.__Canon, mscorlib],[System.__Canon, mscorlib]].FindEntry(System.__Canon)+ab
mscorlib_ni!System.Collections.Generic.Dictionary`2[[System.__Canon, mscorlib],[System.__Canon, mscorlib]].TryGetValue(System.__Canon, System.__Canon ByRef)+14
Microsoft.Crm.CrmCache`1[[System.__Canon, mscorlib]].AggregateCacheCount(Boolean)+e7
Microsoft.Crm.CrmCache`1[[System.__Canon, mscorlib]].TryLookupEntryWithExactKey(System.String, System.Object ByRef)+4c
Microsoft.Crm.CrmCache`1[[System.__Canon, mscorlib]].InternalTryLookupEntryAsObject(System.String, System.Object ByRef, Microsoft.Crm.IOrganizationContext)+9f
Microsoft.Crm.CrmCache`1[[System.__Canon, mscorlib]].InternalTryLookupEntry(System.String, System.__Canon ByRef, Microsoft.Crm.IOrganizationContext)+25
Microsoft.Crm.CrmCache`1[[System.__Canon, mscorlib]].TryLookupEntry(System.String, System.__Canon ByRef, Microsoft.Crm.IOrganizationContext)+44
Microsoft.Crm.Caching.BasicCrmCache`2[[System.Guid, mscorlib],[System.__Canon, mscorlib]].LookupEntry(System.Guid, Microsoft.Crm.IOrganizationContext)+78
Microsoft.Crm.Metadata.MetadataForMetadata.GetInstance(Microsoft.Crm.IOrganizationContext)+10d
Microsoft.Crm.Query.CrmSqlSelectCommandStrategy+QuickFindConditionBuilder..ctor(Microsoft.Xrm.Sdk.Query.LogicalOperator, System.String, Microsoft.Crm.Metadata.EntityMetadata, Microsoft.Crm.Platform.DatabaseQueryTarget, Microsoft.Crm.BusinessEntities.ExecutionContext)+186
Microsoft.Crm.Query.CrmSqlSelectCommandStrategy+QuickFindPredicateBuilder.CreateConditionBuilder(Microsoft.Xrm.Sdk.Query.LogicalOperator, Microsoft.Crm.Metadata.EntityMetadata, System.String, Microsoft.Crm.Platform.DatabaseQueryTarget)+80
Microsoft.Crm.Query.CrmSqlSelectCommandStrategy+PredicateBuilder.BeginWritingFilter(Microsoft.Xrm.Sdk.Query.LogicalOperator, Microsoft.Crm.Metadata.EntityMetadata, System.String, Microsoft.Crm.Platform.DatabaseQueryTarget)+1b
Microsoft.Crm.Query.SelectVisitor.Visit(Microsoft.Crm.Query.FilterExpression)+69
Microsoft.Crm.Query.SelectVisitor.Visit(Microsoft.Crm.Query.FilterExpression)+11d
Microsoft.Crm.Query.SelectVisitor.Visit(Microsoft.Crm.Query.FilterExpression)+11d
Microsoft.Crm.Query.SelectVisitor.Visit(Microsoft.Crm.Query.FilterExpression)+11d
Microsoft.Crm.Query.SelectVisitor.Visit(Microsoft.Crm.Query.EntityExpression)+303
Microsoft.Crm.Query.SelectPlan.GetSql()+1b
Microsoft.Crm.Query.QueryPlan.get_Command()+2e
Microsoft.Crm.BusinessEntities.BusinessProcessObject.DoRetrieveMultiple(Microsoft.Crm.BusinessEntities.BusinessEntityCollection, Microsoft.Crm.Query.EntityExpression, Microsoft.Crm.Platform.DatabaseQueryTarget, Microsoft.Crm.BusinessEntities.PagingHelper, Microsoft.Crm.BusinessEntities.ExecutionContext, Boolean, Boolean)+1d0
Microsoft.Crm.BusinessEntities.BusinessProcessObject.DoRetrieveMultiple(Microsoft.Crm.BusinessEntities.BusinessEntityCollection, Microsoft.Crm.Query.EntityExpression, Microsoft.Crm.Platform.DatabaseQueryTarget, Microsoft.Crm.BusinessEntities.ExecutionContext, Boolean, Boolean)+142
Microsoft.Crm.BusinessEntities.BusinessProcessObject.RetrieveMultiple(Microsoft.Crm.Query.EntityExpression, Microsoft.Crm.Platform.DatabaseQueryTarget, Microsoft.Crm.BusinessEntities.ExecutionContext)+1d6
Microsoft.Crm.BusinessEntities.BusinessProcessObject.RetrieveMultiple(Microsoft.Crm.Query.EntityExpression, Microsoft.Crm.BusinessEntities.ExecutionContext)+17
Microsoft.Crm.ObjectModel.MultiEntitySearchService.ExecuteEntitySearch(Microsoft.Crm.Caching.EntitySearchConfiguration, Microsoft.Crm.BusinessEntities.ExecutionContext, Microsoft.Xrm.Sdk.QuickFindResultCollection, Microsoft.Crm.ObjectModel.MultiEntitySearchSettings)+114
Microsoft.Crm.ObjectModel.MultiEntitySearchService.ExecuteSearches(Microsoft.Crm.Caching.EntitySearchConfiguration, System.Threading.Tasks.ParallelLoopState, Microsoft.Xrm.Sdk.QuickFindResultCollection, Microsoft.Crm.ObjectModel.MultiEntitySearchSettings, System.String, Microsoft.Crm.BusinessEntities.ExecutionContext, System.Web.HttpContext)+1f8
Microsoft.Crm.ObjectModel.MultiEntitySearchService+<>c__DisplayClass8.b__6(Microsoft.Crm.Caching.EntitySearchConfiguration, System.Threading.Tasks.ParallelLoopState)+3f
mscorlib_ni!System.Threading.Tasks.Parallel+<>c__DisplayClass42_0`2[[System.__Canon, mscorlib],[System.__Canon, mscorlib]].b__1()+344
mscorlib_ni!System.Threading.Tasks.Task.InnerInvokeWithArg(System.Threading.Tasks.Task)+20
mscorlib_ni!System.Threading.Tasks.Task+<>c__DisplayClass176_0.b__0(System.Object)+115
mscorlib_ni!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)+15e
mscorlib_ni!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)+17
mscorlib_ni!System.Threading.Tasks.Task.ExecuteWithThreadLocal(System.Threading.Tasks.Task ByRef)+21d
mscorlib_ni!System.Threading.Tasks.Task.ExecuteEntry(Boolean)+98
mscorlib_ni!System.Threading.Tasks.ThreadPoolTaskScheduler.TryExecuteTaskInline(System.Threading.Tasks.Task, Boolean)+34
mscorlib_ni!System.Threading.Tasks.TaskScheduler.TryRunInline(System.Threading.Tasks.Task, Boolean)+1bb
mscorlib_ni!System.Threading.Tasks.Task.InternalRunSynchronously(System.Threading.Tasks.TaskScheduler, Boolean)+aa
mscorlib_ni!System.Threading.Tasks.Parallel.PartitionerForEachWorker[[System.__Canon, mscorlib],[System.__Canon, mscorlib]](System.Collections.Concurrent.Partitioner`1, System.Threading.Tasks.ParallelOptions, System.Action`1, System.Action`2, System.Action`3, System.Func`4, System.Func`5, System.Func`1, System.Action`1)+473
mscorlib_ni!System.Threading.Tasks.Parallel.ForEachWorker[[System.__Canon, mscorlib],[System.__Canon, mscorlib]](System.Collections.Generic.IEnumerable`1, System.Threading.Tasks.ParallelOptions, System.Action`1, System.Action`2, System.Action`3, System.Func`4, System.Func`5, System.Func`1, System.Action`1)+236
mscorlib_ni!System.Threading.Tasks.Parallel.ForEach[[System.__Canon, mscorlib]](System.Collections.Generic.IEnumerable`1, System.Threading.Tasks.ParallelOptions, System.Action`2)+95
Microsoft.Crm.ObjectModel.MultiEntitySearchService.ExecuteParallelSearches(Microsoft.Crm.Caching.MultiEntitySearchConfigurationCollection, System.Threading.Tasks.ParallelOptions, System.String, Microsoft.Xrm.Sdk.QuickFindResultCollection, Microsoft.Crm.ObjectModel.MultiEntitySearchSettings, Microsoft.Crm.BusinessEntities.ExecutionContext)+106
Microsoft.Crm.ObjectModel.MultiEntitySearchService.MultiEntitySearch(System.String, System.String, System.String[], Microsoft.Crm.BusinessEntities.ExecutionContext)+2af
[[DebuggerU2MCatchHandlerFrame]]
[[HelperMethodFrame_PROTECTOBJ] (System.RuntimeMethodHandle.InvokeMethod)] System.RuntimeMethodHandle.InvokeMethod(System.Object, System.Object[], System.Signature, Boolean)
mscorlib_ni!System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(System.Object, System.Object[], System.Object[])+80
mscorlib_ni!System.Reflection.RuntimeMethodInfo.Invoke(System.Object, System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo)+92
System_Web_Services_ni!System.Web.Services.Protocols.LogicalMethodInfo.Invoke(System.Object, System.Object[])+c0
Microsoft.Crm.Extensibility.InternalOperationPlugin.Execute(System.IServiceProvider)+e6
Microsoft.Crm.Extensibility.V5PluginProxyStep.ExecuteInternal(Microsoft.Crm.Extensibility.PipelineExecutionContext)+5b9
Microsoft.Crm.Extensibility.VersionedPluginProxyStepBase.Execute(Microsoft.Crm.Extensibility.PipelineExecutionContext)+19d
Microsoft.Crm.Extensibility.PipelineInstrumentationHelper.Execute(Boolean, System.String, ExecuteWithInstrumentation, Microsoft.Crm.Extensibility.PipelineExecutionContext)+206
Microsoft.Crm.Extensibility.Pipeline.Execute(Microsoft.Crm.Extensibility.PipelineExecutionContext)+28b
Microsoft.Crm.Extensibility.PipelineInstrumentationHelper.Execute(Boolean, System.String, ExecuteWithInstrumentation, Microsoft.Crm.Extensibility.PipelineExecutionContext)+80
Microsoft.Crm.Extensibility.MessageProcessor.Execute(Microsoft.Crm.Extensibility.PipelineExecutionContext)+504
Microsoft.Crm.Extensibility.InternalMessageDispatcher.Execute(Microsoft.Crm.Extensibility.PipelineExecutionContext)+117
Microsoft.Crm.Extensibility.ExternalMessageDispatcher.ExecuteInternal(Microsoft.Crm.Extensibility.IInProcessOrganizationServiceFactory, Microsoft.Crm.Extensibility.IPlatformMessageDispatcherFactory, System.String, System.String, Int32, Int32, Microsoft.Xrm.Sdk.ParameterCollection, Microsoft.Crm.Extensibility.CorrelationToken, Microsoft.Crm.Sdk.CallerOriginToken, Microsoft.Crm.BusinessEntities.UserAuth, System.Guid, System.Guid, Microsoft.Crm.Core.Security.Identity.UserType, System.Guid, Int32, System.Nullable`1, System.Version)+7e4
Microsoft.Crm.Extensibility.ExternalMessageDispatcher.Execute(Microsoft.Crm.Extensibility.IInProcessOrganizationServiceFactory, Microsoft.Crm.Extensibility.IPlatformMessageDispatcherFactory, System.String, System.String, Int32, Int32, Microsoft.Xrm.Sdk.ParameterCollection, Microsoft.Crm.Extensibility.CorrelationToken, Microsoft.Crm.Sdk.CallerOriginToken, Microsoft.Crm.BusinessEntities.UserAuth, System.Guid, System.Guid, Microsoft.Crm.Core.Security.Identity.UserType, System.Guid, Int32, System.Nullable`1)+c7
Microsoft.Crm.Extensibility.OrganizationSdkServiceInternal.ExecuteRequestRequestWithInstrumentation(Microsoft.Xrm.Sdk.OrganizationRequest, Microsoft.Crm.Extensibility.CorrelationToken, Microsoft.Crm.Sdk.CallerOriginToken, Microsoft.Crm.Performance.WebServiceType, Microsoft.Crm.BusinessEntities.UserAuth, System.Guid, Microsoft.Crm.OrganizationContext, Boolean, Boolean, System.Object, Microsoft.Crm.Core.Security.Identity.UserType)+859
Microsoft.Crm.Extensibility.OrganizationSdkServiceInternal.ExecuteRequest(Microsoft.Xrm.Sdk.OrganizationRequest, Microsoft.Crm.Extensibility.CorrelationToken, Microsoft.Crm.Sdk.CallerOriginToken, Microsoft.Crm.Performance.WebServiceType, Boolean, Microsoft.Crm.BusinessEntities.ExecutionContext)+1a4
Microsoft.Crm.Extensibility.OrganizationSdkServiceInternal.Execute(Microsoft.Xrm.Sdk.OrganizationRequest, Microsoft.Crm.Extensibility.CorrelationToken, Microsoft.Crm.Sdk.CallerOriginToken, Microsoft.Crm.Performance.WebServiceType, Boolean, Microsoft.Crm.BusinessEntities.ExecutionContext)+72
Microsoft.Crm.Extensibility.OrganizationSdkService.Execute(Microsoft.Xrm.Sdk.OrganizationRequest)+48
DynamicClass.SyncInvokeExecute(System.Object, System.Object[], System.Object[])+59
System_ServiceModel_ni!System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(System.Object, System.Object[], System.Object[] ByRef)+4c7
System_ServiceModel_ni!System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(System.ServiceModel.Dispatcher.MessageRpc ByRef)+26f
System_ServiceModel_ni!System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(System.ServiceModel.Dispatcher.MessageRpc ByRef)+228
System_ServiceModel_ni!System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean)+dc
System_ServiceModel_ni!System.ServiceModel.Dispatcher.MessageRpc+Wrapper.Resume(Boolean ByRef)+43
System_ServiceModel_ni!System.ServiceModel.Dispatcher.ThreadBehavior.ResumeProcessing(System.ServiceModel.Dispatcher.IResumeMessageRpc)+28
mscorlib_ni!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)+15e
mscorlib_ni!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)+17
mscorlib_ni!System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()+70
mscorlib_ni!System.Threading.ThreadPoolWorkQueue.Dispatch()+160
[[DebuggerU2MCatchHandlerFrame]]
[[ContextTransitionFrame]]
[[DebuggerU2MCatchHandlerFrame]]