Event processing method and device

By converting the computationally intensive events into pending tasks, which are processed by the task processing process, the problem of subsequent event processing blocked caused by CPU resource occupation when processing computationally intensive events is solved, and the CDN network response speed and customer experience are improved.

CN119728756AInactive Publication Date: 2025-03-28CHINA TELECOM CLOUD TECH CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202411754492.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-02
Publication Date
2025-03-28
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

When existing reverse proxy servers handle computing-intensive events, they will occupy CPU resources and not release them, resulting in subsequent event processing being blocked, affecting the CDN network response speed and customer experience.

Method used

By creating compute-intensive events as pending tasks and being processed by the task processing process, it avoids it occupies CPU resources in the event processing process, ensuring that the processing of other events is not blocked.

Benefits of technology

It effectively avoids the impact of computing-intensive event processing on other event processing, improves the response speed of the CDN network, and improves the user experience of customers.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119728756A_ABST
    Figure CN119728756A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides an event processing method and device, the method is applied to a reverse proxy server, the reverse proxy server relates to an event processing process and a task processing process, and the method comprises the following steps: obtaining a to-be-processed event; controlling the event processing process to process the to-be-processed events in sequence; when a current to-be-processed event in the to-be-processed events is processed, if the current to-be-processed event is blocked and the current to-be-processed event is an event of a specified type, creating the current to-be-processed event as a to-be-processed task, and processing the to-be-processed task through the task processing process. In the event processing process through the event processing process, the current to-be-processed event is created as the to-be-processed task, and the to-be-processed task is entrusted to the task processing process for processing, so that the processing of the current to-be-processed event is prevented from influencing the processing of other to-be-processed events, and the network use experience of a customer is ensured.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] Embodiments of the present invention relate to the technical field of cloud computing, and in particular to an event processing method, an event processing device, an electronic device, and a computer-readable storage medium. Background Art

[0002] In the CDN (Content Delivery Network) usage scenario, there are some drawbacks in the event processing flow of the existing reverse proxy server: specifically, a single process of the reverse proxy server collects a batch of events when processing requests through the Epoll model and the event-driven model. Although other events in the same batch can be processed first in the event of event blocking, if the processing of a certain event is time-consuming and will always occupy the CPU (Central Processing Unit) without releasing it, it will affect the processing of other subsequent events, resulting in a decrease in the response speed of the CDN network, thereby affecting the customer experience. Summary of the invention

[0003] In view of the above problems, an event processing method and device are proposed to overcome the above problems or at least partially solve the above problems. The specific technical solution is as follows:

[0004] In a first aspect of the present invention, an event processing method is first provided, which is applied to a reverse proxy server, wherein the reverse proxy server involves an event processing process and a task processing process, and the method comprises:

[0005] Get pending events;

[0006] Controlling the event processing process to process the pending events in sequence;

[0007] When processing the current pending event among the pending events, if the current pending event is blocked and the current pending event is an event of a specified type, the current pending event is created as a pending task, and the pending task is processed by the task processing process.

[0008] In one embodiment of the present invention, the current to-be-processed event is created as a to-be-processed task, and the to-be-processed task is processed by the task processing process, including:

[0009] Controlling the task delegation response interface of the reverse proxy server to create the current pending event as a pending task; wherein the pending task has a corresponding task type;

[0010] Controlling the task delegation response interface to write the pending task into the task shared memory queue;

[0011] Controlling the task processing process to obtain the to-be-processed task from the task shared memory queue;

[0012] The task processing process is controlled to call a corresponding task processing plug-in to process the task to be processed according to the task type corresponding to the task to be processed.

[0013] In one embodiment of the present invention, after controlling the task processing process to obtain the to-be-processed task from the task shared memory queue and calling the corresponding task processing plug-in to process the to-be-processed task according to the task type corresponding to the to-be-processed task, the method further includes:

[0014] After controlling the task processing process to call the task processing plug-in to process the pending task, the task delegation response interface is notified that the pending task is processed and the task processing result of the pending task is saved in the task processing result hash table.

[0015] In one embodiment of the present invention, after controlling the task processing process to call the task processing plug-in to process the pending task, notifying the task delegation response interface that the pending task processing is completed, and saving the task processing result of the pending task in the task processing result hash table, the method further includes:

[0016] When the task delegation response interface notifies that the processing of the pending task is completed, the event processing process is controlled to obtain the task processing result corresponding to the pending task from the task processing result hash table.

[0017] In an embodiment of the present invention, when the task delegation response interface receives a notification that the pending task has been processed, after controlling the event processing process to obtain the task processing result corresponding to the pending task from the task processing result hash table, the method further includes:

[0018] The event processing process is controlled to process other pending events according to the task processing results corresponding to the pending tasks.

[0019] In one embodiment of the present invention, the task processing process is controlled in the following manner:

[0020] Check the used space of the task shared memory queue at preset time intervals;

[0021] If the used space of the task shared memory queue is greater than or equal to a preset first threshold and the number of opened task processing processes does not reach a preset first limit number, a new task processing process is opened;

[0022] If the used space of the task shared memory queue is less than a preset second threshold and the number of opened task processing processes does not reach a preset second limit number, reducing the number of opened task processing processes;

[0023] The preset first threshold is greater than the preset second threshold, and the preset first limit quantity is greater than the preset second limit quantity.

[0024] In one embodiment of the present invention, the specified type is a computationally intensive type; and the task processing process is a process inside the reverse proxy server.

[0025] The embodiment of the present invention further discloses an event processing device, which is applied to a reverse proxy server. The reverse proxy server involves an event processing process and a task processing process. The device includes:

[0026] A pending event acquisition module is used to acquire pending events;

[0027] A pending event processing module, used to control the event processing process to sequentially process the pending events;

[0028] The pending task creation module is used to create a pending task when processing the current pending event in the pending events. If the current pending event is blocked and the current pending event is an event of a specified type, the current pending event is created as a pending task and the pending task is processed by the task processing process.

[0029] In another aspect of the present invention, a computer-readable storage medium is provided, wherein instructions are stored in the computer-readable storage medium, and when the computer-readable storage medium is run on a computer, the computer executes any of the above-mentioned event processing methods.

[0030] In another aspect of the present invention, a computer program product comprising instructions is provided, which, when executed on a computer, enables the computer to execute any of the above-mentioned event processing methods.

[0031] Compared with the related art, the embodiments of the present invention have at least the following advantages:

[0032] In an embodiment of the present invention, the reverse proxy server involves an event processing process and a task processing process. When obtaining pending events, the event processing process is controlled to process the pending events in sequence. When processing the current pending event among the pending events, if the current pending event is blocked and the current pending event is an event of a specified type, the current pending event is created as a pending task, and the pending task is processed by the task processing process. In the process of processing events through the event processing process of the embodiment of the present invention, if the current pending event is blocked and the current pending event is an event of a specified type, the current pending event can be created as a pending task and entrusted to the task processing process for processing, which can avoid the processing of the current pending event affecting the processing of other pending events, ensure the response speed, and then ensure the customer's experience of using the network. BRIEF DESCRIPTION OF THE DRAWINGS

[0033] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art.

[0034] Figure 1 A flowchart of each process processing mode of Nginx is provided in an embodiment of the present invention;

[0035] Figure 2 A local task delegation processing flow chart is provided in an embodiment of the present invention;

[0036] Figure 3 A flowchart of a method for handling an event provided in an embodiment of the present invention;

[0037] Figure 4 A schematic diagram of a framework of a lightweight system for local delegation of tasks based on Nginx is provided in an embodiment of the present invention;

[0038] Figure 5 A schematic diagram of a lightweight processing flow of a task local delegation based on Nginx provided in an embodiment of the present invention;

[0039] Figure 6 A CPU resource dynamic management flow chart provided in an embodiment of the present invention;

[0040] Figure 7 A structural block diagram of an event processing device provided in an embodiment of the present invention;

[0041] Figure 8 The present invention is a block diagram of an electronic device provided in an embodiment of the present invention. DETAILED DESCRIPTION

[0042] The technical solutions in the embodiments of the present invention will be described below in conjunction with the accompanying drawings in the embodiments of the present invention.

[0043] In order to enable those skilled in the art to better understand the embodiments of the present invention, some terms or nouns involved in the embodiments of the present invention are explained below.

[0044] Web server (World Wide Web server): generally refers to a website server, which is a program residing on a certain type of computer on the Internet that can process requests from web clients such as browsers and return corresponding responses.

[0045] Reverse proxy server: Located between the user and the target server, the reverse proxy server is equivalent to the target server for the user, that is, the user can directly access the reverse proxy server to obtain the resources of the target server. At the same time, the user does not need to know the address of the target server, nor does it need to make any settings on the user side. Reverse proxy servers are usually used for Web acceleration, that is, using reverse proxy as a front-end machine for Web servers to reduce the load on the network and server and improve access efficiency.

[0046] CDN: It is a distributed content distribution network built on a data network, consisting of server clusters distributed in different regions. These server clusters store copies of data, so the server can quickly respond to data requests based on which server is closest to the user.

[0047] Nginx: It is a very powerful high-performance Web and reverse proxy server, which is characterized by small memory usage and strong concurrency. Nginx's concurrency capability makes it widely used in CDN.

[0048] Epoll model: It is an improvement made by the Linux kernel to handle large batches of file descriptors. It is an enhanced version of the multiplexed IO interface select / poll under Linux. It can significantly improve the system CPU utilization when only a small number of programs are active among a large number of concurrent connections. The main advantages of the Epoll model include supporting a process to open a large number of socket descriptors, no maximum concurrent connection limit, and IO efficiency does not decrease linearly with the increase in the number of file descriptors.

[0049] Event-driven: refers to a strategy for making decisions in the process of continuous transaction management, that is, following the events that occur at the current point in time, mobilizing available resources, and performing related tasks to solve emerging problems and prevent transaction accumulation.

[0050] Dynamic Library (Dynamic Link Library): A dynamic library / third-party dynamic library is a library that contains code and data that can be used by multiple programs at the same time. Dynamic libraries provide a way for a process to call functions that are not part of its executable code. Dynamic libraries help share data and resources, and multiple applications can access the contents of a single copy of a dynamic library in memory at the same time.

[0051] Compute-intensive: A task or application that requires a lot more computation than memory access, communication, and input and output.

[0052] Queue: It is a special linear list that only allows deletion operations at the front end of the list and insertion operations at the back end of the list. The end where the insertion operation is performed is called the tail of the queue, and the end where the deletion operation is performed is called the head of the queue.

[0053] Shared Memory: In a multi-processor computer system, a large amount of memory that can be accessed by different central processing units (CPUs).

[0054] CDN is an application technology that was born out of the continuous development of Internet application services. With the increase in Internet users, the demand for traffic and bandwidth is also increasing, and the load on the original server is also increasing, which can easily lead to website paralysis. CDN uses server clusters to store data copies in places relatively close to user access to alleviate the load on the original server, greatly improving the access speed of the website and user experience.

[0055] As one of the commonly used reverse proxy servers of CDN, Nginx has the advantages of high performance, good concurrency, high scalability, and easy configuration. Nginx can ensure the stability of the website and greatly improve the response speed when handling high concurrency. At the same time, Nginx supports multiple platforms, allowing it to be developed and run on different platforms.

[0056] Nginx uses the Linux Epoll model, and a single process can handle tens of thousands of requests at the same time, depending on the CPU and memory. Nginx also uses an event-driven model to handle requests, in which once a new event occurs (such as a new connection, or new data on an existing connection), it is processed accordingly. Therefore, when processing a connection, Nginx will not be blocked, but can continue to process other connections.

[0057] Reference Figure 1, is a flowchart of each process processing mode of Nginx provided in an embodiment of the present invention. A single process collects n events through the Epoll model, and then processes these batches of events in series. If reading and writing are blocked during the processing of a certain event, other events can be processed continuously. After the blocking processing is completed, the event can be processed again.

[0058] In the CDN usage scenario, there are some drawbacks in the existing Nginx processing flow:

[0059] Question 1: When a single process processes requests through the Epoll model and event-driven model, it collects a batch of events (such as HTTP events). Although other events in the same batch can be processed first in the case of IO blocking, if an event (such as Figure 1 Event 2) is computationally intensive (such as image processing events). It takes time to process and will occupy the CPU without releasing it. This will affect the processing of subsequent events 3 and even n, resulting in a decrease in response speed and a long first packet time. In severe cases, it may even cause a large number of 5xx requests to time out, affecting the customer experience.

[0060] Question 2: When some customers make requests to CDN, they will provide third-party dynamic libraries and API interfaces at the same time. CDN needs to integrate these dynamic libraries within the program to support customer business. For example, for authentication requirements, some customers will choose to provide dynamic libraries for the core algorithm of authentication, so that the core encryption and decryption algorithm will not be leaked. CDN calls the third-party dynamic library and determines whether the authentication is successful based on the results, thereby meeting the authentication requirements. However, in this scenario, there will be security risks. For example, a bug (failure) in the third-party dynamic library will cause the Nginx process to crash directly, affecting the service; in addition, the implementation of the third-party dynamic library is a black box for CDN. If it is used by someone with ulterior motives, the stack data inside the CDN process may be leaked.

[0061] Problem 3: Some customer requests will take up a lot of computing resources, which will affect other events in the same process. Events in the same process come from different customer requests, so a single customer's needs will affect the needs of all other customers on the node, causing widespread customer complaints. Therefore, it is necessary to manage resources for customer needs that take up a lot of computing resources, reduce CPU consumption, and improve customer experience.

[0062] In summary, the current Nginx processing flow still has some limitations in CDN demand scenarios, so the embodiment of the present invention proposes a lightweight device and system for local delegation of tasks based on Nginx. The tasks to be solved by the embodiment of the present invention are as follows:

[0063] For problem one, event processing can be delegated, and the results can be obtained after the external processing is completed, so that subsequent events of the same process will not be blocked. When delegating to the outside: Method 1 is to delegate to an external service. In this case, the service component needs to be deployed separately and needs to communicate with the external service through network requests. Deploying service components separately not only requires additional operation and maintenance, but also needs to ensure high availability of the service, which greatly increases the operation and maintenance costs. Communication through network requests will also increase the response time and affect performance; Method 2 is to delegate to other processes, deploy them on the same machine, and exchange data between processes through shared memory to reduce communication performance consumption. By integrating the program into the CDN and deploying it in the same container, the purpose of reducing maintenance costs is achieved. The embodiment of the present invention adopts Method 2. Of course, Method 1 can also be selected according to needs.

[0064] Regarding the second question, after the event is delegated to an external party, the third-party dynamic library and API (Application Programming Interface) interface provided by the customer is physically isolated from the CDN, thereby avoiding security risks such as program crashes and data leakage caused by external dynamic libraries or APIs.

[0065] For question 3, in order to achieve domain name-level resource control, events that consume CPU resources need to be delegated to external parties for resource control.

[0066] In summary, in order to solve the problems existing in Nginx process event processing in the current CDN, it is necessary to delegate the task. Considering the deployment and performance, a lightweight method based on Nginx task local delegation is finally implemented. For example, refer to Figure 2 , is a local task delegation processing flow provided in an embodiment of the present invention. The task delegation processing flow is as follows:

[0067] Assume that the events to be processed include event 1, event 2, and event n, and event 2 is computationally intensive. Figure 1 For the computationally intensive event 2, it is converted into a task and added to the shared memory queue, waiting to be assigned to the Nginx local task processing process for processing; when the task processing process obtains the tasks to be processed from the shared memory queue, it only obtains one task from the shared memory queue at a time to avoid the situation where computationally intensive tasks block subsequent tasks. When the processing process processes event 2, it calls the corresponding task type plug-in (task type 1 plug-in, task type n plug-in) for processing; other events still follow the original processing flow of Nginx.

[0068] In addition, since local task processes also need to occupy CPU resources, in order not to affect the basic performance of CDN, it is necessary to limit the resources that can be consumed by local task processes: limit the local task delegation process, limit the minimum and maximum number of processes that can be opened, and secondly limit the usage space of the task shared memory queue. Set the maximum and minimum thresholds for the usage space of the shared memory queue. When the used space of the shared memory queue reaches the maximum threshold, increase the number of task delegation processes until the maximum number of processes is reached. When the used space of the shared memory queue reaches the minimum threshold, reduce the number of task delegation processes until the minimum number of processes is reached. By dynamically managing the number of task processing processes according to the used space of the shared memory queue, the task delegation resources can be adaptively managed.

[0069] Reference Figure 3 , is a flow chart of the steps of an event processing method provided in an embodiment of the present invention, such as Figure 3 As shown, it is applied to a reverse proxy server, and the reverse proxy server involves an event processing process and a task processing process. The method may specifically include the following steps:

[0070] Step 301: Obtain events to be processed;

[0071] Step 302: Control the event processing process to process the pending events in sequence;

[0072] Among them, the reverse proxy server can be Nginx or other reverse proxy servers in CDN, and the embodiment of the present invention does not need to be limited to this. The reverse proxy server can involve two processes, one is an event processing process (Nginx process), and the other is a task processing process. The event processing process and the task processing process are two independent processes. The task processing process is usually multiple, and of course it can also be one. Each task processing process only processes one task at the same time. Specifically, the event processing process is used to process events triggered by the client through the client. For example, the client (such as a browser or application, etc.) sends a request to the CDN. The content of the request can include pictures, videos, or API calls, etc. After receiving the request from the client, the reverse proxy server can generate corresponding events and process them according to the content of the request. The task processing process is used to process the task of event conversion, as well as other tasks in the reverse server to be processed. In some specific examples, the task processing process can be a process inside the reverse proxy server, or it can be a process outside the reverse proxy server, and the embodiment of the present invention does not need to be limited to this.

[0073] In an embodiment of the present invention, the reverse proxy server Nginx can adopt the Epoll model of Linux, and a single process (event processing process) can process tens of thousands of requests at the same time, depending on the CPU and memory. The reverse proxy server can process the client's request with an event-driven model. In the Epoll model, once a new event occurs (such as a new connection, or new data on an existing connection), it is processed accordingly. Therefore, when processing a connection, Nginx will not be blocked, but can continue to process other connections. The event processing process of the reverse proxy server of the embodiment of the present invention can collect n events through the Epoll model, and use the collected n events as pending events, and then process these batches of pending events in series.

[0074] Step 303: When processing the current pending event among the pending events, if the current pending event is blocked and the current pending event is an event of a specified type (task type), the current pending event is created as a pending task, and the pending task is processed by the task processing process.

[0075] In a specific implementation, there may be multiple types of events to be processed, such as data request types, computationally intensive types, and other types, wherein computationally intensive events refer to events that require a large amount of CPU resources to process. Since computationally intensive events involve complex calculations, data processing, image processing, encryption and decryption, and other operations, they will take up a large amount of CPU resources, resulting in a long processing time, which may easily block the processing of other events. In one embodiment of the present invention, the specified type is a computationally intensive type. Of course, events of the specified type may also be regarded as all events, or may be events with potential safety hazards or events that require resource management and control, and the embodiments of the present invention do not need to be limited to this.

[0076] In an embodiment of the present invention, in the process of sequentially processing this batch of pending events, the pending event currently being processed is the current pending event. If read and write blocking occurs during the processing of the current pending event, and the type of the current pending event is a specified type, such as a computationally intensive type, the current pending event can be created as a pending task, and the pending task can be delegated to the task processing process for processing. In this way, it is possible to avoid processing the current pending event for too long, which affects the processing of other events. By converting events of specified types such as computationally intensive events, events with potential safety hazards, and events that require resource management into tasks, and delegating the tasks to the local process (task processing process), the processing of other events in the event processing process can be unblocked, the response speed can be improved, and the security risks such as program crashes or data leaks in third-party dynamic libraries or API interfaces provided by customers can be avoided. At the same time, resource management at the domain name granularity can be enabled to avoid single-customer problems affecting all customers on the machine; each task processing process only processes one event at a time, further avoiding computationally intensive tasks blocking subsequent task processing. Of course, if the event processing process does not encounter read or write blockage in the process of processing this batch of pending events in series, or the pending events that encounter read or write blockage are not events of the specified type, then other pending events in the same batch will continue to be processed first, and after the read or write blockage processing is completed, the pending events that are blocked will continue to be processed.

[0077] In the above-mentioned event processing method, the reverse proxy server involves an event processing process and a task processing process. When obtaining pending events, the event processing process is controlled to process the pending events in sequence. When processing the current pending event among the pending events, if the current pending event is blocked and the current pending event is an event of a specified type, the current pending event is created as a pending task, and the pending task is processed by the task processing process. In the process of processing events through the event processing process of the embodiment of the present invention, if the current pending event is blocked and the current pending event is an event of a specified type, the current pending event can be created as a pending task and entrusted to the task processing process for processing, which can avoid the processing of the current pending event affecting the processing of other pending events, ensure the response speed, and then ensure the customer's experience of using the network.

[0078] In one embodiment of the present invention, the current to-be-processed event is created as a to-be-processed task, and the to-be-processed task is processed by the task processing process, including:

[0079] Controlling the task delegation response interface of the reverse proxy server to create the current pending event as a pending task; wherein the pending task has a corresponding task type;

[0080] Controlling the task delegation response interface to write the pending task into the task shared memory queue;

[0081] Controlling the task processing process to obtain the to-be-processed task from the task shared memory queue;

[0082] The task processing process is controlled to call a corresponding task processing plug-in to process the task to be processed according to the task type corresponding to the task to be processed.

[0083] In the embodiment of the present invention, it is assumed that the pending events include event 1, event 2 ... event n, and event 2 is computationally intensive. In the process of sequentially processing the pending events, if read-write blocking occurs when processing event 2, the event 2 can be converted into a pending task (task) and added to the shared memory queue, waiting to be assigned to the local task processing process of the reverse proxy server for processing. For example, if the client authentication needs to call an external dynamic library, a new task (pending task) is created for event 2 through the task delegation response interface, and the task type is an authentication task, and the task information is the parameters and encryption and decryption keys required for authentication. When the task processing process obtains the tasks to be processed from the shared memory queue, only one task is obtained from the shared memory queue each time to avoid the situation where the computationally intensive tasks block the subsequent tasks. When the task processing process processes the task of event 2, the corresponding task type plug-in is called for processing. For example, if the task of event 2 is an authentication task, the task processing process x calls the authentication processing plug-in, and transmits the authentication parameters and encryption and decryption keys to the processing plug-in to process the task accordingly. Of course, other events still follow the original processing flow of the reverse proxy server.

[0084] In one embodiment of the present invention, after controlling the task processing process to obtain the to-be-processed task from the task shared memory queue and calling the corresponding task processing plug-in to process the to-be-processed task according to the task type corresponding to the to-be-processed task, the method further includes:

[0085] After controlling the task processing process to call the task processing plug-in to process the pending task, the task delegation response interface is notified that the pending task is processed and the task processing result of the pending task is saved in the task processing result hash table.

[0086] In an embodiment of the present invention, a task shared memory queue is used to store tasks that have not yet been assigned to a process. The task processing process obtains the task information and task type that need to be processed from the task shared memory queue. After the task processing process completes processing of the pending tasks by calling the task processing plug-in, the task delegation response interface can complete the processing of the pending tasks. At the same time, the task processing results of the pending tasks can be stored in the task processing result hash table to store the task processing results. In this way, the task results can be quickly retrieved from the task processing result hash table according to the task type.

[0087] In one embodiment of the present invention, after controlling the task processing process to call the task processing plug-in to process the pending task, notifying the task delegation response interface that the pending task processing is completed, and saving the task processing result of the pending task in the task processing result hash table, the method further includes:

[0088] When the task delegation response interface notifies that the processing of the pending task is completed, the event processing process is controlled to obtain the task processing result corresponding to the pending task from the task processing result hash table.

[0089] In the embodiment of the present invention, the task delegation response interface receives the task completion notification, queries the task processing result corresponding to the task in the task processing result hash table according to the task type, and responds the task processing result to the event processing process.

[0090] In an embodiment of the present invention, when the task delegation response interface receives a notification that the pending task has been processed, after controlling the event processing process to obtain the task processing result corresponding to the pending task from the task processing result hash table, the method further includes:

[0091] The event processing process is controlled to process other pending events according to the task processing results corresponding to the pending tasks.

[0092] In the embodiment of the present invention, after the event processing process obtains the task processing result of the task to be processed, it can execute other subsequent events according to the task processing result of the task to be processed.

[0093] For example, refer to Figure 4 , is a schematic diagram of a framework of a lightweight system for local delegation of tasks based on Nginx in an embodiment of the present invention, according to Figure 4 The framework diagram shown is mainly composed of task management module, plug-in management module, resource dynamic management module, storage module and processing plug-in module. The work content of each module is:

[0094] (1) Task management module: responsible for adding tasks of different task types to the task shared memory queue in the storage module to wait for the task delegation process (task processing process) to process them; at the same time, querying the task processing result hash table in the storage module and responding to the task delegation with the completed task results.

[0095] (2) Plug-in management module: manages processing plug-ins of different task types. When the process starts, all processing plug-ins are registered through the plug-in management module. When processing tasks, the plug-in management module calls the corresponding plug-ins for processing.

[0096] (3) Dynamic resource management module: Adaptively adjusts the number of task delegation processes based on the usage of the shared memory queue to reduce resource consumption without affecting the performance of the original CDN process.

[0097] (4) Storage module: Contains task shared memory queue and task processing result hash table. Task shared memory queue is used to store tasks that have not been assigned to a process. The task processing process obtains the task information and type to be processed from the task shared memory queue. The task processing result hash table stores the results of task processing and can quickly retrieve the task results according to the task type.

[0098] (5) Processing plug-in module: A module that supports processing of different task types. The specific processing of tasks is implemented by the processing plug-in. When the plug-in is started, it is registered to the plug-in management module and called by the plug-in management module. After the plug-in processing is completed, the task management module is notified that the task has been completed, and the result is stored in the task processing result hash table for the task management module to query.

[0099] Reference Figure 5 , is a schematic diagram of a lightweight processing flow of a task local delegation based on Nginx provided in an embodiment of the present invention, which mainly includes the following steps:

[0100] Step 1: When the Nginx process handles an event, if the event needs to be delegated to the task local delegation framework, a task is created through the task delegation response interface and written into the task shared memory queue. If customer authentication requires calling an external dynamic library, a new task is created through the task delegation response interface (task management module). The task type is an authentication task, and the task information is the parameters that need to be verified for authentication and the encryption and decryption keys.

[0101] Step 2: After processing the previous task, multiple task processing processes obtain a task from the task shared memory queue, including the task type and task information to be processed. For example, task processing process x obtains the authentication task, the parameters required for authentication, and information such as encryption and decryption keys. In order to reduce the communication consumption caused by multiple task processing processes processing the same event and avoid computationally intensive tasks affecting subsequent tasks of the process, the same task can only be processed by one task processing process at the same time, and one task processing process can only process one task at a time. If there is no task in the task shared memory queue, the task processing process will gradually increase the detection time until the maximum detection time when it cannot obtain the task, to avoid the task processing process constantly detecting the task shared memory queue to cause an infinite loop and affect CPU performance.

[0102] Step 3: The task processing process calls the corresponding task processing plug-in to process the task. For example, the task processing process x calls the authentication processing plug-in and passes the authentication parameters and encryption and decryption keys to the processing plug-in.

[0103] Step 4: After the task processing plug-in is completed, the task delegation response interface is notified that the processing is completed, and the type of task processing and the processing result are saved in the task processing result hash table. For example, after the authentication processing plug-in is completed, the task delegation response interface is notified that the processing is completed, and the processing result corresponding to the authentication task is written into the task processing result hash table.

[0104] Step 5: The task delegation response interface receives the task completion notification, queries the task processing result hash table according to the task type, and responds the result to the Nginx process. For example, the task delegation response interface receives the authentication task processing completion, queries the task processing result hash table through the authentication task task type to obtain the processing result, and the task processing is completed.

[0105] Step 6: The Nginx process executes subsequent events based on the task processing results.

[0106] In one embodiment of the present invention, the task processing process is controlled in the following manner:

[0107] Check the used space of the task shared memory queue at preset time intervals;

[0108] If the used space of the task shared memory queue is greater than or equal to a preset first threshold and the number of opened task processing processes does not reach a preset first limit number, a new task processing process is opened;

[0109] If the used space of the task shared memory queue is less than a preset second threshold and the number of opened task processing processes does not reach a preset second limit number, reducing the number of opened task processing processes;

[0110] The preset first threshold is greater than the preset second threshold, and the preset first limit quantity is greater than the preset second limit quantity.

[0111] In the embodiment of the present invention, since the local task processing process also needs to occupy CPU resources, in order not to affect the basic performance of the CDN, it is necessary to limit the resources that can be consumed by the local task processing process:

[0112] For example, refer to Figure 6 , is a CPU resource dynamic management flow chart provided in an embodiment of the present invention, and the main steps may include:

[0113] Step 1: Start a minimum number of task processes (processes / task processing processes / task delegation processes).

[0114] Step 2: Check the used space of the task shared memory queue regularly. The task shared memory queue is used to store tasks converted from events.

[0115] Step 3: If the used space of the task shared memory queue is greater than or equal to the maximum threshold (preset first threshold), go to step 4; if the used space of the task shared memory queue is less than the minimum threshold (preset second threshold), go to step 5; otherwise go to step 2.

[0116] Step 4: If the opened task process has reached the maximum limit (the preset first limit number), go to step 2; otherwise, open a new task process and go to step 2.

[0117] Step 5: If the opened task process has reached the minimum limit (preset second limit number), go to step 2; otherwise, reduce the task process and go to step 2.

[0118] The embodiment of the present invention adaptively adjusts the number of task delegation processes according to the used space of the task shared memory queue to limit the machine resources that the task delegation process can consume, which can avoid the task delegation process consuming too many resources and affecting the Nginx process (event processing process) to handle events; at the same time, the adaptive adjustment does not require human control, which can reduce the operation and maintenance manpower cost.

[0119] It should be noted that, for the sake of simplicity, the method embodiments are described as a series of action combinations, but those skilled in the art should be aware that the embodiments of the present invention are not limited by the order of the actions described, because according to the embodiments of the present invention, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily required by the embodiments of the present invention.

[0120] Reference Figure 7 , is a structural block diagram of an event processing device provided in an embodiment of the present invention, such as Figure 7 As shown, it is applied to a reverse proxy server, and the reverse proxy server involves an event processing process and a task processing process. The device may specifically include the following modules:

[0121] The pending event acquisition module 701 is used to acquire pending events;

[0122] The pending event processing module 702 is used to control the event processing process to sequentially process the pending events;

[0123] The pending task creation module 703 is used to create a pending task when processing the current pending event in the pending events. If the current pending event is blocked and the current pending event is an event of a specified type, the current pending event will be created as a pending task and the pending task will be processed by the task processing process.

[0124] In one embodiment of the present invention, the to-be-processed task creation module 703 is used to:

[0125] Controlling the task delegation response interface of the reverse proxy server to create the current pending event as a pending task; wherein the pending task has a corresponding task type;

[0126] Controlling the task delegation response interface to write the pending task into the task shared memory queue;

[0127] Controlling the task processing process to obtain the to-be-processed task from the task shared memory queue;

[0128] The task processing process is controlled to call a corresponding task processing plug-in to process the task to be processed according to the task type corresponding to the task to be processed.

[0129] In one embodiment of the present invention, the device further comprises:

[0130] After controlling the task processing process to call the task processing plug-in to process the pending task, the task delegation response interface is notified that the pending task is processed and the task processing result of the pending task is saved in the task processing result hash table.

[0131] In one embodiment of the present invention, the device further comprises:

[0132] When the task delegation response interface notifies that the processing of the pending task is completed, the event processing process is controlled to obtain the task processing result corresponding to the pending task from the task processing result hash table.

[0133] In one embodiment of the present invention, the device further comprises:

[0134] The event processing process is controlled to process other pending events according to the task processing results corresponding to the pending tasks.

[0135] In one embodiment of the present invention, the task processing process is controlled in the following manner:

[0136] Check the used space of the task shared memory queue at preset time intervals;

[0137] If the used space of the task shared memory queue is greater than or equal to a preset first threshold and the number of opened task processing processes does not reach a preset first limit number, a new task processing process is opened;

[0138] If the used space of the task shared memory queue is less than a preset second threshold and the number of opened task processing processes does not reach a preset second limit number, reducing the number of opened task processing processes;

[0139] The preset first threshold is greater than the preset second threshold, and the preset first limit quantity is greater than the preset second limit quantity.

[0140] In one embodiment of the present invention, the specified type is a computationally intensive type; and the task processing process is a process inside the reverse proxy server.

[0141] In an embodiment of the present invention, the reverse proxy server involves an event processing process and a task processing process. When obtaining pending events, the event processing process is controlled to process the pending events in sequence. When processing the current pending event among the pending events, if the current pending event is blocked and the current pending event is an event of a specified type, the current pending event is created as a pending task, and the pending task is processed by the task processing process. In the process of processing events through the event processing process of the embodiment of the present invention, if the current pending event is blocked and the current pending event is an event of a specified type, the current pending event can be created as a pending task and entrusted to the task processing process for processing, which can avoid the processing of the current pending event affecting the processing of other pending events, ensure the response speed, and then ensure the customer's experience of using the network.

[0142] As for the above-mentioned device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0143] It should be noted that the embodiments of the present invention may involve the use of user data. In actual applications, user-specific personal data can be used in the scheme described herein within the scope permitted by applicable laws and regulations, subject to the requirements of applicable laws and regulations of the country where the user is located (for example, with the user's explicit consent, effective notification to the user, etc.).

[0144] The embodiment of the present invention further provides an electronic device, such as Figure 8 As shown, it includes a processor 501, a communication interface 502, a memory 503 and a communication bus 504, wherein the processor 501, the communication interface 502, and the memory 503 communicate with each other through the communication bus 504.

[0145] Memory 503, used for storing computer programs;

[0146] The processor 501 is used to implement any event processing method described in the above embodiments when executing the program stored in the memory 503:

[0147] Get pending events;

[0148] Controlling the event processing process to process the pending events in sequence;

[0149] When processing the current pending event among the pending events, if the current pending event is blocked and the current pending event is an event of a specified type, the current pending event is created as a pending task, and the pending task is processed by the task processing process.

[0150] The communication bus mentioned in the above terminal can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.

[0151] The communication interface is used for communication between the above terminal and other devices.

[0152] The memory may include a random access memory (RAM) or a non-volatile memory, such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.

[0153] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.

[0154] In another embodiment of the present invention, a computer-readable storage medium is provided. The computer-readable storage medium stores instructions. When the instructions are executed on a computer, the computer executes the event processing method described in any one of the above embodiments.

[0155] In another embodiment of the present invention, a computer program product including instructions is provided. When the computer program product is run on a computer, the computer executes the event processing method described in any one of the above embodiments.

[0156] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented by software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present invention is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from one website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server or data center that includes one or more available media integrated. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state hard disk Solid State Disk (SSD)), etc.

[0157] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or still includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "including one..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.

[0158] Each embodiment in this specification is described in a related manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0159] The above description is only a preferred embodiment of the present invention and is not intended to limit the protection scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention are included in the protection scope of the present invention.

Claims

1. An event processing method, characterized in that: Applied to a reverse proxy server, the reverse proxy server involves an event processing process and a task processing process, the method comprises: Get pending events; Controlling the event processing process to process the pending events in sequence; When processing the current pending event among the pending events, if the current pending event is blocked and the current pending event is an event of a specified type, the current pending event is created as a pending task, and the pending task is processed by the task processing process.

2. The method according to claim 1, characterized in that Creating the current pending event as a pending task, and processing the pending task through the task processing process, including: Controlling the task delegation response interface of the reverse proxy server to create the current pending event as a pending task; wherein the pending task has a corresponding task type; Controlling the task delegation response interface to write the pending task into the task shared memory queue; Controlling the task processing process to obtain the to-be-processed task from the task shared memory queue; The task processing process is controlled to call a corresponding task processing plug-in to process the task to be processed according to the task type corresponding to the task to be processed.

3. The method according to claim 2, characterized in that After controlling the task processing process to obtain the to-be-processed task from the task shared memory queue, and calling the corresponding task processing plug-in to process the to-be-processed task according to the task type corresponding to the to-be-processed task, the method further includes: After controlling the task processing process to call the task processing plug-in to process the pending task, the task delegation response interface is notified that the pending task is processed and the task processing result of the pending task is saved in the task processing result hash table.

4. The method according to claim 3, characterized in that After controlling the task processing process to call the task processing plug-in to process the pending task, notifying the task delegation response interface that the pending task processing is completed, and saving the task processing result of the pending task in the task processing result hash table, the method further includes: When the task delegation response interface notifies that the processing of the pending task is completed, the event processing process is controlled to obtain the task processing result corresponding to the pending task from the task processing result hash table.

5. The method according to claim 4, characterized in that When the task delegation response interface receives a notification that the pending task has been processed, after controlling the event processing process to obtain the task processing result corresponding to the pending task from the task processing result hash table, the method further includes: The event processing process is controlled to process other pending events according to the task processing results corresponding to the pending tasks.

6. The method according to claim 1, characterized in that The task processing process is controlled in the following way: Check the used space of the task shared memory queue at preset time intervals; If the used space of the task shared memory queue is greater than or equal to a preset first threshold and the number of opened task processing processes does not reach a preset first limit number, a new task processing process is opened; If the used space of the task shared memory queue is less than a preset second threshold and the number of opened task processing processes does not reach a preset second limit number, reducing the number of opened task processing processes; The preset first threshold is greater than the preset second threshold, and the preset first limit quantity is greater than the preset second limit quantity.

7. The method according to claim 1, characterized in that The specified type is a computationally intensive type; the task processing process is a process inside the reverse proxy server.

8. An event processing device, characterized in that: Applied to a reverse proxy server, the reverse proxy server involves an event processing process and a task processing process, the device comprises: A pending event acquisition module is used to acquire pending events; A pending event processing module, used to control the event processing process to sequentially process the pending events; The pending task creation module is used to create a pending task when processing the current pending event in the pending events. If the current pending event is blocked and the current pending event is an event of a specified type, the current pending event is created as a pending task and the pending task is processed by the task processing process.

9. An electronic device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus; Memory, used to store computer programs; A processor, for implementing the method steps described in any one of claims 1 to 7 when executing a program stored in a memory.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.

Citation Information

Patent Citations

  • Asynchronous task execution method, device and system

    CN106980546A

  • Event processing method and device

    CN108733496A

  • Task process blocking management method

    CN112015525A

  • Data persistence method and device

    CN117056403A