The disclosure claims the priority to Chinese Patent Application No. 202210142967.8, filed with the Chinese Patent Office on Feb. 16, 2022 and entitled “Method and apparatus for processing messages, terminal device, and storage medium”, which is incorporated herein in its entirety by reference.
The disclosure relates to the technical field of data transmission, and particularly relates to a method and apparatus for processing messages, a terminal device, and a storage medium.
The message in a network may be approximately divided into two types. One type is a real-time message, which has an enormously high requirement for the real-time performance. Such message includes but is not limited to an Address Resolution Protocol (ARP) message, an Internet Control Message Protocol (ICMP) message, a multicast message, a Transmission Control Protocol (TCP) packet, etc. The other one type is a non-real-time message, which is insensitive to the time delay. A certain time delay is acceptable when this message is processed. Such message includes but is not limited to various file download messages, etc.
In the related art, when a home gateway operates, if it takes too much time to process the non-real-time messages, time delays of the real-time messages will be too long, and the real-time messages may be discarded, which severely affects user experience. Moreover, a polling strategy is adopted in the related art, and a single processing amount of each priority is limited. If some messages have extremely high requirements for real-time performance, and a maximum processing amount of the priority is reached, the messages may only be processed in a next round, so the messages will lose the real-time performance. In addition, if a message processing rate of a central processing unit (CPU) is less than a message arrival rate, packets will be lost. Priority of the discarded messages cannot be determined, and high-priority messages or low-priority messages may be discarded. If real-time messages are discarded, user experience will be severely affected.
The technical problem to be solved by examples of the disclosure is to provide a method and apparatus for processing messages, a terminal device, and a storage medium, which can reduce a packet loss rate of real-time messages, shorten network time delays of the real-time messages, guarantee timeliness of the real-time messages, and improve user experience.
In order to realize the above objective, an example of the disclosure provides a method for processing messages. The method includes:
As an improvement to the above solution, the adjusting a single processing amount of the non-real-time messages dynamically according to the number of real-time messages in the priority processing queue, and obtaining an adjusted single processing amount of the non-real-time messages in S2 include: determining the number of the real-time messages in the priority processing queue; and adjusting the single processing amount of the non-real-time messages dynamically according to a numerical relation between the number of the real-time messages, a first threshold and a second threshold, and obtaining the adjusted single processing amount of the non-real-time messages, wherein the first threshold is less than the second threshold.
As an improvement to the above solution, the adjusting the single processing amount of the non-real-time messages dynamically according to a numerical relation between the number of the real-time messages, a first threshold and a second threshold, and obtaining the adjusted single processing amount of the non-real-time messages include: determining a maximum message processing amount of a Central Processing Unit (CPU) in a time unit as the adjusted single processing amount in a case that the number of the real-time messages is 0; taking, in a case that the number of the real-time messages is greater than 0 and less than the first threshold, or the number of the real-time messages is greater than or equal to the first threshold and less than or equal to the second threshold, the number of the real-time messages as variables of a predetermined functions, adjusting the single processing amount of the non-real-time messages dynamically by means of the predetermined functions, and obtaining the adjusted single processing amount of the non-real-time messages; and determining a predetermined constant as the adjusted single processing amount in a case that the number of the real-time messages is greater than the second threshold.
As an improvement to the above solution, the predetermined functions are linear functions, and a slope and an adjustment constant of a linear function in the case that the number of the real-time messages is greater than 0 and less than the first threshold are different from a slope and an adjustment constant of a linear function in the case that the number of the real-time messages is greater than or equal to the first threshold and less than or equal to the second threshold.
As an improvement to the above solution, the first threshold is A=a×L, the second threshold is B=b×L, L is a length of the priority processing queue, a and b are coefficients, and a+b=1.
As an improvement to the above solution, the processing the non-real-time messages cached in the common queue according to the adjusted single processing amount in S4 includes:
As an improvement to the above solution, in a case that a message in the common queue overflows, a non-real-time message stored for a longest time at a head of the common queue is discarded.
An example of the disclosure further provides an apparatus for processing messages. The apparatus includes:
As an improvement to the above solution, the checking module adjusts the single processing amount of the non-real-time messages dynamically according to the number of the real-time messages in the priority processing queue, and obtains the adjusted single processing amount of the non-real-time messages as follows: determining the number of the real-time messages in the priority processing queue; and adjusting the single processing amount of the non-real-time messages dynamically according to a numerical relation between the number of the real-time messages, a first threshold and a second threshold, and obtaining the adjusted single processing amount of the non-real-time messages, wherein the first threshold is less than the second threshold.
As an improvement to the above solution, the checking module adjusts the single processing amount of the non-real-time messages dynamically according to a numerical relation between the number of the real-time messages, a first threshold and a second threshold, and obtains the adjusted single processing amount of the non-real-time messages as follows: determining a maximum message processing amount of a Central Processing Unit (CPU) in a time unit as the adjusted single processing amount in a case that the number of the real-time messages is 0; taking, in a case that the number of the real-time messages is greater than 0 and less than the first threshold, or the number of the real-time messages is greater than or equal to the first threshold and less than or equal to the second threshold, the number of the real-time messages as variables of predetermined functions, adjusting the single processing amount of the non-real-time messages dynamically by means of the predetermined functions, and obtaining the adjusted single processing amount of the non-real-time messages; and determining a predetermined constant as the adjusted single processing amount in a case that the number of the real-time messages is greater than the second threshold.
As an improvement to the above solution, the predetermined function are linear functions, and a slope and an adjustment constant of a linear function in the case that the number of the real-time messages is greater than 0 and less than the first threshold are different from a slope and an adjustment constant of a linear function in the case that the number of the real-time messages is greater than or equal to the first threshold and less than or equal to the second threshold.
As an improvement to the above solution, the first threshold is A=a×L, the second threshold is B=b×L, L is a length of the priority processing queue, a and b are coefficients, and a+b=1.
An example of the disclosure further provides a terminal device. The terminal device includes a processor, a memory and a computer program stored in the memory and configured to be executed by the processor. The processor implements any one of the above methods for processing messages when executing the computer program.
An example of the disclosure further provides a computer-readable storage medium. The computer-readable storage medium includes a stored computer program. When running, the computer program controls a device in which the computer-readable storage medium is located to execute any one of the above methods for processing messages.
Compared with the related art, the method and apparatus for processing messages, a terminal device, and a storage medium provided in examples of the disclosure have beneficial effects as follows: an original coherent flow of receiving and processing messages is divided into flows as follows: the messages are received and cached first, and then the messages are processed according to a designed message processing strategy. A processing amount of non-real-time messages is dynamically adjusted according to the number of real-time messages in a priority processing queue, and a single processing amount of the non-real-time messages is obtained. After all the real-time messages are processed, the non-real-time messages are processed according to the single processing amount of the non-real-time messages. Moreover, after a single processing amount of non-real-time messages are processed every time, whether a new message is required to be received in the firmware buffer is checked such that high-priority messages can be prevented from losing. If yes, the next step is returned to the messages receiving step. If no, a single processing amount of non-real-time messages are continued to be processed until all the non-real-time messages are completely processed. Therefore, a packet loss rate of the real-time messages can be reduced, network time delays of the real-time messages can be reduced, timeliness of the real-time messages can be guaranteed, and user experience can be improved.
The technical solutions of the examples of the disclosure will be clearly and completely described below in combination with the accompanying drawings of the examples of the disclosure. Apparently, the described examples are merely some examples, rather than all examples of the disclosure. All other examples obtained by a person of ordinary skill in the art on the basis of the examples of the disclosure without creative efforts shall fall within the protection scope of the disclosure.
With reference to
S1: The messages are received from a firmware buffer sequentially, messages satisfying a real-time message condition are cached into a priority processing queue, and messages not satisfying the real-time message condition are cached into a common queue, wherein the messages satisfying the real-time message condition are real-time messages, and the messages not satisfying the real-time message condition are non-real-time messages.
S2: Whether all messages in the firmware buffer are completely received is checked; if no, S1 is returned to be performed until all the messages in the firmware buffer are completely received; and if yes, a single processing amount of the non-real-time messages is adjusted dynamically according to the number of the real-time messages in the priority processing queue, and an adjusted single processing amount of the non-real-time messages is obtained.
S3: All the real-time messages cached in the priority processing queue are processed.
S4: The non-real-time messages cached in the common queue are processed according to the single processing amount, whether a new message is required to be received from the firmware buffer is checked after a single processing amount of non-real-time messages are processed every time, if yes, S1 is returned to be performed, and if no, a single processing amount of non-real-time messages are continued to be processed until all the non-real-time messages are completely processed.
As at least one alternative embodiment, firstly, during hardware packet reception, messages are cached in the firmware buffer, then the hardware packet reception is interrupted, and the software packet reception is notified. Software receives the messages one by one from the buffer. When each packet is received, whether the real-time message condition is satisfied is determined. The messages satisfying the real-time message condition, that is, the real-time messages, are cached in the priority processing queue. The messages not satisfying the real-time message condition, that is, the non-real-time messages, are cached in the common queue. In this process, all the messages in the firmware buffer are required to be completely received first. Since software processing time of some messages is long, by taking out the messages in time and vacating hardware resources, packet loss can be avoided to a certain extent. Then, whether all the messages in the firmware buffer are completely received is checked. If no, messages are continued to be received until all the messages in the firmware buffer are completely received. If yes, a single processing amount of non-real-time messages is dynamically adjusted according to number x of the real-time messages in the priority processing queue, and the adjusted single processing amount y of the non-real-time messages is obtained. All the real-time messages cached in the priority processing queue are processed. The non-real-time messages cached in the common queue are processed according to the single processing amount. Whether a new message is required to be received from the firmware buffer is checked after a single processing amount of non-real-time messages are processed every time. If yes, messages are returned to be received. If no, a single processing amount of non-real-time messages are continued to be processed until all the non-real-time messages are completely processed.
It should be noted that the messages are cached in the firmware buffer during hardware packet reception, and software may process messages at the same time. When the software processes the messages, the hardware may continue to receive the messages and caches the messages in the firmware buffer. Therefore, after a single amount of non-real-time messages are processed, it is required to return to check whether a new message is required to be received. Determination methods of different real-time messages are different. The Address Resolution Protocol (ARP) message, the Internet Control Messages Protocol (ICMP) message, the Transmission Control Protocol (TCP) message, etc. may be identified by identifying a data link layer/Internet Protocol (IP) used by these messages. Multicast messages may be identified by determining whether a matching Media Access Control (MAC) address satisfies a multicast MAC address.
In the example, by adjusting a flow of receiving and processing messages by a home gateway, an original coherent flow of receiving and processing messages is divided into flows as follows: the messages are received and cached first, and then the messages are processed according to a designed message processing strategy. A processing amount of non-real-time messages is dynamically adjusted according to the number of real-time messages in a priority processing queue, and a single processing amount of the non-real-time messages is obtained. After all the real-time messages are processed, the non-real-time messages are processed according to the single processing amount of the non-real-time messages. Moreover, after a single processing amount of non-real-time messages are processed every time, whether a new message is required to be received from the firmware buffer is checked such that high-priority messages can be prevented from losing. If yes, messages are returned to be received. If no, a single processing amount of non-real-time messages are continued to be processed until all the non-real-time messages are completely processed. Therefore, a packet loss rate of the real-time messages can be reduced, network time delays of the real-time messages can be reduced, timeliness of the real-time messages can be guaranteed, and user experience can be improved.
In another preferred example, the step of adjusting the single processing amount of the non-real-time messages dynamically according to the number of the real-time messages in the priority processing queue, and obtaining the adjusted single processing amount of the non-real-time messages in S2 includes: the number of the real-time messages in the priority processing queue is determined; and the single processing amount of the non-real-time messages is adjusted dynamically according to a numerical relation between the number of the real-time messages, a first threshold and a second threshold, and the adjusted single processing amount of the non-real-time messages is obtained, wherein the first threshold is less than the second threshold.
In the example, the single processing amount of the non-real-time messages may be dynamically adjusted according to the number of the real-time messages such that network time delay of the real-time messages can be reduced, and timeliness of the real-time messages can be ensured.
In the above example, the step of adjusting the single processing amount of the non-real-time messages dynamically according to the numerical relation between the number of the real-time messages, the first threshold and the second threshold, and obtaining the adjusted single processing amount of the non-real-time messages includes: the maximum message processing amount of the Central Processing Unit (CPU) in a time unit is determined as the single processing amount in the case that the number of the real-time messages is 0; in the case that the number of the real-time messages is greater than 0 and less than the first threshold, or the number of the real-time messages is greater than or equal to the first threshold and less than or equal to the second threshold, the number of the real-time messages is taken as variables of predetermined functions, the single processing amount of the non-real-time messages are adjusted dynamically by means of the predetermined functions, and the adjusted single processing amount of the non-real-time messages are obtained; and a predetermined constant is determined as the single processing amount in the case that the number of the real-time messages is greater than the second threshold.
Under the condition that the predetermined functions are linear functions, a slope and an adjustment constant of a linear function in a case that the number of the real-time messages is greater than 0 and less than the first threshold are different from a slope and an adjustment constant of a linear function in a case that the number of the real-time messages is greater than or equal to the first threshold and less than or equal to the second threshold.
The step of adjusting the single processing amount of the non-real-time messages dynamically according to the number of the real-time messages in the priority processing queue, and obtaining the adjusted single processing amount of the non-real-time messages in S2 includes:
the single processing amount of the non-real-time messages is adjusted dynamically by means of the piecewise function
the adjusted single processing amount y of the non-real-time messages is obtained.
As at least one alternative embodiment, x is the number of the real-time messages in the priority processing queue, A is a first threshold, B is a second threshold, y1 is the maximum message processing amount of the CPU in a time unit, y2 is a preset constant used for controlling the processing rate of the non-real-time messages when the real-time messages are seriously accumulated, c1 and c3 are adjustment constants, and c2 and c4 are slopes.
As at least one alternative embodiment, in the example, it is suggested that y1 is the maximum message processing amount of the CPU in the time unit, and can also be set according to actual requirements during specific application. The single processing amount of the non-real-time messages is dynamically adjusted by means of the piecewise function
and the adjusted single processing amount y of the non-real-time messages is obtained. When number x of the real-time messages in the priority processing queue is increased from 0 to A, the single processing amount of non-real-time messages slowly decreases. When number x of the real-time messages in the priority processing queue increases from A to B, the single processing amount of non-real-time messages greatly decreases. When number x of the real-time messages in the priority processing queue is greater than B, it is indicated that the real-time messages are seriously accumulated. It is required to strictly limit the single processing amount of the non-real-time messages, and the real-time messages are processed first such that timeliness of the real-time messages is ensured. Specific interval settings can be adjusted according to actual requirements.
It should be noted that single processing amount y of the non-real-time messages non-linearly decreases as number x of cached real-time messages increases. The greater x is, the faster a decrease speed of y is. A processing rate of the non-real-time messages has a nonlinear relation with single processing amount y. When y is small, the processing rate of the non-real-time messages rapidly increases. As y increases, the processing rate of the non-real-time messages slowly increases. When y reaches a threshold, the processing rate of the non-real-time messages basically stops increasing. It should be noted that in cases of different models, interval ranges may fluctuate to a certain extent.
In the example, a dynamic adjustment formula is a linear function such that the system can be effectively prevented from complexly operating, and can be prevented from affecting the performance of processing messages.
In another preferred example, the first threshold is A=a×L, the second threshold is B=b×L, L is a length of the priority processing queue, a and b are coefficients, and a+b=1. For example, in the example, a is ⅓, b is ⅔, and the piecewise function is as follows:
In another preferred example, the step of processing the non-real-time messages cached in the common queue according to the single processing amount in S4 includes:
As at least one alternative embodiment, the single processing amount y is retrieved after it is detected that all the real-time messages in the priority processing queue are completely processed. The non-real-time messages cached in the common queue are processed according to the single processing amount y every time. Whether a new message is required to be received from the firmware buffer is checked after the single processing amount of non-real-time messages are processed every time, if yes, S1 is returned to be performed, and if no, the single processing amount of non-real-time messages are continued to be processed until all the non-real-time messages are completely processed.
As a preferred solution, in a case that a message in the common queue overflows, a non-real-time message stored for the longest time at a head of the common queue is discarded.
It should be noted that a message processing capacity of the CPU should be greater than the receiving rate of the real-time messages such that an overflow phenomenon of the priority processing queue can be avoided. If performance saturation occurs on a gateway, the non-real-time messages are discarded such that the real-time messages can be ensured to be processed in time, and packets cannot be lost as much as possible. If overflow is about to occur on a common queue, a message stored for the longest time at a head of the queue is selected to be discarded such that a new message can be received.
Accordingly, the disclosure further provides an apparatus for processing messages, which may implement all flows of the method for processing messages in the above example.
With reference to
a receiving module 301, configured to receive the messages from a firmware buffer sequentially, cache messages satisfying a real-time message condition into a priority processing queue, and cache messages not satisfying the real-time message condition into a common queue, wherein the messages satisfying the real-time message condition are real-time messages, and the messages not satisfying the real-time message condition are non-real-time messages;
a checking module 302, configured to check whether all messages in the firmware buffer are completely received; if no, return to S1 until all the messages in the firmware buffer are completely received; and if yes, adjust a single processing amount of the non-real-time messages dynamically according to the number of the real-time messages in the priority processing queue, and obtain an adjusted single processing amount of the non-real-time messages;
As at least one alternative embodiment, the checking module adjusts the single processing amount of the non-real-time messages dynamically according to the number of the real-time messages in the priority processing queue, and obtains the adjusted single processing amount of the non-real-time messages as follows: determine the number of the real-time messages in the priority processing queue; and adjust the single processing amount of the non-real-time messages dynamically according to a numerical relation between the number of the real-time messages, a first threshold and a second threshold, and obtain the adjusted single processing amount of the non-real-time messages, wherein the first threshold is less than the second threshold.
As at least one alternative embodiment, the checking module adjusts the single processing amount of the non-real-time messages dynamically according to a numerical relation between the number of the real-time messages, a first threshold and a second threshold, and obtains the adjusted single processing amount of the non-real-time messages as follows: determine a maximum message processing amount of the CPU in a time unit as the adjusted single processing amount in a case that the number of the real-time messages is 0; takes, in a case that the number of the real-time messages is greater than 0 and less than the first threshold, or the number of the real-time messages is greater than or equal to the first threshold and less than or equal to the second threshold, the number of the real-time messages as variables of predetermined functions, adjust the single processing amount of the non-real-time messages dynamically by means of the predetermined functions, and obtain the adjusted single processing amount of the non-real-time messages; and determine a predetermined constant as the adjusted single processing amount in a case that the number of the real-time messages is greater than the second threshold.
As at least one alternative embodiment, the predetermined functions are linear functions, and a slope and an adjustment constant of a linear function in the case that the number of the real-time messages is greater than 0 and less than the first threshold are different from a slope and an adjustment constant of a linear function in the case that the number of the real-time messages is greater than or equal to the first threshold and less than or equal to the second threshold.
As at least one alternative embodiment, the checking module 302 adjusts a single processing amount of the non-real-time messages dynamically according to the number of the real-time messages in the priority processing queue, and obtains an adjusted single processing amount of the non-real-time messages as follows:
and obtain the adjusted single processing amount y of the non-real-time messages.
As at least one alternative embodiment, x is the number of the real-time messages in the priority processing queue, A is a first threshold, B is a second threshold, y1 is the maximum message processing amount of the CPU in a time unit, y2 is a preset constant used for controlling the processing rate of the non-real-time messages when the real-time messages are seriously accumulated, c1 and c3 are adjustment constants, and c2 and c4 are slopes.
As at least one alternative embodiment, the first threshold is A=a×L, the second threshold is B=b×L, L is a length of the priority processing queue, a and b are coefficients, and a+b=1.
As at least one alternative embodiment, the non-real-time message processing module 304 processes the non-real-time messages cached in the common queue according to the single processing amount as follows:
As at least one alternative embodiment, in a case that a message in the common queue overflows, a non-real-time message stored for the longest time at a head of the common queue is discarded.
During specific implementation, the working principle, control flow and achieved technical effect of the apparatus for processing messages provided in an example of the disclosure are correspondingly the same as those of the method for processing messages in the above example, and will not be repeated herein.
With reference to
Preferably, the computer program may be partitioned into one or more modules/units (such as computer program 1, computer program 2, . . . ). The one or more modules/units are stored in the memory 402 and executed by the processor 401, so as to complete the disclosure. The one or more modules/units may be a series of computer program instruction segments capable of completing a particular function. The instruction segments are used for describing an execution process of the computer program in the terminal device.
The processor 401 may be a central processing unit (CPU), and may be a different general purpose processor, a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or a different programmable logic device, a discrete gate or transistor logic device, a discrete hardware component, etc. The general purpose processor may be a microprocessor. The processor 401 may be any conventional processor. The processor 401 is a control center of a terminal device, and is connected to various parts of the terminal device by various interfaces and circuits.
The memory 402 mainly includes a program storage region and a data storage region. The program storage region can store an operating system, an application required by at least one function, etc. The data storage region can store related data, etc. In addition, the memory 402 may be a high-speed random access memory, or a nonvolatile memory, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card and a flash card, or the memory 402 may be a different volatile solid state memory device.
It should be noted that the above terminal device may include but is not limited to a processor and a memory. Those skilled in the art may understand that the schematic structural diagram of
An example of the disclosure further provides a computer-readable storage medium. The computer-readable storage medium includes a stored computer program. When running, the computer program controls a device in which the computer-readable storage medium is located to execute the method for processing messages in any one of the above examples.
Examples of the disclosure provide a method and apparatus for processing messages, a terminal device, and a storage medium. An original coherent flow of receiving and processing messages is divided into flows as follows: the messages are received and cached first, and then the messages are processed according to a designed message processing strategy. A processing amount of non-real-time messages is dynamically adjusted according to the number of real-time messages in a priority processing queue, and a single processing amount of the non-real-time messages is obtained. After all the real-time messages are processed, the non-real-time messages are processed according to the single processing amount of the non-real-time messages. Moreover, after the single processing amount of non-real-time messages are processed every time, whether a new message is required to be received from the firmware buffer is checked such that high-priority messages can be prevented from being lost. If yes, messages are received. If no, a single processing amount of non-real-time messages are continued to be processed until all the non-real-time messages are completely processed. Therefore, a packet loss rate of the real-time messages can be reduced, network time delays of the real-time messages can be reduced, timeliness of the real-time messages can be guaranteed, and user experience can be improved.
It should be noted that a system example described above is merely schematic, wherein the unit described as a separate component may be physically separated or not, and a component displayed as a unit may be a physical unit or not, that is, the component may be located at one place, or distributed on multiple network units. Some or all of modules can be selected according to actual requirements to achieve the objective of the solution of the example. In addition, in accompanying drawings of the system example provided in the disclosure, a connection relation between modules indicates that there is communication connection between the modules. Specifically, the communication connection may be implemented as one or more communication buses or signal lines. Those of ordinary skill in the art can understand and implement the disclosure without making creative efforts.
The above embodiments are preferred embodiments of the disclosure. It should be noted that those of ordinary skill in the art can further make several improvements and modifications without departing from a principle of the disclosure. These improvements and modifications should also be regarded as falling within the protection scope of the disclosure.
Number | Date | Country | Kind |
---|---|---|---|
202210142967.8 | Feb 2022 | CN | national |
Filing Document | Filing Date | Country | Kind |
---|---|---|---|
PCT/CN2023/076263 | 2/15/2023 | WO |