CN109062706B - Electronic device, method for limiting inter-process communication thereof and storage medium - Google Patents

Electronic device, method for limiting inter-process communication thereof and storage medium Download PDF

Info

Publication number
CN109062706B
CN109062706B CN201810700051.3A CN201810700051A CN109062706B CN 109062706 B CN109062706 B CN 109062706B CN 201810700051 A CN201810700051 A CN 201810700051A CN 109062706 B CN109062706 B CN 109062706B
Authority
CN
China
Prior art keywords
server
client
ratio
communication
binder request
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201810700051.3A
Other languages
Chinese (zh)
Other versions
CN109062706A (en
Inventor
周明君
方攀
陈岩
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Oppo Chongqing Intelligent Technology Co Ltd
Original Assignee
Oppo Chongqing Intelligent Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Oppo Chongqing Intelligent Technology Co Ltd filed Critical Oppo Chongqing Intelligent Technology Co Ltd
Priority to CN201810700051.3A priority Critical patent/CN109062706B/en
Publication of CN109062706A publication Critical patent/CN109062706A/en
Application granted granted Critical
Publication of CN109062706B publication Critical patent/CN109062706B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/546Message passing systems or structures, e.g. queues
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/547Remote procedure calls [RPC]; Web services
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/54Indexing scheme relating to G06F9/54
    • G06F2209/541Client-server
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/54Indexing scheme relating to G06F9/54
    • G06F2209/548Queue

Abstract

The application discloses a method for limiting inter-process communication, which comprises the following steps: when a client sends a binder request to a server, the binder request is intercepted and the accumulated communication times of the current client and the server and the accumulated total communication times of the current server are obtained; calculating the ratio of the accumulated communication times to the accumulated total communication times, and judging whether the ratio is greater than a set ratio; if yes, adding the intercepted binder request to the tail end of the waiting queue; wherein the binder requests in the wait queue are processed after a set time period. The application also discloses an electronic device and a storage medium. Through the mode, the method and the device can limit the ratio of the communication frequency of the client and the server to the total communication frequency of the server to a set ratio, so that the fluency of the system can be guaranteed.

Description

Electronic device, method for limiting inter-process communication thereof and storage medium
Technical Field
The present invention relates to the field of electronic device technologies, and in particular, to an electronic device, a method for restricting inter-process communication thereof, and a storage medium.
Background
At present, with the continuous development of science and technology, electronic devices such as smart phones and the like are gradually becoming necessities of daily life of people.
The android system is a common operating system of electronic devices such as smart phones, two processes in the android system generally need to communicate with each other, and a user space between the processes cannot be shared, so that a Binder mechanism is generally needed for communication between the two processes. The existing electronic device does not have a monitoring mechanism for carrying out communication conditions between processes by adopting a Binder mechanism, and cannot optimize the communication processes between the processes, so that the system smoothness is not high.
Disclosure of Invention
The embodiment of the application adopts a technical scheme that: there is provided a method of restricting inter-process communication, the method comprising: when a client sends a binder request to a server, intercepting the binder request and acquiring the accumulated communication times of the current client and the server and the accumulated total communication times of the current server; calculating the ratio of the accumulated communication times to the accumulated total communication times, and judging whether the ratio is greater than a set ratio; if yes, adding the binder request to the tail end of the waiting queue; wherein bin requests in the wait queue are processed after a set period of time.
Another technical scheme adopted by the embodiment of the application is as follows: an electronic device is provided, the electronic device including: the acquisition module is used for intercepting the binder request and acquiring the accumulated communication times of the current client and the server and the accumulated total communication times of the current server when the client sends the binder request to the server; the calculation module is used for calculating the ratio of the accumulated communication times to the accumulated total communication times; the judging module is used for judging whether the ratio is larger than a set ratio or not; the execution module is used for adding the binder request to the tail end of the waiting queue when the ratio is greater than the set ratio; wherein bin requests in the wait queue are processed after a set period of time.
The embodiment of the application adopts another technical scheme that: there is provided an electronic device comprising a processor and a memory electrically connected to the processor, the memory for storing a computer program and the processor for invoking the computer program to implement the method as described above.
The embodiment of the application adopts another technical scheme that: a storage medium for storing a computer program executable to implement the above method.
The method comprises the steps that when a client sends a binder request to a server, the binder request is intercepted, and the accumulated communication times of the current client and the server and the accumulated total communication times of the current server are obtained; calculating the ratio of the accumulated communication times to the accumulated total communication times, and judging whether the ratio is greater than a set ratio; if yes, adding the binder request to the tail end of the waiting queue; the binder request in the waiting queue is processed after a set time period, and the ratio of the communication frequency of the client and the server to the total communication frequency of the server can be limited to a set ratio, so that the fluency of the system can be ensured.
Drawings
FIG. 1 is a schematic flow chart diagram illustrating a method for restricting interprocess communication according to a first embodiment of the present application;
FIG. 2 is a schematic diagram of inter-process communication in an embodiment of the present application;
FIG. 3 is a schematic diagram of a Binder communication mechanism;
FIG. 4 is an interaction diagram of a client and a server;
FIG. 5 is a flowchart illustrating a method for restricting interprocess communication according to a second embodiment of the present application;
FIG. 6 is a schematic diagram of the interaction of a client, a server, and a wait queue;
FIG. 7 is a flowchart illustrating a method for restricting interprocess communication according to a third embodiment of the present application;
FIG. 8 is a flowchart illustrating a method for restricting interprocess communication according to a fourth embodiment of the present application;
FIG. 9 is a block diagram of an electronic device according to an embodiment of the present application;
fig. 10 is a schematic diagram of a hardware structure of an electronic device according to an embodiment of the present application.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application. It is to be understood that the specific embodiments described herein are merely illustrative of the application and are not limiting of the application. It should be further noted that, for the convenience of description, only some of the structures related to the present application are shown in the drawings, not all of the structures. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
The terms "first", "second", etc. in this application are used to distinguish between different objects and not to describe a particular order. Furthermore, the terms "include" and "have," as well as any variations thereof, are intended to cover non-exclusive inclusions. For example, a process, method, system, article, or apparatus that comprises a list of steps or elements is not limited to only those steps or elements listed, but may alternatively include other steps or elements not listed, or inherent to such process, method, article, or apparatus.
Reference herein to "an embodiment" means that a particular feature, structure, or characteristic described in connection with the embodiment can be included in at least one embodiment of the application. The appearances of the phrase in various places in the specification are not necessarily all referring to the same embodiment, nor are separate or alternative embodiments mutually exclusive of other embodiments. It is explicitly and implicitly understood by one skilled in the art that the embodiments described herein can be combined with other embodiments.
And each android system process can only run in the virtual address space owned by the process. The virtual address space includes a user space and a kernel space that are independent of each other. For user space, different processes are not shared with each other, while kernel space between different processes is shareable. Each communication of two different processes (e.g., client and server) is implemented by a Binder driver located in the kernel space.
According to the embodiment of the application, the accumulated communication times between one client and the server and the total times of communication between the server and different clients are monitored, and the ratio of the times to the total times is limited to the set ratio, so that the problem that the system is not smooth due to too many communication times between the client and the server is avoided, and specific reference is made to the following description.
Referring to fig. 1, fig. 1 is a flowchart illustrating a method for restricting inter-process communication according to a first embodiment of the present application.
In this embodiment, the method for restricting inter-process communication may include the steps of:
step 101: when the client sends the binder request to the server, the binder request is intercepted and the accumulated communication times of the current client and the server and the accumulated total communication times of the current server are obtained.
The Binder mechanism is a mode of inter-process communication (IPC) in the android system. The four major components in the android system are respectively: activity, Service, Broadcast receiver, Content Provider, different apps. The four components run in different processes, and the Binder mechanism is a bridge for communication among the processes.
As shown in fig. 2, fig. 2 is a schematic diagram of a principle of inter-process communication in the embodiment of the present application, and a process of each android system can only run in a virtual address space owned by its own process. The virtual address space includes a user space and a kernel space that are independent of each other. For user space, the client and the server are not shared with each other, while the kernel space between the client and the server is sharable. Each communication between the client and the server is realized by a Binder driver in the kernel space.
Based on the principle of the binder mechanism, it is understood that the client and the server may be any two processes, which may be an application or a service, for example, communication between applications or communication between applications. The client refers to a client process, and the server refers to a server process.
Referring to fig. 3, fig. 3 is a schematic diagram of a Binder communication mechanism, in which the Binder communication employs a C/S architecture, and from a component perspective, the Binder communication mechanism includes a Client process (Client), a Server process (Server), a Service Manager (Service Manager) and a Binder driver, where the Service Manager is used for managing various services in the system.
Wherein, the Client process is a process using the service.
The Server process is a process that provides a service.
The Service Manager process is used for converting the Binder name in character form into the reference of the Binder in the Client, so that the Client can obtain the reference of the Binder entity in the Server through the Binder name.
The Binder driver is responsible for establishing Binder communication between processes, transmitting the Binder between the processes, managing the reference count of the Binder, transmitting and interacting data packets between the processes and the like.
In the communication process based on the binder mechanism, the following three processes are mainly included:
registration Service (add Service): the Server process registers the Service to the Service Manager first. The process comprises the following steps: the Server is a client and the Service Manager is a Server.
Get Service (get Service): before a Client process uses a certain Service, the Client process needs to acquire the corresponding Service from the Service Manager. The process comprises the following steps: the Client is a Client and the Service Manager is a server.
Using the service: the Client establishes a communication path with the Server process where the Service is located according to the obtained Service information, and then can directly interact with the Service. The process comprises the following steps: the client is a client and the server is a server.
It can be understood that the interactions among the Client, the Server and the Service Manager in fig. 3 are all represented by dotted lines, because they do not interact directly with each other, but interact with the Binder driver, thereby implementing an IPC communication mode. The Binder driver is located in the kernel space, and the Client, the Server and the Service Manager are located in the user space. The Binder driver and the Service Manager can be regarded as a basic framework of an Android platform, the Client and the Server are application layers of the Android, and developers can directly carry out IPC communication by means of the basic platform framework of the Android by only customizing the Client and the Server.
In the electronic device, multiple applications may acquire the same service at the same time, and therefore, one server may perform inter-process communication with multiple clients, in which case, because the number of communications of the server is large, the thread usage amount is large, and the communication is too frequent, a system may be stuck.
Optionally, in this embodiment, the server may be a system server.
Optionally, when the number of times of communication between the client and the server is obtained, an accumulative method may be adopted, specifically, as shown in fig. 4, fig. 4 is an interaction diagram of the client and the server, in the communication process between the client and the server, three processes are mainly included, the client initiates a communication request to the server, the server responds to the communication request initiated by the client, and data interaction is performed between the client and the server. Alternatively, the communication request may be a Binder request as described above.
The communication process is completed through the above process, and therefore, the number of times of communication can be accumulated by any one of the three nodes.
Alternatively, the value of the cumulative number of communications may be incremented by one each time the client sends a binder request to the server, and the value of the cumulative total number of communications may be incremented by one each time the server receives a binder request.
Optionally, step 101 may specifically be: and when the client side initiates a communication request to the server side, adding one to the value of the accumulated communication times.
Optionally, step 101 may specifically be: and when the server side responds to the communication request initiated by the client side, adding one to the value of the accumulated communication times.
Optionally, step 101 may specifically be: and when the process-to-process communication between the client and the server is completed, adding one to the value of the accumulated communication times.
In a specific embodiment, the server may not respond to the communication request of the client due to busy reasons, or the client may not complete communication with the server due to breakdown reasons, so in this embodiment, the value of the accumulated number of times of communication may be incremented by one when the communication between the client and the server is completed. Therefore, the deviation of the counted communication times caused by error accumulation can be avoided.
It can be understood that, since the cumulative communication times and the cumulative total communication times are recorded, when the client sends the binder request to the server, the value of the cumulative communication times and the value of the cumulative total communication times at this time are obtained, and then subsequent calculation and judgment are performed.
When the client sends the binder request to the server, the binder request is intercepted, the interception refers to interception and acquisition, the binder request sent by the client cannot reach the server temporarily, is stored firstly, and whether the intercepted binder request is sent to the server is determined after subsequent calculation and judgment.
Step 102: and calculating the ratio of the accumulated communication times to the accumulated total communication times, and judging whether the ratio is greater than a set ratio.
The set ratio can be set according to related data recorded in the past. For example, when the system is in a pause (for example, when the CPU occupancy is high, the memory occupancy is high, and the total system load is large), the ratio of the current cumulative communication number to the cumulative total communication number is recorded, and the average value of the ratios recorded in a period of time is obtained and stored as the set ratio.
Optionally, the ratio is presented in the form of a percentage.
If the determination result in step 102 is yes, step 103 is executed.
If the determination result in the step 102 is negative, the step 104 is executed.
Step 103: adding the binder request to the end of the waiting queue; wherein the binder requests in the wait queue are processed after a set time period.
In step 103, the binder request intercepted in step 101 is added to the end of the waiting queue.
Wherein, step 103 may specifically be: and sending the binder request in the waiting queue to the server after a set time period so as to allow the server to respond to the binder request in the waiting queue and perform interprocess communication with the client.
The binder request in the waiting (pending) queue is not immediately responded by the server, but the binder request in the waiting queue is sent to the server after a set time period, which is equivalent to establishing a buffering mechanism, and the server is allowed to respond to the binder request after the set time period or when the server is not busy, and the inter-process communication between the server and the client is carried out.
Alternatively, in another embodiment, step 103 may specifically be: after the time period is set, the binder request in the waiting queue is used as the client to send the binder request to the server, the step 101 is returned, namely, when the client sends the binder request to the server, the step of intercepting the binder request and acquiring the accumulated communication times of the current client and the server and the accumulated total communication times of the current server is returned, the ratio is acquired and calculated again, then the size relation between the ratio and the set ratio is judged, and whether the binder request is responded or whether the binder request is reserved in the waiting queue is determined according to the judgment result.
The following is illustrated by a specific example, which is illustrated according to chronological order:
1. the first process of the application program A (client) is in binder communication with the system service (server), at this time, the client accumulates 1 communication time, if the server accumulates 20 total communication times, the ratio is 5%.
2. The second process of the application program A carries out binder communication with the system service, the client side accumulates the communication times for 2 times, and if the accumulated total communication times of the server side is 20 times, the ratio is 10%;
3. the second process of the application program A carries out binder communication with the system service, the client side accumulates the communication times for 3 times, if the accumulated total communication times of the server side is 25 times, the ratio is 12%;
4. the third process of the application program A carries out binder communication with the system service, the client side accumulates 4 times of communication times, and if the accumulated total communication times of the server side is 26 times, the ratio is 15.3%;
5. the first process of the application program A carries out binder communication with the system service, at this time, the client side accumulates the communication times for 5 times, and if the accumulated total communication times of the service side is 27 times, the ratio is 18.5%.
In the above example, if the set ratio is 17%, the binder request sent by the client for the fifth time is added to the waiting queue.
It is understood that the client and the server in the above embodiments are self-definable, and thus the above manner may be applied to any application or service to monitor the communication times thereof.
In the embodiment, the ratio of the accumulated communication times of the client to the accumulated total communication times of the server is obtained and calculated to judge whether the system is blocked or crashed due to the fact that the server is too busy, and the ratio is limited to the set ratio so as to guarantee smooth operation of the system; the busy degree of the server side can be measured more objectively and accurately by the ratio compared with the measurement simply according to the accumulated communication times of the client side, and the busy degree of the server side can be reflected better.
Step 104: and sending the intercepted binder request to a server side so as to allow the server side to respond to the binder request sent by the client side and carry out interprocess communication with the client side.
If the ratio of the communication times of the client to the total communication times of the server is smaller than the set ratio, the busy degree of the server is not affected, and the server responds to the client to send a binder request and performs normal communication between the client and the server.
Referring to fig. 5, fig. 5 is a flowchart illustrating a method for restricting inter-process communication according to a second embodiment of the present application.
In this embodiment, the method for restricting inter-process communication may include the steps of:
step 501: and in the current time period, adding one to the numerical value of the accumulated communication times when the client sends a binder request to the server, and adding one to the numerical value of the accumulated total communication times when the server receives the binder request.
In the embodiment, the time is divided into a plurality of time periods, and the number of communications of the client is accumulated in each time period, and the total number of communications of the server is accumulated. Clearing the accumulated times each time when the time period is over, and recounting in the next time period.
When the client sends a binder request to the server, the client and the server are explained to communicate once, and the accumulated communication times is increased by one.
And when the server receives the binder request, the server is explained to communicate once, and the accumulated total communication frequency is increased by one. It should be noted that the binder request received by the server may be from the above-mentioned client or other clients, and the total number of communications by the server is accumulated.
Step 502: in the current time period, when the client sends a binder request to the server, the binder request is intercepted, and the numerical value of the accumulated communication times and the numerical value of the accumulated total communication times are obtained.
And in the current time period, acquiring the current numerical value of the accumulated communication times and the numerical value of the accumulated total communication times at the time node of sending the binder request to the server side by the client side. When the client sends the binder request to the server, the binder request is intercepted. The description of the interception of the binder request may refer to the above description and is not repeated herein.
Step 503: and calculating the ratio of the accumulated communication times to the accumulated total communication times, and judging whether the ratio is greater than a set ratio.
If the determination result in the step 503 is yes, the step 504 is executed.
If the determination result in the step 503 is negative, the step 505 is executed.
Step 504: adding the binder request to the end of the waiting queue; wherein the binder requests in the wait queue are processed after a set time period.
Step 505: and sending the intercepted binder request to a server side so as to allow the server side to respond to the binder request sent by the client side and carry out interprocess communication with the client side.
The steps 503 and 505 are similar to those described in the first embodiment, and refer to the above description for details, which are not repeated herein.
As shown in fig. 6, fig. 6 is an interaction diagram of a client, a server, and a wait queue.
And in the Nth time period, the client and the server add one to the accumulated communication times every time the client and the server communicate.
When the client sends a communication request 1 to the server, the accumulated communication times of the client is 1, the accumulated total communication times of the server is 5, and the ratio is 20%.
When the client sends a communication request 2 to the server, the accumulated communication times of the client is 2, the accumulated total communication times of the server is 6, and the ratio is 33.3%.
When the client sends a communication request 3 to the server, the cumulative communication number of the client is 3, the cumulative total communication number of the server is 15, and the ratio is 20%.
When the client sends a communication request 4 to the server, the accumulated communication times of the client is 4, the accumulated total communication times of the server is 20, and the ratio is 20%.
When the client sends a communication request 5 to the server, the cumulative communication number of the client is 5, the cumulative total communication number of the server is 25, and the ratio is still 20%.
When the client sends a communication request 6 to the server, the accumulated communication times of the client is 6, the accumulated total communication times of the server is 26, and the ratio is still 20 percent
When the client sends a communication request 7 to the server, the cumulative number of communications of the client is 7, the cumulative number of communications of the server is 27, and the ratio is 25.9%.
If the ratio is set to 25%, during the nth cycle, communication request 2 and communication request 7 will be added to the waiting queue. The server side responds to the communication request 1 and the communication requests 3-6, so that the server side and the client side can communicate.
And clearing the accumulated communication times and the total accumulated communication times when the Nth period is finished.
At the beginning of the (N + 1) th time period, the server preferentially processes the binder requests in the waiting queue.
Optionally, when the next period starts, the binder request at the head end in the wait queue is used as the binder request sent by the client to the server, and the step 502 is returned.
Fig. 7 is a flowchart illustrating a method for restricting inter-process communication according to a third embodiment of the present application, as shown in fig. 7.
In this embodiment, the method for restricting inter-process communication may include the steps of:
step 701: when the client sends the binder request to the server, the binder request is intercepted and the accumulated communication times of the current client and the server and the accumulated total communication times of the current server are obtained.
Step 702: and judging whether the server side meets a preset condition or not.
If the determination result in step 702 is yes, that is, the server side meets the preset condition, step 703 is executed.
If the determination result in the step 702 is negative, that is, the server does not satisfy the preset condition, step 705 is executed.
Optionally, the preset condition includes at least one of that the number of available threads of the server is less than the set number of threads, and the importance level of the server is greater than the preset level.
It will be appreciated that communication between two processes typically uses multiple threads. For example, the Android System specifies that a System Server process can create 32 Binder threads at most for interprocess data communication; the Surface flag process can create 4 Binder threads at most for interprocess data communication; the program application process can create up to 8 Binder threads for interprocess data communication.
Therefore, subsequent calculation and judgment can be performed when the number of threads used by the server side meets the requirement, for example, one server side has 32 threads in total, 16 threads are used, and the remaining 16 available threads are used, that is, when the number of used threads is more than half, judgment on whether the number of communication times is more than the set threshold value is started.
Each process has a corresponding priority, which determines when it runs and how much CPU time it receives, and the server is no exception as a process.
For example, the Priority is 32 levels in total, is a value from 0 to 31, and is called a Base Priority Level (Base Priority Level). The system schedules the process operation according to different priorities, the 0-15 level is a common priority, the priority of the process can be dynamically changed, the high-priority process is preferentially operated, only the high-priority process is not operated, the low-priority process is scheduled to be operated, and the processes with the same priority are alternately operated according to time slices. The 16-31 level is a real-time priority, and the real-time priority is the biggest difference from the ordinary priority in that the processes with the same priority do not run according to the time slice rotation, but the process running first controls the CPU first, and if the process does not actively give up control, the process with the same level or low priority cannot run.
The importance level of the server may refer to its priority level in the system, and in other embodiments, the importance level of the server may also be a preset importance level.
Because the more important server side generally has larger influence on the fluency of the system, when the importance level of the server side is greater than the set level, subsequent calculation and judgment are performed, on one hand, the communication between the client side and the important server side can be effectively limited, so that the fluency of the system is improved, and on the other hand, unnecessary processes can be reduced without monitoring all the server sides.
Step 703: and calculating the ratio of the accumulated communication times to the accumulated total communication times, and judging whether the ratio is greater than a set ratio.
If the determination result in step 703 is yes, step 704 is executed.
If the determination result in step 704 is negative, step 705 is executed.
Step 704: adding the binder request to the end of the waiting queue; wherein the binder requests in the wait queue are processed after a set time period.
Step 705: and sending the intercepted binder request to a server side so as to allow the server side to respond to the binder request sent by the client side and carry out interprocess communication with the client side.
The description of steps 703-705 may specifically refer to the above description, and will not be described herein again.
Fig. 8 is a flowchart illustrating a method for restricting inter-process communication according to a fourth embodiment of the present application, as shown in fig. 8.
In this embodiment, the method for restricting inter-process communication may include the steps of:
step 801: when the client sends the binder request to the server, the binder request is intercepted and the accumulated communication times of the current client and the server and the accumulated total communication times of the current server are obtained.
Step 802: and judging whether the service condition of the current system meets the preset condition or not.
If the determination result in step 802 is yes, that is, the current usage of the system meets the preset condition, then step 803 is executed.
If the determination result in step 802 is negative, that is, the current usage situation of the system does not meet the preset situation, step 805 is executed.
The preset condition may be a condition that the operation status of the current system is busy, and optionally, the preset condition may include: at least one of the number of processes currently running in the system is greater than the set number of processes, the number of threads currently running in the system is greater than the set number of threads, and the total load of the system is greater than the set load. It is understood that the preset condition may also include other conditions that may reflect a large degree of busy current operation of the system, for example, the CPU occupancy of the current system is greater than a set value, the memory occupancy of the current system is greater than a set value, and the like.
By the mode, subsequent calculation and judgment can be carried out only when the current system is busy in operation, on one hand, the ratio of the communication times of the client and the server can be effectively limited when the system is busy, so that the fluency of the system is improved, on the other hand, the system can be free from limitation when the system is idle, and unnecessary processes are reduced.
Step 803: and calculating the ratio of the accumulated communication times to the accumulated total communication times, and judging whether the ratio is greater than a set ratio.
If the determination result in step 803 is yes, step 804 is executed.
If the determination result in step 804 is negative, step 805 is executed.
Step 804: adding the binder request to the end of the waiting queue; wherein the binder requests in the wait queue are processed after a set time period.
Step 805: and sending the intercepted binder request to a server side so as to allow the server side to respond to the binder request sent by the client side and carry out interprocess communication with the client side.
The description of the step 803-805 can be referred to the above description, and will not be described herein again.
Optionally, on the basis of any of the above embodiments, a process of monitoring and recording a time node of communication is added, and specifically, the following steps may be further added:
when a client side initiates a communication request to a server side, a first time point is recorded.
And recording the second time point when the server side responds to the communication request initiated by the client side.
And acquiring service waiting time according to the first time point and the second time point.
The service waiting time is a time period between the first time point and the second time point.
Service latency is saved to provide data support for subsequent optimization and validation of operating systems based on service latency.
And recording a third time point when the interprocess communication between the client and the server is completed.
And acquiring the total time of the inter-process communication according to the first time point and the third time point.
The total time of inter-process communication is the time period between the first time point and the third time point.
And saving the acquired total inter-process communication time, and providing data support for subsequent optimization and verification of the operating system.
It acquires the duration of the communication from three different aspects, including the service waiting duration, the communication service duration and the total duration.
Specifically, an average value or a total time length of each time length may be obtained. As shown in the following table:
Figure BDA0001714077750000131
Figure BDA0001714077750000141
for example, the average value of the service waiting time periods is the average value of a1, b1, and c 1; the average value of the communication service duration is the average value of a2, b2 and c 2; the total inter-process communication duration is the average of a3, b3, and c 3.
Alternatively, other statistical methods of statistics may be used to make statistics on the data, such as variance.
In addition, when the communication times, the service waiting duration, the communication service duration, and the total inter-process communication duration are counted and monitored, a histogram may be generated according to the communication times, the service waiting duration, the communication service duration, and the total inter-process communication duration.
The communication times, the service waiting time, the communication service time, the total inter-process communication time and the histogram can be further uploaded to a server, so that a developer can optimize and verify the operating system based on the data.
Referring to fig. 9, fig. 9 is a schematic block diagram of an electronic device according to an embodiment of the disclosure.
In the present embodiment, the electronic device 90 may include the following modules:
the obtaining module 91 is configured to intercept the binder request and obtain the cumulative communication times of the current client and the server and the cumulative total communication times of the current server when the client sends the binder request to the server.
And the calculating module 92 is used for calculating the ratio of the accumulated communication times to the accumulated total communication times.
And the judging module 93 is configured to judge whether the ratio is greater than a set ratio.
An executing module 94, configured to add the binder request to the end of the waiting queue when the ratio is greater than the set ratio; wherein the binder requests in the wait queue are processed after a set time period.
The specific content of the steps executed by the modules may refer to the above description, and is not described herein again.
Referring to fig. 10, fig. 10 is a schematic diagram of a hardware structure of an electronic device according to an embodiment of the present application.
In the present embodiment, the electronic device 10 includes a processor 11 and a memory 12.
The memory 12 is electrically connected to the processor 11.
The memory 12 is used for storing a computer program, which the processor 11 is used for executing to implement the method of any of the above embodiments.
Embodiments of the present invention also provide a computer-readable storage medium for storing a computer program, which can be executed by a processor to implement the method provided in the above embodiments. It is understood that the method executed by the computer program stored in the readable storage medium in this embodiment is similar to the method provided in the foregoing embodiments, and the principle and steps thereof are the same, and are not described herein again.
The storage medium may be a usb disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk, or an optical disk, which can store program codes.
The electronic device in any of the above embodiments of the present invention may be a smart phone, a wearable smart device, a tablet computer, a palm computer, a digital PDA, or other electronic devices.
The method comprises the steps that when a client sends a binder request to a server, the accumulative communication times of the current client and the server and the accumulative total communication times of the current server are obtained; calculating the ratio of the accumulated communication times to the accumulated total communication times, and judging whether the ratio is greater than a set ratio; if yes, adding the binder request to the tail end of the waiting queue; the server side responds to the binder requests in the waiting queue after a set time period, and the ratio of the communication frequency of the client side and the server side to the total communication frequency of the server side can be limited to a set ratio, so that the fluency of the system can be ensured.
The above description is only for the purpose of illustrating embodiments of the present application and is not intended to limit the scope of the present application, and all modifications of equivalent structures and equivalent processes, which are made by the contents of the specification and the drawings of the present application or are directly or indirectly applied to other related technical fields, are also included in the scope of the present application.

Claims (12)

1. A method for restricting interprocess communication, the method comprising:
in the current time period, when a client sends a binder request to a server, the numerical value of the accumulated communication times is increased by one, and when the server receives the binder request, the numerical value of the accumulated total communication times is increased by one;
in the current time period, when a client sends a binder request to a server, intercepting the binder request and acquiring the numerical value of the accumulated communication times of the current client and the server and the numerical value of the accumulated total communication times of the current server;
calculating the ratio of the accumulated communication times to the accumulated total communication times, and judging whether the ratio is greater than a set ratio;
if yes, adding the binder request to the tail end of the waiting queue; wherein bin requests in the wait queue are processed after a set period of time.
2. The method of claim 1, wherein the step of processing the binder request in the wait queue after a set period of time comprises:
and sending the binder request in the waiting queue to the server after a set time period so as to allow the server to respond to the binder request in the waiting queue and perform interprocess communication with the client.
3. The method of claim 1, wherein the step of processing the binder request in the wait queue after a set period of time comprises:
and after a set time period, taking the binder request in the waiting queue as a client to send the binder request to a server, and returning to the step of intercepting the binder request and acquiring the current numerical value of the accumulated communication times of the client and the server and the current numerical value of the accumulated total communication times of the server when the client sends the binder request to the server.
4. The method of claim 1, further comprising:
clearing the numerical value of the accumulated communication times and the numerical value of the accumulated total communication times when the current time period is finished;
and when the next time period starts, taking the binder request at the head end of the waiting queue as the binder request sent by the client to the server, returning to the step of intercepting the binder request and acquiring the numerical value of the accumulated communication times and the numerical value of the accumulated total communication times when the client sends the binder request to the server in the current time period.
5. The method of claim 1,
after the step of calculating a ratio of the cumulative number of communications to the cumulative total number of communications, and determining whether the ratio is greater than a set ratio, the method further includes:
and if not, sending the intercepted binder request to the server side so as to allow the server side to respond to the binder request sent by the client side and carry out interprocess communication with the client side.
6. The method of claim 1,
before the step of judging whether the ratio is larger than the set ratio, the method further comprises the following steps:
judging whether the server side meets a preset condition or not;
if the server side meets the preset condition, executing the step of judging whether the ratio is larger than a set ratio;
and if the server does not meet the preset condition, sending the intercepted binder request to the server so as to allow the server to respond to the binder request sent by the client and perform interprocess communication with the client.
7. The method according to claim 6, wherein the preset condition includes at least one of the number of available threads of the server being less than a set number of threads and the importance level of the server being greater than a preset level.
8. The method of claim 1,
before the step of judging whether the ratio is larger than the set ratio, the method further comprises the following steps:
judging whether the service condition of the current system meets a preset condition or not;
if the service condition of the current system accords with a preset condition, executing the step of judging whether the ratio is larger than a set ratio;
and if the service condition of the current system does not accord with the preset condition, sending the intercepted binder request to the server so as to allow the server to respond to the binder request sent by the client and carry out interprocess communication with the client.
9. The method of claim 8, wherein the predetermined condition comprises: at least one of the number of processes currently running in the system is greater than the set number of processes, the number of threads currently running in the system is greater than the set number of threads, and the total load of the system is greater than the set load.
10. An electronic device, comprising:
the acquisition module is used for adding one to the numerical value of the accumulated communication times when the client sends a binder request to the server in the current time period, and adding one to the numerical value of the accumulated total communication times when the server receives the binder request; and the system is used for intercepting the binder request and acquiring the numerical value of the accumulated communication times of the current client and the server and the numerical value of the accumulated total communication times of the current server when the client sends the binder request to the server in the current time period;
the calculation module is used for calculating the ratio of the accumulated communication times to the accumulated total communication times;
the judging module is used for judging whether the ratio is larger than a set ratio or not;
the execution module is used for adding the binder request to the tail end of a waiting queue when the ratio is larger than the set ratio; wherein bin requests in the wait queue are processed after a set period of time.
11. An electronic device, comprising a processor and a memory electrically connected to the processor, the memory being configured to store a computer program, the processor being configured to invoke the computer program to implement the method of any one of claims 1-9.
12. A storage medium, characterized in that the storage medium stores a computer program that can be executed to implement the method of any one of claims 1-9.
CN201810700051.3A 2018-06-29 2018-06-29 Electronic device, method for limiting inter-process communication thereof and storage medium Active CN109062706B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201810700051.3A CN109062706B (en) 2018-06-29 2018-06-29 Electronic device, method for limiting inter-process communication thereof and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201810700051.3A CN109062706B (en) 2018-06-29 2018-06-29 Electronic device, method for limiting inter-process communication thereof and storage medium

Publications (2)

Publication Number Publication Date
CN109062706A CN109062706A (en) 2018-12-21
CN109062706B true CN109062706B (en) 2021-03-05

Family

ID=64818611

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201810700051.3A Active CN109062706B (en) 2018-06-29 2018-06-29 Electronic device, method for limiting inter-process communication thereof and storage medium

Country Status (1)

Country Link
CN (1) CN109062706B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2023240506A1 (en) * 2022-06-15 2023-12-21 北京小米移动软件有限公司 Request processing method and apparatus, server, and storage medium

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107861817A (en) * 2017-11-30 2018-03-30 努比亚技术有限公司 Memory Optimize Method, mobile terminal and readable storage medium storing program for executing based on thread block
CN108052390A (en) * 2017-11-30 2018-05-18 努比亚技术有限公司 Memory method for cleaning, mobile terminal and readable storage medium storing program for executing based on thread block

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPH02109154A (en) * 1988-10-18 1990-04-20 Nippon Telegr & Teleph Corp <Ntt> Job control method
CN103685336B (en) * 2012-08-31 2018-03-02 腾讯科技(深圳)有限公司 overload protection method, device and server
CN105335231B (en) * 2014-08-15 2020-01-31 阿里巴巴集团控股有限公司 server thread dynamic allocation method and device
CN104219316B (en) * 2014-09-12 2018-03-23 微梦创科网络科技(中国)有限公司 A kind of call request processing method and processing device in distributed system
CN106210031A (en) * 2016-07-06 2016-12-07 北京金山安全软件有限公司 Service execution method, device, client and server

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107861817A (en) * 2017-11-30 2018-03-30 努比亚技术有限公司 Memory Optimize Method, mobile terminal and readable storage medium storing program for executing based on thread block
CN108052390A (en) * 2017-11-30 2018-05-18 努比亚技术有限公司 Memory method for cleaning, mobile terminal and readable storage medium storing program for executing based on thread block

Also Published As

Publication number Publication date
CN109062706A (en) 2018-12-21

Similar Documents

Publication Publication Date Title
US10628216B2 (en) I/O request scheduling method and apparatus by adjusting queue depth associated with storage device based on hige or low priority status
US9201693B2 (en) Quota-based resource management
CN109117280B (en) Electronic device, method for limiting inter-process communication thereof and storage medium
CN109117279B (en) Electronic device, method for limiting inter-process communication thereof and storage medium
CN109697122B (en) Task processing method, device and computer storage medium
WO2022068697A1 (en) Task scheduling method and apparatus
CN111897637B (en) Job scheduling method, device, host and storage medium
US10944683B1 (en) Hybrid queue system for request throttling
CN109002364B (en) Method for optimizing inter-process communication, electronic device and readable storage medium
CN111277640B (en) User request processing method, device, system, computer equipment and storage medium
US10733022B2 (en) Method of managing dedicated processing resources, server system and computer program product
JP2013218744A (en) Resource-based scheduler
CN109032812B (en) Mobile terminal, limiting method for interprocess communication of mobile terminal and storage medium
CN112817772A (en) Data communication method, device, equipment and storage medium
CN109062706B (en) Electronic device, method for limiting inter-process communication thereof and storage medium
CN109062707B (en) Electronic device, method for limiting inter-process communication thereof and storage medium
JP6189545B2 (en) Network application parallel scheduling to reduce power consumption
CN109002381B (en) Process communication monitoring method, electronic device and computer readable storage medium
CN109032814B (en) Mobile terminal, method for monitoring interprocess communication of mobile terminal and storage medium
CN112860387A (en) Distributed task scheduling method and device, computer equipment and storage medium
CN108804152B (en) Method and device for adjusting configuration parameters
CN114661415A (en) Scheduling method and computer system
CN109039952B (en) Mobile terminal, limiting method for interprocess communication of mobile terminal and storage medium
CN109144745B (en) Method for monitoring interprocess communication, electronic device and readable storage medium
CN109117340B (en) Mobile terminal, method for monitoring interprocess communication of mobile terminal and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant