当前位置:网站首页>Special topic of APP performance design and Optimization - poor implementation affecting performance
Special topic of APP performance design and Optimization - poor implementation affecting performance
2022-07-28 04:48:00 【Software testing Intelligence Agency】
This article will focus on bad implementations that affect performance , It mainly includes Binder Shared memory exhausted 、Binder Thread pool exhausted 、 Create a large number of BpBinder or Binder Objects, etc .
In order to better understand the following , Let's give you a brief introduction Binder:
【 notes 】 because Binder The complexity of the mechanism , I won't go into that , Simply summarize , To better understand the content of this article .
Binder Belong to a kind of IPC Communication mechanism , It is used to realize the communication between different processes , Mainly by ServiceManager、Server( Server side )、Binder drive 、Client( client )4 Part of the form , among Client、Server、Service Manager Run in user space ,Binder The driver runs in kernel space . Once complete Binder IPC The communication process is usually as follows :
1)Binder The driver creates a data receiving buffer in kernel space ;
2) Open up a kernel cache in kernel space , Establish the mapping relationship between the kernel cache and the data receiving cache in the kernel , And the mapping relationship between the data receiving buffer and the user space address of the receiving process in the kernel ;
3) Sender process through system call copy_from_user() Put the data copy To the kernel cache in the kernel , Due to the memory mapping between the kernel cache and the user space of the receiving process , Therefore, it is equivalent to sending data to the user space of the receiving process , Complete an inter process communication .

because Binder It plays an extremely important role in the process of cross process communication , Any process or exception will have a negative impact .
01 Binder Shared memory exhausted
Binder Performance of ( One less time copy_to_user) And safety are the biggest advantages , But because of Binder There are restrictions on the amount of data transferred in the kernel and user mode , So avoid passing Binder Transfer a lot of data . A process is used to receive Binder The shared memory of data is 1M-8K, about oneway Halve it . meanwhile ,Binder driver Also have 4M Upper limit , When multiple threads share this shared memory , once driver It is found that the shared memory of the data receiver is insufficient , It will return an error .

Binder Impact of shared memory exhaustion :
Binder The call takes a long time , Even fail ;
If it is the key process of user operation , It will lead to Caton .
Optimization Suggestions :
Timely release data(Server End ) or reply(Client End ), Suggest using AIDL frame ;
Binder Avoid parameter transmission of big data during interface design , Available if needed Ashmem Pass on ;
Avoid a large number of threads calling a certain in parallel at the same time in a short time Server, If there is need to , Peak shaving is required .
02 Binder Thread pool exhausted
Server There are a certain number of Binder Thread pool to respond Client Call to , A process of Binder The default maximum number of threads is 16(1 Main threads and 15 Non main threads ), Requests that exceed will be blocked waiting for idle Binder Threads , namely Binder Thread pool exhaustion will cause subsequent calls to be blocked .

Binder The impact of thread pool exhaustion :
Synchronously called Client End blocked , If it is in the key process of user operation , Then Caton phenomenon occurs ;
system_server And other key service processes of the system Binder Thread pool exhausted , Cause the whole machine to jam .
Optimization Suggestions :
Avoid a large number of threads calling a certain in parallel at the same time in a short time Server, Peak shaving is required if necessary ;
promote Binder Implementation efficiency of interface implementation .
03 Create a large number of BpBinder or Binder object
BpBinder It is in the client Binder quote , Save the target service handle Information , That is, on the server side Binder Reference information of entity , Used to query Binder node , Same with Binder Physical communication .
The system doesn't limit Server Terminal Binder objects creating , Theoretically speaking, it can be created in large quantities , But a Service You should only create one Binder object ,BpBinder Object has upper limit 6000/2500 individual , More will be killed , So I suggest the same Service Of BpBinder Realize in-process sharing .
Create a large number of BpBinder or Binder The influence of the object :
Memory footprint , frequent GC, Even because OOM And dodge back ;
The whole machine is stuck .
Optimization Suggestions :
One Service Only one Binder Object instances , Merge by usage scenario and lifecycle Service;
Timely release those that are no longer in use BpBinder.
04 The use of multiple ServiceConnection object Bind The same Service
ServiceConnection It's actually a Service, Provide to AMS maintain , Used to manage objectives Service The callback . The same ServiceConnection Objects can manage multiple Service,Client The end has achieved different Service Reuse of ,AMS Maintain only one IServiceConnection; But it's different ServiceConnection Objects are not reused , Even if it's the same Service.
The use of multiple ServiceConnection object Bind The same Service Influence :
increase AMS The burden of maintenance ,Service Start of / Exit will hold AMS Traverse after lock SC;
Long term holding AMS lock , Cause the whole machine to jam .
Optimization Suggestions :
Reuse the same ServiceConnection object , Especially the same Service;
monitor Service The death callback of , If necessary, you can immediately re Bind;
In time unbind No longer used Service.
05 Get system services as you use them
System services are provided by ServiceManager maintain , Get system services IBinder The process of is also a cross process Binder call . The system services commonly used by applications have been started by ATMS Take it with you , Other system service systems are used for general applications hiden Interface to limit . When there are frequent adjustments checkService Interface , Mainly system services or system applications .
Get system services as you go :
Unnecessary cross process synchronous calls take time 1ms about , Some even reach s level (logcat -b events -s service_manager_slow);
Increase the system load .
Optimization Suggestions :
After a successful acquisition, the local cache ;
adopt IBinder Of linkToDeath The mechanism senses the exit of the service , Clear local after service exit IBinder cache , Ask again when you need it next time Servicemanager obtain .
In addition to the above bad implementation , There are also component object leaks ( Native removeContextRegistrations Yes SC、Receiver and Window Leakage inspection )、 The system core process calls non ONEWAY Of IPC Interface ( There is a risk that the core process will get stuck ) as well as HIDL Only for cross process calls ( about Client and Server Co process scenario , Do not use HIDL) etc. .
Come here ,APP The performance design and optimization topic comes to an end , Welcome to leave messages backstage , Express your opinions on the article , Or feedback what you want to see , I hope we can make progress together ~
Last : Get one by yourself 216 Page software testing engineer interview guide document information 【 Free of charge 】. And the corresponding video learning tutorial is free to share !, It includes basic knowledge 、Linux necessary 、Shell、 The principles of the Internet 、Mysql database 、 Special topic of bag capturing tools 、 Interface testing tool 、 Test advanced -Python Programming 、Web automated testing 、APP automated testing 、 Interface automation testing 、 Testing advanced continuous integration 、 Test architecture development test framework 、 Performance testing 、 Safety test, etc. .


边栏推荐
- 100 lectures on Excel practical application cases (XI) - tips for inserting pictures in Excel
- 【sylar】框架篇-Chapter24-支持业务模块化
- 塑料可以执行GB/T 2408 -燃烧性能的测定吗
- 【sylar】框架篇-Chapter20-守护进程模块
- How to upgrade a pair of 12.2 RAC(primary) and a pair of 12.2 RAC(dataguard) to 19c
- go-zero单体服务使用泛型简化注册Handler路由
- 01-Node-Express系统框架搭建(express-generator)
- Explain initialization list
- Analysis of the reason why easycvr service can't be started and tips for dealing with easy disk space filling
- [Sylar] framework chapter -chapter21- environment variable module
猜你喜欢

启发国内学子学习少儿机器人编程教育

Youxuan database participated in the compilation of the Research Report on database development (2022) of the China Academy of communications and communications

Research on the design of robot education in stem course

Leetcode 454. Adding four numbers II

Constructor of member function

Inspire domestic students to learn robot programming education for children
![RuntimeError: stack expects each tensor to be equal size, but got [8] at entry 0 and [2] at entry 2](/img/66/27de1ac0f642fc91fca5196ea6e141.png)
RuntimeError: stack expects each tensor to be equal size, but got [8] at entry 0 and [2] at entry 2

提升学生群体中的STEAM教育核心素养

机器人教育在STEM课程中的设计研究

Strlen introduction, and the difference between sizeof
随机推荐
100 lectures on Excel practical application cases (XI) - tips for inserting pictures in Excel
CMake使用基础汇总
[idea] check out master invalid path problem
Mac installs mysql5.7 through brew
scipy.stats.chi2
【sylar】框架篇-Chapter8-定时器模块
gerrit操作-回退掉某个patch_set
[函数文档] torch.histc 与 paddle.histogram 与 numpy.histogram
猿辅导技术进化论:助力教与学 构想未来学校
Method of converting UI file to py file
transform: failed to synchronize: cudaErrorAssert: device-side assert triggered
[Sylar] framework -chapter7-io coordination scheduling module
外卖系统 文件上传
Jupyter notebook installation code prompt function
Transformer landing | next vit realizes the real-time landing of industrial tensorrt, surpassing RESNET and cswin
Is low code the future of development? On low code platform
[Sylar] framework -chapter12 bytearray module
Introduction to this pointer
Redis类型
Attempt method in laravel user authentication