使用SolrNet.dll进行垃圾回收导致CPU占用过多

时间:2018-06-22 14:46:22

标签: asp.net .net solr garbage-collection

  • 我们有一个使用Solr实现的WebAPI应用程序,该应用程序使用Azure VM中托管的SolrNet.dll。
  • VM上的CPU状况很高。
  • 其原因是GC(垃圾收集过程)的连续触发直接与应用程序内的高分配率成正比。
  • 具有较高分配的对象添加如下。
  • 捕获转储时服务器上的CPU消耗:

命令:Procdump.exe -ma 10172 -C 65 -s 5 -n 3

0:105> lmvm SolrNet
Browse full module list
start             end                 module name
0000004c`57d50000 0000004c`57db0000   SolrNet    (deferred)             
    Image path: SolrNet.dll
    Image name: SolrNet.dll
    Browse all global symbols  functions  data
    Using CLR debugging support for all symbols
    Has CLR image header, track-debug-data flag not set
    Timestamp:        Tue Apr 16 03:52:53 2013 (516C7DBD)
    CheckSum:         00000000
    ImageSize:        00060000
    File version:     0.4.0.2002
    Product version:  0.4.0.2002
    File flags:       0 (Mask 3F)
    File OS:          4 Unknown Win32
    File type:        2.0 Dll
    File date:        00000000.00000000
    Translations:     0000.04b0
    ProductName:      SolrNet
    InternalName:     SolrNet.dll
    OriginalFilename: SolrNet.dll
    ProductVersion:   0.4.0.2002
    FileVersion:      0.4.0.2002
    FileDescription:  SolrNet
    LegalCopyright:   Copyright Mauricio Scheffer 2007-2013
    Comments:         SolrNet



CPU utilization: 100%
Worker Thread: Total: 53 Running: 18 Idle: 35 MaxLimit: 800 MinLimit: 8
Work Request in Queue: 0
--------------------------------------
Number of Timers: 2
--------------------------------------
Completion Port Thread:Total: 4 Free: 4 MaxFree: 16 CurrentLimit: 4 MaxLimit: 800 MinLimit: 200


Top 10 threads which are consuming HIGH CPU cycles are below:

Showing top 10 threads
Thread ID   User Time
==============================
       58 | 0 days 0:00:26.812
       64 | 0 days 0:00:23.750
       55 | 0 days 0:00:23.718
       75 | 0 days 0:00:22.546
       47 | 0 days 0:00:21.875
       46 | 0 days 0:00:21.625
       63 | 0 days 0:00:18.953
       22 | 0 days 0:00:18.921
       24 | 0 days 0:00:18.453
       28 | 0 days 0:00:18.359
==============================
Thread ID   User Time


Taking one of the random thread from above, I could see the below callstack:

0:064> kL
# Child-SP          RetAddr           Call Site
00 0000004c`5ea1ab38 00007ffa`057e1118 ntdll!ZwWaitForSingleObject+0xa
01 0000004c`5ea1ab40 00007ff9`fdc07a1f KERNELBASE!WaitForSingleObjectEx+0x94
02 0000004c`5ea1abe0 00007ff9`fdc079d7 clr!CLREventWaitHelper2+0x3c
03 0000004c`5ea1ac20 00007ff9`fdc07958 clr!CLREventWaitHelper+0x1f
04 0000004c`5ea1ac80 00007ff9`fdc14c2d clr!CLREventBase::WaitEx+0x7c
05 (Inline Function) --------`-------- clr!CLREventBase::Wait+0xffffffff`fffa63f1
06 0000004c`5ea1ad10 00007ff9`fdc14ef4 clr!SVR::gc_heap::wait_for_gc_done+0x66
07 0000004c`5ea1ad40 00007ff9`fdc06709 clr!SVR::GCHeap::GarbageCollectGeneration+0x108
08 (Inline Function) --------`-------- clr!SVR::gc_heap::try_allocate_more_space+0x535
09 (Inline Function) --------`-------- clr!SVR::gc_heap::allocate_more_space+0x54a
0a (Inline Function) --------`-------- clr!SVR::gc_heap::allocate+0x5a1
0b (Inline Function) --------`-------- clr!SVR::GCHeap::Alloc+0x601
0c (Inline Function) --------`-------- clr!Alloc+0x961
0d (Inline Function) --------`-------- clr!AllocateObject+0x9e3
0e 0000004c`5ea1ada0 00007ff9`a0190d0a clr!JIT_New+0xac9
0f 0000004c`5ea1b1e0 00007ff9`a018fb43 SolrNet!SolrNet.Impl.FieldParsers.AggregateFieldParser.CanHandleType(System.Type)+0x3a
10 0000004c`5ea1b220 00007ff9`a018f9c6 SolrNet!SolrNet.Impl.DocumentPropertyVisitors.RegularDocumentVisitor.Visit(System.Object, System.String, System.Xml.Linq.XElement)+0xe3
11 0000004c`5ea1b290 00007ff9`a018f7d1 SolrNet!SolrNet.Impl.DocumentPropertyVisitors.AggregateDocumentVisitor.Visit(System.Object, System.String, System.Xml.Linq.XElement)+0x76
12 0000004c`5ea1b2f0 00007ff9`a0179c3c SolrNet!SolrNet.Impl.SolrDocumentResponseParser`1[[System.__Canon, mscorlib]].ParseDocument(System.Xml.Linq.XElement)+0x121
13 0000004c`5ea1b350 00007ff9`a017959e SolrNet!SolrNet.Impl.SolrDocumentResponseParser`1[[System.__Canon, mscorlib]].ParseResults(System.Xml.Linq.XElement)+0xec
14 0000004c`5ea1b3b0 00007ff9`a0178b56 SolrNet!SolrNet.Impl.ResponseParsers.ResultsResponseParser`1[[System.__Canon, mscorlib]].Parse(System.Xml.Linq.XDocument, SolrNet.Impl.AbstractSolrQueryResults`1)+0x28e
15 0000004c`5ea1b430 00007ff9`a0032c1e SolrNet!SolrNet.Impl.ResponseParsers.AggregateResponseParser`1[[System.__Canon, mscorlib]].Parse(System.Xml.Linq.XDocument, SolrNet.Impl.AbstractSolrQueryResults`1)+0xc6
16 0000004c`5ea1b4a0 00007ff9`9f97ceef SolrNet!SolrNet.Impl.SolrQueryExecuter`1[[System.__Canon, mscorlib]].Execute(SolrNet.ISolrQuery, SolrNet.Commands.Parameters.QueryOptions)+0xae
17 0000004c`5ea1b500 00007ff9`9f973145 BusinessLogic!.BusinessLogic.ProductBAL.SearchProducts(API.Models.RequestQueryListDTO)+0x1aff
18 0000004c`5ea1c3d0 00007ff9`9f4f1c0b GetAPIs!GetAPI.Controllers.SearchProductsController.GET(API.Models.RequestQueryListDTO)+0x165
19 0000004c`5ea1c540 00007ff9`9f96da55 DynamicClass.lambda_method(System.Runtime.CompilerServices.Closure, System.Object, System.Object[])+0x8b
1a 0000004c`5ea1c580 00007ff9`9f95f680 System_Web_Http!System.Web.Http.Controllers.ReflectedHttpActionDescriptor+ActionExecutor+c__DisplayClass10.b__9(System.Object, System.Object[])+0x15
1b 0000004c`5ea1c5c0 00007ff9`9f95e494 System_Web_Http!System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(System.Web.Http.Controllers.HttpControllerContext, System.Collections.Generic.IDictionary`2, System.Threading.CancellationToken)+0x80
1c 0000004c`5ea1c620 00007ff9`9f95deb5 System_Web_Http!System.Web.Http.Controllers.ApiControllerActionInvoker+d__0.MoveNext()+0xb4
1d 0000004c`5ea1c690 00007ff9`9f95de02 mscorlib!System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[[System.Int32, mscorlib]].Start[[System.IO.StreamReader+d__97, mscorlib]](d__97 ByRef)+0x4ddb45
1e 0000004c`5ea1c740 00007ff9`9f95dd05 System_Web_Http!System.Web.Http.Controllers.ApiControllerActionInvoker.InvokeActionAsyncCore(System.Web.Http.Controllers.HttpActionContext, System.Threading.CancellationToken)+0xa2
1f 0000004c`5ea1c820 00007ff9`9f95d7d4 System_Web_Http!System.Web.Http.Controllers.ApiControllerActionInvoker.InvokeActionAsync(System.Web.Http.Controllers.HttpActionContext, System.Threading.CancellationToken)+0x15
20 0000004c`5ea1c850 00007ff9`9f95d5a5 System_Web_Http!System.Web.Http.Controllers.ActionFilterResult+d__2.MoveNext()+0x1c4
21 0000004c`5ea1c8f0 00007ff9`9f95d4f9 mscorlib!System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[[System.Int32, mscorlib]].Start[[System.IO.StreamReader+d__97, mscorlib]](d__97 ByRef)+0x4dd235
22 0000004c`5ea1c9a0 00007ff9`9f95ca3d System_Web_Http!System.Web.Http.Controllers.ActionFilterResult.ExecuteAsync(System.Threading.CancellationToken)+0x99
23 0000004c`5ea1ca70 00007ff9`9f95c8a5 System_Web_Http!System.Web.Http.Filters.AuthorizationFilterAttribute+d__2.MoveNext()+0x12d
24 0000004c`5ea1cac0 00007ff9`9f95c7f3 mscorlib!System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[[System.Int32, mscorlib]].Start[[System.IO.StreamReader+d__97, mscorlib]](d__97 ByRef)+0x4dc535
25 0000004c`5ea1cb70 00007ff9`9f95c6b4 System_Web_Http!System.Web.Http.Filters.AuthorizationFilterAttribute.ExecuteAuthorizationFilterAsyncCore(System.Web.Http.Controllers.HttpActionContext, System.Threading.CancellationToken, System.Func`1>)+0xa3
26 0000004c`5ea1cc30 00007ff9`9f95c572 System_Web_Http!System.Web.Http.Filters.AuthorizationFilterAttribute.System.Web.Http.Filters.IAuthorizationFilter.ExecuteAuthorizationFilterAsync(System.Web.Http.Controllers.HttpActionContext, System.Threading.CancellationToken, System.Func`1>)+0x14
27 0000004c`5ea1cc60 00007ff9`9f95c160 System_Web_Http!System.Web.Http.Controllers.AuthorizationFilterResult.ExecuteAsync(System.Threading.CancellationToken)+0xe2
28 0000004c`5ea1ccc0 00007ff9`9f4896b5 GetAPIs!GetAPI.Filters.AddChallengeOnUnauthorizedResult+d__7.MoveNext()+0x90
29 0000004c`5ea1cdb0 00007ff9`9f95c031 mscorlib!System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[[System.Int32, mscorlib]].Start[[System.IO.StreamReader+d__97, mscorlib]](d__97 ByRef)+0x9345
2a 0000004c`5ea1ce60 00007ff9`9f5e0db3 GetAPIs!GetAPI.Filters.AddChallengeOnUnauthorizedResult.ExecuteAsync(System.Threading.CancellationToken)+0xf1
2b 0000004c`5ea1cef0 00007ff9`9f5e0865 System_Web_Http!System.Web.Http.Controllers.AuthenticationFilterResult+d__0.MoveNext()+0x4e3



From the above callstack, we see that this thread is allocating the memory and it has triggered the GC.


GC (alloc)
----------
Allocating Memory       True
Causing GC              True
Allocating Large Object False
Waiting for GC          True

Because of this thread there are all the below threads which are waiting for the GC to finish.


GC Kind: Server
Finalizer thread: 29

GC triggered by thread: 64

Threads waiting for GC: 
46, 56, 66, 79, 80, 82, 84, 93, 94, 96, 101, 102, 103, 104, 109, 118, 119

GC Threads: 21, 22, 23, 24, 25, 26, 27, 28, 67, 68, 69, 70, 71, 72, 73, 74


Randomly picking one of the waiting thread it looks like below:

0:082> kL
# Child-SP          RetAddr           Call Site
00 0000004c`5f42af78 00007ffa`057e1118 ntdll!ZwWaitForSingleObject+0xa
01 0000004c`5f42af80 00007ff9`fdc07a1f KERNELBASE!WaitForSingleObjectEx+0x94
02 0000004c`5f42b020 00007ff9`fdc079d7 clr!CLREventWaitHelper2+0x3c
03 0000004c`5f42b060 00007ff9`fdc07958 clr!CLREventWaitHelper+0x1f
04 0000004c`5f42b0c0 00007ff9`fdc14cae clr!CLREventBase::WaitEx+0x7c
05 (Inline Function) --------`-------- clr!CLREventBase::Wait+0x15
06 0000004c`5f42b150 00007ff9`fdc0d2c3 clr!SVR::GCHeap::WaitUntilGCComplete+0x2f
07 0000004c`5f42b180 00007ff9`fdc11ddd clr!Thread::RareDisablePreemptiveGC+0x180
08 (Inline Function) --------`-------- clr!Thread::DisablePreemptiveGC+0x17bafc
09 (Inline Function) --------`-------- clr!GCHolderBase::EnterInternalCoop+0x17bb0c
0a 0000004c`5f42b210 00007ff9`fdb3cfee clr!GCCoop::GCCoop+0x3d
0b 0000004c`5f42b240 00007ff9`9e8c37d5 clr!RuntimeTypeHandle::GetGenericTypeDefinition+0xc6
0c 0000004c`5f42b310 00007ff9`9e8ecf6c mscorlib!DomainNeutralILStubClass.IL_STUB_PInvoke(System.RuntimeTypeHandle, System.Runtime.CompilerServices.ObjectHandleOnStack)+0x85
0d 0000004c`5f42b3c0 00007ff9`a0190eec mscorlib!System.RuntimeTypeHandle.GetGenericTypeDefinition(System.RuntimeType)+0x4c
0e 0000004c`5f42b400 00007ff9`a0190e71 SolrNet!SolrNet.Utils.TypeHelper.IsNullableType(System.Type)+0x2c
0f 0000004c`5f42b430 00007ff9`a0190dd2 SolrNet!SolrNet.Utils.TypeHelper.GetUnderlyingNullableType(System.Type)+0x11
10 0000004c`5f42b470 00007ff9`9eb063b0 SolrNet!SolrNet.Impl.FieldParsers.NullableFieldParser.CanHandleType(System.Type)+0x32
11 0000004c`5f42b4b0 00007ff9`a018fb43 System_Core!System.Linq.Enumerable.Any[[System.__Canon, mscorlib]](System.Collections.Generic.IEnumerable`1, System.Func`2)+0xb0
12 0000004c`5f42b520 00007ff9`a018f9c6 SolrNet!SolrNet.Impl.DocumentPropertyVisitors.RegularDocumentVisitor.Visit(System.Object, System.String, System.Xml.Linq.XElement)+0xe3
13 0000004c`5f42b590 00007ff9`a018f7d1 SolrNet!SolrNet.Impl.DocumentPropertyVisitors.AggregateDocumentVisitor.Visit(System.Object, System.String, System.Xml.Linq.XElement)+0x76
14 0000004c`5f42b5f0 00007ff9`a0179c3c SolrNet!SolrNet.Impl.SolrDocumentResponseParser`1[[System.__Canon, mscorlib]].ParseDocument(System.Xml.Linq.XElement)+0x121
15 0000004c`5f42b650 00007ff9`a017959e SolrNet!SolrNet.Impl.SolrDocumentResponseParser`1[[System.__Canon, mscorlib]].ParseResults(System.Xml.Linq.XElement)+0xec
16 0000004c`5f42b6b0 00007ff9`a0178b56 SolrNet!SolrNet.Impl.ResponseParsers.ResultsResponseParser`1[[System.__Canon, mscorlib]].Parse(System.Xml.Linq.XDocument, SolrNet.Impl.AbstractSolrQueryResults`1)+0x28e
17 0000004c`5f42b730 00007ff9`a0032c1e SolrNet!SolrNet.Impl.ResponseParsers.AggregateResponseParser`1[[System.__Canon, mscorlib]].Parse(System.Xml.Linq.XDocument, SolrNet.Impl.AbstractSolrQueryResults`1)+0xc6
18 0000004c`5f42b7a0 00007ff9`9f97ce51 SolrNet!SolrNet.Impl.SolrQueryExecuter`1[[System.__Canon, mscorlib]].Execute(SolrNet.ISolrQuery, SolrNet.Commands.Parameters.QueryOptions)+0xae
All of them are related to the SolrNet component being leveraged by the application. 

任何人都可以帮助我们,如何解决垃圾回收器问题并减少CPU利用率。

0 个答案:

没有答案