当前位置:网站首页>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
边栏推荐
- rust统计文件中单词出现的次数
- 写作写作写作写作
- 第十届全球云计算大会 | 华云数据荣获“2013-2022十周年特别贡献奖”
- 让更多港澳青年了解南沙特色文创产品!“南沙麒麟”正式亮相
- Eliminate the writing of 'if () else{}'
- The 2022 China Xinchuang Ecological Market Research and model selection evaluation report released that Huayun data was selected as the mainstream manufacturer of Xinchuang IT infrastructure!
- 星环科技重磅推出数据要素流通平台Transwarp Navier,助力企业实现隐私保护下的数据安全流通与协作
- Sophon base 3.1 launched mlops function to provide wings for the operation of enterprise AI capabilities
- Penetrate the whole intranet through socks agent
- Access the database and use redis as the cache of MySQL (a combination of redis and MySQL)
猜你喜欢
Record eval() and no in pytoch_ grad()
ConvMAE(2022-05)
vs2017 qt的各种坑
Sophon AutoCV:助力AI工业化生产,实现视觉智能感知
Nanjing University: Discussion on the training program of digital talents in the new era
模拟百囚徒问题
Whether to take a duplicate subset with duplicate elements [how to take a subset? How to remove duplicates?]
瞅一瞅JUC提供的限流工具Semaphore
【HCIA-cloud】【1】云计算的定义、什么是云计算、云计算的架构与技术说明、华为云计算产品、华为内存DDR配置工具说明
vulnhub之darkhole_2
随机推荐
Check namespaces and classes
Privacy computing helps secure data circulation and sharing
Star Ring Technology launched transwarp Navier, a data element circulation platform, to help enterprises achieve secure data circulation and collaboration under privacy protection
Failed to virtualize table with JMeter
Isprs2022 / Cloud Detection: Cloud Detection with Boundary nets Boundary Networks Based Cloud Detection
Penetrate the whole intranet through socks agent
About Statistical Power(统计功效)
Tupu software digital twin | visual management system based on BIM Technology
Nacos distributed transactions Seata * * install JDK on Linux, mysql5.7 start Nacos configure ideal call interface coordination (nanny level detail tutorial)
记一次使用Windbg分析内存“泄漏”的案例
使用JMeter录制脚本并调试
Thoroughly understand why network i/o is blocked?
How to improve the thermal management in PCB design with the effective placement of thermal through holes?
图扑软件数字孪生 | 基于 BIM 技术的可视化管理系统
第十一届中国云计算标准和应用大会 | 云计算国家标准及白皮书系列发布 华云数据全面参与编制
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
Electron installation problems
Leetcode notes: Weekly contest 300
About Estimation with Cross-Validation
瞅一瞅JUC提供的限流工具Semaphore