当前位置:网站首页>Write it down once Net travel management background CPU Explosion Analysis
Write it down once Net travel management background CPU Explosion Analysis
2022-07-03 03:46:00 【Dotnet cross platform】
One : background
1. Tell a story
Some time ago, a friend found me on wechat , Talk about him web System cpu After running for a period of time, it exploded , Let me help you see what's going on , Let's see , Make a statement , I think dump It's free. , It's mainly about tempering your skills , There is no high technical analysis cost of a software engineer .
Without further ado , Let's go windbg speak .
Two :WinDbg analysis
1. CPU Is it really high
Is it really high , We have to verify it by ourselves , Use !tp Just take a look at the order .
0:065> !tp
CPU utilization: 81%
Worker Thread: Total: 32 Running: 7 Idle: 25 MaxLimit: 8191 MinLimit: 32
Work Request in Queue: 1
AsyncTimerCallbackCompletion [email protected]
--------------------------------------
Number of Timers: 1
--------------------------------------
Completion Port Thread:Total: 4 Free: 4 MaxFree: 64 CurrentLimit: 4 MaxLimit: 1000 MinLimit: 32 From the perspective of hexagrams , Do exist CPU High explosion , Based on past experience , The boom in managed programs is mostly due to GC Triggered , But the trigger GC There are many strange reasons , After all, clr level GC The cause of triggering is as high as 14 Kind of , The code is as follows :
static const char* const str_gc_reasons[] =
{
"alloc_soh",
"induced",
"lowmem",
"empty",
"alloc_loh",
"oos_soh",
"oos_loh",
"induced_noforce",
"gcstress",
"induced_lowmem",
"induced_compacting",
"lowmemory_host",
"pm_full_gc",
"lowmemory_host_blocking"
};2. It's really GC Trigger
Verify whether the current program is GC Trigger , There are many ways , It can be used !t perhaps !t -special, But these two methods are not particularly accurate , The most accurate is based on GC Mode goes directly to CLR Search for global variables in clr!SVR::gc_heap::gc_started The value of , Refer to the following :
0:038> dp clr!SVR::gc_heap::gc_started L1
712d3190 00000001 You can see , At this time gc_started=1, explain GC Is the trigger state , Next, you can search from all the thread stacks garbage_collect perhaps gc1 What keywords can .
0:038> k
# ChildEBP RetAddr
00 0318f934 70de8248 clr!SVR::gc_heap::relocate_survivor_helper+0x1ea
01 0318f944 70de83df clr!SVR::gc_heap::relocate_survivors_in_plug+0x24
02 0318f970 70de84ac clr!SVR::gc_heap::relocate_survivors_in_brick+0x70
03 0318f9a8 70de830b clr!SVR::gc_heap::relocate_survivors+0xe4
04 0318fa00 70de218a clr!SVR::gc_heap::relocate_phase+0xb9
05 0318fbb4 70de18bf clr!SVR::gc_heap::plan_phase+0x136e
06 0318fbec 70de1d49 clr!SVR::gc_heap::gc1+0x101
07 0318fc3c 70de1421 clr!SVR::gc_heap::garbage_collect+0x746
08 0318fc58 70ddacde clr!SVR::gc_heap::gc_thread_function+0x14a
09 0318fc6c 70ddac6f clr!SVR::gc_heap::gc_thread_stub+0x72
0a 0318fc80 770a6a14 clr!GCThreadStub+0x1f
0b 0318fc94 77e4a9ef kernel32!BaseThreadInitThunk+0x24
0c 0318fcdc 77e4a9ba ntdll!__RtlUserThreadStart+0x2f
0d 0318fcec 00000000 ntdll!_RtlUserThreadStart+0x1b From the perspective of hexagrams ,gc_thread_stub Indicates that the current is a GC Threads , It is in relocate_phase Stage , This shows that the current is a Compression recovery ,GC See the official documents for the recycling flow chart .
GarbageCollectGeneration()
{
SuspendEE();
garbage_collect();
RestartEE();
}
garbage_collect()
{
generation_to_condemn();
gc1();
}
gc1()
{
mark_phase();
plan_phase();
}
plan_phase()
{
// actual plan phase work to decide to
// compact or not
if (compact)
{
relocate_phase();
compact_phase();
}
else
make_free_lists();
} At this stage , The managed heap can also be in a corrupt state , You can use it. !dumpheap -stat To validate the .
0:038> !dumpheap -stat
The garbage collector data structures are not in a valid state for traversal.
It is either in the "plan phase," where objects are being moved around, or
we are at the initialization or shutdown of the gc heap. Commands related to
displaying, finding or traversing objects as well as gc heap segments may not
work properly. !dumpheap and !verifyheap may incorrectly complain of heap
consistency errors.
Object <exec cmd="!ListNearObj /d 03301000">03301000</exec> has an invalid method table.3. Why does compression recycling occur
Generally speaking ,GC It is divided into cleaning and compression recycling , The latter is a heavyweight operation , Very hurt GC, It's a little better in the temporary section , Next, let's look at the current GC Which generation is being recycled ? You can go to CLR Check the judgment generation field inside .clr!WKS::GCHeap::GcCondemnedGeneration.
0:038> dp clr!SVR::GCHeap::GcCondemnedGeneration L1
712d79d8 00000002 A bad , The result is a 2, This 2 Express fullGC, That is, full recovery , Most of them correspond to gc_reason=lowmem The situation of , That is, there is not enough memory .
4. Is there really insufficient memory
To find out , We use it !address -summary Take a look at the current virtual memory situation .
0:038> !address -summary
--- Usage Summary ---------------- RgnCount ----------- Total Size -------- %ofBusy %ofTotal
<unknown> 1835 dce6e000 ( 3.452 GB) 91.56% 86.29%
Image 842 f436000 ( 244.211 MB) 6.33% 5.96%
Free 312 eba5000 ( 235.645 MB) 5.75%
Stack 451 2d80000 ( 45.500 MB) 1.18% 1.11%
Heap 72 2342000 ( 35.258 MB) 0.91% 0.86%
TEB 150 96000 ( 600.000 kB) 0.02% 0.01%
Other 7 4e000 ( 312.000 kB) 0.01% 0.01%
PEB 1 1000 ( 4.000 kB) 0.00% 0.00%
--- Type Summary (for busy) ------ RgnCount ----------- Total Size -------- %ofBusy %ofTotal
MEM_PRIVATE 2051 dd635000 ( 3.459 GB) 91.76% 86.48%
MEM_IMAGE 1267 11ad1000 ( 282.816 MB) 7.33% 6.90%
MEM_MAPPED 40 2345000 ( 35.270 MB) 0.91% 0.86%
--- State Summary ---------------- RgnCount ----------- Total Size -------- %ofBusy %ofTotal
MEM_COMMIT 2604 cbe7d000 ( 3.186 GB) 84.51% 79.65%
MEM_RESERVE 754 255ce000 ( 597.805 MB) 15.49% 14.60%
MEM_FREE 312 eba5000 ( 235.645 MB) 5.75%
--- Largest Region by Usage ----------- Base Address -------- Region Size ----------
<unknown> 3300000 20087000 ( 512.527 MB)
Image 6f819000 f5f000 ( 15.371 MB)
Free fea50000 1590000 ( 21.562 MB)
Stack 3110000 7a000 ( 488.000 kB)
Heap 3bc80000 621000 ( 6.129 MB)
TEB fe6e5000 1000 ( 4.000 kB)
Other fea10000 33000 ( 204.000 kB)
PEB fea49000 1000 ( 4.000 kB) From the perspective of hexagrams , Current MEM_COMMIT=3.186G, maximal Free block Free=15.371MB, According to the memory address shown before , We found that this program is 32bit , ran 64bit On the machine , In this case, the program can occupy up to 4G Memory space , although MEM_RESERVE= 597.805 MB, But this RESERVE It's scattered , Essentially, the program at this time is Virtual address tension , because Virtual address nervous , Lead to GC Constantly doing Full memory Recycling .
3、 ... and : summary
Based on the above analysis , GC The main reason for triggering is 32bit programmatic 4G Due to memory limitations , Lead to GC Keep recycling in full , This kind of scene really makes GC Very embarrassed , The priority solution is to change the program to 64bit, Let's see how to optimize program memory later , After all, now Managed heap In a damaged state , It's not easy to analyze .
边栏推荐
- 【DRM】DRM bridge驱动调用流程简单分析
- 错误 C2694 “void Logger::log(nvinfer1::ILogger::Severity,const char *)”: 重写虚函数的限制性异常规范比基类虚成员函数
- Learning notes of C programming [compiled by Mr. Tan Haoqiang] (Chapter III sequence programming) 04 C sentence
- Change and access of median value of listening object
- docker安装及启动mysql服务
- Applet get user avatar and nickname
- MongoDB主配置文件
- Web session management security issues
- The series of hyperbolic function in daily problem
- Without sxid, suid & sgid will be in danger- Shangwen network xUP Nange
猜你喜欢

Summary of electromagnetic spectrum

Without sxid, suid & sgid will be in danger- Shangwen network xUP Nange
![[embedded module] OLED display module](/img/c4/474f5ee580d132654fbd1a4cd53bab.jpg)
[embedded module] OLED display module

docker安装及启动mysql服务

Message queue addition failure

没有sXid,suid&sgid将进入险境!-尚文网络xUP楠哥

Tidal characteristics of the Bohai Sea and the Yellow Sea
![Learning notes of C programming [compiled by Mr. Tan Haoqiang] (Chapter III sequence programming) 04 C sentence](/img/60/bae0e8d92a53bcd2b2de3fb22b3b99.jpg)
Learning notes of C programming [compiled by Mr. Tan Haoqiang] (Chapter III sequence programming) 04 C sentence

Pytoch lightweight visualization tool wandb (local)

Positioning (relative positioning, absolute positioning, fixed positioning, Z-index) 2022-2-11
随机推荐
navicat 导出数据库的表结构
Captura下载安装及在Captura配置FFmpeg
Application of derivative in daily question
Introduction to mongodb
[MySQL] the difference between left join, right join and join
Ffmpeg one / more pictures synthetic video
C# WebRequest POST模式 ,基于“Basic Auth”口令认证模式,使用multipart/form-data方式上传文件及提交其他数据
Nce detail of softmax approximation
User value is the last word in the competition of mobile phone market
[AI practice] Application xgboost Xgbregressor builds air quality prediction model (I)
C programming learning notes [edited by Mr. Tan Haoqiang] (Chapter III sequence programming) 03 operators and expressions
pytorch开源吗?
QQ小程序开发之 一些前期准备:预约开发账号、下载安装开发者工具、创建qq小程序
The difference between static web pages and dynamic web pages & the difference between Web1.0 and Web2.0 & the difference between get and post
[learning notes] seckill - seckill project - (11) project summary
Basic operations of mongodb [add, delete, modify, query]
Without sxid, suid & sgid will be in danger- Shangwen network xUP Nange
Limit of one question per day
Summary of matrix knowledge points in Chapter 2 of Linear Algebra (Jeff's self perception)
403 error displayed when vs cloning