Data processing method and device, electronic equipment and computer readable storage medium

By determining the target time for processing requests for the target coroutine and managing permissions, and by using the exchange of private token addresses and global token addresses and atomic operations, the problem of coroutine blocking in coroutine mode is solved, thereby improving hardware resource utilization and response speed.

CN117785434BActive Publication Date: 2026-11-06XINGIN INFORMATION TECH (SHANGHAI) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211261366.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-10-14
Publication Date
2026-11-06
Estimated Expiration
2042-10-14

AI Technical Summary

Technical Problem

In coroutine mode, if a coroutine in a thread becomes blocked, the thread will be in a waiting state, resulting in idle CPU, low hardware resource utilization, and slow response speed.

Method used

By determining the target time for the target coroutine to process the request, and after confirming that it has the authority to call hardware resources, the probability of coroutine blocking is reduced and the utilization rate and response speed of hardware resources are improved by using the exchange and atomic operation of private token addresses and global token addresses.

Benefits of technology

It effectively reduces the chance of coroutine and thread blocking, and improves the utilization of hardware resources and the response speed of the server.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117785434B_ABST
    Figure CN117785434B_ABST
Patent Text Reader

Abstract

The application discloses a data processing method and device, an electronic device and a computer readable storage medium. The data processing method is applied to a data processing device, the data processing device runs n threads, the n threads include a target thread, and the method comprises the following steps: determining a target time at which a target coroutine in the target thread processes a first request; and calling the target coroutine to process the first request at the target time.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and in particular to a data processing method and apparatus, electronic device and computer-readable storage medium. Background Technology

[0002] Using coroutines to handle client requests on the server side can reduce time overhead and improve system processing efficiency. However, in coroutine mode, if a coroutine in a thread becomes blocked, the thread will be in a waiting state, which will lead to the central processing unit (CPU) of that thread becoming idle. This results in low utilization of the hardware resources of the data processing device and slow response speed to requests. Summary of the Invention

[0003] This application provides a data processing method and apparatus, an electronic device, and a computer-readable storage medium.

[0004] In a first aspect, a data processing method is provided, the data processing method being applied to a data processing device, the data processing device running n threads, the n threads including a target thread, the method comprising:

[0005] Determine the target time for the target coroutine in the target thread to process the first request;

[0006] The data processing device invokes the target coroutine to process the first request at the target time.

[0007] In this respect, the data processing device avoids the target coroutine from queuing to wait for the first request by determining the time for the target coroutine to process the first request. This reduces the probability of the target coroutine being blocked, and in turn reduces the probability of the target thread being blocked, thereby improving the hardware resource utilization of the data processing device and the response speed of the server.

[0008] In any embodiment of this application, determining the target time for the target coroutine in the target thread to process the first request includes:

[0009] If it is determined that the target coroutine has the authority to invoke hardware resources, the target time for the target coroutine in the target thread to process the first request is determined.

[0010] In this implementation, the data processing device determines the target time for the target coroutine to process the first request when it determines that the target coroutine has the authority to call hardware resources. This allows for better management of each thread and helps improve the processing efficiency of the data processing device.

[0011] In conjunction with any embodiment of this application, before determining the target time for the target coroutine in the target thread to process the first request, given that the target coroutine has the authority to invoke hardware resources, the method further includes:

[0012] If the private token address of the target coroutine is successfully exchanged with the global token address of the data processing device, it is determined that the target coroutine has the authority to call hardware resources; the global token address stores a global token, and the global token has the authority to call hardware resources.

[0013] In this implementation, the data processing device grants the target coroutine permission to access hardware resources by exchanging the target coroutine's private token address with the data processing device's global token address. Since the exchange between the target coroutine's private token address and the data processing device's global token is a lock-free operation, this implementation reduces the likelihood of blocking when the target coroutine obtains the global token from the global token address.

[0014] In conjunction with any embodiment of this application, before determining that the target coroutine has permission to call hardware resources after the private token address of the target coroutine is successfully exchanged with the global token address of the data processing device, the method further includes:

[0015] Perform atomic operations on the private token address and the global token address;

[0016] If it is determined that the original value of the private token address has been changed, it is determined that the private token address of the target coroutine has been successfully exchanged with the global token address of the data processing device.

[0017] In this implementation, the data processing device performs atomic operations on the private token address and the global token address to exchange the private token address and the global token address. Since atomic operations are lock-free operations, exchanging the private token address and the global token address through atomic operations can reduce the probability of the target coroutine becoming blocked.

[0018] In any embodiment of this application, the atomic operation on the private token address and the global token address includes:

[0019] The target coroutine obtains the target number of requests to be processed; the requests to be processed are requests with a predetermined processing time.

[0020] If the number of targets is less than or equal to a threshold, the target coroutine sends an atomic operation request to the data processing device.

[0021] Upon detecting the atomic operation request, the data processor performs an atomic operation on the private token address and the global token address.

[0022] In this implementation, the target coroutine sends an atomic operation request to the data processing device when it determines that the number of targets is less than or equal to a threshold, which can improve the response speed of the data processing device.

[0023] In conjunction with any embodiment of this application, after the data processing device invokes the target coroutine to process the first request at the target time, the method further includes:

[0024] Once the target coroutine has finished processing the first request, the token stored in the global token address is cleared.

[0025] In this implementation, the data processing device can reclaim resources from the global token address by clearing the token in the global token. Since the global token address becomes the private address of the target coroutine after the successful exchange between the private token address and the global token address, the clearing of the token stored in the global token address (i.e., the aforementioned global token) by the target coroutine is a local operation of the target coroutine. Thus, this resource reclamation operation will not affect the operation of the global coroutine, thereby reducing the probability of coroutine blocking in the data processing device.

[0026] In any embodiment of this application, determining the target time for the target coroutine in the target thread to process the first request includes:

[0027] Obtain the target number of requests to be processed; the requests to be processed are those with a predetermined processing time.

[0028] The target time is obtained based on the target number and the processing time of the pending requests.

[0029] In conjunction with any embodiment of this application, before the data processing device invokes the target coroutine to process the first request at the target time, the method further includes: the data processing device invoking the target coroutine to process a second request before the target time; the second request is different from the first request.

[0030] In this implementation, the second request differs from the first request; that is, the data processing device can call the target coroutine to process the second request before calling it to process the first request. In other words, the target coroutine does not need to wait before the data processing device calls it to process the first request. This improves the efficiency of the target coroutine in processing requests, thereby increasing the response speed of the data processing device to requests.

[0031] Secondly, a data processing apparatus is provided, the data processing apparatus running n threads, the n threads including a target thread, the data processing apparatus comprising:

[0032] The first processing unit is used to determine the target time for the target coroutine in the target thread to process the first request;

[0033] The second processing unit is used by the data processing device to call the target coroutine to process the first request at the target time.

[0034] In conjunction with any embodiment of this application, the first processing unit is configured to:

[0035] If it is determined that the target coroutine has the authority to invoke hardware resources, the target time for the target coroutine in the target thread to process the first request is determined.

[0036] In any embodiment of this application, the first processing unit is further configured to determine that the target coroutine has the authority to call hardware resources when the private token address of the target coroutine is successfully exchanged with the global token address of the data processing device; the global token address stores a global token, and the global token has the authority to call hardware resources.

[0037] In conjunction with any embodiment of this application, the first processing unit is further configured to:

[0038] Perform atomic operations on the private token address and the global token address;

[0039] If it is determined that the original value of the private token address has been changed, it is determined that the private token address of the target coroutine has been successfully exchanged with the global token address of the data processing device.

[0040] In conjunction with any embodiment of this application, the first processing unit is configured to:

[0041] The target coroutine obtains the target number of requests to be processed; the requests to be processed are requests with a predetermined processing time.

[0042] If the number of targets is less than or equal to a threshold, the target coroutine sends an atomic operation request to the data processing device.

[0043] Upon detecting the atomic operation request, the data processor performs an atomic operation on the private token address and the global token address.

[0044] In conjunction with any embodiment of this application, the first processing unit is further configured to:

[0045] Once the target coroutine has finished processing the first request, the token stored in the global token address is cleared.

[0046] In conjunction with any embodiment of this application, the first processing unit is configured to:

[0047] Obtain the target number of requests to be processed; the requests to be processed are those with a predetermined processing time.

[0048] The target time is obtained based on the target number and the processing time of the pending requests.

[0049] In any embodiment of this application, the first processing unit is further configured to: the data processing device invoke the target coroutine to process the second request before the target time; the second request is different from the first request.

[0050] Thirdly, an electronic device is provided, characterized in that it comprises: a processor and a memory, the memory being used to store computer program code, the computer program code including computer instructions, wherein, when the processor executes the computer instructions, the electronic device performs a method as described in the first aspect above and any possible implementation thereof.

[0051] Fourthly, another electronic device is provided, comprising: a processor, a transmitting device, an input device, an output device, and a memory, the memory being used to store computer program code, the computer program code including computer instructions, wherein, when the processor executes the computer instructions, the electronic device performs the method as described in the first aspect above and any possible implementation thereof.

[0052] Fifthly, a computer-readable storage medium is provided, wherein a computer program is stored therein, the computer program including program instructions that, when executed by a processor, cause the processor to perform a method as described in the first aspect above and any possible implementation thereof.

[0053] In a sixth aspect, a computer program product is provided, the computer program product comprising a computer program or instructions, wherein, when the computer program or instructions are executed on a computer, the computer performs the method described in the first aspect and any possible implementation thereof.

[0054] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and are not intended to limit this application. Attached Figure Description

[0055] To more clearly illustrate the technical solutions in the embodiments of this application or the background art, the accompanying drawings used in the embodiments of this application or the background art will be described below.

[0056] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with this application and, together with the specification, serve to explain the technical solutions of this application.

[0057] Figure 1 A flowchart illustrating a data processing method provided in an embodiment of this application;

[0058] Figure 2 A flowchart illustrating the processing of a first request is provided for an embodiment of this application;

[0059] Figure 3 This application provides a schematic diagram of a process for invoking a target coroutine to process a first request sent by a client, as illustrated in an embodiment of the present application.

[0060] Figure 4 This is a schematic diagram of the structure of a data processing device provided in an embodiment of this application;

[0061] Figure 5 This is a schematic diagram of the hardware structure of an electronic device provided in an embodiment of this application. Detailed Implementation

[0062] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of the present application.

[0063] The terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish different objects, not to describe a specific order. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or apparatus that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to these processes, methods, products, or apparatuses.

[0064] It should be understood that in this application, "at least one (item)" refers to one or more, "more than one" refers to two or more, "at least two (items)" refers to two or three or more, and "and / or" is used to describe the relationship between related objects, indicating that there can be three relationships. For example, "A and / or B" can indicate three cases: only A exists, only B exists, and both A and B exist simultaneously, where A and B can be singular or plural. The character " / " can indicate that the related objects before and after are in an "or" relationship, referring to any combination of these items, including any combination of single or plural items. For example, at least one of a, b, or c can be: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, and c can be single or multiple. The character " / " can also represent the division sign in mathematical operations, for example, a / b = a divided by b; 6 / 3 = 2. "At least one of the following" or similar expressions.

[0065] In this document, the term "embodiment" means that a particular feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of this application. The appearance of this phrase in various places throughout the specification does not necessarily refer to the same embodiment, nor is it a separate or alternative embodiment mutually exclusive with other embodiments. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments.

[0066] Servers typically handle client requests using a thread-based model, where the server invokes a thread to process the request. In this model, if a thread becomes blocked, the server uses system calls to switch to another idle, unblocked thread to handle the request. However, the time overhead of thread switching reduces system efficiency. Therefore, some methods use coroutines to handle client requests. In coroutines, one CPU on the server executes one thread, and each thread includes at least one coroutine. With coroutines, thread switching is avoided, reducing time overhead and improving system speed.

[0067] However, in coroutine mode, if a coroutine in a thread becomes blocked, the thread will be in a waiting state, which will cause the CPU executing the thread to be idle, resulting in low utilization of hardware resources of the data processing device and slow response speed of the thread to requests.

[0068] Based on this, this application provides a technical solution to reduce the probability of coroutine blocking on the server side in coroutine mode, or even avoid blocking altogether, thereby improving the utilization of server hardware resources and the response speed of the server.

[0069] The execution entity in this application embodiment is a data processing device, which is the aforementioned server. The data processing device can be any electronic device capable of executing the technical solutions disclosed in the method embodiments of this application. Optionally, the data processing device can be one of the following: a server, a computer.

[0070] It should be understood that the method embodiments of this application can also be implemented by a processor executing computer program code. The embodiments of this application are described below with reference to the accompanying drawings. Please refer to... Figure 1 , Figure 1 This is a flowchart illustrating a data processing method provided in an embodiment of this application.

[0071] 101. Determine the target time for the target coroutine in the target thread to process the first request.

[0072] In this embodiment, the data processing device runs n threads, where n is a positive integer. Each of the n threads includes at least one coroutine. In one possible implementation, the data processing device has n cores, i.e., the number of CPUs in the data processing device is n. Each CPU runs one thread. The target thread is any one of the n threads, and the target coroutine is any coroutine of the target thread.

[0073] In this embodiment, the first request is a request sent by a client that has established a connection with the data processing device. The target time is the time when the target coroutine processes the first request, that is, the data processing device determines that the target coroutine processes the first request at the target time.

[0074] In one possible implementation, the data processing device determines the target time based on the number of requests to be processed and the processing time of each request. For example, before the CPU of the data processing device calls the target coroutine to process the first request, there are still 3 requests to be processed, and the processing time of each request is 1 minute. Therefore, the target time for the target coroutine to process the first request is 3 minutes after the current time.

[0075] In another possible implementation, the data processing device determines the processing order of the first request based on its transmission time. Based on the processing order and the processing duration of each request, it determines the target time for the target coroutine to process the first request. For example, if the first request is the third earliest among all unprocessed requests, then its processing order is 3. If the processing duration of each request is 1 minute, then the target time for the target coroutine to process the first request is 2 minutes after the current time.

[0076] 102. The aforementioned data processing device invokes the aforementioned target coroutine to process the first request at the aforementioned target time.

[0077] In this embodiment of the application, the data processing device determines the time for the target coroutine to process the first request, thereby avoiding the target coroutine from queuing and waiting to process the first request. This reduces the probability of the target coroutine being blocked, and further reduces the probability of the target thread being blocked, thereby improving the hardware resource utilization of the data processing device and improving the response speed of the server.

[0078] As an optional implementation, the data processing device performs the following steps during step 101:

[0079] 201. If it is determined that the above-mentioned target coroutine has the authority to call hardware resources, determine the target time for the target coroutine in the above-mentioned target thread to process the first request.

[0080] Optionally, if the data processing device determines that the target coroutine does not have the authority to call hardware resources, it may not determine a target time for the target coroutine to process the first request.

[0081] In this implementation, the data processing device determines the target time for the target coroutine to process the first request when it determines that the target coroutine has the authority to call hardware resources. This allows for better management of each thread and helps improve the processing efficiency of the data processing device.

[0082] As an alternative implementation, the data device determines that the target coroutine has permission to invoke hardware resources by performing the following steps:

[0083] 301. If the private token address of the target coroutine is successfully exchanged with the global token address of the data processing device, it is determined that the target coroutine has the authority to call hardware resources.

[0084] In this embodiment, the private token address of the target coroutine is only open to the target coroutine; that is, threads other than the target coroutine cannot access this private token address. The global token address is open to all coroutines within the target thread; that is, any coroutine in the target thread can access the global token address. The global token address stores the global token, which has the permission to invoke hardware resources. In other words, the thread that obtains the global token has the permission to invoke hardware resources to process requests. Both the private token address and the global token address are pointer addresses.

[0085] The successful exchange of the target goroutine's private token address and global token address indicates that the global token address is the target goroutine's private address, meaning only the target goroutine can access it. Simultaneously, the target goroutine obtains the global token from this address. Correspondingly, the target goroutine's private token address becomes a global address, meaning any goroutine within the target thread can access the target goroutine's private token address.

[0086] Therefore, if the private token address of the target coroutine is successfully exchanged with the global token address of the data processing device, the data processing device determines that the target coroutine has the authority to call hardware resources.

[0087] Optionally, if the private token address of the target coroutine fails to exchange with the global token address of the data processing device, the data processing device determines that the target coroutine does not have permission to call hardware resources.

[0088] In this implementation, the data processing device grants the target coroutine permission to access hardware resources by exchanging the target coroutine's private token address with the data processing device's global token address. Since the exchange between the target coroutine's private token address and the data processing device's global token is a lock-free operation, this implementation reduces the likelihood of blocking when the target coroutine obtains the global token from the global token address.

[0089] As an optional implementation, the data processing device determines that the private token address of the target coroutine has been successfully exchanged with the global token address of the data processing device by performing the following steps:

[0090] 401. Perform atomic operations on the aforementioned private token address and the aforementioned global token address.

[0091] In this embodiment, atomic operations are implemented using atomic instructions from the processor. Specifically, two memory addresses are compared, and if the comparison result shows that they are equal, the original values ​​of the two memory addresses are swapped, thus completing the swap of the two addresses.

[0092] 402. If it is determined that the original value of the above-mentioned private token address has been changed, it is determined that the private token address of the above-mentioned target coroutine and the global token address of the above-mentioned data processing device have been successfully exchanged.

[0093] The fact that the original value of the private token address has been changed indicates that the comparison result obtained by performing atomic operations on the global token address and the private token address is equal, which means that the private token address and the global token address have been successfully exchanged.

[0094] In this implementation, the data processing device performs atomic operations on the private token address and the global token address to exchange the private token address and the global token address. Since atomic operations are lock-free operations, exchanging the private token address and the global token address through atomic operations can reduce the probability of the target coroutine becoming blocked.

[0095] As an optional implementation, the data processing device performs the following steps during step 401:

[0096] 501. The target coroutine above obtains the target number of requests to be processed.

[0097] In this embodiment of the application, the request to be processed is a request with a determined processing time, that is, the coroutines that process the request to be processed all have the authority to call hardware resources.

[0098] In one possible implementation, the global token includes the target number of pending requests, which the target goroutine uses to determine the target number.

[0099] 502. When the number of targets is less than or equal to the threshold, the target coroutine sends an atomic operation request to the data processing device.

[0100] In this embodiment, the atomic operation request is used to request an atomic operation from the data processing device. Because the hardware resources of the data processing device are limited, it restricts the number of requests it can process per unit time, thus limiting client traffic. For example, the data processing device limits processing to a maximum of 40 requests per minute. If the number of requests with a known processing time is large, even if the target coroutine has permission to access hardware resources, the target time for processing the first request will be far from the current time, resulting in a long response time for the first request. Therefore, when the number of requests with a known processing time is small, the target coroutine sends an atomic operation request to the data processing device.

[0101] In this embodiment, a threshold is used to determine whether the number of requests with a determined processing time is high or low. Specifically, if the number of requests with a determined processing time is less than or equal to the threshold, it indicates that the number of requests with a determined processing time is low. If the number of requests with a determined processing time is greater than the threshold, it indicates that the number of requests with a determined processing time is high. Therefore, when the target number is less than or equal to the threshold, the target coroutine sends atomic operation requests to the data processing device, thereby improving the response speed of the data processing device.

[0102] 503. Upon detecting the aforementioned atomic operation request, the aforementioned data processor performs atomic operations on the aforementioned private token address and the aforementioned global token address.

[0103] In this implementation, the target coroutine sends an atomic operation request to the data processing device when it determines that the number of targets is less than or equal to a threshold, which can improve the response speed of the data processing device.

[0104] As an optional implementation, after completing step 102, the data processing device further performs the following steps:

[0105] 601. After the target goroutine has processed the first request, clear the token stored in the global token address.

[0106] By executing step 601, the target coroutine can reclaim resources from the global token address. Since the global token address becomes the target coroutine's private address after the successful exchange between the target coroutine's private token address and the global token address, the target coroutine's cleanup of the token stored in the global token address (i.e., the aforementioned global token) is a local operation of the target coroutine. Thus, this resource reclamation operation will not affect the operation of the global coroutine, thereby reducing the probability of coroutines in the data processing device becoming blocked.

[0107] As an optional implementation, the data processing device determines the target time for the target coroutine in the target thread to process the first request by performing the following steps:

[0108] 701. Get the target number of requests to be processed.

[0109] In this embodiment of the application, the request to be processed is a request with a determined processing time, that is, the coroutines that process the request to be processed all have the authority to call hardware resources.

[0110] In one possible implementation, the global token includes the target number of pending requests, which the target goroutine uses to determine the target number.

[0111] 702. Based on the target quantity and the processing time of the pending requests, the target time is obtained.

[0112] In this embodiment of the application, the processing time for each pending request is the same. Therefore, the time required to process all pending requests can be determined based on the target number and the processing time of the pending requests, thereby determining the target time.

[0113] In one possible implementation, the product of the target number and the processing time of each pending request is determined to obtain the time required to process all pending requests. The sum of the time required to process all pending requests and the current time is used as the target time. For example, if the target number is 4 and the processing time of each pending request is 10 seconds, then the time required to process all pending requests is 40 seconds. If the current time is 9:30:15 AM on September 19, 2022, then the target time is 9:30:55 AM on September 19, 2022.

[0114] In another possible implementation, the product of the target number and the processing time of the pending requests is determined to obtain the time required to process all pending requests. The sum of the time required to process all pending requests, the current time, and the preset time is used as the target time. For example, if the target number is 4 and the processing time of the pending requests is 10 seconds, then the time required to process all pending requests is 40 seconds. If the current time is 9:30:15 AM on September 19, 2022, and the preset time is 1 second, then the target time is 9:30:56 AM on September 19, 2022.

[0115] As described in step 502, due to the limited hardware resources of the data processing device, the number of requests that the data processing device can process per unit time is limited; that is, the speed at which the data processing device processes requests is limited. For example, if the data processing device can process a maximum of 120 requests in 1 minute, then the data processing device processes requests at a speed of 2 requests per second. In other words, the processing time for each request is 1 / 2 second = 0.5 seconds, meaning that the processing time for a request to be processed can be determined based on the speed at which the requests are processed.

[0116] As an optional implementation, before invoking the target coroutine to process the first request at the target time, the data processing device further performs the following steps:

[0117] 801. Before the target time mentioned above, call the target goroutine to process the second request.

[0118] In this embodiment, the second request differs from the first request. Specifically, the data processing device can invoke the target coroutine to process the second request before invoking it to process the first request. In other words, the target coroutine does not need to wait before the data processing device invokes it to process the first request. This improves the efficiency of the target coroutine in processing requests, thereby increasing the response speed of the data processing device to requests.

[0119] It should be understood that in the embodiments of this application, the target coroutine and target thread are merely descriptive objects selected for concisely illustrating the technical solution. They should not be interpreted as the n threads including only the target thread, or the target thread including only the target coroutine, nor should they be interpreted as the data processing device only calling the target coroutine to process the first request through the aforementioned technical solution, so that the target coroutine does not need to wait before processing the first request. In practical applications, the data processing device can determine the reference time for any one of the n threads to process the request according to the aforementioned technical solution, and then call the corresponding coroutine to process the request at the reference time. In this way, each coroutine in the n threads does not need to wait before processing the request. This can improve the response speed of the data processing device to requests.

[0120] Based on the technical solutions provided in the embodiments of this application, the embodiments of this application also provide a possible application scenario.

[0121] Considering the limited hardware configuration and network bandwidth of the server (such as a physical server), it is necessary to limit the number of client requests processed by the server to protect the security of the server's database. Based on the technical solution provided in this application, calling a server-side coroutine in coroutine mode to process requests can both improve processing speed and reduce the probability of coroutine blocking.

[0122] For details on the server-side process of handling the first request, please refer to [link / reference]. Figure 2 ,like Figure 2 As shown, after receiving the first request from the client, the protocol layer determines whether rate limiting is needed for that request. If rate limiting is not required, the filter layer promptly invokes a coroutine to process the request. If rate limiting is required, the invoking component in the filter layer obtains the rate limiting rate (i.e., the speed at which requests are processed), determines the processing time for a single request based on the rate limiting rate, and then invokes the target coroutine to process the request according to the previously described technical solution. After processing the first request from the client, the target coroutine used to process the request is released. Optionally, the invoking component can be a pluggable module.

[0123] Optionally, the flowchart illustrating the process of the calling component invoking the target coroutine to process the first request sent by the client according to the technical solution described above is as follows: Figure 3 As shown. In Figure 3 In this process, the target goroutine first obtains the address of the most recently issued global token. Based on the global token address, it determines the target quantity. It then checks if the target quantity is less than or equal to a threshold. If not, it does not send an atomic operation request to the server; otherwise, it generates a private token and stores it in a private token address. This private token carries the following information: the target quantity and the target goroutine's identifier. The server then sends an atomic operation request to the server. Upon detecting the atomic operation request from the target goroutine, the server performs an atomic operation on the private token address and the global token address. If the atomic operation fails to exchange the private token address and the global token address, the target goroutine continues to obtain the address of the most recently issued global token. If the atomic operation successfully exchanges the private token address and the global token address, the server determines the target goroutine's target time to process the first request and calls the target goroutine to process the first request at the target time. After processing the first request, the target goroutine clears the token stored in the global token address.

[0124] Those skilled in the art will understand that, in the above-described method of the specific implementation, the order in which each step is written does not imply a strict execution order and does not constitute any limitation on the implementation process. The specific execution order of each step should be determined by its function and possible internal logic.

[0125] If the technical solution of this application involves personal information, the product using this technical solution has clearly informed the user of the personal information processing rules and obtained the user's voluntary consent before processing the personal information. If the technical solution of this application involves sensitive personal information, the product using this technical solution has obtained the user's separate consent before processing the sensitive personal information, and also meets the requirement of "express consent". For example, at personal information collection devices such as cameras, clear and prominent signs are set up to inform users that they have entered the scope of personal information collection and that personal information will be collected. If an individual voluntarily enters the collection scope, it is deemed that they have agreed to the collection of their personal information; or on the personal information processing device, while using clear signs / information to inform users of the personal information processing rules, authorization is obtained from the individual through pop-up information or by asking the individual to upload their personal information; wherein, personal information processing may include information such as the personal information processor, the purpose of personal information processing, the processing method, and the types of personal information processed.

[0126] The methods of the embodiments of this application have been described in detail above, and the apparatus of the embodiments of this application is provided below.

[0127] Please see Figure 4 , Figure 4 This is a schematic diagram of a data processing device provided in an embodiment of this application. The data processing device 1 includes a first processing unit 11 and a second processing unit 12. Specifically:

[0128] The first processing unit 11 is used to determine the target time for the target coroutine in the target thread to process the first request;

[0129] The second processing unit 12 is used by the data processing device to call the target coroutine to process the first request at the target time.

[0130] In any embodiment of this application, the first processing unit 11 is configured to:

[0131] If it is determined that the target coroutine has the authority to invoke hardware resources, the target time for the target coroutine in the target thread to process the first request is determined.

[0132] In conjunction with any embodiment of this application, the first processing unit 11 is further configured to determine that the target coroutine has the authority to call hardware resources when the private token address of the target coroutine is successfully exchanged with the global token address of the data processing device; the global token address stores a global token, and the global token has the authority to call hardware resources.

[0133] In conjunction with any embodiment of this application, the first processing unit 11 is further configured to:

[0134] Perform atomic operations on the private token address and the global token address;

[0135] If it is determined that the original value of the private token address has been changed, it is determined that the private token address of the target coroutine has been successfully exchanged with the global token address of the data processing device.

[0136] In any embodiment of this application, the first processing unit 11 is configured to:

[0137] The target coroutine obtains the target number of requests to be processed; the requests to be processed are requests with a predetermined processing time.

[0138] If the number of targets is less than or equal to a threshold, the target coroutine sends an atomic operation request to the data processing device.

[0139] Upon detecting the atomic operation request, the data processor performs an atomic operation on the private token address and the global token address.

[0140] In conjunction with any embodiment of this application, the first processing unit 11 is further configured to:

[0141] Once the target coroutine has finished processing the first request, the token stored in the global token address is cleared.

[0142] In any embodiment of this application, the first processing unit 11 is configured to:

[0143] Obtain the target number of requests to be processed; the requests to be processed are those with a predetermined processing time.

[0144] The target time is obtained based on the target number and the processing time of the pending requests.

[0145] In any embodiment of this application, the first processing unit 11 is further configured to: call the target coroutine to process the second request before the target time; the second request is different from the first request.

[0146] In this embodiment of the application, the data processing device determines the time for the target coroutine to process the first request, thereby avoiding the target coroutine from queuing and waiting to process the first request. This reduces the probability of the target coroutine being blocked, and further reduces the probability of the target thread being blocked, thereby improving the hardware resource utilization of the data processing device and improving the response speed of the server.

[0147] In some embodiments, the functions or modules of the apparatus provided in this application can be used to perform the methods described in the above method embodiments. The specific implementation can be referred to the description of the above method embodiments, and for the sake of brevity, it will not be repeated here.

[0148] Figure 5 This is a schematic diagram of the hardware structure of an electronic device provided in an embodiment of this application. The electronic device 2 includes a processor 21 and a memory 22. Optionally, the electronic device 2 also includes an input device 23 and an output device 24. The processor 21, memory 22, input device 23, and output device 24 are coupled together via connectors, which include various interfaces, transmission lines, or buses, etc., and are not limited in this embodiment. It should be understood that in the various embodiments of this application, coupling refers to mutual connection in a specific way, including direct connection or indirect connection through other devices, such as through various interfaces, transmission lines, buses, etc.

[0149] Processor 21 may include one or more processors, such as one or more CPUs. If the processor is a CPU, it may be a single-core CPU or a multi-core CPU. Optionally, processor 21 may be a processor group composed of multiple GPUs, with the multiple processors coupled to each other via one or more buses. Optionally, the processor may also be other types of processors, etc., which are not limited in this embodiment.

[0150] The memory 22 can be used to store computer program instructions, as well as various types of computer program code, including program code for executing the scheme of this application. Optionally, the memory includes, but is not limited to, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM), or compact disc read-only memory (CD-ROM), which is used for related instructions and data.

[0151] Input device 23 is used to input data and / or signals, and output device 24 is used to output data and / or signals. Input device 23 and output device 24 can be independent devices or an integrated device.

[0152] It is understood that in this embodiment of the application, the memory 22 can be used not only to store related instructions, but also to store related data. For example, the memory 22 can be used to store the first request obtained through the input device 23, etc. This embodiment of the application does not limit the specific data stored in the memory.

[0153] Understandable Figure 5 This is merely a simplified design of an electronic device. In practical applications, the electronic device may also include other necessary components, including, but not limited to, any number of input / output devices, processors, memories, etc., and all electronic devices that can implement the embodiments of this application are within the protection scope of this application.

[0154] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0155] Those skilled in the art will readily understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here. Those skilled in the art will also readily understand that the various embodiments of this application have different focuses, and for the sake of convenience and brevity, the same or similar parts may not be repeated in different embodiments. Therefore, parts not described or not described in detail in one embodiment can be referred to the descriptions in other embodiments.

[0156] In the several embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.

[0157] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0158] In addition, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.

[0159] In the above embodiments, implementation can be achieved entirely or partially through software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented entirely or partially as 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, all or part of the processes or functions described in the embodiments of this application are generated. 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 through the computer-readable storage medium. The computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available media may be magnetic media (e.g., floppy disks, hard disks, magnetic tapes), optical media (e.g., digital versatile discs (DVDs)), or semiconductor media (e.g., solid-state disks (SSDs)).

[0160] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. This program can be stored in a computer-readable storage medium, and when executed, it can include the processes described in the above method embodiments. The aforementioned storage medium includes various media capable of storing program code, such as read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

Claims

1. A data processing method, characterized in that, The data processing method is applied to a data processing device, the data processing device running n threads, the n threads including a target thread, where n is a positive integer, and the method includes: If the private token address of the target coroutine in the target thread is successfully exchanged with the global token address of the data processing device, the target time for the target coroutine in the target thread to process the first request is determined; the global token address stores a global token, which has the authority to call hardware resources; The data processing device invokes the target coroutine to process the first request at the target time.

2. The method according to claim 1, characterized in that, Before determining the target time for the target coroutine to process the first request in the target thread, after the private token address of the target coroutine has been successfully exchanged with the global token address of the data processing device, the method further includes: If the private token address and the global token address are equal, the original values ​​of the private token address and the global token address are swapped. If it is determined that the private token address has been changed to the original value of the global token address, and the global token address has been changed to the original value of the private token address, then it is determined that the private token address of the target coroutine and the global token address of the data processing device have been successfully exchanged.

3. The method according to claim 2, characterized in that, The step of swapping the original values ​​of the private token address and the global token address when the private token address and the global token address are equal includes: The target coroutine obtains the target number of requests to be processed; the requests to be processed are requests with a predetermined processing time. If the number of targets is less than or equal to a threshold, the target coroutine sends an atomic operation request to the data processing device. When the data processing device detects the atomic operation request and the private token address and the global token address are equal, it swaps the original values ​​of the private token address and the global token address.

4. The method according to claim 2, characterized in that, After the data processing device invokes the target coroutine to process the first request at the target time, the method further includes: Once the target coroutine has finished processing the first request, the token stored in the global token address is cleared.

5. The method according to any one of claims 1 to 4, characterized in that, Determining the target time for the target coroutine in the target thread to process the first request includes: Obtain the target number of requests to be processed; the requests to be processed are those with a predetermined processing time. The target time is obtained based on the target number and the processing time of the pending requests.

6. The method according to any one of claims 1 to 4, characterized in that, Before the data processing device invokes the target coroutine to process the first request at the target time, the method further includes: the data processing device invoking the target coroutine to process a second request before the target time; the second request is different from the first request.

7. A data processing apparatus, characterized in that, The data processing device runs n threads, where n threads include a target thread, and n is a positive integer. The data processing device includes: The first processing unit is configured to determine the target time for the target coroutine in the target thread to process the first request, provided that the private token address of the target coroutine in the target thread is successfully exchanged with the global token address of the data processing device; the global token address stores a global token, which has the authority to call hardware resources. The second processing unit is used by the data processing device to call the target coroutine to process the first request at the target time.

8. An electronic device, characterized in that, include: A processor and a memory, the memory being used to store computer program code, the computer program code including computer instructions, wherein, when the processor executes the computer instructions, the electronic device performs the method as described in any one of claims 1 to 6.

9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, the computer program including program instructions that, when executed by a processor, cause the processor to perform the method according to any one of claims 1 to 6.

Citation Information

Patent Citations

  • Interface pressure testing method and related equipment

    CN111782482A

  • Distributed Rate Limiting Of Handling Requests

    US20130091241A1