Heterogeneous event processing method and device, electronic equipment and storage medium

By using polling threads to cache event references in heterogeneous event processing and using file descriptors to convert states, the problems of high memory usage and performance overhead in the prior art are solved, and a simpler and more general heterogeneous event processing method is achieved.

CN119473544APending Publication Date: 2025-02-18BEIJING YIHUI INFORMATION TECH CO LTD
View PDF 0 Cites 3 Cited by

Patent Information

Application Number
CN202411522792.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-29
Publication Date
2025-02-18

AI Technical Summary

Technical Problem

The existing heterogeneous event processing methods increase memory usage and performance overhead, and are not versatile, so it requires unified abstraction of heterogeneous events, increasing system complexity and design difficulty.

Method used

The polling thread saves the event reference of the pending event in the cache, and performs a write operation based on the preset file descriptor of the target file, converting its state to readable. After the business main thread listens to the readable state, it obtains Event references and processes event information.

Benefits of technology

Reduces memory usage and performance overhead, no need to copy cache event messages or synchronize message queue locks, reduces system complexity, and applies to any event model.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119473544A_ABST
    Figure CN119473544A_ABST
Patent Text Reader

Abstract

The invention discloses a heterogeneous event processing method and device, electronic equipment and a storage medium. The method comprises the steps that under the condition that a polling thread polls a to-be-processed event, the polling thread stores an event reference of the to-be-processed event in a cache; the polling thread executes write-in operation on the target file based on a preset file descriptor of the target file, so that the state of the target file is converted into a readable state; and under the condition that the business main thread monitors the readable state of the target file, determining an event reference corresponding to the target file based on the file descriptor, acquiring event information of the to-be-processed event based on the event reference, and processing the to-be-processed event based on the event information. In the technical scheme of the invention, the polling thread only needs to cache the reference of the current event information and wait for further processing of the service main thread, the event message does not need to be copied and cached, the message queue lock does not need to be synchronously operated, and the memory occupation and the performance overhead are reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of heterogeneous event scheduling and processing, and in particular to a method, device, electronic device and storage medium for processing heterogeneous events. Background Art

[0002] Event polling is an event scheduling mechanism. In the event scheduling mechanism, there is generally a main loop, which blocks waiting for events. When an event occurs, the event-related handler is called. In this event polling, all events have the same abstract model, so that they can be processed in a loop. For example, in Linux, various IOs are abstracted as files, and the select / poll / epoll system call method is used to perform IO multiplexing operations, thereby realizing polling of various IO events.

[0003] In a program, if there are multiple different event abstract models at the same time, these events are called heterogeneous events. Each event model has a corresponding event polling mechanism, but heterogeneous events cannot be uniformly scheduled in a main loop.

[0004] For heterogeneous events, the existing technology integrates multiple event models into one program and uses multi-threaded parallel polling. The event polling thread caches the event information in the message queue and notifies the business main thread for processing through a semaphore.

[0005] However, the existing heterogeneous event processing methods have the following disadvantages: 1) Increased memory usage and performance overhead: event information needs to be copied to the message queue, and synchronization lock operations are also required. 2) Lack of versatility: heterogeneous events need to be uniformly abstracted, that is, an intermediate model needs to be designed to encapsulate different event information, which increases system complexity and design difficulty. Summary of the invention

[0006] The present invention provides a method, device, electronic device and storage medium for processing heterogeneous events, so as to realize the processing of heterogeneous events, reduce memory usage and performance overhead, and the system is simple and has strong versatility.

[0007] According to one aspect of the present invention, a method for processing heterogeneous events is provided, comprising:

[0008] When the polling thread polls an event to be processed, the polling thread saves the event reference of the event to be processed in a cache;

[0009] The polling thread performs a write operation on the target file based on a preset file descriptor of the target file, so that the state of the target file is converted into a readable state;

[0010] In the case where the service main thread monitors the readable state of the target file, determining the event reference cached by the polling thread corresponding to the target file based on the file descriptor;

[0011] The business main thread obtains event information of the event to be processed based on the event reference, and processes the event to be processed based on the event information.

[0012] According to another aspect of the present invention, there is provided a device for processing heterogeneous events, comprising:

[0013] A polling thread, for storing an event reference of an event to be processed in a cache when a pending event is polled;

[0014] The polling thread is further used to perform a write operation on the target file based on a preset file descriptor of the target file, so that the state of the target file is converted into a readable state;

[0015] The main business thread is used to determine the event reference cached by the polling thread corresponding to the target file based on the file descriptor when the readable state of the target file is monitored;

[0016] The business main thread is further used to obtain event information of the event to be processed based on the event reference, and process the event to be processed based on the event information.

[0017] According to another aspect of the present invention, an electronic device is provided, the electronic device comprising:

[0018] at least one processor;

[0019] and a memory communicatively connected to the at least one processor; wherein,

[0020] The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the method for processing heterogeneous events described in any embodiment of the present invention.

[0021] According to another aspect of the present invention, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the method for processing heterogeneous events described in any embodiment of the present invention when executed.

[0022] The technical solution of the embodiment of the present invention includes: when the polling thread polls the event to be processed, the polling thread saves the event reference of the event to be processed in the cache; the polling thread performs a write operation on the target file based on the preset file descriptor of the target file to convert the state of the target file to a readable state; when the main business thread monitors the readable state of the target file, the event reference cached by the polling thread corresponding to the target file is determined based on the file descriptor; the main business thread obtains the event information of the event to be processed based on the event reference, and processes the event to be processed based on the event information. The polling thread of the embodiment of the present invention only needs to cache the reference of the current event information and wait for the main business thread to further process it. It does not need to copy and cache the event message, nor does it need to synchronize the message queue lock operation, thereby reducing memory usage and performance overhead. In addition, the solution of the embodiment of the present invention does not need to uniformly abstract heterogeneous events. Each event model can record events independently, is applicable to any event model, and does not increase the system abstraction cost.

[0023] It should be understood that the contents described in this section are not intended to identify the key or important features of the embodiments of the present invention, nor are they intended to limit the scope of the present invention. Other features of the present invention will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0024] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0025] Figure 1 It is a flow chart of the processing of heterogeneous events in the prior art;

[0026] Figure 2 A flowchart of a method for processing heterogeneous events provided in the first embodiment of the present invention;

[0027] Figure 3 A flowchart of a method for processing heterogeneous events provided in Embodiment 2 of the present invention;

[0028] Figure 4 A polling thread workflow diagram provided in Embodiment 2 of the present invention;

[0029] Figure 5 A flowchart of the main business thread provided in the second embodiment of the present invention;

[0030] Figure 6An architectural diagram of a system for processing heterogeneous events provided in Embodiment 2 of the present invention;

[0031] Figure 7 A schematic diagram of the structure of a device for processing heterogeneous events provided in Embodiment 3 of the present invention;

[0032] Figure 8 This is a schematic diagram of the structure of an electronic device provided in Embodiment 4 of the present invention. DETAILED DESCRIPTION

[0033] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.

[0034] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0035] In order to further clarify the technical effects of the present invention, before introducing specific embodiments, the problems existing in the prior art are explained as follows:

[0036] For heterogeneous events, the existing technology integrates multiple event models into one program to perform heterogeneous event scheduling. Multiple event models require multi-threaded parallel polling. Each thread event model synchronizes the event to the main thread for business processing. The general solution for heterogeneous event scheduling: multi-threading + message queue implementation based on thread synchronization. Figure 1 It is a flowchart of the processing of heterogeneous events in the prior art, such as Figure 1 As shown, the scheme works as follows:

[0037] 1. The event polling thread (T1-Tn) caches the event information in the message queue and sends a semaphore to notify the main business thread. 2. The main business thread waits for the semaphore. When the semaphore is obtained, it indicates that a new event has been generated in the message queue. It obtains the event information from the message queue and processes the event. 3. When the event polling thread and the main business thread access the message queue, they must first obtain the synchronization lock and release the synchronization lock after completing the message queue operation.

[0038] The existing technology has the following disadvantages: 1. Increased memory usage and performance overhead: The event polling thread caches event information in the message queue, and the business main thread asynchronously reads event information from the message queue. The event information needs to be copied once, which not only increases memory usage, but also increases performance overhead; multi-threading also requires synchronization lock operations on the message queue, which also increases performance overhead. 2. Lack of versatility: This solution requires unified abstraction of heterogeneous events, that is, designing an intermediate model to encapsulate different event information, which increases system complexity and design difficulty.

[0039] In the technical solution of the present invention, the polling thread only needs to cache the reference of the current event information and wait for the main business thread to further process it. There is no need to copy and cache the event message, nor to lock and synchronize the message queue, thus reducing memory usage and performance overhead. The technical solution of the present invention does not require unified abstraction of heterogeneous events. Each event model can record events independently, is applicable to any event model, and does not increase the system abstraction cost.

[0040] Embodiment 1

[0041] Figure 2 This is a flowchart of a method for processing heterogeneous events provided in the first embodiment of the present invention. This embodiment is applicable to the case of processing heterogeneous events to be processed. The method can be executed by a processing device for heterogeneous events. The processing device for heterogeneous events can be implemented in the form of hardware and / or software. The processing device for heterogeneous events can be configured in a computer device. Figure 1 As shown, the method includes:

[0042] S110. When the polling thread polls an event to be processed, the polling thread saves an event reference of the event to be processed in a cache.

[0043] The polling thread may be an event polling thread; the pending event may be an event that needs to be processed, for example, the pending event may be a network connection event, such as TCP connection establishment, data reception and transmission, etc. The pending event may also be a file system event, such as file reading and writing. The event reference is used to determine the storage location of the event information of the pending event.

[0044] Specifically, when the polling thread polls an event to be processed, the event reference of the event to be processed may be saved in the cache.

[0045] In the embodiment of the present invention, the number of the polling threads is at least two, and the type of the polling threads corresponds to the event model of the event to be processed.

[0046] There may be multiple events to be processed, and the event models of the events to be processed may be the same or different. If the event models of two events to be processed are different, they are heterogeneous events. The different event models of the events to be processed can be understood as these events are provided by different libraries or frameworks.

[0047] It is understandable that in order to process heterogeneous events, multiple parallel polling threads can be set, each of which corresponds to an event model. For example, if the polling thread is A and the corresponding event model is a, the polling thread A can poll the pending events of event model a.

[0048] S120. The polling thread performs a write operation on the target file based on a preset file descriptor of the target file, so as to convert the state of the target file into a readable state.

[0049] The preset target file may be a pre-established file, and the type of the target file may be a text file or an event file, etc. The embodiment of the present invention does not limit the type of the target file.

[0050] Specifically, the polling thread can perform a write operation on the target file based on the file descriptor of the target file and write the corresponding data, so that the state of the target file is converted to a readable state. Based on this operation, the polling thread can notify the business main thread that a pending event has been polled.

[0051] S130. When the service main thread monitors the readable state of the target file, determine the event reference cached by the polling thread corresponding to the target file based on the file descriptor.

[0052] It should be noted that the main business thread can monitor the write operation of the target file. If the target file is converted to a readable state, it means that the polling thread has polled the pending event to be processed. Furthermore, the main business thread can determine the event reference of the pending event polled by the polling thread according to the file descriptor.

[0053] S140: The business main thread obtains event information of the event to be processed based on the event reference, and processes the event to be processed based on the event information.

[0054] Among them, the event reference can be used to determine the storage location of the event information.

[0055] Specifically, the business main thread can obtain the event reference in the cache, and then determine the specific storage location of the event information of the event to be processed based on the event reference, and then read and access the event information, and process the event business according to the event information.

[0056] The beneficial effect of this is that after the polling thread listens to the event to be processed, the polling thread only needs to cache the reference of the current event information and wait for the main business thread to further process it. There is no need to copy and cache the event information, nor to lock and synchronize the message queue, thus reducing memory usage and performance overhead. There is no need to uniformly abstract heterogeneous events. Each event model can record events independently. This method is applicable to any event model and does not increase the system abstraction cost.

[0057] Embodiment 2

[0058] Figure 3 This is a flowchart of a method for processing heterogeneous events provided in the second embodiment of the present invention. This embodiment further introduces the specific processing process of the polling thread and the main business thread for the event to be processed. The specific implementation method can refer to the technical solution of this embodiment. Among them, the technical terms that are the same or corresponding to the above embodiments are not repeated here. Figure 3 As shown, the method includes:

[0059] S210, the polling thread initializes the event engine. After initializing the event engine, the polling thread calls a blocking interface to wait for an event.

[0060] Specifically, when the program starts, the polling thread needs to initialize the event engine. The initialization process includes registering event operations, that is, indicating to the system or event engine which types of events need to be monitored. Different event models (such as POSIX signals, file I / O, network I / O, etc.) correspond to different initialization requirements. After the initialization is completed, the polling thread enters a loop program, constantly calling the blocking interface to wait for the occurrence of events.

[0061] S220: When the blocking interface monitors the event to be processed and the blocking interface has not timed out, the polling thread polls and saves the event reference of the event to be processed in a cache.

[0062] Specifically, when the thread returns from the blocking interface, it needs to determine whether the interface has timed out. If it has timed out, it means that no event has occurred within the specified time, and the thread will continue to poll for events. If it has not timed out, it means that an event has occurred. When polling obtains a new event, it is an event to be processed. At this time, the polling thread saves the reference of the event to be processed in a cache. The purpose of saving the event reference is to enable the main business thread to easily access the relevant information of the event to be processed when processing the event to be processed later.

[0063] S230: The polling thread performs a write operation on the target file based on a preset file descriptor of the target file, so as to convert the state of the target file into a readable state.

[0064] Specifically, the polling thread can perform a write operation on the target file through the file descriptor. The target file is used to notify the business main thread that there are new pending events to be processed. The write operation sets the target file to a readable state, thereby triggering the IO multiplexing interface of the business main thread to return.

[0065] In a preferred implementation, Figure 4 The polling thread workflow diagram provided in the second embodiment of the present invention is as follows: Figure 4 As shown:

[0066] 1. When the program starts, it is generally necessary to initialize the event engine. Different initialization tasks are required depending on the event model, and there is usually a registration event operation.

[0067] 2. Start event polling. The polling thread generally calls the blocking interface in a loop program to wait for events.

[0068] 3. When the polling thread returns from the blocking interface, it determines whether the interface has timed out. If so, it goes to step 2 to continue polling events. Otherwise, it gets a new event.

[0069] 4. When polling for new events, save the event reference in the cache (ref-n).

[0070] 5. The polling thread performs a write operation on the target file through the file descriptor (fd-n), making the target file readable.

[0071] 6. The polling thread blocks and waits for the semaphore (sem-n). When the main business thread processes the event and sends the semaphore, the polling thread returns from the block and goes to step 2 to continue polling events.

[0072] S240: The service main thread calls the IO multiplexing interface to monitor whether the status of the target file has been converted to a readable state.

[0073] In the embodiment of the present invention, each polling event system and data structure may be initialized first, and then the IO multiplexing interface may be called after the initialization is completed.

[0074] After initialization is completed, the main business thread calls the IO multiplexing interface provided by the system (such as select(), poll(), epoll(), etc.) to block and query IO events. Through these interfaces, the main business thread simultaneously monitors whether the status of the target file corresponding to each polling thread has been converted to a readable state, that is, monitors whether an IO file readable event has occurred.

[0075] When the business main thread returns from the blocked state, it first needs to determine whether the interface has timed out. If it has timed out, it means that no IO event has occurred within the specified time, and the business main thread will continue to poll for IO file readable events. If it has not timed out, it means that an IO file readable event has occurred, and the business main thread will continue to execute the next step.

[0076] S250. Determine the polling thread that performs a write operation on the target file based on the file descriptor, and obtain the event reference cached by the polling thread.

[0077] The event reference is used to determine the storage location of the event information of the event to be processed.

[0078] Specifically, when the main business thread listens to the IO file readable event, it can further obtain the file descriptor of the target file. Through the target file descriptor, the main business thread can access the event reference of the pending event associated with the polling thread.

[0079] S260: The business main thread obtains event information of the event to be processed based on the event reference, and processes the event to be processed based on the event information.

[0080] Specifically, the business main thread can access and read event information based on the event reference, and execute corresponding processing logic according to the type and content of the event.

[0081] In an embodiment of the present invention, after processing the pending event based on the event information, the method further includes: the business main thread performs a read operation on the target file based on the file descriptor to clear the target file, and sends a semaphore to the polling thread; when the polling thread receives the semaphore, it starts polling for the second pending event.

[0082] The second event to be processed may be understood as a newly generated event to be processed.

[0083] After processing the current pending event, the main business thread performs a read file operation through the file descriptor to clear the target file. This is to ensure that the file will become readable again only when the polling thread rewrites the operation, thereby avoiding repeated processing of the same event.

[0084] After clearing the file, the main business thread sends a semaphore (sem-i) to wake up the corresponding polling thread. The semaphore is used to notify the polling thread that the current event has been processed and that it can continue to poll for new events, i.e., the second pending event. The main business thread continues to monitor the IO file readable event to determine whether there is a target file in a readable state. In this way, the main business thread and the event polling thread form a collaborative loop mechanism that can efficiently handle events occurring in the system.

[0085] In a preferred embodiment, Figure 5 The business main thread workflow diagram provided for the second embodiment of the present invention includes the following steps:

[0086] 1. When the main business thread starts, each polling event system and data structure needs to be initialized.

[0087] 2. After the business main thread completes initialization, it calls the system IO multiplexing interface (such as select, poll, epoll, etc.) to block and query IO events.

[0088] 3. When the main business thread returns from blocking, it determines whether the interface has timed out. If so, it goes to step 2 to continue polling events. Otherwise, it gets a new IO event.

[0089] 4. When the business main thread obtains a new IO event, it obtains the file descriptor fd-i. Through fd-i, it can obtain the event reference cache ref-i and semaphore sem-i associated with the polling thread.

[0090] 5. The main business thread accesses the event reference, reads the event information, and processes the event business.

[0091] 6. After the main business thread completes the event business, it clears the file through the fd-i read file operation, so that the readable event will occur again only when the file is rewritten by the polling thread.

[0092] 7. After the business main thread completes the above steps, it sends a semaphore (sem-i) to wake up the corresponding polling thread, and the business main thread goes to step 2 to continue listening for IO file readable events.

[0093] like Figure 6As shown, it is an architecture diagram of a heterogeneous event processing system provided in the second embodiment of the present invention. Specifically, 1. The event polling thread (T1-Tn) records the event reference in the cache, and at the same time writes the file operation so that the business main thread receives the file read event, and finally blocks and waits for the semaphore. 2. The business main thread listens to the file read event, obtains the associated event reference according to the file fd, and processes the event business; 3. After the business main thread completes the business processing, it clears the file through the read operation in order to listen to the next read event, and finally sends a semaphore to wake up the event polling thread. 4. There is no restriction on the file type monitored by the business main thread, as long as it is a file that supports IO multiplexing on the operating system; for the Linux system, the virtual device file eventfd is preferably used, and reading and writing are more efficient.

[0094] The technical solution of the embodiment of the present invention includes: when the polling thread polls the event to be processed, the polling thread saves the event reference of the event to be processed in the cache; the polling thread performs a write operation on the target file based on the preset file descriptor of the target file to convert the state of the target file to a readable state; when the main business thread monitors the readable state of the target file, the event reference cached by the polling thread corresponding to the target file is determined based on the file descriptor; the main business thread obtains the event information of the event to be processed based on the event reference, and processes the event to be processed based on the event information. The polling thread of the embodiment of the present invention only needs to cache the reference of the current event information and wait for the main business thread to further process it. It does not need to copy and cache the event message, nor does it need to synchronize the message queue lock operation, thereby reducing memory usage and performance overhead. In addition, the solution of the embodiment of the present invention does not need to uniformly abstract heterogeneous events. Each event model can record events independently, is applicable to any event model, and does not increase the system abstraction cost.

[0095] Embodiment 3

[0096] Figure 7 This is a schematic diagram of the structure of a device for processing heterogeneous events provided by Embodiment 3 of the present invention. Figure 7 As shown, the device comprises:

[0097] The polling thread 310 is used to save the event reference of the event to be processed in the cache when polling the event to be processed;

[0098] The polling thread 310 is further used to perform a write operation on the target file based on a preset file descriptor of the target file, so that the state of the target file is converted into a readable state;

[0099] The service main thread 320 is used to determine the event reference cached by the polling thread corresponding to the target file based on the file descriptor when the readable state of the target file is monitored;

[0100] The business main thread 320 is further used to obtain event information of the event to be processed based on the event reference, and process the event to be processed based on the event information.

[0101] The technical solution of the embodiment of the present invention includes: when the polling thread polls the event to be processed, the polling thread saves the event reference of the event to be processed in the cache; the polling thread performs a write operation on the target file based on the preset file descriptor of the target file to convert the state of the target file to a readable state; when the main business thread monitors the readable state of the target file, the event reference cached by the polling thread corresponding to the target file is determined based on the file descriptor; the main business thread obtains the event information of the event to be processed based on the event reference, and processes the event to be processed based on the event information. The polling thread of the embodiment of the present invention only needs to cache the reference of the current event information and wait for the main business thread to further process it. It does not need to copy and cache the event message, nor does it need to synchronize the message queue lock operation, thereby reducing memory usage and performance overhead. In addition, the solution of the embodiment of the present invention does not need to uniformly abstract heterogeneous events. Each event model can record events independently, is applicable to any event model, and does not increase the system abstraction cost.

[0102] Optionally, the number of the polling threads is at least two, and the type of the polling thread corresponds to the event model of the event to be processed.

[0103] Optionally, the polling thread 310 is also used to initialize the event engine, and after initializing the event engine, call a blocking interface to wait for an event;

[0104] When the blocking interface monitors the event to be processed and the blocking interface has not timed out, the polling thread polls 310 to save the event reference of the event to be processed in a cache.

[0105] Optionally, the business main thread 320 is further used to call an IO multiplexing interface to monitor whether the state of the target file has been converted to a readable state.

[0106] Optionally, the business main thread 320 is also used for:

[0107] Determine the polling thread that performs a write operation on the target file based on the file descriptor, and obtain the event reference cached by the polling thread;

[0108] The event reference is used to determine the storage location of the event information of the event to be processed.

[0109] Optionally, after processing the pending event based on the event information, the business main thread 320 is further used to perform a read operation on the target file based on the file descriptor to clear the target file, and send a semaphore to the polling thread 310;

[0110] The polling thread 310 is further configured to start polling for a second event to be processed when receiving the semaphore.

[0111] The device for processing heterogeneous events provided in the embodiment of the present invention can execute the method for processing heterogeneous events provided in any embodiment of the present invention, and has the functional modules and beneficial effects corresponding to the execution method.

[0112] Embodiment 4

[0113] Figure 8 A schematic diagram of the structure of an electronic device provided for Embodiment 4 of the present invention. 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 may also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.), 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 invention described and / or required herein.

[0114] like Figure 8 As shown, the electronic device 10 includes at least one processor 11, and a memory connected to the at least one processor 11, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., wherein the memory stores a computer program that can be executed by at least one processor, and the processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or the computer program loaded from the storage unit 18 to the random access memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the electronic device 10 can also be stored. The processor 11, ROM 12 and RAM 13 are connected to each other through a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.

[0115] A number of components in the electronic device 10 are connected to the I / O interface 15, including: an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a disk, an optical disk, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.

[0116] The processor 11 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 11 executes the various methods and processes described above, such as a method for processing heterogeneous events.

[0117] In some embodiments, the method for processing heterogeneous events may be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as a storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps of the method for processing heterogeneous events described above may be performed. Alternatively, in other embodiments, the processor 11 may be configured to execute the method for processing heterogeneous events in any other appropriate manner (e.g., by means of firmware).

[0118] 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.

[0119] Computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that when the computer program is executed by the processor, the functions / operations specified in the flow chart and / or block diagram are implemented. The computer program 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.

[0120] In the context of the present invention, a computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by or in combination with an instruction execution system, device or equipment. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices or equipment, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. 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.

[0121] To provide interaction with a user, the systems and techniques described herein may be implemented on an electronic device 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 a pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form (including acoustic input, voice input, or tactile input).

[0122] The systems and techniques described herein may be implemented in a computing system that includes backend 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 frontend 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 backend components, middleware components, or frontend 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), a blockchain network, and the Internet.

[0123] A computing 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 client and server relationship 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 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 VPS services.

[0124] 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 described in the present invention can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solution of the present invention can be achieved, and this document does not limit this.

[0125] The above specific implementations do not constitute a limitation on the protection scope of the present invention. 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 invention should be included in the protection scope of the present invention.

Claims

1. A method for processing heterogeneous events, characterized in that: include: When the polling thread polls an event to be processed, the polling thread saves the event reference of the event to be processed in a cache; The polling thread performs a write operation on the target file based on a preset file descriptor of the target file, so that the state of the target file is converted into a readable state; In the case where the service main thread monitors the readable state of the target file, determining the event reference cached by the polling thread corresponding to the target file based on the file descriptor; The business main thread obtains event information of the event to be processed based on the event reference, and processes the event to be processed based on the event information.

2. The method according to claim 1, characterized in that The number of the polling threads is at least two, and the type of the polling threads corresponds to the event model of the event to be processed.

3. The method according to claim 2, characterized in that When the polling thread polls an event to be processed, the polling thread saves the event reference of the event to be processed in a cache, including: The polling thread initializes the event engine. After the event engine is initialized, the polling thread calls a blocking interface to wait for an event. When the blocking interface monitors the event to be processed and the blocking interface has not timed out, the polling thread polls and saves the event reference of the event to be processed in a cache.

4. The method according to claim 2, characterized in that: Before the main service thread monitors the readable state of the target file, the method includes: The business main thread calls the IO multiplexing interface to monitor whether the state of the target file has been converted to a readable state.

5. The method according to claim 4, characterized in that The determining, based on the file descriptor, the event reference cached by the polling thread corresponding to the target file comprises: Determine the polling thread that performs a write operation on the target file based on the file descriptor, and obtain the event reference cached by the polling thread; The event reference is used to determine the storage location of the event information of the event to be processed.

6. The method according to claim 1, characterized in that After processing the event to be processed based on the event information, the method further includes: The main service thread performs a read operation on the target file based on the file descriptor to clear the target file, and sends a semaphore to the polling thread; When receiving the semaphore, the polling thread starts polling for the second event to be processed.

7. A device for processing heterogeneous events, characterized in that: include: A polling thread, for storing an event reference of an event to be processed in a cache when a pending event is polled; The polling thread is further used to perform a write operation on the target file based on a preset file descriptor of the target file, so that the state of the target file is converted into a readable state; The main business thread is used to determine the event reference cached by the polling thread corresponding to the target file based on the file descriptor when the readable state of the target file is monitored; The business main thread is further used to obtain event information of the event to be processed based on the event reference, and process the event to be processed based on the event information.

8. The device according to claim 7, characterized in that The number of the polling threads is at least two, and the type of the polling threads corresponds to the event model of the event to be processed.

9. An electronic device, characterized in that: The electronic device comprises: at least one processor; and a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the method for processing heterogeneous events according to any one of claims 1 to 6.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the method for processing heterogeneous events according to any one of claims 1 to 6 when executed.

Citation Information

Cited By

  • Data interaction method and device and electronic equipment

    CN121277909A

  • User mode thread operation control method and device oriented to pthread and libc compatible interception and storage medium

    CN122132150A

  • A user-mode thread running control method, device and storage medium for pthread and libc compatible interception

    CN122132150B