当前位置:网站首页>The main thread anr exception is caused by too many binder development threads
The main thread anr exception is caused by too many binder development threads
2022-07-05 18:25:00 【Sharp surge】
Understand Ctrip ANR front , Let's get to know binder The previous life and present life of thread pool .
stay android In the system , adopt binder Conduct IPC when , The server always plays some Binder Threads To respond to client requests . This involves passing BInder Thread pool open up binder Threads .
Those Binder How to create threads , How to manage ?
stay APP Process creation or AIDL When the service process is created ,AMS Will notify Zygote process fork One APP process , stay Zygote Initialize the APP Process time , Will be called to Native Layer of app_main.cpp Medium onZygoteInit().
stay frameworks/base/cmds/app_process/app_main.cpp in
virtual void onZygoteInit()
{
sp<ProcessState> proc = ProcessState::self();
ALOGV("App process: starting thread pool.\n");
proc->startThreadPool(); // Open thread pool
}about Binder Number of thread pools , Creating for the current process ProcessState When , adopt mMaxThread Into Binder Drive the maximum that can be created Binder Number of threads , The default is 15 individual .

The first of this variable stay The first definition is dead .
native/libs/binder/ProcessState.cpp
#define DEFAULT_MAX_BINDER_THREADS 15 // Thread pool The largest number
binder The maximum number of threads is 15 individual .
Ctrip actual combat case analysis .
Let's take a look at this log :

Obviously, I was doing Binder signal communication ,ANR It happened in transcatNative Function , transcatNative The function of the initiator of the functional client .
Illustrate this anr Medium The client may be waiting Binder End to end response , We know Binder Communication is blocking and waiting for response by default for the caller , Only when there is a return result can the execution continue .
There are two situations :
When the server calls a method There's a blockage , Cause the client to hang .
Binder Thread pool exceeded 15 individual , As a result, the allocation cannot continue , Client pending .
Through analysis happen anr When cpu The state of , Sure, but binder The number of threads is more than 15 individual , That is, it can be determined to be binder Thread pools cause .
Why? Binder Thread pools can cause ANR Well ?
Let's imagine this situation ,A The process initiates the... At the same time 16 individual binder After the request , Because there is no C The process can handle , Because the thread pool is full at this time .
The client initiated the 16 individual binder Request to be in the blocking state at this time .

At a deeper level It is other processes that give systemserver send out Binder Messages are blocked , And there is no opposite end binder Thread . As a result, the caller needs to wait for the result , It's caused ANR.
So the focus of the problem , stay binder Thread allocation completed , No new thread assignments , Cause the caller to hang on the main thread .
There will be Binder cause ANR Or other abnormal conditions ?
The answer is yes .
Activity To transfer data Pass on 1M when , Caused an anomaly
Activity When asynchronous Pass on 512k when Caused an anomaly
Binder Server Server side Virtualization of complex objects results in ANR
边栏推荐
- U-Net: Convolutional Networks for Biomedical Images Segmentation
- Penetrate the whole intranet through socks agent
- vs2017 qt的各种坑
- Xiaobai getting started with NAS - quick building private cloud tutorial series (I) [easy to understand]
- Use JMeter to record scripts and debug
- 图像分类,看我就够啦!
- 吳恩達團隊2022機器學習課程,來啦
- Huaxia Fund: sharing of practical achievements of digital transformation in the fund industry
- SAP 特征 特性 说明
- 开户注册股票炒股安全吗?有没有风险的?靠谱吗?
猜你喜欢

记录Pytorch中的eval()和no_grad()

Record a case of using WinDbg to analyze memory "leakage"

Can communication of nano

Vulnhub's darkhole_ two

图像分类,看我就够啦!

Nacos distributed transactions Seata * * install JDK on Linux, mysql5.7 start Nacos configure ideal call interface coordination (nanny level detail tutorial)

《2022中国信创生态市场研究及选型评估报告》发布 华云数据入选信创IT基础设施主流厂商!

Let more young people from Hong Kong and Macao know about Nansha's characteristic cultural and creative products! "Nansha kylin" officially appeared

使用JMeter录制脚本并调试

Huaxia Fund: sharing of practical achievements of digital transformation in the fund industry
随机推荐
Memory leak of viewpager + recyclerview
Isprs2022 / Cloud Detection: Cloud Detection with Boundary nets Boundary Networks Based Cloud Detection
Sophon KG升级3.1:打破数据间壁垒,解放企业生产力
Eliminate the writing of 'if () else{}'
ConvMAE(2022-05)
在通达信上做基金定投安全吗?
Image classification, just look at me!
Is it safe to open an account and register stocks for stock speculation? Is there any risk? Is it reliable?
jdbc读大量数据导致内存溢出
GIMP 2.10教程「建议收藏」
[use electron to develop desktop on youqilin]
Electron installation problems
Maximum artificial island [how to make all nodes of a connected component record the total number of nodes? + number the connected component]
Fix vulnerability - mysql, ES
Record a case of using WinDbg to analyze memory "leakage"
About statistical power
关于服装ERP,你想知道的都在这里了
苹果手机炒股安全吗?打新债是骗局吗?
爱因斯坦求和einsum
兄弟组件进行传值(显示有先后顺序)