当前位置:网站首页>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
边栏推荐
- [paddlepaddle] paddedetection face recognition custom data set
- Can communication of nano
- 生词生词生词生词[2]
- 开户注册挖财安全吗?有没有风险的?靠谱吗?
- The 11th China cloud computing standards and Applications Conference | cloud computing national standards and white paper series release, and Huayun data fully participated in the preparation
- ConvMAE(2022-05)
- Vulnhub's darkhole_ two
- The 10th global Cloud Computing Conference | Huayun data won the "special contribution award for the 10th anniversary of 2013-2022"
- Tupu software digital twin | visual management system based on BIM Technology
- RPC协议详解
猜你喜欢
随机推荐
【PaddleClas】常用命令
Electron安装问题
About Estimation with Cross-Validation
Star Ring Technology launched transwarp Navier, a data element circulation platform, to help enterprises achieve secure data circulation and collaboration under privacy protection
SAP 特征 特性 说明
图片数据不够?我做了一个免费的图像增强软件
兄弟组件进行传值(显示有先后顺序)
Memory management chapter of Kobayashi coding
南京大学:新时代数字化人才培养方案探讨
About Statistical Power(统计功效)
node_exporter内存使用率不显示
English sentence pattern reference
About statistical power
Sophon kg upgrade 3.1: break down barriers between data and liberate enterprise productivity
The easycvr platform reports an error "ID cannot be empty" through the interface editing channel. What is the reason?
破解湖+仓混合架构顽疾,星环科技推出自主可控云原生湖仓一体平台
Check namespaces and classes
在通达信上做基金定投安全吗?
[paddlepaddle] paddedetection face recognition custom data set
Sophon CE社区版上线,免费Get轻量易用、高效智能的数据分析工具