CN114327992A - Event processing method, device, equipment and storage medium - Google Patents
Event processing method, device, equipment and storage medium Download PDFInfo
- Publication number
- CN114327992A CN114327992A CN202210036444.5A CN202210036444A CN114327992A CN 114327992 A CN114327992 A CN 114327992A CN 202210036444 A CN202210036444 A CN 202210036444A CN 114327992 A CN114327992 A CN 114327992A
- Authority
- CN
- China
- Prior art keywords
- event
- node
- red
- black tree
- overtime
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Images
Landscapes
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The application discloses an event processing method, an event processing device, event processing equipment and a storage medium, and belongs to the field of data processing. The method comprises the following steps: receiving an event response message, wherein the event response message comprises a data identifier of a target event; searching a first target node in a preset data red-black tree based on the target event data identification, wherein keys of the nodes in the data red-black tree comprise the data identification of the event, and values of the nodes in the data red-black tree comprise the timeout time of the event; based on the value of the first target node, searching a second target node in a preset overtime red-black tree, wherein the second target node is a node matched with the value of the first target node in the overtime red-black tree, the overtime red-black tree comprises a node of an event with the overtime being later than the current time, and a key of the node in the overtime red-black tree comprises the overtime of the event; and if the second target node does not exist in the overtime red-black tree, releasing the resource corresponding to the target event. According to the embodiment of the application, the processing efficiency of the timeout processing mechanism can be improved.
Description
Technical Field
The present application relates to the field of data processing, and in particular, to an event processing method, apparatus, device, and storage medium.
Background
With the development of mobile internet technology, the number of concurrent requests received by online systems is increasing, and mutual calling among systems in a network can be realized, so that the events to be processed need to wait for a long time due to factors such as network fluctuation and system performance bottleneck. The long wait for excessive events can affect the performance of the system. In order to improve system performance and resource utilization, an event timeout handling mechanism is developed.
However, in the event timeout processing mechanism at the present stage, the processing efficiency of the timeout processing mechanism is still low due to the large number of events.
Disclosure of Invention
The embodiment of the application provides an event processing method, an event processing device and a storage medium, which can improve the processing efficiency of a timeout processing mechanism.
In a first aspect, an embodiment of the present application provides an event processing method, including: receiving an event response message, wherein the event response message comprises a data identifier of a target event; searching a first target node in a preset data red-black tree based on the data identification of the target event, wherein the first target node is a node matched with the data identification of the target event in the data red-black tree, a key of the node in the data red-black tree comprises the data identification of the event, and a value of the node in the data red-black tree comprises the timeout time of the event; based on the value of the first target node, searching a second target node in a preset overtime red-black tree, wherein the second target node is a node matched with the value of the first target node in the overtime red-black tree, the overtime red-black tree comprises a node of an event with the overtime being later than the current time, and a key of the node in the overtime red-black tree comprises the overtime of the event; and if the second target node does not exist in the overtime red-black tree, releasing the resource corresponding to the target event.
In a second aspect, an embodiment of the present application provides an event processing apparatus, including: the receiving module is used for receiving an event response message, and the event response message comprises a data identifier of a target event; the searching module is used for searching a first target node in a preset data red-black tree based on the data identifier of the target event, wherein the first target node is a node matched with the data identifier of the target event in the data red-black tree, a key of the node in the data red-black tree comprises the data identifier of the event, and a value of the node in the data red-black tree comprises the timeout time of the event; the node searching unit is further used for searching a second target node in a preset overtime red-black tree based on the value of the first target node, wherein the second target node is a node matched with the value of the first target node in the overtime red-black tree, the overtime red-black tree comprises a node of an event with the overtime being later than the current time, and a key of the node in the overtime red-black tree comprises the overtime of the event; and the processing module is used for releasing the resources corresponding to the target event if the second target node does not exist in the overtime red-black tree.
In a third aspect, an embodiment of the present application provides an event processing apparatus, including: a processor and a memory storing computer program instructions; the event handling method of the first aspect is implemented when the processor executes the computer program instructions.
In a fourth aspect, the present application provides a computer-readable storage medium, on which computer program instructions are stored, and when executed by a processor, the computer program instructions implement the event processing method of the first aspect.
The embodiment of the application provides an event processing method, device, equipment and storage medium, which can be used for setting a data red-black tree and an overtime red-black tree and storing relevant information of an event by using nodes in the data red-black tree and nodes in the overtime red-black tree. And under the condition of receiving the event response message, searching a first target node matched with the key in the data red-black tree by using the data identifier of the target event in the event response message, thereby obtaining the value of the first target node, namely the timeout time of the target event. The overtime red-black tree comprises nodes of events with overtime time later than the current time, namely the events corresponding to the nodes in the overtime red-black tree are not yet overtime events, and a second target node matched with the key can be searched in the overtime red-black tree by utilizing the overtime time of the target event. And if the second target node does not exist in the overtime red-black tree, the target event is overtime, and the target event resource can be released. The overtime processing mechanism is realized through the query of the data red-black tree and the overtime red-black tree, the time complexity of the overtime processing mechanism can be controlled to be O (logn), namely, to be logarithmic time, and the processing efficiency of the overtime processing mechanism is improved.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings needed to be used in the embodiments of the present application will be briefly described below, and for those skilled in the art, other drawings can be obtained according to the drawings without creative efforts.
FIG. 1 is a flow diagram of an embodiment of an event processing method provided herein;
FIG. 2 is a diagram illustrating an example of a red-black tree provided by an embodiment of the present application;
FIG. 3 is a flow diagram of another embodiment of an event processing method provided herein;
FIG. 4 is a flow diagram of yet another embodiment of an event processing method provided herein;
FIG. 5 is a flow chart of yet another embodiment of an event processing method provided herein;
FIG. 6 is a schematic structural diagram of an embodiment of an event processing apparatus provided in the present application;
FIG. 7 is a schematic structural diagram of another embodiment of an event processing device provided in the present application;
FIG. 8 is a schematic structural diagram of an event processing device according to another embodiment of the present disclosure;
fig. 9 is a schematic structural diagram of an embodiment of an event processing device provided in the present application.
Detailed Description
Features and exemplary embodiments of various aspects of the present application will be described in detail below, and in order to make objects, technical solutions and advantages of the present application more apparent, the present application will be further described in detail below with reference to the accompanying drawings and specific embodiments. It should be understood that the specific embodiments described herein are intended to be illustrative only and are not intended to be limiting. It will be apparent to one skilled in the art that the present application may be practiced without some of these specific details. The following description of the embodiments is merely intended to provide a better understanding of the present application by illustrating examples thereof.
With the development of mobile internet technology, the number of concurrent requests received by online systems is increasing, and mutual calling among systems in a network can be realized, so that the events to be processed need to wait for a long time due to factors such as network fluctuation and system performance bottleneck. The long wait for excessive events can affect the performance of the system. In order to improve system performance and resource utilization, an event timeout handling mechanism is developed. In some event timeout handling mechanisms, the number of events is large, so that the processing efficiency of the timeout handling mechanism is still low.
The embodiment of the application provides an event processing method, an event processing device, event processing equipment and a storage medium, which can utilize a data ReblackTree and an overtime ReblackTree to realize rapid insertion, search, deletion and the like of an event, can control the time complexity of an overtime processing mechanism to be O (logn), namely control the time complexity to be logarithmic time, and therefore improve the processing efficiency of the overtime processing mechanism.
The following describes an event processing method, an event processing apparatus, a device, and a storage medium in the present application.
The present application provides an event processing method, which may be applied to an inter-system call scenario or other scenarios, and is not limited herein. The event processing method may be executed by an event processing apparatus or device, and is not limited herein. Fig. 1 is a flowchart of an embodiment of an event processing method provided in the present application. As shown in fig. 1, the event processing method may include steps S101 to S104.
In step S101, an event response message is received.
The event response message is a response message of the event request message. When the event, namely Job, is acquired, an event request message may be sent to the system that needs to be called first, and after an event response message sent by the called system is received, whether the event is overtime or not and corresponding processing is performed on the event may be determined.
The event reply message includes a data identification of the target event. The data identifies data that may identify an event. The data of the target event identifies data that may identify the target event. In some examples, the data identification may include a data domain index. The data domain index of an event is the index of the event in the data domain.
In step S102, a first target node is searched in a preset data red-black tree based on the data identifier of the target event.
The red-black tree is a self-balancing binary search tree, and meets a specific characteristic rule to ensure that the longest possible path from a root node to a leaf node is not more than twice as long as the shortest possible path in the red-black tree. Fig. 2 is a schematic diagram of an example of a red-black tree according to an embodiment of the present disclosure. As shown in fig. 2, the red-black tree includes nodes, where the black nodes in fig. 2 are black nodes of the red-black tree, and the blank nodes are red nodes of the red-black tree. The nodes of the red and black tree store the relevant information of the event, and the information can be stored in a key mode and a value mode.
The data red and black tree is a red and black tree which is inquired by data information. The key of the node in the data red black tree includes a data identification of the event, and the value of the node in the data red black tree includes a timeout time of the event. For example, the data red-black tree includes three nodes, which are node 1, node 2, and node 3; the node 1 corresponds to the event 1, the key of the node 1 comprises the data identification of the event 1, and the value of the node 1 comprises the timeout time of the event 1; the node 2 corresponds to the event 2, the key of the node 2 comprises the data identification of the event 2, and the value of the node 2 comprises the timeout time of the event 2; node 3 corresponds to event 3, the key of node 3 includes the data identification of event 3, and the value of node 3 includes the timeout time for event 3. In some examples, the timeout time may be characterized by a character string, the precision of the character string is consistent with that of the timeout time, and the precision of the timeout time may be controlled by controlling the precision of the character string of the timeout time, so that the precision control of the timeout time is more convenient and free. For example, if the accuracy of the control string is up to second, the accuracy of the timeout time may also be up to second; if the accuracy of the control string is to millisecond, the accuracy of the timeout time may also be to millisecond.
In some examples, the values of the nodes in the data red and black tree may also include pointers to events that point to the data structure of time.
The first target node is a node in the data red-black tree, which is matched with the data identifier of the target event. Specifically, a node whose key is consistent with the data identifier of the target event may be searched in the data red and black tree, and the node whose key is consistent with the data identifier of the target event in the data red and black tree may be determined as the first target node. The key of the first target node includes a data identification of the target event and the value of the first target node includes a timeout time for the target event.
In step S103, a second target node is searched in a preset timeout red-black tree based on the value of the first target node.
The overtime red-black tree is a red-black tree which is inquired by using the overtime information. The overtime red-black tree comprises nodes of events with overtime time later than the current time, namely, the events corresponding to the nodes in the overtime red-black tree are all events which are not overtime yet. The key of a node in the timeout red-black tree includes the timeout time of the event. The timeout time of an event is the point in time at which the event times out. The content of the timeout period can be referred to the related description in the above embodiments, and is not described herein again. And if the current time is later than the timeout time of the event, determining that the event is timed out. In some examples, the values of the nodes in the timed-out red-black tree may include data identifications of events. The data identification may include a data domain index. The value of a node in the timed-out red-black tree may also include a pointer to an event, the pointer to the event pointing to the data structure of the event.
The second target node is a node in the timeout red-black tree that matches the value of the first target node. Specifically, a node whose key coincides with the timeout time in the values of the first target node may be searched for in the timeout red-black tree, and the node whose key coincides with the timeout time in the values of the first target node in the timeout red-black tree may be determined as the second target node.
In step S104, if there is no second target node in the overtime red-black tree, the resource corresponding to the target event is released.
Because the overtime red-black tree comprises the node of the event with the overtime time later than the current time and does not comprise the node of the event with the overtime time earlier than the current time, if the second target node can be found in the overtime red-black tree, the target event is not overtime; if the second target node is not found in the overtime red-black tree, the target event is overtime, and resources corresponding to the target event can be released, so that the resource utilization rate is improved, the response time is shortened, and the event processing efficiency is improved. The released resources may include connection resources, wait resources, etc., and are not limited herein.
In some examples, if the second target node does not exist in the timeout red-black tree, the first target node may also be deleted in the data red-black tree, that is, the node corresponding to the timeout event is deleted from the data red-black tree. The node balance of the data red-black tree after the first target node is deleted can be adjusted according to the self-balancing characteristic of the red-black tree.
In some examples, if there is no second target node in the timeout red-black tree, a timeout notification message may be sent to the system sending the event reply message to notify the system sending the event reply message that the target event has timed out.
In the embodiment of the application, a data red-black tree and a timeout red-black tree can be set, and the nodes in the data red-black tree and the nodes in the timeout red-black tree are used for storing the relevant information of the event. And under the condition of receiving the event response message, searching a first target node matched with the key in the data red-black tree by using the data identifier of the target event in the event response message, thereby obtaining the value of the first target node, namely the timeout time of the target event. The overtime red-black tree comprises nodes of events with overtime time later than the current time, namely the events corresponding to the nodes in the overtime red-black tree are not yet overtime events, and a second target node matched with the key can be searched in the overtime red-black tree by utilizing the overtime time of the target event. And if the second target node does not exist in the overtime red-black tree, the target event is overtime, and the target event resource can be released. The overtime processing mechanism is realized by inquiring the data red-black tree and the overtime red-black tree, the time complexity of the overtime processing mechanism can be controlled to be O (logn), namely, to be logarithmic time, the processing efficiency of the overtime processing mechanism is improved, and the read-write efficiency of an overtime control thread and a communication thread for the overtime processing mechanism is also improved.
The event processing method in the embodiment of the application is realized by utilizing two red-black trees, namely a data red-black tree and a timeout red-black tree. Compared with the technical scheme that the time wheel is combined with the red-black trees, and each time unit in the time wheel is provided with one red-black tree, the red-black trees are fewer, and resources occupied by the red-black trees are reduced, so that the waste of the resources is avoided. In addition, the accuracy of the overtime time can be controlled through the accuracy of the data red-black tree and the character string of the overtime time corresponding to the node in the overtime red-black tree, the node of an event in the data red-black tree is unique, the node of the event in the overtime red-black tree is also unique, the error identification of the event cannot occur, and the accuracy of an overtime processing mechanism is improved.
In some embodiments, the target event may be processed without timing out the target event. Fig. 3 is a flowchart of another embodiment of an event processing method provided in the present application. Fig. 3 is different from fig. 1 in that the event processing method shown in fig. 3 may further include step S105 and step S106.
In step S105, if there is a second target node in the timeout red-black tree, the target event is processed, and the second target node is deleted.
And a second target node exists in the overtime red-black tree, which indicates that the target event is not overtime and can be normally processed. And the event corresponding to the node in the overtime red-black tree is an event which is not overtime and is not processed, and the second target node can be deleted from the overtime red-black tree because the target event is about to be processed.
In some examples, the value of a node in the timed-out red-black tree includes a pointer to an event, the pointer pointing to a data structure of the event. The step of processing the target event may be specifically subdivided into: acquiring a value of a second target node, wherein the value of the second target node comprises a pointer of a target event; obtaining a data structure body of the target event based on the pointer of the target event; and processing the data structure of the target event by using the processing thread, namely, after finding the data structure of the target event according to the pointer of the target event, handing the target event to the processing thread for subsequent processing. The subsequent processing is related to the specific content of the event, and is not limited herein.
In step S106, the node balance of the timeout red-black tree is adjusted.
The node balance of the overtime red-black tree after the second target node is deleted can be adjusted according to the self-balancing characteristic of the red-black tree.
In some embodiments, under the condition that an event is acquired in real time, a node corresponding to the event can be generated in real time, and the corresponding node is inserted into the data red-black tree and the overtime red-black tree, so that the data red-black tree and the overtime red-black tree are constructed and updated. Fig. 4 is a flowchart of an event processing method according to another embodiment of the present application. Fig. 4 is different from fig. 1 in that the event processing method shown in fig. 4 may further include steps S107 to S111.
In step S107, an event is acquired, and the data identification and the timeout time of the event are obtained.
In some examples, in addition to obtaining the data identification and timeout time of the event, a pointer to the event may be obtained.
In step S108, a first node is generated according to the data identifier and the timeout time of the event, and the first node is inserted into the data red-black tree.
The key of the first node includes a data identification of the event and the value of the first node includes a timeout time for the event. And inserting the first node into the data red-black tree to realize the updating of the data red-black tree so as to facilitate the subsequent node searching in the data red-black tree when receiving the event response message.
In step S109, a second node is generated according to the timeout time of the event, and the second node is inserted into the timeout red-black tree.
The key of the second node includes a timeout time for the event. And inserting the second node into the overtime red-black tree to realize the updating of the overtime red-black tree, so that the nodes can be conveniently searched in the overtime red-black tree when an event response message is received subsequently, and whether the event is overtime or not is judged.
In step S110, an event request message is generated according to the data identifier of the event.
The event request message includes a data identification of the event. In some examples, the identifier of the event may be set at a specific position of a header of the event request message, which is not limited herein.
In step S111, an event request message is transmitted.
The event request message is used to request a corresponding Call operation from a system that needs to be called, for example, to request access to a database, or to request an interface of a Remote Procedure Call (RPC), and the like, and is not limited herein. The event request message corresponds to the event response message, i.e., one event request message may correspond to one event response message. Specifically, the event request message may be sent to the system that needs to be invoked, and after receiving the time request message, the system that needs to be invoked may feed back an event response message.
By the event request message, the event response message, the data red-black tree and the overtime red-black tree, the high-efficiency and high-performance overtime processing mechanism of the event called between systems can be realized.
The execution sequence between the steps S107 to S111 and the steps S101 to S104 is not limited, and the steps S107 to S111 may be executed before the steps S101 to S104, after the steps S101 to S104, or during the steps S101 to S104.
In some embodiments, the timeout red-black tree may be traversed, and the node corresponding to the timeout event is deleted from the timeout red-black tree, so as to ensure that all events corresponding to the node in the timeout red-black tree are events that have not timed out. Fig. 5 is a flowchart of a further embodiment of an event processing method provided in the present application. Fig. 5 is different from fig. 1 in that the event processing method shown in fig. 5 may further include steps S112 to S116.
In step S112, the timeout red-black tree is traversed.
Specifically, each node in the timeout red-black tree is traversed. In some examples, the traversal may be performed periodically on the timeout red-black tree, and the period may be set according to a scene, a requirement, experience, and the like, and is not limited herein. In some examples, the timeout red and black tree may be traversed when a preset trigger condition is reached, where the trigger condition may be set according to a scene, a requirement, experience, and the like, and is not limited herein.
In step S113, for each traversal, the current time and the third node with the earliest timeout time in the keys in the timeout red-black tree are acquired.
The current time is the time point for traversing. The third node is the node with the earliest overtime time in the key in the overtime red-black tree. For example, the timeout red-black tree includes five nodes, node 1, node 2, node 3, node 4, and node 5; the keys of node 1 include a timeout period of 300 ms at 24 min 35 s at 15 h, 1 month, 5 d, 2022, the keys of node 2 include a timeout period of 506 ms at 25 min 18 s at 15 h, 1 month, 5 d, 2022, the keys of node 3 include a timeout period of 257 ms at 25 min 30 s at 15 h, 1 month, 5 d, 2022, the keys of node 4 include a timeout period of 183 ms at 26 min 3 s at 15 h, 1 month, 5 d, 2022, the keys of node 5 include a timeout period of 67 ms at 30 min 57 s at 15 h, 1 month, 5 d, 2022; wherein the third node is node 1.
In step S114, in the case where the timeout time of the key of the third node is earlier than the current time, the third node is deleted in the timeout reddish black tree.
And the timeout time of the key of the third node is earlier than the current time, which indicates that the event corresponding to the third node is overtime, and the third node is deleted from the overtime red-black tree so as to ensure that the events corresponding to the nodes in the overtime red-black tree are events which are not overtime.
In step S115, when the timeout time in the key of the third node is later than the current time and the interval duration between the timeout time and the current time in the key of the third node is greater than or equal to the first preset duration, the timeout red-black tree is traversed again after sleeping for the second preset duration.
The overtime time of the key of the third node is later than the current time, which indicates that the event corresponding to the third node is not overtime. The first preset time length is a time length threshold for determining whether a new node may be inserted into the overtime red-black tree, and may be set according to a scene, a requirement, experience, and the like, which is not limited herein. The second preset time is less than the interval time between the timeout time in the key of the third node and the current time, and may be set according to a scene, a requirement, experience, and the like, which is not limited herein.
The interval duration between the overtime time of the key in the third node and the current time is greater than or equal to the first preset duration, which indicates that a new node may be inserted into the overtime red-black tree between the current time and the overtime time of the key in the third node, the second preset duration can be put to sleep, and the overtime red-black tree is traversed again when the overtime time of the key in the third node is not reached, so as to determine whether a node with the overtime time earlier than the current time exists in the key, and thus the accuracy of the overtime red-black tree is ensured. And if the node with the overtime time being earlier than the current time exists in the key, deleting the node with the overtime time being earlier than the current time in the key from the overtime red-black tree.
In step S116, when the timeout time in the key of the third node is later than the current time and the interval duration between the timeout time and the current time in the key of the third node is less than the first preset duration, the timeout red-black tree is traversed again after sleeping for the third preset duration.
The interval duration between the overtime time and the current time in the key of the third node is less than the first preset duration, which means that the possibility that a new node is inserted into the overtime red-black tree between the current time and the overtime time in the key of the third node is small and can be ignored, the new node can directly sleep for the third preset duration, and the third preset duration wakes up to traverse the overtime red-black tree again. The third preset time is the interval time between the overtime of the key in the third node and the current time.
In some examples, in the step S114, in the case that the timeout time of the key of the third node is earlier than the current time, a node whose timeout time is second earliest in the key may be further searched in the timeout red-black tree, whether the timeout time of the node whose timeout time is second earliest in the key is earlier than the current time is determined, and if the timeout time is later than the current time, whether an interval duration between the timeout time and the current time in the key of the node is less than a first preset duration may be determined, and corresponding processing may be performed according to the result; and if the time is earlier than the current time, deleting the node in the overtime red-black tree, searching the node with the third-earliest overtime time in the key in the overtime red-black tree, and so on until the overtime time of the searched node is later than the current time, judging whether the interval duration between the overtime time and the current time in the key of the searched node is less than a first preset duration, and carrying out corresponding processing according to the result.
The execution sequence between the steps S112 to S116 and the steps S101 to S104 is not limited, and the steps S112 to S116 may be executed before the steps S101 to S104, after the steps S101 to S104, or during the steps S101 to S104.
In the embodiment of the application, the overtime red-black tree is updated in real time by traversing the overtime red-black tree and comparing the overtime time in the key of the node with the current time, so that the accuracy of the overtime red-black tree is ensured, and the accuracy of an overtime processing mechanism is ensured.
The application also provides an event processing device. Fig. 6 is a schematic structural diagram of an embodiment of an event processing apparatus provided in the present application. As shown in fig. 6, the event processing apparatus 200 may include a receiving module 201, a searching module 202, and a processing module 203.
The receiving module 201 may be used to receive an event response message.
The event reply message includes a data identification of the target event.
The search module 202 may be configured to search for a first target node in a preset data red-black tree based on the data identifier of the target event, and further configured to search for a second target node in a preset timeout red-black tree based on the value of the first target node.
The first target node is a node in the data red-black tree, which is matched with the data identifier of the target event. The key of the node in the data red black tree includes a data identification of the event, and the value of the node in the data red black tree includes a timeout time of the event. The second target node is a node in the timeout red-black tree that matches the value of the first target node. The overtime red black tree includes nodes of the event having a timeout time later than the current time, and keys of the nodes in the overtime red black tree include the timeout time of the event.
In some examples, the timeout time is characterized by a string of characters, the accuracy of the string of characters being consistent with the accuracy of the timeout time.
In some examples, the data identification includes a data domain index.
In some examples, the values of the nodes in the data red-black tree also include pointers to events.
In some examples, the values of the nodes in the timed-out red-black tree include data identifications of the events.
The processing module 203 may be configured to release the resource corresponding to the target event if the second target node does not exist in the timeout red-black tree.
In the embodiment of the application, a data red-black tree and a timeout red-black tree can be set, and the nodes in the data red-black tree and the nodes in the timeout red-black tree are used for storing the relevant information of the event. And under the condition of receiving the event response message, searching a first target node matched with the key in the data red-black tree by using the data identifier of the target event in the event response message, thereby obtaining the value of the first target node, namely the timeout time of the target event. The overtime red-black tree comprises nodes of events with overtime time later than the current time, namely the events corresponding to the nodes in the overtime red-black tree are not yet overtime events, and a second target node matched with the key can be searched in the overtime red-black tree by utilizing the overtime time of the target event. And if the second target node does not exist in the overtime red-black tree, the target event is overtime, and the target event resource can be released. The overtime processing mechanism is realized by inquiring the data red-black tree and the overtime red-black tree, the time complexity of the overtime processing mechanism can be controlled to be O (logn), namely, to be logarithmic time, the processing efficiency of the overtime processing mechanism is improved, and the read-write efficiency of an overtime control thread and a communication thread for the overtime processing mechanism is also improved.
The event processing method in the embodiment of the application is realized by utilizing two red-black trees, namely a data red-black tree and a timeout red-black tree. Compared with the technical scheme that the time wheel is combined with the red-black trees, and each time unit in the time wheel is provided with one red-black tree, the red-black trees are fewer, and resources occupied by the red-black trees are reduced, so that the waste of the resources is avoided. In addition, the accuracy of the overtime time can be controlled through the accuracy of the data red-black tree and the character string of the overtime time corresponding to the node in the overtime red-black tree, the node of an event in the data red-black tree is unique, the node of the event in the overtime red-black tree is also unique, the error identification of the event cannot occur, and the accuracy of an overtime processing mechanism is improved.
In some embodiments, the processing module 203 may further be configured to: if the overtime red-black tree does not have the second target node, deleting the first target node from the data red-black tree; and adjusting the node balance of the data red and black tree.
In some embodiments, the processing module 203 may further be configured to: if the overtime red-black tree has a second target node, processing the target event and deleting the second target node; and adjusting the node balance of the overtime red-black tree.
In some embodiments, the value of a node in the timed-out red-black tree includes a pointer to an event, the pointer pointing to a data structure of the event. The processing module 203 may be configured to: acquiring a value of a second target node, wherein the value of the second target node comprises a pointer of a target event; obtaining a data structure body of the target event based on the pointer of the target event; and processing the data structure body of the target event by using the processing thread.
Fig. 7 is a schematic structural diagram of another embodiment of an event processing apparatus provided in the present application. Fig. 7 is different from fig. 6 in that the event processing apparatus 200 shown in fig. 7 may further include an acquisition module 204, a node operation module 205, a generation module 206, and a transmission module 207.
The obtaining module 204 may be configured to obtain the event, obtain a data identifier of the event, and obtain the timeout time.
The node operations module 205 may be configured to: generating a first node according to the data identification and the overtime time of the event, and inserting the first node into the data red-black tree, wherein the key of the first node comprises the data identification of the event, and the value of the first node comprises the overtime time of the event; and generating a second node according to the timeout time of the event, and inserting the second node into the timeout red-black tree, wherein the key of the second node comprises the timeout time of the event.
The generating module 206 may be configured to generate an event request message according to the data identifier of the event, where the event request message includes the data identifier of the event, and the event request message corresponds to the event response message.
The sending module 207 may be configured to send an event request message.
Fig. 8 is a schematic structural diagram of an event processing device according to still another embodiment of the present disclosure. Fig. 8 differs from fig. 6 in that the event processing apparatus 200 shown in fig. 8 may further include a traversal module 208.
The traversal module 208 can be configured to: traversing the overtime red-black tree; each traversal, acquiring the current time and a third node with the earliest overtime time in the key in the overtime red-black tree; in the case where the timeout time is earlier than the current time in the key of the third node, the third node is deleted in the timeout red-black tree.
In some embodiments, traversal module 208 may also be configured to: when the timeout time in the key of the third node is later than the current time and the interval duration between the timeout time and the current time in the key of the third node is longer than or equal to the first preset duration, the timeout red-black tree is traversed again after sleeping for the second preset duration; and traversing the overtime red-black tree again after sleeping for a third preset time under the condition that the overtime time in the key of the third node is later than the current time and the interval time between the overtime time and the current time in the key of the third node is shorter than the first preset time, wherein the third preset time is the interval time between the overtime time of the key of the third node and the current time.
The application also provides event processing equipment. Fig. 9 is a schematic structural diagram of an embodiment of an event processing device provided in the present application. As shown in fig. 9, the event processing apparatus 300 includes a memory 301, a processor 302, and a computer program stored on the memory 301 and executable on the processor 302.
In one example, the processor 302 may include a Central Processing Unit (CPU), or an Application Specific Integrated Circuit (ASIC), or may be configured to implement one or more Integrated circuits of the embodiments of the present Application.
The Memory 301 may include Read-Only Memory (ROM), Random Access Memory (RAM), magnetic disk storage media devices, optical storage media devices, flash Memory devices, electrical, optical, or other physical/tangible Memory storage devices. Thus, in general, the memory includes one or more tangible (non-transitory) computer-readable storage media (e.g., memory devices) encoded with software comprising computer-executable instructions and when the software is executed (e.g., by one or more processors), it is operable to perform the operations described with reference to the event processing methods in accordance with embodiments of the present application.
The processor 302 runs a computer program corresponding to the executable program code by reading the executable program code stored in the memory 301 for implementing the event processing method in the above-described embodiment.
In one example, the event processing device 300 can also include a communication interface 303 and a bus 304. As shown in fig. 9, the memory 301, the processor 302, and the communication interface 303 are connected via a bus 304 to complete communication therebetween.
The communication interface 303 is mainly used for implementing communication between modules, apparatuses, units and/or devices in the embodiment of the present application. Input devices and/or output devices may also be accessed through communication interface 303.
The bus 304 comprises hardware, software, or both that couple the components of the event processing device 300 to one another. By way of example, and not limitation, Bus 304 may include an Accelerated Graphics Port (AGP) or other Graphics Bus, an Enhanced Industry Standard Architecture (EISA) Bus, a Front-Side Bus (FSB), a HyperTransport (HT) interconnect, an Industry Standard Architecture (ISA) Bus, an InfiniBand interconnect, a Low Pin Count (LPC) Bus, a memory Bus, a Micro Channel Architecture (MCA) Bus, a Peripheral Component Interconnect (PCI) Bus, a PCI-Express (PCI-E) Bus, a Serial Advanced Technology Attachment (SATA) Bus, a Video Electronics Standards Association Local Bus (VLB) Bus, or other suitable Bus, or a combination of two or more of these. Bus 304 may include one or more buses, where appropriate. Although specific buses are described and shown in the embodiments of the application, any suitable buses or interconnects are contemplated by the application.
The present application further provides a computer-readable storage medium, where computer program instructions are stored on the computer-readable storage medium, and when the computer program instructions are executed by a processor, the event processing method in the foregoing embodiments can be implemented, and the same technical effects can be achieved. The computer-readable storage medium may include a non-transitory computer-readable storage medium, such as a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and the like, which is not limited herein.
It should be clear that the embodiments in this specification are described in a progressive manner, and the same or similar parts in the embodiments are referred to each other, and each embodiment focuses on the differences from the other embodiments. For apparatus embodiments, device embodiments, computer-readable storage medium embodiments, reference may be made in the descriptive section to method embodiments. The present application is not limited to the particular steps and structures described above and shown in the drawings. Those skilled in the art may make various changes, modifications and additions or change the order between the steps after appreciating the spirit of the present application. Also, a detailed description of known process techniques is omitted herein for the sake of brevity.
Aspects of the present application are described above with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems) and computer program products according to embodiments of the application. It will be understood that each block of the flowchart illustrations and/or block diagrams, and combinations of blocks in the flowchart illustrations and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, enable the implementation of the functions/acts specified in the flowchart and/or block diagram block or blocks. Such a processor may be, but is not limited to, a general purpose processor, a special purpose processor, an application specific processor, or a field programmable logic circuit. It will also be understood that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware for performing the specified functions or acts, or combinations of special purpose hardware and computer instructions.
It will be appreciated by persons skilled in the art that the above embodiments are illustrative and not restrictive. Different features which are present in different embodiments may be combined to advantage. Other variations to the disclosed embodiments can be understood and effected by those skilled in the art upon studying the drawings, the specification, and the claims. In the claims, the term "comprising" does not exclude other means or steps; the word "a" or "an" does not exclude a plurality; the terms "first" and "second" are used to denote a name and not to denote any particular order. Any reference signs in the claims shall not be construed as limiting the scope. The functions of the various parts appearing in the claims may be implemented by a single hardware or software module. The mere fact that certain measures are recited in mutually different dependent claims does not indicate that a combination of these measures cannot be used to advantage.
Claims (13)
1. An event processing method, comprising:
receiving an event response message, wherein the event response message comprises a data identifier of a target event;
based on the data identification of the target event, searching a first target node in a preset data red-black tree, wherein the first target node is a node in the data red-black tree, which is matched with the data identification of the target event, a key of a node in the data red-black tree comprises the data identification of the event, and a value of the node in the data red-black tree comprises the timeout time of the event;
based on the value of the first target node, searching a second target node in a preset overtime red-black tree, wherein the second target node is a node matched with the value of the first target node in the overtime red-black tree, the overtime red-black tree comprises a node of an event with the overtime being later than the current time, and a key of the node in the overtime red-black tree comprises the overtime of the event;
and if the second target node does not exist in the overtime red-black tree, releasing the resource corresponding to the target event.
2. The method of claim 1, further comprising:
if the second target node does not exist in the overtime red-black tree, deleting the first target node in the data red-black tree;
and adjusting the node balance of the data red and black tree.
3. The method of claim 1, further comprising:
if the second target node exists in the overtime red-black tree, processing the target event, and deleting the second target node;
and adjusting the node balance of the overtime red-black tree.
4. The method of claim 3, wherein the value of a node in the timed-out red-black tree comprises a pointer to an event, the pointer pointing to a data structure of the event;
the processing the target event comprises:
acquiring a value of the second target node, wherein the value of the second target node comprises a pointer of the target event;
obtaining a data structure body of the target event based on the pointer of the target event;
and processing the data structure body of the target event by using a processing thread.
5. The method of claim 1, further comprising:
acquiring an event, and acquiring a data identifier and timeout time of the event;
generating a first node according to the data identification and the timeout time of the event, and inserting the first node into the data red-black tree, wherein the key of the first node comprises the data identification of the event, and the value of the first node comprises the timeout time of the event;
and generating a second node according to the timeout time of the event, and inserting the second node into the timeout red-black tree, wherein the key of the second node comprises the timeout time of the event.
6. The method of claim 5, after obtaining the event, the data identification of the event, and the timeout time, further comprising:
generating an event request message according to the data identifier of the event, wherein the event request message comprises the data identifier of the event and corresponds to the event response message;
and sending the event request message.
7. The method of claim 1, further comprising:
traversing the overtime red-black tree;
acquiring current time and a third node with the earliest overtime time in the key in the overtime red-black tree in each traversal;
deleting the third node in the timeout Redwood tree if a timeout time in a key of the third node is earlier than the current time.
8. The method of claim 7, further comprising:
when the timeout time in the key of the third node is later than the current time and the interval duration between the timeout time in the key of the third node and the current time is greater than or equal to a first preset duration, after sleeping for a second preset duration, traversing the timeout red-black tree again;
and traversing the overtime red-black tree again after sleeping for a third preset time under the condition that the overtime time in the key of the third node is later than the current time and the interval time between the overtime time in the key of the third node and the current time is less than the first preset time, wherein the third preset time is the interval time between the overtime time of the key of the third node and the current time.
9. The method according to claims 1 to 9, characterized in that the time-out time is characterized by a string, the accuracy of which coincides with the accuracy of the time-out time.
10. The method according to claims 1 to 9,
the data identification comprises a data domain index;
the values of the nodes in the data red and black tree also comprise pointers of events;
the value of a node in the timed-out red-black tree includes the data identification of an event.
11. An event processing apparatus, comprising:
the receiving module is used for receiving an event response message, and the event response message comprises a data identifier of a target event;
a searching module, configured to search a first target node in a preset data red-black tree based on a data identifier of the target event, where the first target node is a node in the data red-black tree that matches the data identifier of the target event, a key of the node in the data red-black tree includes the data identifier of the event, and a value of the node in the data red-black tree includes a timeout time of the event; the node searching unit is further configured to search a second target node in a preset timeout red-black tree based on the value of the first target node, where the second target node is a node in the timeout red-black tree that matches the value of the first target node, the timeout red-black tree includes a node of an event whose timeout time is later than the current time, and a key of the node in the timeout red-black tree includes the timeout time of the event;
and the processing module is used for releasing the resource corresponding to the target event if the second target node does not exist in the overtime RexBlack Tree.
12. An event processing apparatus, characterized by comprising: a processor and a memory storing computer program instructions;
the processor, when executing the computer program instructions, implements an event processing method as claimed in any one of claims 1 to 10.
13. A computer-readable storage medium, having stored thereon computer program instructions, which when executed by a processor, implement the event processing method of any one of claims 1 to 10.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202210036444.5A CN114327992A (en) | 2022-01-13 | 2022-01-13 | Event processing method, device, equipment and storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202210036444.5A CN114327992A (en) | 2022-01-13 | 2022-01-13 | Event processing method, device, equipment and storage medium |
Publications (1)
Publication Number | Publication Date |
---|---|
CN114327992A true CN114327992A (en) | 2022-04-12 |
Family
ID=81027183
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202210036444.5A Pending CN114327992A (en) | 2022-01-13 | 2022-01-13 | Event processing method, device, equipment and storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN114327992A (en) |
-
2022
- 2022-01-13 CN CN202210036444.5A patent/CN114327992A/en active Pending
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN111683359B (en) | BLE communication method, device, equipment and storage medium | |
CN110825448B (en) | Method, device, electronic equipment and storage medium for realizing multi-service module mutual calling | |
CN112181614B (en) | Task timeout monitoring method, device, equipment, system and storage medium | |
CN110427386B (en) | Data processing method, device and computer storage medium | |
CN114760369B (en) | Protocol metadata extraction method, device, equipment and storage medium | |
CN111641554B (en) | Message processing method and device and computer readable storage medium | |
CN108572876A (en) | A kind of implementation method and device of Read-Write Locks | |
CN109063142B (en) | Webpage resource pushing method, server and storage medium | |
CN111324621B (en) | Event processing method, device, equipment and storage medium | |
CN111897828A (en) | Data batch processing implementation method, device, equipment and storage medium | |
CN111464515A (en) | Data conversion method, device, equipment and storage medium | |
CN112165505B (en) | Decentralized data processing method, electronic device and storage medium | |
CN114327992A (en) | Event processing method, device, equipment and storage medium | |
CN115827280A (en) | Message processing method and device, electronic equipment and storage medium | |
CN112214669B (en) | Home decoration material formaldehyde release data processing method and device and monitoring server | |
CN115470302A (en) | Database bidirectional synchronization method, medium and equipment based on canal | |
CN110896391B (en) | Message processing method and device | |
CN112130860B (en) | JSON object analysis method and device, electronic equipment and storage medium | |
CN114675871A (en) | Resource updating method and device, electronic equipment, server and storage medium | |
CN111918257A (en) | Head-mounted display device, data transmission method thereof and readable storage medium | |
CN113704320B (en) | Data processing method, device, electronic equipment and storage medium | |
CN113901431B (en) | Method and device for extracting characteristic information of authenticated user | |
CN115529271B (en) | Service request distribution method, device, equipment and medium | |
CN116360708B (en) | Data writing method and device, electronic equipment and storage medium | |
CN112039729B (en) | Device identification method, server, electronic device, and storage medium |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination |