Event processing method and device, equipment, storage medium and program product
By detecting events and event data status in response procedures, configuration and scheduling the processing of event data, the problem of low response and processing efficiency in existing technologies has been solved, and more efficient event response and data processing are achieved.
Patent Information
- Application Number
- CN202411412013.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-10
- Publication Date
- 2025-01-28
- Estimated Expiration
- 2044-10-10
AI Technical Summary
When existing responsive programs process events and event data, their response capabilities and processing efficiency are low, making it difficult to effectively manage and schedule the processing of multiple events.
By detecting the occurrence of events and the readable status of the event data, the configuration and scheduling coroutine are used to process the event data, and new events and data status are continuously detected by non -blocking methods to improve the response and processing efficiency.
Improving the efficiency of event response capacity and the processing of event data, can more effectively manage and dispatch the processing of multiple events, and improve the overall performance of the system.
Smart Images

Figure CN119376976A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer technology, specifically to technical fields such as event response, data processing and thread scheduling, and especially to methods, devices, electronic devices, computer-readable storage media and computer program products for processing events. Background Art
[0002] Program Reactor is a technical architecture that is usually used to process and manage events and responses in a program. In other words, a responsive program can also be understood as an event-driven network I / O design pattern.
[0003] In a responsive program, event sources (such as network connections, file system changes, etc.) are registered to the event distributor (Reactor). Then, the event distributor is responsible for listening to all registered event sources and forwarding events and event data from the event source to the corresponding event processor for processing. Therefore, how to improve the responsiveness of responsive programs to events and the ability to process event data is worthy of attention and urgent need. Summary of the invention
[0004] The embodiments of the present disclosure provide a method, an apparatus, an electronic device, a computer-readable storage medium, and a computer program product for processing an event.
[0005] In a first aspect, an embodiment of the present disclosure proposes a method for processing events, including: in response to detecting that an event has occurred, configuring a corresponding coroutine for the event; in response to detecting that event data of the event is in a readable state, scheduling a coroutine to process the event data.
[0006] In some embodiments, in response to detecting that event data of an event is in a readable state, scheduling a coroutine to process the event data, including: in response to detecting that event data of an event is in a readable state, scheduling a coroutine to process the event data, and detecting in a non-blocking manner whether a new event has occurred, and / or the reading status of event data of an event that has occurred.
[0007] In some embodiments, in response to detecting that an event has occurred, configuring a corresponding coroutine for the event, including: in response to detecting that an event has occurred, communicating the event to a multi-function thread in a thread pool; using the multi-function thread to configure a corresponding coroutine for the event from a set of coroutines associated with the multi-function thread, and establishing a communication pipeline for the multi-function thread to communicate with an event source of the event; using the multi-function thread to activate the coroutine, wherein the multi-function thread, in response to detecting that event data of the event from the communication pipeline for communicating between the multi-function thread and the event source of the event is in a readable state, schedules the activated coroutine to process the event data.
[0008] In some embodiments, it also includes: detecting whether an event message appears in the communication pipeline, wherein the event message indicates that a new event has occurred, or that the reading state of event data of an event that has occurred has changed to a readable state.
[0009] In some embodiments, it also includes: in response to the detection function being called by the coroutine, detecting whether a new event occurs, and the reading status of the event data of the event that has occurred, wherein the coroutine calls the detection function in response to the processing progress of processing the event data reaching the detection point position.
[0010] In some embodiments, in response to detecting that event data of an event is in a readable state, scheduling a coroutine to process the event data includes: in response to detecting that event data corresponding to at least two coroutines are each in a readable state, adding a scheduling action for the coroutine to a scheduling queue; based on the scheduling queue, scheduling at least two coroutines to process the corresponding event data in an interleaved manner.
[0011] In some embodiments, at least two coroutines are interleaved to process corresponding event data, including: in response to the processing progress of the event data corresponding to the first coroutine currently scheduled in the scheduling queue reaching a yield point, and there is a second coroutine that can be scheduled in the scheduling queue, the first coroutine is cut out and the second coroutine is scheduled.
[0012] In some embodiments, it also includes: in response to the processing progress of the event data corresponding to the first coroutine currently scheduled in the scheduling queue reaching the yield point, and there is no second coroutine that can be scheduled in the scheduling queue, cutting out the first coroutine and detecting in a blocking manner whether a new event has occurred, and / or the reading status of the event data of the event that has occurred.
[0013] In a second aspect, an embodiment of the present disclosure proposes a device for processing events, comprising: a coroutine configuration unit, configured to configure a corresponding coroutine for the event in response to detecting that an event has occurred; and a coroutine scheduling unit, configured to schedule a coroutine to process the event data in response to detecting that the event data of the event is in a readable state.
[0014] In some embodiments, the coroutine scheduling unit is further configured to: include: in response to detecting that the event data of an event is in a readable state, scheduling the coroutine to process the event data, and detecting in a non-blocking manner whether a new event has occurred, and / or the reading status of the event data of an event that has occurred.
[0015] In some embodiments, the coroutine configuration unit includes: an event communication subunit, configured to communicate the event to a multi-function thread in a thread pool in response to detecting that an event has occurred; a first multi-function thread utilization subunit, configured to utilize the multi-function thread to configure a corresponding coroutine for the event from a group of coroutines associated with the multi-function thread, and to establish a communication pipeline for the multi-function thread to communicate with the event source of the event; a second multi-function thread utilization subunit, configured to utilize the multi-function thread to activate the coroutine, wherein the multi-function thread, in response to detecting that the event data of the event from the communication pipeline for communicating between the multi-function thread and the event source of the event is in a readable state, schedules the activated coroutine to process the event data.
[0016] In some embodiments, it also includes: an event message detection unit configured to detect whether an event message appears in the communication pipeline, wherein the event message indicates that a new event has occurred, or that the reading state of event data of an event that has occurred has changed to a readable state.
[0017] In some embodiments, it also includes: a response detection unit, which is configured to detect whether a new event occurs and the reading status of event data of an event that has occurred in response to a detection function being called by a coroutine, wherein the coroutine calls the detection function in response to the processing progress of processing the event data reaching a detection point position.
[0018] In some embodiments, a coroutine scheduling unit includes: a scheduling queue maintenance subunit, configured to add a scheduling action for the coroutine to a scheduling queue in response to detecting that event data corresponding to at least two coroutines are in a readable state; and a coroutine scheduling subunit, configured to interleavely schedule at least two coroutines to process corresponding event data based on the scheduling queue.
[0019] In some embodiments, at least two coroutines are interleaved to process corresponding event data, including: in response to the processing progress of the event data corresponding to the first coroutine currently scheduled in the scheduling queue reaching a yield point, and there is a second coroutine that can be scheduled in the scheduling queue, the first coroutine is cut out and the second coroutine is scheduled.
[0020] In some embodiments, it also includes: a post-yield event detection unit, which is configured to cut out the first coroutine in response to the processing progress of the event data corresponding to the first coroutine currently scheduled in the scheduling queue reaching the yield point position, and there is no second coroutine that can be scheduled in the scheduling queue, and detect whether a new event occurs in a blocking manner, and / or the reading status of the event data of the event that has occurred.
[0021] In a third aspect, an embodiment of the present disclosure provides an electronic device, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can implement the method for processing events as described in any implementation method in the first aspect when executing the instructions.
[0022] In a fourth aspect, an embodiment of the present disclosure provides a non-transitory computer-readable storage medium storing computer instructions, which are used to enable a computer to implement the method for processing events as described in any implementation manner in the first aspect when executed.
[0023] In a fifth aspect, an embodiment of the present disclosure provides a computer program product comprising a computer program, which, when executed by a processor, can implement the method for processing events as described in any implementation manner in the first aspect.
[0024] The method, device, electronic device, computer-readable storage medium and computer program product for processing events provided by the embodiments of the present disclosure are applied to the thread of a responsive program, and can respond when an event is detected, and configure a corresponding coroutine for the event. Then, if the event data of the detected event is in a readable state for the thread, the coroutine is scheduled to process the event data.
[0025] The present disclosure can not only improve the ability to respond to events, but also improve the scheduling and processing efficiency of processing event data of events.
[0026] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present disclosure, nor is it intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] Other features, objects and advantages of the present disclosure will become more apparent from the detailed description of non-limiting embodiments made with reference to the following drawings:
[0028] Figure 1 is an exemplary system architecture in which the present disclosure may be applied;
[0029] Figure 2 A flowchart of a process for processing an event provided by an embodiment of the present disclosure;
[0030] Figure 3 A flowchart of another process of processing an event provided by an embodiment of the present disclosure;
[0031] Figure 4A flowchart of a process for processing an event in an application scenario provided by an embodiment of the present disclosure;
[0032] Figure 5 A structural block diagram of a device for processing events provided in an embodiment of the present disclosure;
[0033] Figure 6 A schematic diagram of the structure of an electronic device suitable for executing a method for processing events provided in an embodiment of the present disclosure. DETAILED DESCRIPTION
[0034] The following is a description of exemplary embodiments of the present disclosure in conjunction with the accompanying drawings, including various details of the embodiments of the present disclosure to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present disclosure. Similarly, for clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description. It should be noted that the embodiments in the present disclosure and the features in the embodiments may be combined with each other without conflict.
[0035] In addition, in the technical solutions involved in the present disclosure, the acquisition, storage, use, processing, transportation, provision and disclosure of user personal information involved (for example, the events involved in the subsequent disclosure may correspond to user personal information, or may actually be events that require the use of user personal information) shall comply with the relevant laws and regulations and shall not violate public order and good morals.
[0036] Figure 1 An exemplary system architecture 100 is shown to which embodiments of the method, apparatus, electronic device, and computer-readable storage medium for processing events disclosed herein can be applied.
[0037] like Figure 1 As shown, the system architecture 100 may include terminal devices 101, 102, 103, a network 104 and a server 105. The network 104 is used to provide a medium for communication links between the terminal devices 101, 102, 103 and the server 105. The network 104 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.
[0038] Users can use terminal devices 101, 102, 103 to interact with server 105 through network 104 to receive or send messages, etc. Terminal devices 101, 102, 103 and server 105 may be installed with various applications for realizing information communication between the two.
[0039] Terminal devices 101, 102, 103 and server 105 can be hardware or software. When terminal devices 101, 102, 103 are hardware, they can be various electronic devices with display screens, including but not limited to smart phones, tablet computers, laptop computers, desktop computers, etc.; when terminal devices 101, 102, 103 are software, they can be installed in the electronic devices listed above, which can be implemented as multiple software or software modules, or as a single software or software module, and no specific limitation is made here. When server 105 is hardware, it can be implemented as a distributed server cluster composed of multiple servers, or as a single server; when the server is software, it can be implemented as multiple software or software modules, or as a single software or software module, and no specific limitation is made here.
[0040] For example, an event processing application of event processing nature and type may be configured in the server 105. In this case, the terminal devices 101, 102, 103 can act as event sources and communicate with the server 105 based on their locally configured event processing applications to utilize the server 105 for "event processing".
[0041] Accordingly, the server 105 can respond based on the responsive program method. Specifically, the thread (e.g., thread 110) in the server 105 used for the responsive program can respond to the detection of an event (e.g., an "event" in which the terminal device 101, 102, 103 requests the server 105 to process a task or perform an action), configure a corresponding coroutine for the event; then, in response to the event data of the event being in a readable state, the thread 110 schedules the coroutine to process the event data.
[0042] It should be noted that, in addition to being obtained from the terminal devices 101, 102, and 103 through the network 104, "events" can also be local "events" of the server 105. For example, pending tasks and pending events are pre-stored in the server 105 in various ways. Therefore, when the server 105 detects that these events have been stored locally and need to be executed (for example, events that have been stored locally before starting processing), it can choose to directly obtain these data from the local. In this case, the exemplary system architecture 100 may also not include the terminal devices 101, 102, 103 and the network 104.
[0043] Due to the demand for computing resources and computing power, the methods for processing events provided in the subsequent embodiments of the present disclosure are generally executed by the server 105 with stronger computing power and more computing resources. Correspondingly, the device for processing events is generally also set in the server 105 (for example, set and applied to the thread 110 of the responsive program). However, it should also be pointed out that when the terminal devices 101, 102, and 103 also have computing power and computing resources that meet the requirements, the terminal devices 101, 102, and 103 can also complete the above-mentioned various operations that are handed over to the server 105 through the event processing applications installed thereon, and then output the same results as the server 105 (for example, the thread 110 of the responsive program is also in the terminal devices 101, 102, and 103). Especially when there are multiple terminal devices with different computing capabilities, but the event processing application determines that the terminal device has a stronger computing capability and more remaining computing resources, the terminal device can be allowed to perform the above-mentioned operations, thereby appropriately reducing the computing pressure of the server 105. Accordingly, the device of the event processing application can also be set in the terminal devices 101, 102, and 103. In this case, the exemplary system architecture 100 may also not include the server 105 and the network 104.
[0044] It should be understood that Figure 1 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0045] Please refer to Figure 2 , Figure 2 A flowchart of a process of processing an event provided by an embodiment of the present disclosure includes process 200, and process 200 includes the following steps:
[0046] Step 201, in response to detecting that an event has occurred, configuring a corresponding coroutine for the event;
[0047] In the embodiments of the present disclosure, for example, Figure 1 The thread 110 shown is applied to the responsive program as the execution subject.
[0048] In some embodiments, the execution subject can communicate with objects and devices such as terminal devices 101, 102, 103 based on the communication pipeline. Accordingly, the execution subject can choose to determine whether an event message occurs based on the detection of the communication pipeline with these objects and devices. For example, the communication pipeline can be a socket in the responsive program model.
[0049] Socket is a basis of network programming, which can provide a mechanism for data exchange between the execution subject and other components in the server 105, or between the terminal devices 101, 102 and 103. Accordingly, through Socket, the execution subject can realize communication with other objects and devices.
[0050] Accordingly, the execution entity can detect these communication channels to determine whether any event occurs.
[0051] Specifically, the execution subject may choose to detect whether an event message appears in the communication channel, and the event message indicates that a new event has occurred, or the read state of the event data of the event that has occurred has changed to a readable state. Accordingly, if a new event occurs, or the read state of the event data of the event that has occurred has changed (from unreadable) to a readable state, the execution subject may respond to it.
[0052] First, the case where a new event occurs is used for explanation (for example, such an event can actually be exemplified as a Socket connection being established). If the execution subject determines that a new event occurs, it can respond to it.
[0053] For example, the response method can be, as will be discussed below, that the execution subject configures a corresponding coroutine for the event indicated by the event message. For example, when a socket connection is established, the execution subject can determine that an event has occurred in the communication channel and configure a corresponding coroutine for the event.
[0054] As a result, the execution subject can determine whether an event has occurred based on the detection of the communication channel without having to wait for or request an indication of the event occurrence from the event source. This approach can improve the execution subject's response efficiency to events.
[0055] Next, if the execution subject detects that an event has occurred, the execution subject can choose to respond to it and configure the corresponding coroutine for the event.
[0056] A coroutine is a lightweight thread that can be suspended while waiting for certain operations (such as I / O), allowing other coroutines to run, thereby improving concurrency performance. In other words, a coroutine can be a special function that can be suspended during execution and resumed later.
[0057] For example, a coroutine can perform processing actions based on the assigned tasks and events during the process of being called by the execution subject, and during this process, if a specific event occurs, the coroutine can be temporarily suspended so that it can be temporarily released (processed). In this way, the execution subject can use the processing resources and processing threads corresponding to the coroutine to process other tasks.
[0058] Correspondingly, after other "specific events" are processed, the execution subject can choose to continue scheduling the coroutine to resume execution and continue to complete the events that were not completed previously.
[0059] Step 202 , in response to detecting that the event data of the event is in a readable state, scheduling a coroutine to process the event data.
[0060] In an embodiment of the present disclosure, based on step 201, as discussed above, this step is intended to detect the reading status of event data corresponding to the (occurred) event by the above-mentioned execution entity (for example, the event may be an event message sent by a terminal device arriving at the server where the execution entity is located).
[0061] During the detection process, if the event data reading status of an event that has occurred changes from an unreadable state to a readable state (for example, because the event data of the event has been prepared, it can be provided to the execution subject or other threads by the event source, causing the reading status to change from an unreadable state to a readable state), the execution subject can choose to call the corresponding coroutine to actually process the event data.
[0062] In some optional implementations of this embodiment, the action corresponding to the event may actually include a data pulling action from the event source, that is, the event data is actually provided to the execution subject through the "pulling action" executed by the coroutine.
[0063] In such a case, the execution subject may choose to detect whether the event data in the event source is already in a state that can be pulled, to determine whether the reading state of the event data of the event is already in a readable state.
[0064] Then, the execution body can schedule the coroutine accordingly, so that the coroutine can actually pull and process the event data.
[0065] For example, the event source can be configured to expose and provide a data interface that can be used to pull the event data to the execution subject after the event data is prepared locally. Accordingly, the execution subject can determine that the event data is already in a readable state when it detects that the event source exposes and provides a data interface that can be used to pull the event data.
[0066] In some optional implementations of the present embodiment, when the execution subject schedules the coroutine to process the event data, it can also continue to detect whether a new event has occurred and / or the reading status of the event data of the event that has occurred in a non-blocking manner. That is, when the execution subject detects that the event data of the event is in a readable state and schedules the coroutine to process the corresponding event data, it can choose to detect whether a new event has occurred and / or the (data) reading status of the event data of the event that has occurred in a non-blocking manner. The non-blocking method, for example, can be a method of communicating between the execution subject and other event sources in an asynchronous state using the message mechanism of the Socket event.
[0067] Therefore, the execution subject will not interrupt or block the detection of new events and new event data during the process of scheduling the coroutine to process event data.
[0068] This can avoid the detection of new events and new event data being blocked by the scheduling coroutine, which affects the execution efficiency of the execution subject for the event.
[0069] The method for processing events provided by the embodiment of the present disclosure is applied to the thread of a responsive program. In response to detecting that an event has occurred, a corresponding coroutine is configured for the event; in response to detecting that the event data of the event is in a readable state, the coroutine is scheduled to process the event data. In this way, not only the responsiveness to events can be improved, but also the scheduling and processing efficiency of processing the event data of the event can be improved.
[0070] In some embodiments, the execution subject may only provide detection, and configure the coroutine by utilizing the multi-functional threads in the thread pool, and call the coroutine to specifically process the event data of the event.
[0071] Specifically, the execution subject can communicate the event to the multi-function thread in the thread pool in response to detecting the occurrence of an event. The multi-function thread in the thread pool can "assign" and "bind" the event to a coroutine in a group of coroutines corresponding to the multi-function thread, and establish a communication channel for communicating with the event source of the event. Then, the execution subject can use the multi-function thread to activate the coroutine so that the coroutine is in an available state.
[0072] Subsequently, as an alternative or in addition, the detection of the read state of the "event data" may be performed by the multi-function thread. That is, the multi-function thread detects the communication channel through which it communicates with the event source of the event to detect the read state of the event data. If the multi-function thread detects that the read state of the event data has changed to a readable state, it may schedule the currently activated coroutine to process the event data.
[0073] In this way, the execution subject only needs to continuously and persistently detect whether a new event has occurred, so that the execution subject can focus more on detecting whether an event has occurred, and improve the efficiency of responding to the event. In this way, the configuration of the thread pool can be simplified by configuring multi-functional threads, so that a single "multi-functional thread" can be used to fully implement actions such as configuring coroutines, reading status detection, and coroutine scheduling, simplifying the architecture of the thread pool and improving the utilization rate of threads in the thread pool.
[0074] In some embodiments, in order to further simplify the configuration and reduce the difficulty of configuration, the execution subject can also choose to schedule the coroutine by itself, that is, no longer use the multi-function thread in the thread pool to finally realize the scheduling of the coroutine. In this way, not only can the management, scheduling and control efficiency of the coroutine be improved (for example, there is no need to "communicate" with the thread pool), but also there is no need to configure the thread pool additionally, simplifying the configuration and saving configuration resources.
[0075] For this, please refer to Figure 3 , Figure 3 A flowchart of another process of processing an event provided by an embodiment of the present disclosure includes process 300, and process 300 includes the following steps:
[0076] Step 301, in response to detecting that an event has occurred, configuring a corresponding coroutine for the event.
[0077] Specifically, when the execution subject detects that an event has occurred, it can respond to it by directly generating a coroutine and assigning it to the event to configure the corresponding coroutine for the event.
[0078] Step 302, detecting the number of coroutines whose corresponding event data is in a readable state.
[0079] Specifically, the execution subject can detect whether the event data corresponding to the coroutine is already in a readable state in the manner discussed above.
[0080] Furthermore, considering that in this way, the scheduling capability of the thread pool cannot be utilized, a "conflict" may occur because at least two event data are in a readable state at the same time. To avoid such a conflict, the execution subject can also detect the number of coroutines whose corresponding event data are in a readable state.
[0081] If only the event data corresponding to one coroutine is in a readable state, the execution subject can execute step 303 to schedule the coroutine.
[0082] If the event data corresponding to at least two coroutines are in a readable state, the execution entity can execute step 304.
[0083] Step 304: Add the scheduling action for the coroutine to the scheduling queue.
[0084] Specifically, if there are at least two coroutines whose corresponding event data are both in a readable state, the execution subject can manage the calling order of these coroutines based on the scheduling queue. The execution subject can add the scheduling action for the coroutine to the scheduling queue.
[0085] For example, the execution subject may sequentially store and add each coroutine to the scheduling queue based on the time sequence in which the corresponding event data changes to a readable state.
[0086] In some embodiments, if the time when the event data corresponding to two coroutines are changed to a readable state is the same, the execution subject can sequentially store and add the scheduling actions corresponding to each coroutine to the scheduling queue based on the generation and binding time of each coroutine. Accordingly, in some embodiments, the subsequent scheduling queue can be used to indicate that each coroutine is called sequentially based on the storage order.
[0087] It should be understood that in some embodiments, it may not be necessary to schedule coroutines according to the "scheduling logic" of "the order in which the event data is changed to a readable state and the order in which the coroutine is generated". In this case, the execution subject may also choose to select the next scheduled task to be executed from the scheduling sequence, for example, according to the event processing priority, or randomly.
[0088] Accordingly, corresponding to these "scheduling logics", for the execution subject, it can store the coroutine into the scheduling queue only in response to the change of the read state of the event data corresponding to the coroutine to the readable state. For example, without the need for the "scheduling logic" of "the order of coroutine generation time according to the order of events when the event data changes to the readable state", the execution subject can arbitrarily select a coroutine that meets the requirements to call, and then store other coroutines that meet the requirements into the scheduling queue.
[0089] Step 305: Based on the scheduling queue, at least two coroutines are called alternately to process corresponding event data.
[0090] Specifically, the execution subject can interleave and call each coroutine based on the order indicated by the scheduling queue in combination with actual needs to process the corresponding events. For example, corresponding to the above discussion, in accordance with the corresponding storage order in the scheduling queue. Or, select a coroutine from the scheduling queue at any time, etc., which will not be repeated here. In some optional implementations of this embodiment, for the interleaved scheduling of at least two coroutines, the execution subject can determine whether there is a second coroutine in the scheduling queue that can be (continued) scheduled after the processing progress of the event data corresponding to the first coroutine currently scheduled in the scheduling queue reaches the yield point.
[0091] Typically, the yield point position can be, for example, the progress position corresponding to a sleep-type operation, the progress position for the completion of the processing of event data, and the like. Accordingly, when the processing progress of the event data corresponding to the currently scheduled first coroutine reaches these (progress) positions (for example, the position of executing to the sleep-type operation), it can choose to yield. At the same time, if the first coroutine is to be yielded (or cut out), and there is a second coroutine that can be scheduled in the scheduling queue, the second coroutine can be scheduled after the first coroutine yields, so as to realize the staggered scheduling of the coroutines. In this way, after the coroutine is cut out, it can directly switch to other coroutines to cut in, and will not return to the thread local. In this way, the scheduling efficiency of the coroutine can be improved.
[0092] In some optional implementations of this embodiment, if the processing progress of the event data corresponding to the first coroutine currently scheduled in the scheduling queue reaches the yield point position (for example, the position of executing to the sleep type operation), and there is no second coroutine that can be scheduled in the scheduling queue, then the first coroutine can be selected to yield, and the execution subject can detect whether a new event occurs and / or the reading status of the event data of the event that has occurred in a blocking manner (that is, whether it has changed to a readable state). Thus, when there is no subsequent coroutine that can be scheduled, the execution subject, that is, the thread, is used to continue the detection.
[0093] Generally, the scheduling order may depend on the priority algorithm of the scheduling queue and the actual situation during the time execution process. For example, during the process of event 1 processing event data, the processing progress position reaches the sleep type operation. At this time, the coroutine processing event 1 can be switched out and switched into the coroutine processing event 2. Correspondingly, if the coroutine processing event 2 also reaches the processing progress position and reaches the sleep type operation, and the waiting time of the coroutine processing event 1 has expired, the execution subject can choose to switch back to the coroutine processing event 1.
[0094] In addition, if the waiting time of the coroutine processing event 1 has expired, the execution subject can similarly schedule other coroutines to process, for example, event 3 and event 4, based on whether there are other coroutines in the scheduling queue that can be scheduled to process the event.
[0095] In some scenarios, if the waiting time of the coroutine processing event 1 has not expired, and there are no other events, or the coroutines can be scheduled, the execution body will wait until the waiting time of one of the coroutines processing event 1 or event 2 expires. In this way, scheduling is achieved in an interleaved manner.
[0096] The blocking mode can be a standard communication mode, a buffered communication mode, etc. Similarly, taking Socket as an example, in the blocking mode, when a message is sent using a TCP protocol, if the lower-level protocol does not have available space to store user data, the application process will block and wait until the protocol has available space. Unlike the non-blocking mode, where the call will return directly without waiting, in the blocking mode, when the application process calls the receiving function to receive a message, if there is no data arriving, the call will be blocked until data arrives or an error occurs.
[0097] This can avoid incorrectly occupying the coroutine for a long time, causing the coroutine to be unable to complete the event data processing action and unable to give up.
[0098] In some embodiments, for a coroutine, it can usually also require the execution subject to detect the event data of new events and events that have occurred in its corresponding communication pipeline (for example, whether new event data has occurred, the reading status of the new event data). For example, one or more detection point positions can be configured in the processing progress of the coroutine processing event data. Accordingly, after the processing progress of the coroutine processing event data reaches these detection point positions, it can choose to require the execution subject to perform "detection". In this way, the coroutine can continuously determine the action mode based on the detection results of the thread (for example, when the currently processed event data is updated, the coroutine can continue to process based on the updated event data).
[0099] For example, the coroutine can request and instruct the thread as the execution subject to detect its corresponding communication channel by calling the detection function. Usually, when the execution subject performs such "detection", it can detect only whether the event data (for example, data content) of the event corresponding to the coroutine has changed and whether there is a new event configured to the coroutine through the detection of the corresponding communication channel.
[0100] In some optional implementations of the present embodiment, for the behavior of the coroutine calling the detection function, the execution subject may also choose to provide a comprehensive "detection" for more and all coroutines at the same time, that is, the actual response method of the execution subject to the detection function can be adjusted to detect all communication channels, rather than just the communication channel of the coroutine that calls the detection function. That is, the execution subject can choose to "detect" the reading status of the events and event data of all coroutines bundled to the execution subject in full, and even detect the communication channels corresponding to other threads. In this way, the reading status of events and event data can be fully maintained in a more proactive, timely and positive manner to improve the detection quality.
[0101] To deepen understanding, the present disclosure also provides a specific implementation solution in combination with a specific application scenario, see Figure 4 Process 400 is shown.
[0102] When detecting the occurrence of event messages 411 and 412 , thread 410 of the responsive program can determine that events 421 and 422 have occurred accordingly.
[0103] For events 421 and 422 , illustratively, thread 410 may execute S401 to generate a coroutine 431 corresponding to event 421 and a coroutine 432 corresponding to event 422 .
[0104] Next, thread 410 may (continuously) execute S402 to detect the read status of event data 423 of event 421 and event data 424 of event 422 .
[0105] Subsequently, if the event data 423 and 424 are “prepared”, the thread 410 may detect the data call interface 425 of the event data 423 and the data call interface 426 of the event data 423 .
[0106] In this case, in response to the event data 423 and 424 being in a readable state, the thread 410 may execute S403 , schedule the coroutine 431 to process the event data 423 , and store the scheduling action of the coroutine 432 into the scheduling queue 441 .
[0107] As discussed above, for ease of understanding, a scenario in which priority is given to scheduling a coroutine generated earlier is selected as an example, and the generation time of coroutine 431 is earlier than that of coroutine 432. Accordingly, thread 410 will choose to prioritize calling coroutine 431 generated earlier than coroutine 432, and store (the scheduling action of) coroutine 432 in scheduling queue 441.
[0108] Next, if the processing progress of coroutine 431 reaches a yield point, and there is a scheduling action for coroutine 432 in scheduling queue 441 , thread 410 may execute S404 to continue scheduling 432 .
[0109] Further references Figure 5 As an implementation of the methods shown in the above figures, the present disclosure provides an embodiment of a device for processing events. Figure 2 Corresponding to the method embodiment shown, the device can be specifically applied to various electronic devices.
[0110] like Figure 5 As shown, the device 500 for processing events in this embodiment may include: a coroutine configuration unit 501 and a coroutine scheduling unit 502. The coroutine configuration unit 501 is configured to configure a corresponding coroutine for the event in response to detecting that an event has occurred; the coroutine scheduling unit 502 is configured to schedule a coroutine to process the event data in response to detecting that the event data of the event is in a readable state.
[0111] In the present embodiment, in the device 500 for processing events, the specific processing of the coroutine configuration unit 501 and the coroutine scheduling unit 502 and the technical effects thereof can be referred to in Figure 2 The relevant descriptions of steps 201 - 202 in the corresponding embodiment are not repeated here.
[0112] In some embodiments, the coroutine scheduling unit 502 is further configured to: include: in response to detecting that the event data of an event is in a readable state, scheduling a coroutine to process the event data, and detecting in a non-blocking manner whether a new event has occurred, and / or the reading status of the event data of an event that has occurred.
[0113] In some optional implementations of the present embodiment, the coroutine configuration unit 501 includes: an event communication subunit, configured to communicate the event to a multi-function thread in a thread pool in response to detecting the occurrence of an event; a first multi-function thread utilization subunit, configured to utilize the multi-function thread to configure a corresponding coroutine for the event from a group of coroutines associated with the multi-function thread, and to establish a communication pipeline for the multi-function thread to communicate with the event source of the event; a second multi-function thread utilization subunit, configured to utilize the multi-function thread to activate the coroutine, wherein the multi-function thread, in response to detecting that the event data of the event is in a readable state from the communication pipeline for communicating between the multi-function thread and the event source of the event, schedules the activated coroutine to process the event data.
[0114] In some optional implementations of this embodiment, the device 500 also includes: an event message detection unit, configured to detect whether an event message appears in the communication pipeline, wherein the event message indicates that a new event has occurred, or that the reading state of event data of an event that has occurred has changed to a readable state.
[0115] In some optional implementations of this embodiment, the device 500 also includes: a response detection unit, configured to detect whether a new event occurs and the reading status of event data of an event that has occurred in response to the detection function being called by the coroutine, wherein the coroutine calls the detection function in response to the processing progress of processing the event data reaching the detection point position.
[0116] In some embodiments, the coroutine scheduling unit 502 includes: a scheduling queue maintenance subunit, configured to add a scheduling action for the coroutine to the scheduling queue in response to detecting that event data corresponding to at least two coroutines are in a readable state; and a coroutine scheduling subunit, configured to schedule at least two coroutines to process corresponding event data in an interleaved manner based on the scheduling queue.
[0117] In some embodiments, at least two coroutines are interleaved to process corresponding event data, including: in response to the processing progress of the event data corresponding to the first coroutine currently scheduled in the scheduling queue reaching a yield point, and there is a second coroutine that can be scheduled in the scheduling queue, the first coroutine is cut out and the second coroutine is scheduled.
[0118] In some embodiments, the device 500 also includes: a post-yield event detection unit, which is configured to cut out the first coroutine in response to the processing progress of the event data corresponding to the first coroutine currently scheduled in the scheduling queue reaching the yield point position, and there is no second coroutine that can be scheduled in the scheduling queue, and detect in a blocking manner whether a new event occurs, and / or the reading status of the event data of the event that has occurred.
[0119] This embodiment exists as an apparatus embodiment corresponding to the above-mentioned method embodiment. The apparatus for processing events provided by this embodiment can not only improve the response capability to events, but also improve the scheduling and processing efficiency of processing event data of events.
[0120] According to an embodiment of the present disclosure, the present disclosure also provides an electronic device, a readable storage medium and a computer program product.
[0121] Figure 6A schematic block diagram of an example electronic device 600 that can be used to implement an embodiment of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present disclosure described and / or required herein.
[0122] like Figure 6 As shown, the device 600 includes a computing unit 601, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 602 or a computer program loaded from a storage unit 608 into a random access memory (RAM) 603. In the RAM 603, various programs and data required for the operation of the device 600 can also be stored. The computing unit 601, the ROM 602, and the RAM 603 are connected to each other via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.
[0123] A number of components in the device 600 are connected to the I / O interface 605, including: an input unit 606, such as a keyboard, a mouse, etc.; an output unit 607, such as various types of displays, speakers, etc.; a storage unit 608, such as a disk, an optical disk, etc.; and a communication unit 609, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 609 allows the device 600 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0124] The computing unit 601 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 601 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The computing unit 601 performs the various methods and processes described above, such as a method for processing events. For example, in some embodiments, the method for processing events may be implemented as a computer software program, which is tangibly contained in a machine-readable medium, such as a storage unit 608. In some embodiments, part or all of the computer program may be loaded and / or installed on the device 600 via ROM 602 and / or communication unit 609. When the computer program is loaded into RAM 603 and executed by the computing unit 601, one or more steps of the method for processing events described above may be performed. Alternatively, in other embodiments, the computing unit 601 may be configured to execute a method for processing events in any other appropriate manner (e.g., by means of firmware).
[0125] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0126] The program code for implementing the method of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that the program code, when executed by the processor or controller, enables the functions / operations specified in the flow chart and / or block diagram to be implemented. The program code may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0127] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0128] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0129] The systems and techniques described herein may be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), and the Internet.
[0130] A computer system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The relationship between the client and the server is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or a cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and virtual private servers (VPS) services. The server can also be divided into a server of a distributed system, or a server combined with a blockchain.
[0131] According to the technical solution of the embodiment of the present disclosure, not only the response capability to events can be improved, but also the scheduling and processing efficiency of processing event data of events can be improved.
[0132] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this disclosure can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solutions provided by this disclosure can be achieved, and this document does not limit this.
[0133] The above specific implementations do not constitute a limitation on the protection scope of the present disclosure. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present disclosure shall be included in the protection scope of the present disclosure.
Claims
1. A method for processing events, applied to a thread of a responsive program, comprising: In response to detecting that an event has occurred, configuring a corresponding coroutine for the event; In response to detecting that the event data of the event is in a readable state, scheduling the coroutine to process the event data.
2. The method according to claim 1, wherein: In response to detecting that the event data of the event is in a readable state, scheduling the coroutine to process the event data includes: In response to detecting that the event data of the event is in a readable state, scheduling the coroutine to process the event data, and detecting in a non-blocking manner whether a new event occurs and / or the reading status of the event data of an event that has occurred.
3. The method according to claim 1, wherein: In response to detecting that an event has occurred, configuring a corresponding coroutine for the event includes: In response to detecting that an event has occurred, communicating the event to a multi-function thread in the thread pool; Using the multifunctional thread, from a group of coroutines associated with the multifunctional thread, configure a corresponding coroutine for the event, and establish a communication channel for the multifunctional thread to communicate with an event source of the event; The coroutine is activated by the multi-function thread, wherein the multi-function thread, in response to detecting that event data of the event is in a readable state from a communication pipe through which the multi-function thread communicates with an event source of the event, schedules the activated coroutine to process the event data.
4. The method according to claim 1, further comprising: Detect whether an event message appears in the communication pipeline, wherein the event message indicates that a new event has occurred, or the reading state of event data of an event that has occurred has changed to the readable state.
5. The method according to claim 1, further comprising: In response to the detection function being called by the coroutine, it detects whether a new event occurs and the reading status of the event data of the event that has occurred, wherein the coroutine calls the detection function in response to the processing progress of processing the event data reaching the detection point position.
6. The method according to claim 1, wherein: In response to detecting that the event data of the event is in a readable state, scheduling the coroutine to process the event data includes: In response to detecting that the event data corresponding to at least two of the coroutines are both in a readable state, adding a scheduling action for the coroutine to a scheduling queue; Based on the scheduling queue, at least two of the coroutines are scheduled alternately to process corresponding event data.
7. The method according to claim 6, wherein: Interleavingly scheduling at least two of the coroutines to process corresponding event data, including: In response to the processing progress of event data corresponding to the first coroutine currently scheduled in the scheduling queue reaching a yield point, and there is a second coroutine that can be scheduled in the scheduling queue, the first coroutine is cut out and the second coroutine is scheduled.
8. The method according to claim 7, further comprising: In response to the processing progress of event data corresponding to the first coroutine currently scheduled in the scheduling queue reaching the yield point, and there is no second coroutine that can be scheduled in the scheduling queue, the first coroutine is cut out to detect whether a new event occurs and / or the reading status of the event data of the event that has occurred in a blocking manner.
9. A device for processing events, applied to a thread of a responsive program, comprising: A coroutine configuration unit, configured to, in response to detecting that an event has occurred, configure a corresponding coroutine for the event; The coroutine scheduling unit is configured to schedule the coroutine to process the event data in response to detecting that the event data of the event is in a readable state.
10. An electronic device comprising: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method for processing an event according to any one of claims 1 to 8.
11. A non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to cause the computer to execute the method for processing an event according to any one of claims 1 to 8.
12. A computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the computer program implements the method for processing an event according to any one of claims 1 to 8.
Citation Information
Patent Citations
Method and equipment used for processing event by website server
CN106844017A
Coroutine implementation method, terminal device and storage medium
CN108021449A
Data processing method, device and equipment and storage medium
CN111078436A
Event processing method and device, equipment and computer readable storage medium
CN113626213A
Method for asynchronously creating internal snapshot of virtual machine, apparatus, system and storage medium
WO2021072880A1
Cited By
Event processing method and apparatus, device, storage medium, and program product
WO2026077055A1