当前位置:网站首页>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
边栏推荐
- 第十届全球云计算大会 | 华云数据荣获“2013-2022十周年特别贡献奖”
- ClickHouse(03)ClickHouse怎么安装和部署
- Is it safe for Apple mobile phone to speculate in stocks? Is it a fraud to get new debts?
- Electron安装问题
- Gimp 2.10 tutorial "suggestions collection"
- JVM第三话 -- JVM性能调优实战和高频面试题记录
- U-Net: Convolutional Networks for Biomedical Images Segmentation
- Sophon Base 3.1 推出MLOps功能,为企业AI能力运营插上翅膀
- 写作写作写作写作
- Sophon CE Community Edition is online, and free get is a lightweight, easy-to-use, efficient and intelligent data analysis tool
猜你喜欢

如何获取飞机穿过雷达两端的坐标

JVM third talk -- JVM performance tuning practice and high-frequency interview question record

瞅一瞅JUC提供的限流工具Semaphore

吳恩達團隊2022機器學習課程,來啦

Introduction to the development function of Hanlin Youshang system of Hansheng Youpin app

Sophon KG升级3.1:打破数据间壁垒,解放企业生产力

SAP 特征 特性 说明

星环科技数据安全管理平台 Defensor重磅发布

星环科技重磅推出数据要素流通平台Transwarp Navier,助力企业实现隐私保护下的数据安全流通与协作

About statistical power
随机推荐
Can communication of nano
Xiaobai getting started with NAS - quick building private cloud tutorial series (I) [easy to understand]
模拟百囚徒问题
Memory leak of viewpager + recyclerview
使用JMeter录制脚本并调试
sample_rate(采樣率),sample(采樣),duration(時長)是什麼關系
[utiliser Electron pour développer le Bureau sur youkirin devrait]
sample_rate(采样率),sample(采样),duration(时长)是什么关系
生词生词生词生词[2]
Eliminate the writing of 'if () else{}'
Introduction to the development function of Hanlin Youshang system of Hansheng Youpin app
使用Jmeter虚拟化table失败
[paddlepaddle] paddedetection face recognition custom data set
Huaxia Fund: sharing of practical achievements of digital transformation in the fund industry
Nacos distributed transactions Seata * * install JDK on Linux, mysql5.7 start Nacos configure ideal call interface coordination (nanny level detail tutorial)
Generate XML schema from class
《2022中国信创生态市场研究及选型评估报告》发布 华云数据入选信创IT基础设施主流厂商!
New words new words new words new words [2]
rust统计文件中单词出现的次数
Thoroughly understand why network i/o is blocked?