Message filtering method and device, storage medium, and electronic device
By parsing and managing the message filtering table and cache table in the terminal, the problem of abnormal status caused by the terminal receiving a large number of messages is solved, effective control of message flow is achieved, and packet loss and impact damage are prevented.
Patent Information
- Application Number
- CN202111182608.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-10-11
- Publication Date
- 2024-10-01
- Estimated Expiration
- 2041-10-11
AI Technical Summary
In a communication network, when a terminal receives a large number of messages, its processing capacity is exceeded, causing the device to enter a serious abnormal state. Existing technologies cannot effectively solve this problem.
When the terminal receives the target message, it parses the filter entries in the filter table queue, determines the message type and priority, discards low-priority messages, and caches the message in the cache table queue, based on preset conditions Manage buffer capacity and establish monitoring message tables to send alarm information and control message flow.
It effectively prevents packet loss, avoids the impact damage of the equipment due to sudden packet traffic, and ensures the normal operation of the terminal.
Smart Images

Figure CN113923169B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of communications, and in particular to a message filtering method and device, a storage medium, and an electronic device. Background Art
[0002] In communications networks, the continuous addition of network devices leads to explosive growth in network packets. This, combined with limited bandwidth, often causes network congestion or traffic storms. In situations of network congestion, methods such as selectively accepting packets, discarding unnecessary packets, and controlling the packet reception rate have become important means of ensuring proper device operation.
[0003] Traditional methods for suppressing network packet reception involve starting a counter on the receiving device to count the number of packets within a specified time window. If the number of packets exceeds the limit, the packets are buffered or dropped. However, if the number of packets exceeds the limit, the packets are immediately dropped, causing anomalies in the service currently processing the packets, thus affecting the normal operation of the device.
[0004] In related technologies, there is no effective solution to the problem that the terminal receives a large number of messages that exceed its processing capacity, causing the device to enter a serious abnormal state. Summary of the Invention
[0005] The embodiments of the present invention provide a message filtering method and device, a storage medium, and an electronic device to at least solve the problem in the related art that a terminal receives a large number of messages that exceed its processing capacity, causing the device to enter a serious abnormal state.
[0006] According to one embodiment of the present invention, a method for filtering a message is provided, comprising: when a terminal receives a target message, parsing all filter tables in a filter table queue of the terminal, wherein the filter table comprises: filter table items, and the filter table items comprise: message type, message priority; traversing the filter table items of all the filter tables, and determining whether there are one or more target filter tables in the filter table items of all the filter tables, wherein the target message type of the target filter table is consistent with the message type of the target message; when it is determined that there are one or more target filter tables in the filter table items of all the filter tables, determining whether the priority of a first message in the target filter table is less than the message priority of the target message, and when the priority of the first message is less than the message priority of the target message, discarding the first message.
[0007] In an exemplary embodiment, when it is determined that one or more target filter tables do not exist in the filter table items of all the filter tables, all cache tables in the cache table queue of the terminal are parsed, wherein the cache table includes: the cache table items include: message type, priority; the cache table items of all cache tables are traversed to determine whether there are one or more target cache tables in the cache table items of all the cache tables, wherein the target message type of the target cache table is consistent with the message type of the target message; when it is determined that there are one or more target cache tables in the cache table items of all the cache tables, the target cache table corresponding to the target message type is determined, and the target message is cached to the target message cache area corresponding to the target cache table.
[0008] In an exemplary embodiment, caching the target message into the target message cache area corresponding to the target cache table includes: determining whether the capacity of the target message cache area meets a preset condition; and caching the target message into the target message cache area corresponding to the target cache table if the preset condition is met.
[0009] In an exemplary embodiment, determining whether the capacity of the target message buffer area meets a preset condition includes: determining whether the number of second messages cached by the target message buffer area is equal to a first preset threshold, wherein the first preset threshold is used to indicate the maximum number of messages cached by the target message buffer area; and determining that the capacity of the target message buffer area meets the preset condition when the number of second messages cached by the target message buffer area is less than the first preset threshold.
[0010] In an exemplary embodiment, after determining whether the capacity of the target message cache area meets a preset condition, the method further includes: when the number of second messages cached in the target cache database is equal to the first preset threshold, determining whether the priority of the second message cached in the target cache database is greater than the priority of the target message; when the priority of the second message is less than the priority of the target message, discarding the second message and caching the target message.
[0011] In an exemplary embodiment, when the terminal receives the target message, before parsing all filter tables in the filter table queue of the terminal, the method also includes: determining the number of received monitoring messages; when the number of the monitoring messages is greater than the filter watermark, establishing a filter table corresponding to the monitoring message, and adding the filter table corresponding to the monitoring message to the filter table queue.
[0012] In an exemplary embodiment, after determining the number of received monitoring messages, the method further includes: when the number of the monitoring messages is less than the filtering waterline and the number of the monitoring messages is greater than the cache waterline, establishing a cache table corresponding to the monitoring message and adding the cache table corresponding to the monitoring message to the cache table queue; obtaining the alarm notification address in the cache table corresponding to the monitoring message, and sending an alarm message to the source end corresponding to the alarm notification address, wherein the alarm information is used to instruct the source end corresponding to the alarm notification address to send the target message according to a preset strategy.
[0013] In an exemplary embodiment, after determining the number of received monitoring messages, the method further includes: when the number of the monitoring messages is less than the cache waterline, determining whether there is a cache table corresponding to the monitoring message in the cache table queue; when there is a cache table corresponding to the monitoring message in the cache table queue, determining the delayed reception time of the target cache table; and writing the target message in the target cache data into the network protocol stack corresponding to the target message according to the delayed reception time.
[0014] According to another embodiment of the present invention, a message filtering device is also provided, including a parsing module for parsing all filter tables in a filter table queue of a terminal when a target message is received by the terminal, wherein the filter table includes: filter table items, and the filter table items include: message type and message priority; a determination module for traversing the filter table items of all the filter tables to determine whether there are one or more target filter tables in the filter table items of all the filter tables, wherein the target message type of the target filter table is consistent with the message type of the target message; a filtering module for determining whether the priority of a first message in the target filter table is less than the message priority of the target message when it is determined that there are one or more target filter tables in the filter table items of all the filter tables, and discarding the first message when the priority of the first message is less than the message priority of the target message.
[0015] According to yet another embodiment of the present invention, a computer-readable storage medium is provided, in which a computer program is stored. The computer program is configured to execute the steps of any one of the above method embodiments when run.
[0016] According to another embodiment of the present invention, an electronic device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to perform the steps in any one of the above method embodiments.
[0017] The present invention provides a message filtering method, comprising: when a terminal receives a target message, parsing all filter tables in a filter table queue of the terminal, wherein the filter table comprises: filter table items, and the filter table items comprise: message type and message priority; traversing the filter table items of all filter tables, and determining whether a target message type consistent with the message type of the target message exists in the filter table items of all filter tables; and when determining whether one or more target filter tables exist in the filter table items of all filter tables, wherein the target message type of the target filter table is consistent with the message type of the target message, filtering the filter table and filtering the message type of the target message. Consistent; when it is determined that there are one or more target filter tables in the filter table items of all the filter tables, determine whether the priority of the first message in the target filter table is less than the message priority of the target message. When the priority of the first message is less than the message priority of the target message, discard the first message. The above scheme solves the problem in the related technology that the terminal receives a large number of messages, which exceeds its processing capacity, causing the device to enter a serious abnormal state, etc., and thus prevents packet loss when the message traffic bursts, and prevents impact damage to the terminal when the message traffic is too large. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of this application. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:
[0019] Figure 1 This is a hardware structure block diagram of a computer terminal for a message filtering method according to an embodiment of the present invention;
[0020] Figure 2 is a flow chart of a method for filtering messages according to an embodiment of the present invention;
[0021] Figure 3 A schematic diagram of a message filtering method according to an optional embodiment of the present invention;
[0022] Figure 4 A flowchart of a counter processing method of a message filtering method according to an optional embodiment of the present invention;
[0023] Figure 5 It is a structural block diagram of a message filtering device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0024] The present invention will be described in detail below with reference to the accompanying drawings and in combination with embodiments. It should be noted that, unless there is a conflict, the embodiments and features in the embodiments of the present application can be combined with each other.
[0025] It should be noted that the terms "history", "second" and the like in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.
[0026] The method embodiments provided in the embodiments of the present application can be executed in a computer terminal or similar computing device. Taking running on a computer terminal as an example, Figure 1 FIG. 1 is a hardware structure diagram of a computer terminal for a message filtering method according to an embodiment of the present invention. Figure 1 As shown, the computer terminal may include one or more ( Figure 1 Only one is shown) a processor 102 (the processor 102 may include but is not limited to a microprocessor MCU or a programmable logic device FPGA and other processing devices) and a memory 104 for storing data. In an exemplary embodiment, the computer terminal may also include a transmission device 106 and an input / output device 108 for communication functions. It will be understood by those skilled in the art that Figure 1 The structure shown is only for illustration and does not limit the structure of the above-mentioned computer terminal. For example, the computer terminal may also include Figure 1 More or fewer components than shown, or with Figure 1 Equivalent functions or comparisons shown Figure 1 Shown are different configurations with more functionality.
[0027] The memory 104 can be used to store computer programs, such as software programs and modules of application software, such as the computer program corresponding to the message filtering method of the computer terminal in the embodiment of the present invention. The processor 102 executes the computer program stored in the memory 104 to execute various functional applications and data processing, thereby implementing the above-mentioned method. The memory 104 may include a high-speed random access memory and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include a memory remotely located relative to the processor 102, and these remote memories can be connected to the computer terminal via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0028] The transmission device 106 is used to receive or send data via a network. A specific example of the aforementioned network may include a wireless network provided by a computer terminal's communications provider. In one embodiment, the transmission device 106 includes a network interface controller (NIC), which can be connected to other network devices via a base station to enable communication with the Internet. In another embodiment, the transmission device 106 may be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0029] In this embodiment, a message filtering method is provided, which is applied to the above-mentioned computer terminal. Figure 2 4 is a flow chart of a method for filtering packets according to an embodiment of the present invention, the flow chart comprising the following steps:
[0030] Step S202: When the terminal receives the target message, all filter tables in the filter table queue of the terminal are parsed, wherein the filter table includes: filter table items, and the filter table items include: message type and message priority;
[0031] It should be noted that the filter table includes: filter table name, packet loss priority, and filter table items (message type, priority).
[0032] Step S204, traversing the filter table entries of all the filter tables to determine whether there are one or more target filter tables in the filter table entries of all the filter tables, wherein the target message type of the target filter table is consistent with the message type of the target message;
[0033] Step S206, when it is determined that there are one or more target filter tables in the filter table entries of all the filter tables, determine whether the priority of the first message in the target filter table is less than the message priority of the target message. If the priority of the first message is less than the message priority of the target message, discard the first message.
[0034] Through the above steps, when a terminal receives a target message, all filter tables in a filter table queue of the terminal are parsed, wherein the filter table includes: a filter table entry, and the filter table entry includes: a message type and a message priority; the filter table entries of all the filter tables are traversed to determine whether one or more target filter tables exist in the filter table entries of all the filter tables, wherein the target message type of the target filter table is consistent with the message type of the target message; when it is determined that one or more target filter tables exist in the filter table entries of all the filter tables, the target filter table corresponding to the target message type is determined; and whether the priority of a first message in the target filter table is less than the message priority of the target message is determined. If the priority of the first message is less than the message priority of the target message, the first message is discarded. The above solution solves the problem in the related art that a terminal enters a serious abnormal state due to receiving a large number of messages that exceeds its processing capacity. Furthermore, packet loss can be prevented when message traffic bursts, and impact damage to the terminal can be prevented when the message traffic is too large.
[0035] In an exemplary embodiment, when it is determined that one or more target filter tables do not exist in the filter table items of all the filter tables, all cache tables in the cache table queue of the terminal are parsed, wherein the cache table includes: the cache table items include: message type, priority; the cache table items of all cache tables are traversed to determine whether there are one or more target cache tables in the cache table items of all the cache tables, wherein the target message type of the target cache table is consistent with the message type of the target message; when it is determined that there are one or more target cache tables in the cache table items of all the cache tables, the target cache table corresponding to the target message type is determined, and the target message is cached to the target message cache area corresponding to the target cache table.
[0036] It should be noted that determining whether there is a target message type consistent with the message type of the target message in the cache table entries of all the cache tables can be understood as: determining whether the message type of the target message is consistent with the target message type in the target cache table, and when it is determined that the message type of the target message is consistent with the target message type in the target cache table, caching the target message to the target message cache area corresponding to the target cache table; when it is determined that the message type of the target message is inconsistent with the target message type in the target cache table, determining whether to cache the target message based on the message priority.
[0037] In an exemplary embodiment, caching the target message into the target message cache area corresponding to the target cache table includes: determining whether the capacity of the target message cache area meets a preset condition; and caching the target message into the target message cache area corresponding to the target cache table if the preset condition is met.
[0038] That is, the relationship between the capacity of the target message buffer area and the preset condition is determined, and when the capacity of the target message buffer area meets the preset condition, the target message is cached in the target message buffer area corresponding to the target cache table.
[0039] Specifically, determine whether the number of second messages cached in the target message buffer area is equal to a first preset threshold, wherein the first preset threshold is used to indicate the maximum number of messages cached in the target message buffer area; when the number of second messages cached in the target message buffer area is less than the first preset threshold, determine that the capacity of the target message buffer area meets the preset conditions.
[0040] That is to say, the relationship between the capacity of the target message buffer area and the preset condition is determined specifically in the following manner: when the number of second messages cached in the target message buffer area is less than the first preset threshold, it is determined that the capacity of the target message buffer area meets the preset condition; when the number of second messages cached in the target message buffer area is equal to the first preset threshold, it is determined that the capacity of the target message buffer area does not meet the preset condition.
[0041] In an exemplary embodiment, after determining whether the capacity of the target message cache area meets a preset condition, if the number of second messages cached in the target cache database is equal to the first preset threshold, determine whether the priority of the second message cached in the target cache database is greater than the priority of the target message; if the priority of the second message is less than the priority of the target message, discard the second message and cache the target message. Further, if the number of second messages cached in the target message cache area is equal to the first preset threshold, that is, if the capacity of the target message cache area does not meet the preset condition, determine the priority of the second message and the priority of the target message, compare the size relationship between the priority of the second message and the priority of the target message, and if the size relationship indicates that the priority of the second message is greater than the priority of the target message, discard the target message; if the size relationship indicates that the priority of the second message is less than the priority of the target message, discard the second message and cache the target message.
[0042] Further, when it is determined that the message type of the target message is inconsistent with the target message type in the target cache table, and the message type of the target message is inconsistent with the target message type in the target filter table, the target message is processed normally.
[0043] In an exemplary embodiment, before parsing the target filter table in the filter table queue, the number of received monitoring messages is determined; when the number of the monitoring messages is greater than the filter waterline, a filter table corresponding to the monitoring message is established, and the filter table corresponding to the monitoring message is added to the filter table queue.
[0044] That is to say, the number of received monitoring messages is determined. If the number of received monitoring messages is greater than the filter waterline, a filter table is established for the monitoring messages, the filter table is added to the filter table queue, and the packet loss priority of the filter table is set to a priority less than the second preset threshold. If a filter table already exists in the filter table queue, the packet loss priority of the filter table is increased by one. If the priority of the filter table is greater than the third preset threshold, all messages corresponding to the filter table are discarded.
[0045] In an exemplary embodiment, when the number of the monitoring messages is less than the filtering waterline and the number of the monitoring messages is greater than the cache waterline, a cache table corresponding to the monitoring message is established, and the cache table corresponding to the monitoring message is added to the cache table queue; the alarm notification address in the cache table corresponding to the monitoring message is obtained, and an alarm message is sent to the source end corresponding to the alarm notification address, wherein the alarm message is used to instruct the source end corresponding to the alarm notification address to send the target message according to a preset strategy.
[0046] Furthermore, when the number of monitoring messages is less than the filtering waterline and the number of the monitoring messages is greater than the cache waterline, a cache table corresponding to the monitoring message is established, and the cache table corresponding to the monitoring message is added to the cache table queue, and the alarm notification address in the cache table corresponding to the monitoring message is determined, and the alarm information is sent to the source end corresponding to the alarm notification address through a UDP message. After the notified source end receives the alarm information, it performs message flow control according to the content of the cache table in the alarm information and the predetermined strategy. If the cache table corresponding to the monitoring message already exists in the cache table queue, the alarm information is directly sent to the source end corresponding to the alarm notification address through a UDP message.
[0047] In an exemplary embodiment, after determining the number of received monitoring messages, if the number of the monitoring messages is less than the cache waterline, determine whether a cache table corresponding to the monitoring message exists in the cache table queue; if there is a cache table corresponding to the monitoring message in the cache table queue, determine the delayed reception time of the cache table corresponding to the monitoring message; and write the target message in the cache table corresponding to the monitoring message into the network protocol stack corresponding to the target message according to the delayed reception time.
[0048] That is, read the delayed receiving time of the cache table corresponding to the monitoring message, start the delayed task processing work queue according to the read delayed receiving time, read the message in the target message cache area corresponding to the cache table corresponding to the monitoring message into the network protocol stack, and at the same time set the cache status of the cache table corresponding to the monitoring message to empty, and move the cache table corresponding to the monitoring message out of the cache queue.
[0049] Furthermore, when the target filter table is closed, the packet loss priority of the target filter table is adjusted to a priority lower than a second preset threshold, and the target filter table is removed from the filter table queue. The filter watermark and cache watermark are dynamically adjusted according to the memory usage or the CPU usage.
[0050] In order to better understand the process of the above-mentioned message filtering method, the process of the above-mentioned message filtering method is described below in combination with optional embodiments, but it is not used to limit the technical solution of the embodiment of the present invention.
[0051] An embodiment of the present invention provides a message filtering method. This method, through a message reception processing flow and a message monitoring counter processing flow, implements caching, alarm notification, and discarding of received messages for a central processing unit (CPU) based on pre-set filter watermarks, cache watermarks, and corresponding cache and filter tables. This method achieves control over message reception and allows flexible control of the impact of network messages on devices based on different application scenarios. The detailed process is as follows:
[0052] Figure 3 Schematic diagram of a method for filtering messages according to an optional embodiment of the present invention, such as Figure 3 As shown in the figure, the specific steps of the message receiving process are as follows:
[0053] Step S301: Counting the received monitoring messages (equivalent to the target messages in the above embodiment);
[0054] Step S302: Read all filter tables in the filter table queue and parse all filter tables;
[0055] Step S303: Determine whether a filter table entry in the filter table queue contains a target message type that is consistent with the message type of the monitored message. If so, and if the filter condition is met, execute step S304; if not, or if the filter condition is not met, execute step S305.
[0056] The filtering condition is: the priority of the second message in the target filtering table is greater than the priority of the monitoring message.
[0057] Step S304: discard the monitoring message and terminate the remaining message receiving process;
[0058] Step S305: Read all cache tables in the cache table queue and parse all cache tables;
[0059] Step S306: Determine whether there is a target message type that is consistent with the message type of the monitored message in the cache table entries in all cache tables. If so, and if the cache conditions are met, execute step S307; if not, or if the cache conditions are not met, execute step S308;
[0060] The preset condition is that: the target message buffer area corresponding to the target buffer table has surplus capacity or the message priority of the monitoring message is greater than the message priority of the first message in the target message buffer area.
[0061] Step S307: Buffer the monitoring message and terminate the remaining message receiving process;
[0062] Step S308: When the monitoring message does not match the cache table and the filter table, the normal message receiving process is entered.
[0063] In the above step S305, the target cache table is parsed in the following manner:
[0064] The notification address stored in the target cache table (equivalent to the alarm notification address in the above embodiment) is read, and an alarm message is sent to the notification address. The content of the message is the content of the cache table. After receiving the alarm message, the notified device (equivalent to the source end in the above embodiment) performs message flow control based on the content of the cache table and a predetermined policy to reduce the number of messages sent by the notified device. Secondly, when a monitoring message is received, the monitoring message is matched with the message type in the target cache table and the matching monitoring message is cached in the cache allocated by the target cache table. Finally, when the target message is stored in the cache allocated by the target cache table, the number of cached messages stored in the target cache table is first read to determine whether the number of caches allocated for the internal cache table has reached the upper limit. If the allocated number of caches has reached the upper limit, the relationship between the priority of the stored message and the priority of the target message is determined. If the relationship indicates that the priority of the stored message is less than the priority of the target message, space is released for the target message. If the priority of the stored message is greater than the priority of the target message, the target message is discarded.
[0065] In the above step S302, the target filter table is parsed in the following manner:
[0066] According to the priority of the messages in the target filter table, the message with the lowest priority is discarded first. In the next cycle, the message with the lowest priority is discarded again until all the messages saved in the target filter table are discarded.
[0067] Figure 4 FIG. 1 is a flow chart of a counter processing method for filtering messages according to an optional embodiment of the present invention, as shown in FIG. Figure 4 As shown, the counter processing flow can be implemented through the following steps:
[0068] Step S401: Count monitoring messages, read the monitoring message counter, and determine the monitoring message count value;
[0069] Step S402: Determine whether the monitoring message count value is greater than the filtering watermark; if the monitoring message count value is greater than the filtering watermark, execute step S403; if the monitoring message count value is less than the filtering watermark, execute step S404;
[0070] Step S403: Add the target filter table corresponding to the monitoring message to the filter table queue, set the packet loss priority of the filter table to a priority lower than the second preset threshold; if the target filter table corresponding to the monitoring message is already in the filter table queue, increase the packet loss priority of the target filter table by one until it exceeds the third preset threshold, and then discard the message corresponding to the target filter table;
[0071] Step S404: Determine whether the monitoring message count value is greater than the cache waterline; if the monitoring message count value is greater than the cache waterline, execute step S405; if the monitoring message count value is less than the cache waterline, execute step S406;
[0072] Step S405: Add the target cache table corresponding to the monitoring message to the cache table queue, and send the alarm information to the source end corresponding to the alarm notification address via a UDP message. If the target cache table corresponding to the monitoring message is already in the cache table queue, directly send the alarm information to the source end corresponding to the alarm notification address via a UDP message.
[0073] Step S406: If the target cache table corresponding to the monitoring message is already in the cache table queue, the target cache table is taken out from the cache table queue and closed;
[0074] Step S407: If the target filter table corresponding to the monitoring message is already in the filter table queue, the target filter table is taken out from the filter table queue and closed;
[0075] Step S408: Clear the monitoring message counter.
[0076] Specifically, the method of closing the target cache table in step S406 is as follows:
[0077] Read the delayed receiving time of the target cache table, start the delayed task processing work queue according to the read delayed receiving time, read the message in the target cache table into the network protocol stack, and at the same time set the cache status of the target cache table to empty, and remove the target cache table from the cache table queue.
[0078] Specifically, the method of closing the target filter table in step S407 is as follows:
[0079] The packet loss priority of the target filter table is adjusted to a priority lower than the second preset threshold, and the target filter table is removed from the filter table queue.
[0080] Furthermore, the filter watermark and cache watermark can be dynamically adjusted according to the memory usage or the CPU usage.
[0081] In summary, by starting a timer to count the number of specific messages, when the set buffering watermark is exceeded, the message buffering action is triggered and the remote device is notified of the suppression action; when the message filtering watermark is exceeded, the message filtering action is triggered. By using the embodiments of the present invention, packet loss can be prevented when message traffic bursts occur, and impact damage to devices can be prevented when message traffic is excessive.
[0082] Through the description of the above embodiments, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus the necessary general hardware platform, and of course it can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for enabling a terminal device (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods described in each embodiment of the present invention.
[0083] This embodiment also provides a message filtering device for implementing the above-mentioned embodiments and preferred embodiments. Details already described will not be repeated here. As used below, the term "module" may refer to a combination of software and / or hardware that implements a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, implementation using hardware, or a combination of software and hardware, is also possible and contemplated.
[0084] Figure 5 is a structural block diagram of a message filtering device according to an embodiment of the present invention; Figure 5 Shown, including:
[0085] The parsing module 52 is configured to parse all filter tables in the filter table queue of the terminal when the terminal receives the target message, wherein the filter table includes: filter table items, and the filter table items include: message type and message priority;
[0086] It should be noted that the target cache table includes: cache table name, alarm notification address, message cache size, cache message delay reception time, cache table entry (message type, priority).
[0087] a determination module 54 configured to traverse the filter table entries of all the filter tables and determine whether one or more target filter tables exist in the filter table entries of all the filter tables, wherein the target message type of the target filter table is consistent with the message type of the target message;
[0088] It should be noted that the filter table includes: filter table name, packet loss priority, filter table items (message type, priority)
[0089] The filtering module 56 is used to determine whether the priority of the first message in the target filter table is less than the message priority of the target message when it is determined that there are one or more target filter tables in the filter table items of all the filter tables, and discard the first message when the priority of the first message is less than the message priority of the target message.
[0090] Through the above module, when a terminal receives a target message, all filter tables in a filter table queue of the terminal are parsed, wherein the filter table includes: a filter table item, and the filter table item includes: a message type and a message priority; the filter table items of all filter tables are traversed to determine whether one or more target filter tables exist in the filter table items of all filter tables, wherein the target message type of the target filter table is consistent with the message type of the target message; when it is determined that one or more target filter tables exist in the filter table items of all filter tables, the target filter table corresponding to the target message type is determined; and whether the priority of a first message in the target filter table is less than the message priority of the target message is determined. If the priority of the first message is less than the message priority of the target message, the first message is discarded. The above solution solves the problem in the related art that a terminal enters a serious abnormal state due to receiving a large number of messages that exceeds its processing capacity. Furthermore, packet loss can be prevented when message traffic bursts, and impact damage to the terminal can be prevented when the message traffic is too large.
[0091] In an exemplary embodiment, the above-mentioned device also includes: a cache module, used to parse all cache tables in the cache table queue of the terminal, wherein the cache table includes: the cache table items include: message type, priority; traverse the cache table items of all cache tables, and determine whether there are one or more target cache tables in the cache table items of all cache tables, wherein the target message type of the target cache table is consistent with the message type of the target message; when it is determined that there are one or more target cache tables in the cache table items of all cache tables, determine the target cache table corresponding to the target message type, and cache the target message to the target message cache area corresponding to the target cache table.
[0092] It should be noted that determining whether there is a target message type consistent with the message type of the target message in the cache table entries of all the cache tables can be understood as: determining whether the message type of the target message is consistent with the target message type in the target cache table, and when it is determined that the message type of the target message is consistent with the target message type in the target cache table, caching the target message to the target message cache area corresponding to the target cache table; when it is determined that the message type of the target message is inconsistent with the target message type in the target cache table, determining whether to cache the target message based on the message priority.
[0093] In an exemplary embodiment, the cache module is further configured to determine whether the capacity of the target message cache area satisfies a preset condition; if the preset condition is satisfied, cache the target message into the target message cache area corresponding to the target cache table.
[0094] That is, the relationship between the capacity of the target message buffer area and the preset condition is determined, and when the capacity of the target message buffer area meets the preset condition, the target message is cached in the target message buffer area corresponding to the target cache table.
[0095] Specifically, the determination module is also used to determine whether the number of second messages cached in the target message cache area is equal to a first preset threshold, wherein the first preset threshold is used to indicate the maximum number of messages cached in the target message cache area; when the number of second messages cached in the target message cache area is less than the first preset threshold, it is determined that the capacity of the target message cache area meets the preset conditions.
[0096] That is to say, the relationship between the capacity of the target message buffer area and the preset condition is determined specifically in the following manner: when the number of second messages cached in the target message buffer area is less than the first preset threshold, it is determined that the capacity of the target message buffer area meets the preset condition; when the number of second messages cached in the target message buffer area is equal to the first preset threshold, it is determined that the capacity of the target message buffer area does not meet the preset condition.
[0097] In an exemplary embodiment, the cache module is also used to determine whether the priority of the second message cached in the target cache database is greater than the priority of the target message when the number of second messages cached in the target cache database is equal to the first preset threshold; and discard the second message and cache the target message when the priority of the second message is less than the priority of the target message.
[0098] Furthermore, when the number of second messages cached in the target message cache area is equal to the first preset threshold, that is, when the capacity of the target message cache area does not meet the preset conditions, the priority of the second message and the priority of the target message are determined, and the size relationship between the priority of the second message and the priority of the target message is compared. When the size relationship indicates that the priority of the second message is greater than the priority of the target message, the target message is discarded; when the size relationship indicates that the priority of the second message is less than the priority of the target message, the second message is discarded and the target message is cached.
[0099] Furthermore, the above-mentioned device also includes a processing module for normally processing the target message when it is determined that the message type of the target message is inconsistent with the target message type in the target cache table, and the message type of the target message is inconsistent with the target message type in the target filtering table.
[0100] In an exemplary embodiment, the above-mentioned device also includes an establishment module for determining the number of received monitoring messages before parsing the target filter table in the filter table queue; when the number of the monitoring messages is greater than the filter waterline, establishing the filter table corresponding to the monitoring message, and adding the target filter table corresponding to the monitoring message to the filter table queue.
[0101] That is to say, determine the number of monitoring messages received, and when the number of monitoring messages received is greater than the filter waterline, establish a corresponding filter table for the monitoring message, add the filter table corresponding to the monitoring message to the filter table queue, and set the packet loss priority of the filter table corresponding to the monitoring message to a priority less than the second preset threshold. If the filter table corresponding to the monitoring message already exists in the filter table queue, add one to the packet loss priority of the filter table corresponding to the monitoring message. When the priority of the filter table corresponding to the monitoring message is greater than the third preset threshold, all messages corresponding to the filter table corresponding to the monitoring message will be discarded.
[0102] In an exemplary embodiment, a module is established, which is also used to establish a cache table corresponding to the monitoring message when the number of the monitoring messages is less than the filtering waterline and the number of the monitoring messages is greater than the cache waterline, and add the cache table corresponding to the monitoring message to the cache table queue; obtain the alarm notification address in the cache table corresponding to the monitoring message, and send an alarm message to the source end corresponding to the alarm notification address, wherein the alarm information is used to instruct the source end corresponding to the alarm notification address to send the target message according to a preset strategy.
[0103] Furthermore, when the number of monitoring messages is less than the filtering waterline and the number of the monitoring messages is greater than the cache waterline, a cache table corresponding to the monitoring message is established, and the cache table corresponding to the monitoring message is added to the cache table queue, and the alarm notification address in the cache table corresponding to the monitoring message is determined, and the alarm information is sent to the source end corresponding to the alarm notification address through a UDP message. After the notified source end receives the alarm information, it performs message flow control according to the content of the cache table in the alarm information and the predetermined strategy. If a cache table corresponding to the monitoring message already exists in the cache table queue, the alarm information is directly sent to the source end corresponding to the alarm notification address through a UDP message.
[0104] In an exemplary embodiment, the processing module is further used to determine whether a cache table corresponding to the monitoring message exists in the cache table queue when the number of the monitoring messages is less than the cache waterline; determine the delayed reception time of the cache table corresponding to the monitoring message when the cache table corresponding to the monitoring message exists in the cache table queue; and write the target message in the target cache data into the network protocol stack corresponding to the target message according to the delayed reception time.
[0105] That is, read the delayed receiving time of the target cache table, start the delayed task processing work queue according to the read delayed receiving time, read the message in the target message cache area corresponding to the cache table corresponding to the monitoring message into the network protocol stack, and at the same time set the cache status of the cache table corresponding to the monitoring message to empty, and move the cache table corresponding to the monitoring message out of the cache queue.
[0106] Furthermore, when the target filter table is closed, the packet loss priority of the filter table corresponding to the monitoring message is adjusted to a priority lower than a second preset threshold, and the filter table corresponding to the monitoring message is removed from the filter table queue. The filter watermark and cache watermark are dynamically adjusted based on memory usage or CPU usage.
[0107] In order to better understand the process of the above-mentioned message filtering method, the process of the above-mentioned message filtering method is described below in combination with optional embodiments, but it is not used to limit the technical solution of the embodiment of the present invention.
[0108] An embodiment of the present invention further provides a storage medium, which includes a stored program, wherein the program executes any of the above methods when it is run.
[0109] In an exemplary embodiment, in this embodiment, the above-mentioned storage medium may be configured to store a computer program for performing the following steps:
[0110] S1, when a terminal receives a target message, parsing all filter tables in a filter table queue of the terminal, wherein the filter table includes: filter table items, and the filter table items include: message type and message priority;
[0111] S2, traversing the filter table entries of all the filter tables, and determining whether there are one or more target filter tables in the filter table entries of all the filter tables, wherein the target message type of the target filter table is consistent with the message type of the target message;
[0112] S3. When it is determined that there are one or more target filter tables in the filter table entries of all the filter tables, determine whether the priority of the first message in the target filter table is less than the message priority of the target message. If the priority of the first message is less than the message priority of the target message, discard the first message.
[0113] In an exemplary embodiment, in this embodiment, the above-mentioned storage medium may include but is not limited to: a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk, and other media that can store computer programs.
[0114] An embodiment of the present invention further provides an electronic device, comprising a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.
[0115] In an exemplary embodiment, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.
[0116] In an exemplary embodiment, in this embodiment, the processor may be configured to execute the following steps through a computer program:
[0117] S1, when a terminal receives a target message, parsing all filter tables in a filter table queue of the terminal, wherein the filter table includes: filter table items, and the filter table items include: message type and message priority;
[0118] S2, traversing the filter table entries of all the filter tables, and determining whether there are one or more target filter tables in the filter table entries of all the filter tables, wherein the target message type of the target filter table is consistent with the message type of the target message;
[0119] S3. When it is determined that there are one or more target filter tables in the filter table entries of all the filter tables, determine whether the priority of the first message in the target filter table is less than the message priority of the target message. If the priority of the first message is less than the message priority of the target message, discard the first message.
[0120] In an exemplary embodiment, specific examples in this embodiment can refer to the examples described in the above embodiments and optional implementation modes, and this embodiment will not be described in detail here.
[0121] Obviously, those skilled in the art will appreciate that the various modules or steps of the present invention described above can be implemented using a general-purpose computing device, can be centralized on a single computing device, or can be distributed across a network of multiple computing devices. In an exemplary embodiment, they can be implemented using program code executable by a computing device, and thus, can be stored in a storage device and executed by the computing device. In some cases, the steps shown or described herein can be performed in a different order than that shown, or can be fabricated into separate integrated circuit modules, or multiple modules or steps can be fabricated into a single integrated circuit module. Thus, the present invention is not limited to any particular combination of hardware and software.
[0122] The foregoing description is merely a preferred embodiment of the present invention and is not intended to limit the present invention. Those skilled in the art will readily appreciate that various modifications and variations of the present invention are possible. Any modifications, equivalent substitutions, or improvements made within the principles of the present invention are intended to be within the scope of protection of the present invention.
Claims
1. A message filtering method, characterized in that: include: When the terminal receives the target message, all filter tables in the filter table queue of the terminal are parsed, wherein the filter table includes: filter table items, and the filter table items include: message type and message priority; Traversing the filter table entries of all the filter tables, and determining whether there are one or more target filter tables in the filter table entries of all the filter tables, wherein the target message type of the target filter table is consistent with the message type of the target message; In the case where it is determined that there are one or more target filter tables in the filter table entries of all the filter tables, determining whether the priority of a first message in the target filter table is less than the message priority of the target message, and discarding the first message if the priority of the first message is less than the message priority of the target message; Wherein, when the terminal receives the target message, before parsing all filter tables in the filter table queue of the terminal, the method further includes: Determine the number of monitoring messages received; When the number of the monitoring messages is greater than the filtering waterline, a filter table corresponding to the monitoring messages is established, and the filter table corresponding to the monitoring messages is added to the filter table queue; After determining the number of received monitoring messages, the method further includes: When the number of the monitoring messages is less than the filtering watermark and the number of the monitoring messages is greater than the cache watermark, a cache table corresponding to the monitoring messages is established, and the cache table corresponding to the monitoring messages is added to the cache table queue; Obtaining an alarm notification address in a cache table corresponding to the monitoring message, and sending an alarm message to a source end corresponding to the alarm notification address, wherein the alarm message is used to instruct the source end corresponding to the alarm notification address to send the target message according to a preset strategy; After determining the number of received monitoring messages, the method further includes: When the number of the monitoring messages is less than the cache waterline, determining whether there is a cache table corresponding to the monitoring message in the cache table queue; In the case where a cache table corresponding to the monitoring message exists in the cache table queue, determining a delayed receiving time of the cache table corresponding to the monitoring message; According to the delayed receiving time, the target message in the target message buffer area corresponding to the buffer table corresponding to the monitoring message is written into the network protocol stack corresponding to the target message.
2. The message filtering method according to claim 1, characterized in that: After traversing the filter table items of all the filter tables and determining whether there are one or more target filter tables in the filter table items of all the filter tables, the method further includes: In the case of determining that one or more target filter tables do not exist in the filter table items of all the filter tables, parsing all cache tables in the cache table queue of the terminal, wherein the cache table includes: the cache table items include: message type, priority; Traversing the cache entries of all the cache tables to determine whether there are one or more target cache tables in the cache entries of all the cache tables, wherein the target message type of the target cache table is consistent with the message type of the target message; When it is determined that one or more target cache tables exist in the cache table entries of all the cache tables, the target message is cached in the target message cache area corresponding to the target cache table.
3. The message filtering method according to claim 2, characterized in that: Caching the target message into a target message cache area corresponding to the target cache table, comprising: Determining whether the capacity of the target message buffer area meets a preset condition; When a preset condition is met, the target message is cached in the target message cache area.
4. The message filtering method according to claim 3, characterized in that: Determining whether the capacity of the target message buffer area meets a preset condition includes: Determine whether the number of second messages cached in the target message buffer area is equal to a first preset threshold, wherein the first preset threshold is used to indicate a maximum number of messages cached in the target message buffer area; When the number of second messages in the target message buffer area is less than the first preset threshold, it is determined that the capacity of the target message buffer area meets a preset condition.
5. The message filtering method according to claim 4, characterized in that: After determining whether the capacity of the target message buffer area meets a preset condition, the method further includes: When the number of second messages cached in the target message cache area is equal to the first preset threshold, determining whether the priority of the second message cached in the target message cache area is greater than the priority of the target message; When the priority of the second message is lower than the priority of the target message, the second message is discarded and the target message is cached.
6. A message filtering device, characterized in that: include: A parsing module, used for parsing all filter tables in the filter table queue of the terminal when the terminal receives the target message, wherein the filter table includes: filter table items, and the filter table items include: message type and message priority; A determination module, configured to traverse the filter table items of all the filter tables, and determine whether there are one or more target filter tables in the filter table items of all the filter tables, wherein the target message type of the target filter table is consistent with the message type of the target message; A filtering module, configured to, when it is determined that there are one or more target filtering tables in the filtering table items of all the filtering tables, determine whether the priority of a first message in the target filtering table is less than the message priority of the target message, and discard the first message when the priority of the first message is less than the message priority of the target message; The device further comprises: an establishment module for determining the number of received monitoring messages before parsing the target filtering table in the filtering table queue; when the number of the monitoring messages is greater than the filtering watermark, establishing the filtering table corresponding to the monitoring message, and adding the target filtering table corresponding to the monitoring message to the filtering table queue; Wherein, the establishment module is also used to establish a cache table corresponding to the monitoring message when the number of the monitoring messages is less than the filtering waterline and the number of the monitoring messages is greater than the cache waterline, and add the cache table corresponding to the monitoring message to the cache table queue; obtain the alarm notification address in the cache table corresponding to the monitoring message, and send an alarm message to the source end corresponding to the alarm notification address, wherein the alarm information is used to instruct the source end corresponding to the alarm notification address to send the target message according to a preset strategy; Among them, the device also includes: a processing module, which is also used to determine whether there is a cache table corresponding to the monitoring message in the cache table queue when the number of the monitoring messages is less than the cache waterline; when there is a cache table corresponding to the monitoring message in the cache table queue, determine the delayed reception time of the cache table corresponding to the monitoring message; and write the target message in the target cache data into the network protocol stack corresponding to the target message according to the delayed reception time.
7. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a stored program, wherein the program executes the method described in any one of claims 1 to 5 when executed.
8. An electronic device comprising a memory and a processor, characterized in that: A computer program is stored in the memory, and the processor is configured to execute the method according to any one of claims 1 to 5 through the computer program.
