我的应用程序已经冻结了很长时间(有时一分钟或更长时间,有时似乎根本没有回来,但这次是大约一分钟)我拿了一些转储进行分析。我拿了三个转储,每个转储大约相隔15秒,但我看不出它们之间有太大不同,所以我将描述最后一个。
我做的第一件事就是通过调试分析运行它,它会产生以下诊断:
GC正在此过程中运行。触发GC的线程是34
我运行!threadpool并通过81%的CPU利用率确认GC:
CPU utilization: 81%
Worker Thread: Total: 19 Running: 19 Idle: 0 MaxLimit: 2047 MinLimit: 16
Work Request in Queue: 2212
AsyncTimerCallbackCompletion TimerInfo@05fc7fb8
*snipped 58 timers*
--------------------------------------
Number of Timers: 59
--------------------------------------
Completion Port Thread:Total: 1 Free: 1 MaxFree: 32 CurrentLimit: 0 MaxLimit: 1000 MinLimit: 16
59个定时器,哇...无论如何,我看到CPU确认了GC的81%。分析中的下一个项目如下:
test.dmp中的以下线程正在等待.net垃圾 收集完成。线程34触发了垃圾收集 收货人线程不会开始做它的工作,直到时间 已禁用抢先GC的线程已完成执行。 以下线程已禁用先发制人GC 34,
(3 9 10 12 19 20 30 31 38 39 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 67 71 72)
44.16%的线程被阻止(34个线程)
看起来我们有一个禁用了Pre-emptive GC标志的线程,这阻止了GC线程的启动。让我们来看看主题:
!threads -live -special
ThreadCount: 79
UnstartedThread: 0
BackgroundThread: 63
PendingThread: 0
DeadThread: 15
Hosted Runtime: no
PreEmptive GC Alloc Lock
ID OSID ThreadOBJ State GC Context Domain Count APT Exception
0 1 29a4 006f2f68 6020 Enabled 00000000:00000000 006ec210 0 STA
3 2 1750 006fddb0 b220 Enabled 00000000:00000000 006ec210 0 MTA (Finalizer)
6 3 14a8 05c77fc8 8009220 Enabled 00000000:00000000 006ec210 0 MTA (Threadpool Completion Port)
7 4 530 0074ac08 100a220 Enabled 00000000:00000000 006ec210 0 MTA (Threadpool Worker)
8 5 2798 05dcf0e0 200b220 Enabled 00000000:00000000 006ec210 0 MTA
9 7 330c 05d0bbb8 1009220 Enabled 00000000:00000000 006ec210 0 MTA (Threadpool Worker)
10 9 2bf4 05b3db70 1019220 Enabled 00000000:00000000 006ec210 0 Ukn (Threadpool Worker)
11 c 2a9c 05b3ea58 3009220 Enabled 00000000:00000000 006ec210 0 MTA (Threadpool Worker)
12 11 2a08 05cf9398 1009220 Enabled 00000000:00000000 006ec210 0 MTA (Threadpool Worker)
14 16 1c48 05cfacc0 200b220 Enabled 00000000:00000000 006ec210 1 MTA
17 27 1cd8 05eacac0 1000220 Enabled 00000000:00000000 006ec210 0 Ukn (Threadpool Worker)
18 25 3ac 05ead9d8 200b220 Enabled 00000000:00000000 006ec210 0 MTA
19 24 32e0 05eac0b0 b220 Enabled 00000000:00000000 006ec210 0 MTA
20 23 d3c 05eabba8 b220 Enabled 00000000:00000000 006ec210 0 MTA
21 22 2bcc 05eab6a0 200b220 Enabled 00000000:00000000 006ec210 0 MTA
22 1f 19d8 05eae8f0 200b220 Enabled 00000000:00000000 006ec210 0 MTA
23 1d 2d68 05eaf300 200b220 Enabled 00000000:00000000 006ec210 0 MTA
24 1c d78 05eaf808 200b220 Enabled 00000000:00000000 006ec210 0 MTA
25 1b 1424 05eafd10 200b220 Enabled 00000000:00000000 006ec210 0 MTA
26 2a 2914 05eb1638 200b220 Enabled 00000000:00000000 006ec210 0 MTA
27 2d 2f80 05eb2550 200b220 Enabled 00000000:00000000 006ec210 0 MTA
28 2f 1bf0 05eb2f60 200b220 Enabled 00000000:00000000 006ec210 0 MTA
29 32 10a4 05cfe920 200b220 Enabled 00000000:00000000 006ec210 0 MTA
30 36 3018 05cff330 b220 Enabled 00000000:00000000 006ec210 0 MTA
31 39 29e0 05cfc5e8 1019220 Enabled 00000000:00000000 006ec210 0 Ukn (Threadpool Worker)
32 3d 11dc 140ed960 200b220 Enabled 00000000:00000000 006ec210 0 MTA
34 34 2928 140eed80 b220 Disabled 00000000:00000000 006ec210 2 MTA (GC)
35 37 1808 140efc98 200b220 Enabled 00000000:00000000 006ec210 0 MTA
36 40 23d4 140ef790 200b220 Enabled 00000000:00000000 006ec210 0 MTA
37 41 32e8 140ef288 200b220 Enabled 00000000:00000000 006ec210 0 MTA
38 35 2f64 140ee370 1009220 Enabled 00000000:00000000 006ec210 0 MTA (Threadpool Worker)
39 4a 33f4 05dd2f20 1019220 Enabled 00000000:00000000 006ec210 0 Ukn (Threadpool Worker)
40 4c 2f4c 05dd3930 200b220 Enabled 00000000:00000000 006ec210 0 MTA
41 4d 3034 05dd3e38 200b220 Enabled 00000000:00000000 006ec210 0 MTA
42 4e 217c 05dd4340 200b220 Enabled 00000000:00000000 006ec210 0 MTA
43 4f 1d58 05dd4848 200b220 Enabled 00000000:00000000 006ec210 0 MTA
44 50 c2c 05dd4d50 200b220 Enabled 00000000:00000000 006ec210 0 MTA
45 62 27fc 4a0f20b8 1009220 Enabled 00000000:00000000 006ec210 0 MTA (Threadpool Worker)
46 65 2e34 4a0fa8b8 1009220 Enabled 00000000:00000000 006ec210 0 MTA (Threadpool Worker)
47 68 28e8 4a0fadc0 1009220 Enabled 00000000:00000000 006ec210 0 MTA (Threadpool Worker)
48 6f 1e6c 4987e468 1019220 Enabled 00000000:00000000 006ec210 0 Ukn (Threadpool Worker)
49 71 33a4 4987c970 1009220 Enabled 00000000:00000000 006ec210 0 MTA (Threadpool Worker)
51 72 172c 4a0b0900 1019220 Enabled 00000000:00000000 006ec210 0 Ukn (Threadpool Worker)
50 5e 1ad4 4a0fb7d0 1009220 Enabled 00000000:00000000 006ec210 0 MTA (Threadpool Worker)
52 73 2380 4a0b0e08 1009220 Enabled 00000000:00000000 006ec210 0 MTA (Threadpool Worker)
53 6d 2958 1455fca8 1019220 Enabled 00000000:00000000 006ec210 0 Ukn (Threadpool Worker)
54 69 2140 4987ce78 1019220 Enabled 00000000:00000000 006ec210 0 Ukn (Threadpool Worker)
55 3e 2c10 49836c90 1019220 Enabled 00000000:00000000 006ec210 0 Ukn (Threadpool Worker)
56 52 1f8c 49837198 1019220 Enabled 00000000:00000000 006ec210 0 Ukn (Threadpool Worker)
57 5b 216c 145606b8 1019220 Enabled 00000000:00000000 006ec210 0 Ukn (Threadpool Worker)
58 5a 16c 4a0aaa80 1009220 Enabled 00000000:00000000 006ec210 0 MTA (Threadpool Worker)
59 47 a48 14560bc0 1009220 Enabled 00000000:00000000 006ec210 0 MTA (Threadpool Worker)
60 3c 243c 4996dae0 1009220 Enabled 00000000:00000000 006ec210 0 MTA (Threadpool Worker)
61 58 3398 4a0fb2c8 1009220 Enabled 00000000:00000000 006ec210 0 MTA (Threadpool Worker)
62 51 23b4 498376a0 1019220 Enabled 00000000:00000000 006ec210 0 Ukn (Threadpool Worker)
63 53 2b48 4a46d358 1009220 Enabled 00000000:00000000 006ec210 0 MTA (Threadpool Worker)
64 56 2504 4a0b1310 1009220 Enabled 00000000:00000000 006ec210 0 MTA (Threadpool Worker)
65 59 2778 497b7f80 1019220 Enabled 00000000:00000000 006ec210 0 Ukn (Threadpool Worker)
66 60 262c 4a05a6e0 200b220 Enabled 00000000:00000000 006ec210 0 MTA
67 3a 1bdc 14252d08 b220 Enabled 00000000:00000000 006ec210 0 MTA
68 54 14bc 14252800 200b220 Enabled 00000000:00000000 006ec210 0 MTA
69 61 2ff0 14349f28 200b220 Enabled 00000000:00000000 006ec210 0 MTA
71 10 26c0 4a0b1818 1009220 Enabled 00000000:00000000 006ec210 0 MTA (Threadpool Worker)
72 6b 26f4 49950518 1009220 Enabled 00000000:00000000 006ec210 0 MTA (Threadpool Worker)
OSID Special thread type
2 2f88 DbgHelper
3 1750 Finalizer
5 2f44 Gate
6 14a8 IOCompletion
7 530 Timer
9 330c ThreadpoolWorker
10 2bf4 ThreadpoolWorker
11 2a9c ThreadpoolWorker
12 2a08 ThreadpoolWorker
17 1cd8 Wait
31 29e0 ThreadpoolWorker
34 2928 SuspendEE
38 2f64 ThreadpoolWorker
39 33f4 ThreadpoolWorker
45 27fc ThreadpoolWorker
46 2e34 ThreadpoolWorker
47 28e8 ThreadpoolWorker
48 1e6c ThreadpoolWorker
49 33a4 ThreadpoolWorker
50 1ad4 ThreadpoolWorker
51 172c ThreadpoolWorker
52 2380 ThreadpoolWorker
53 2958 ThreadpoolWorker
54 2140 ThreadpoolWorker
55 2c10 ThreadpoolWorker
56 1f8c ThreadpoolWorker
57 216c ThreadpoolWorker
58 16c ThreadpoolWorker
59 a48 ThreadpoolWorker
60 243c ThreadpoolWorker
61 3398 ThreadpoolWorker
62 23b4 ThreadpoolWorker
63 2b48 ThreadpoolWorker
64 2504 ThreadpoolWorker
65 2778 ThreadpoolWorker
71 26c0 ThreadpoolWorker
72 26f4 ThreadpoolWorker
75 200c GC
我们可以看到线程34是GC线程,但它也是唯一禁用了PreEmptive GC的线程。触发GC(34)的线程是否可能阻止自己执行GC?如果是这样,那么应用程序如何能够从冻结中返回?该应用程序最终在一分钟之后变得敏感,并继续匆匆忙忙,所以我试图弄清楚这里发生了什么。
堆栈信息太大,无法在此处发布,但我无法在线程34上看到任何可能阻止自己进行GC的事情(如果这是真正发生的事情)。调试analysys的另外一点是以下可能会或可能不会相关:
在0x006e1498检测到可能阻塞或泄漏的关键部分 由test.dmp
中的主题34拥有此锁定的影响 1.3%的线程被阻止 (主题5) 以下功能正在尝试进入此关键部分
CLR!UnsafeEEEnterCriticalSection + 1c的
以下模块涉及此关键部分
来自Microsoft的C:\ Windows \ Microsoft.NET \ Framework \ v4.0.30319 \ clr.dll 公司
然而,线程5甚至不是托管线程;它是一个线程池门线程。
关于我如何找到问题根源的任何想法,为什么GC需要这么长时间才能开始并最终完成?