Asynchronous task processing methods, systems, electronic devices, and storage media
By dividing asynchronous tasks by dimension and rate limiting sorting, the problem of too many asynchronous tasks from a single user affecting the execution of other users is solved, thus achieving efficient task allocation and execution.
Patent Information
- Application Number
- CN202211590096.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-12
- Publication Date
- 2026-03-06
- Estimated Expiration
- 2042-12-12
AI Technical Summary
In some application scenarios, an excessive number of asynchronous tasks for a single user can affect the execution of asynchronous tasks for other users, resulting in excessively long execution times and excessive resource consumption.
By dividing asynchronous tasks into dimensions and rate-limiting sorting, the number of concurrent processing tasks in each dimension is limited. A caching middleware is used to store tasks exceeding the limit, and tasks are executed using a first-in-first-out or weighted queuing strategy. Task status is monitored to avoid timeouts.
This effectively avoids the impact of excessively long execution time of a single task on other tasks, rationally allocates resources, and improves the execution efficiency of asynchronous tasks.
Smart Images

Figure CN115964143B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data processing technology, and in particular to an asynchronous task processing method, system, electronic device, and storage medium. Background Technology
[0002] Asynchronous means that during the call process, the caller does not directly wait for the return result, but executes other tasks until the other tasks are completed, and then sends the completed result back to the caller.
[0003] In related technologies, slow-moving or resource-intensive processing logic can be separated from the main request processing logic and delegated to a more resource-flexible system for asynchronous execution. However, in some application scenarios, if a single user has too many asynchronous tasks, it can affect the execution of asynchronous tasks for other users. Summary of the Invention
[0004] The main objective of this application is to propose an asynchronous task processing method, system, electronic device, and storage medium that can achieve rate limiting of services and rate limiting of a certain dimension of services, and can reasonably allocate service resources to improve the execution efficiency of asynchronous tasks.
[0005] To achieve the above objectives, a first aspect of this application proposes an asynchronous task processing method, the method comprising: acquiring a task request received by a server, the task request including multiple asynchronous tasks to be processed; dividing the asynchronous tasks according to a preset dimension to obtain tag information for each asynchronous task, the tag information including at least a first dimension tag information; acquiring a preset first asynchronous task concurrent processing quantity; performing rate limiting sorting on the asynchronous tasks according to the first dimension tag information and the rate limiting rules of the first dimension to obtain a rate limiting sorting result; and invoking an asynchronous task consumer to execute the asynchronous tasks according to the first asynchronous task concurrent processing quantity and the rate limiting sorting result.
[0006] According to some embodiments of this application, the rate limiting rule for the first-level dimension is: the number of concurrent processing of asynchronous tasks with the same or similar first-level dimension label information does not exceed the preset number of concurrent processing of one-dimensional tasks; the process of rate limiting and sorting the asynchronous tasks according to the first-level dimension label information and the rate limiting rule for the first-level dimension to obtain the rate limiting sorting result includes: determining the number of asynchronous tasks that need to be executed concurrently and the number of asynchronous tasks that need to be stored in the cache middleware for execution according to the number of concurrent processing of the first asynchronous tasks; according to the rate limiting rule for the first-level dimension, if the number of concurrent processing of asynchronous tasks with the same or similar first-level dimension label information exceeds the preset number of concurrent processing of one-dimensional tasks, the excess asynchronous tasks will continue to be stored in the cache middleware for execution, and asynchronous tasks with other types of label information will be added to the concurrently executed asynchronous tasks to obtain the rate limiting sorting result.
[0007] According to some embodiments of this application, the caching middleware is provided with a queue. After the asynchronous task consumer is called to execute the asynchronous task based on the first asynchronous task concurrent processing number and the rate limiting sorting result, the method further includes: the asynchronous task consumer detects that the asynchronous task in the queue has been completed; and adds the asynchronous task waiting in the caching middleware to the queue, wherein the asynchronous task waiting is the asynchronous task that has been scheduled but not completed.
[0008] According to some embodiments of this application, the tag information further includes Nth dimension tag information, where N is a positive integer greater than or equal to 2; after performing rate limiting and sorting on the asynchronous tasks according to the first dimension tag information and the rate limiting rules of the first-level dimension to obtain the rate limiting sorting result, the method further includes: obtaining the Nth dimension tag information and the rate limiting rules of the Nth level dimension; updating the rate limiting sorting on the asynchronous tasks to obtain the updated rate limiting sorting result; the rate limiting rule of the Nth level dimension is that the number of concurrent processing of the same or similar Nth dimension tag information does not exceed the preset number of concurrent processing of N-dimensional tasks. 。
[0009] According to some embodiments of this application, the step of invoking an asynchronous task consumer to execute the asynchronous task based on the number of concurrent asynchronous tasks and the rate limiting sorting result includes: determining a preset execution queuing strategy; wherein the execution queuing strategy includes a first-in-first-out queuing strategy or a weighted queuing strategy; and invoking an asynchronous task consumer to execute the asynchronous task based on the number of concurrent asynchronous tasks, the rate limiting sorting result, and the preset execution queuing strategy.
[0010] According to some embodiments of this application, the step of calling the asynchronous task consumer to execute the asynchronous task based on the number of concurrent asynchronous tasks and the rate limiting sorting result includes: if the execution queuing strategy is first-in-first-out queuing, then the asynchronous task that enters the queue first is executed first, and after the asynchronous task that enters the queue first is completed, the asynchronous task that enters the queue later is executed; if the queuing strategy is weighted queuing, then each time an asynchronous task enters the queue, all the asynchronous tasks in the queue are queued according to their task weights, and the asynchronous task with the larger task weight is executed first, followed by the asynchronous task with the smaller task weight; or the asynchronous task with the smaller task weight is executed first, followed by the asynchronous task with the larger task weight.
[0011] According to some embodiments of this application, after calling the asynchronous task consumer to execute the asynchronous task based on the first concurrent processing number of asynchronous tasks and the rate limiting sorting result, the method further includes: if a single asynchronous task fails to execute, determining whether the number of retries has been exceeded; if not, calling the asynchronous task consumer to re-execute the asynchronous task; and / or, obtaining a preset execution time for the asynchronous task; determining whether the execution time of each asynchronous task exceeds the preset execution time; if the preset execution time is exceeded, determining that the execution status of the asynchronous task is a timeout state.
[0012] To achieve the above objectives, a second aspect of this application proposes an asynchronous task processing system, comprising: a task request acquisition module, configured to acquire task requests received by a server, the task requests including multiple asynchronous tasks to be processed; an asynchronous task partitioning module, configured to partition the asynchronous tasks according to a preset dimension to obtain tag information for each asynchronous task, the tag information including at least first dimension tag information; a first asynchronous task concurrent processing quantity acquisition module, configured to acquire a preset first asynchronous task concurrent processing quantity; an asynchronous task sorting module, configured to perform rate limiting sorting on the asynchronous tasks according to the first dimension tag information and the rate limiting rule of the first dimension to obtain a rate limiting sorting result; and an asynchronous task execution module, configured to call an asynchronous task consumer to execute the asynchronous tasks according to the first asynchronous task concurrent processing quantity and the rate limiting sorting result.
[0013] To achieve the above objectives, a third aspect of this application provides an electronic device comprising a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the asynchronous task processing method described in any one of the embodiments of the first aspect of this application.
[0014] To achieve the above objectives, a fourth aspect of this application provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the asynchronous task processing method described in any one of the first aspects of this application.
[0015] The asynchronous task processing method, system, electronic device, and storage medium proposed in this application can solve the problem in some application scenarios where an excessive number of asynchronous tasks by a single user affects the execution of asynchronous tasks by other users. By implementing rate limiting for asynchronous tasks and rate limiting for a specific dimension of asynchronous tasks, it can prevent the execution time of a single task from being too long, thus affecting the execution of tasks in other dimensions, and can reasonably allocate service resources and improve the execution efficiency of asynchronous tasks. Attached Figure Description
[0016] Figure 1 This is a schematic diagram of the overall hardware architecture of the asynchronous task provided in the embodiments of this application;
[0017] Figure 2 This is a flowchart of the asynchronous task processing method provided in the embodiments of this application;
[0018] Figure 3 yes Figure 2 The flowchart for obtaining the flow-limiting sorting result in step S104;
[0019] Figure 4 This is a flowchart illustrating the process of adding asynchronous task processing in this application;
[0020] Figure 5 yes Figure 2 The flowchart shows how to add the waiting asynchronous task to the queue after step S105;
[0021] Figure 6 yes Figure 2 The flowchart for obtaining the updated rate limiting sorting result after step S104 is as follows;
[0022] Figure 7 yes Figure 2 The flowchart of step S105 in the process;
[0023] Figure 8 yes Figure 2 The flowchart of the queuing strategy in step S105;
[0024] Figure 9 yes Figure 2 The flowchart for determining the execution status of asynchronous tasks after step S105;
[0025] Figure 10 This is an asynchronous task execution state diagram according to an embodiment of this application;
[0026] Figure 11 This is a diagram illustrating the overall execution process of asynchronous tasks in the embodiments of this application;
[0027] Figure 12 This is a schematic diagram of the functional modules of the asynchronous task processing system provided in the embodiments of this application;
[0028] Figure 13 This is a schematic diagram of the hardware structure of the electronic device provided in the embodiments of this application. Detailed Implementation
[0029] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0030] It should be noted that although functional modules are divided in the device schematic diagram and a logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than the module division in the device or the order in the flowchart. The terms "first," "second," etc., in the specification, claims, and the aforementioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence.
[0031] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing embodiments of this application only and is not intended to limit this application.
[0032] In related technologies, time-consuming, resource-intensive, or error-prone logic can be extracted from the main request flow and executed asynchronously. For example, when a user uploads an image, thumbnails of different sizes need to be generated after the image is uploaded. However, the image processing itself doesn't need to be included in the image upload process. Thumbnail generation and other processing logic can be executed asynchronously, and the process can end once the user successfully uploads the image. This prevents the application server from being overwhelmed by computationally intensive tasks like image processing, and users receive faster responses. It's understandable that multiple tasks can be executed asynchronously simultaneously. For instance, image processing can include generating thumbnails, adding watermarks, pornography detection, and transcoding. Simultaneously, document processing operations can also be performed, such as format conversion and document export.
[0033] In some application scenarios, an excessive number of individual asynchronous tasks can affect the execution of asynchronous tasks for other users. For example, if there are too many image processing tasks, their completion will take a certain amount of time, affecting the execution of other asynchronous tasks. Therefore, it is necessary to limit the number of individual asynchronous tasks.
[0034] Based on this, embodiments of this application provide an asynchronous task processing method, system, electronic device, and storage medium, which can achieve rate limiting for asynchronous tasks and rate limiting for a certain dimension of asynchronous tasks, thereby avoiding the excessive execution time of a single task from affecting the execution of subsequent tasks. At the same time, it can reasonably allocate service resources and improve the execution efficiency of asynchronous tasks.
[0035] It should be noted that in all specific embodiments of this application, when processing data related to user identity or characteristics, such as user information, user behavior data, user historical data, and user location information, user permission or consent is obtained first. For example, when obtaining user-stored data and user cached data access requests, user permission or consent is obtained first. Furthermore, the collection, use, and processing of this data comply with relevant laws, regulations, and standards of the relevant countries and regions. In addition, when embodiments of this application need to obtain sensitive personal information of users, separate permission or consent from the user is obtained through pop-ups or redirection to a confirmation page. Only after obtaining the user's separate permission or consent is the necessary user-related data for the normal operation of the embodiments of this application obtained.
[0036] The asynchronous task processing method, system, electronic device, and storage medium provided in this application are specifically described through the following embodiments. First, the overall hardware architecture of the asynchronous task in this application embodiment is described, and the asynchronous task processing method in this application embodiment can be applied to this system architecture.
[0037] Reference Figure 1 In some embodiments, the overall hardware architecture of the asynchronous task includes, but is not limited to, server 101, cache middleware 102, and controller 103. It is understood that cache middleware 102 stores a queue for storing and sorting asynchronous tasks waiting to be executed. Exemplarily, cache middleware 102 can be used to store instructions and data. In some embodiments, cache middleware 102 can be a high-speed cache memory, used to store recently used or repeatedly used instructions or data. It is understood that if the instruction or data needs to be used again, it can be directly retrieved from cache middleware 102. In some embodiments, setting up cache middleware 102 avoids repeated access to asynchronous tasks, reduces the waiting time of the asynchronous task processing system, and thus improves the efficiency of asynchronous task execution.
[0038] In some embodiments, the controller 103 is provided with an asynchronous task executor 104 for invoking an asynchronous task consumer to execute an asynchronous task. In some embodiments, the asynchronous task consumer is used to execute asynchronous tasks. It is understood that the controller 103 can be the nerve center and command center of an electronic device. Specifically, the controller 103 can generate operation control signals according to the instruction opcode and timing signals to complete the control of instruction fetching and execution.
[0039] The asynchronous task processing method in this application can be illustrated by the following embodiments.
[0040] Please refer to Figure 2 One embodiment of this application proposes an asynchronous task processing method, which includes the following steps S101 to S105:
[0041] Step S101: Obtain the task request received by the server. The task request includes multiple asynchronous tasks to be processed.
[0042] Step S102: Divide the asynchronous tasks according to the preset dimensions to obtain the label information of each asynchronous task. The label information shall at least include the first dimension label information.
[0043] Step S103: Obtain the preset number of concurrent asynchronous tasks;
[0044] Step S104: Based on the first dimension label information and the first-level dimension rate limiting rules, perform rate limiting sorting on the asynchronous tasks to obtain the rate limiting sorting result;
[0045] Step S105: Based on the number of concurrent processing of the first asynchronous task and the rate limiting sorting result, call the asynchronous task consumer to execute the asynchronous task.
[0046] In some embodiments, task requests are obtained by the server, and the controller classifies the task requests according to the instruction opcode. It is understood that task requests include asynchronous task requests and non-asynchronous task requests. Asynchronous tasks refer to tasks that are separated from the main process for execution, while non-asynchronous tasks refer to tasks executed by the main process. It is understood that after an asynchronous task is completed, it will return to the main process.
[0047] For example, asynchronous tasks are typically time-consuming, resource-intensive, or error-prone. If they are executed by the main process, it will affect other tasks that are normally shorter in duration, consume fewer resources, or are less prone to errors. In some embodiments, there are multiple asynchronous tasks, such as sending emails or instant messages, checking for spam, document processing, audio and video processing, image processing, calling external third-party services, importing / exporting large amounts of data, etc.
[0048] Understandably, the preset dimension can refer to the dimension of asynchronous tasks. In some embodiments, if asynchronous tasks provide services to various enterprises, then the first dimension of asynchronous tasks can be enterprise task information that is synchronously executed by the asynchronous processing system; the second dimension of asynchronous tasks can be task information of subsidiaries of various enterprises; the third dimension of asynchronous tasks can be departmental task information of various subsidiaries; the fourth dimension of asynchronous tasks can be team task information of various departments, and so on.
[0049] In some embodiments, asynchronous tasks are divided according to preset dimensions to obtain tag information for each asynchronous task. This tag information can include information such as the memory size occupied by the asynchronous task, the time the asynchronous task was stored in the cache middleware, the estimated execution time of the asynchronous task, and the category information of the asynchronous task. In some embodiments, the tag information includes at least the first dimension tag information; optionally, the tag information can also include multiple tags from multiple dimensions. Obtaining the tag information of asynchronous tasks facilitates subsequent asynchronous task invocation, saves invocation time, makes the storage of asynchronous tasks more orderly, and ensures efficient execution of asynchronous tasks.
[0050] In some embodiments, the preset first concurrent asynchronous task processing number is the preset number of asynchronous tasks that the asynchronous task processing system can concurrently process. For example, if there are 4 asynchronous tasks, A, B, C, and D, and the preset first concurrent asynchronous task processing number is 3, then the asynchronous task processing system can concurrently process 3 asynchronous tasks. Optionally, the first concurrent asynchronous task processing number can be determined according to the order in which the 4 asynchronous tasks enter the asynchronous task processing system. In this case, the asynchronous tasks concurrently processed by the asynchronous task processing system are A, B, and C.
[0051] In some embodiments, the first dimension label information is the order in which all asynchronous tasks in the first dimension enter the asynchronous task processing system. For example, the first dimension label information may also be the estimated processing time information of a one-dimensional asynchronous task, the dimension information of each asynchronous task, the weight information of the asynchronous task, the storage information consumed by the asynchronous task, etc., and this application embodiment does not impose specific limitations here.
[0052] Understandably, the first-level rate limiting rule limits the concurrent processing capacity of asynchronous tasks in the first dimension. For example, if the first-level asynchronous tasks include A, B, C, and D, and A has A, B, and C asynchronous tasks in its two dimensions, and the first-level rate limiting rule states that the concurrent processing capacity of asynchronous tasks in the first dimension cannot exceed 2, then after applying the first-level rate limiting rule, the concurrent processing capacity of A's asynchronous tasks cannot exceed 2. Subsequently, if the order in which A's two-dimensional asynchronous tasks enter the asynchronous task processing system is A, B, C, then based on the first-dimensional tag information and the first-level rate limiting rule, the asynchronous tasks are rate-limited and sorted, resulting in a rate-limited sorting result of A and B. In some embodiments, if a single user has too many asynchronous tasks, it can affect the execution of asynchronous tasks for other users. By implementing rate limiting for asynchronous tasks, and rate limiting for a specific dimension of asynchronous tasks, we can avoid the problem of a single task taking too long to execute, thus affecting the execution of subsequent tasks. Simultaneously, we can also rationally allocate service resources and improve the execution efficiency of asynchronous tasks.
[0053] In some embodiments, an asynchronous task consumer is invoked to execute asynchronous tasks based on the number of concurrent asynchronous tasks and the rate-limiting sorting result. It is understood that the asynchronous task consumer executes asynchronous tasks under the control of the controller. For example, if there are asynchronous tasks A, B, C, and D in the first-level dimension, and the corresponding second-level asynchronous tasks A, B, and C are A, B, and C, and the rate-limiting sorting result for A's corresponding second-level asynchronous tasks is A and B; the corresponding second-level asynchronous tasks B are D, E, and F, and the sorting result for B's corresponding second-level asynchronous tasks is D and E; the corresponding second-level asynchronous tasks C are G, H, and I, and the sorting result for C's corresponding second-level asynchronous tasks is G and H; and the corresponding second-level asynchronous tasks D are J, K, and L, and the sorting result for D's corresponding second-level asynchronous tasks is J and K. If the number of concurrent asynchronous tasks in the first asynchronous task is 3, based on the first-level label information, the order in which A, B, C, and D enter the asynchronous task processing system is A, B, C, and D. After rate-limiting sorting, it is determined that the asynchronous tasks to be executed by the asynchronous task consumer are A, B, and D. In some embodiments, if a single user has too many asynchronous tasks, it may affect the execution of asynchronous tasks for other users. By implementing rate limiting for asynchronous tasks, or rate limiting for a specific dimension of asynchronous tasks, we can avoid the problem of a single task taking too long to execute, which could affect the execution of subsequent tasks. At the same time, we can also allocate service resources reasonably and improve the execution efficiency of asynchronous tasks.
[0054] In some embodiments, if the asynchronous task execution system detects that the total number of asynchronous tasks does not exceed the concurrent processing limit for asynchronous tasks, it will no longer rate-limit the asynchronous tasks according to the dimensional rate-limiting rules. That is, after dividing the asynchronous tasks and obtaining their tag information, the system obtains the preset concurrent processing limit for asynchronous tasks. Then, without relying on dimensional rate-limiting rules, it directly sorts the asynchronous tasks based on the dimensional tag information, obtains the rate-limiting ranking result, and then calls the asynchronous task consumer to execute the asynchronous tasks based on the concurrent processing limit and the rate-limiting ranking result. It can be understood that when the number of asynchronous tasks does not exceed the concurrent processing limit, rate-limiting is no longer necessary, thus saving server resources, reducing the waiting time of asynchronous tasks, and improving the execution efficiency of asynchronous tasks.
[0055] In some embodiments, the number of concurrent asynchronous tasks can be the number of asynchronous tasks executed in parallel by the asynchronous task processing system. It is understood that limiting the number of concurrent asynchronous tasks can prevent congestion and lag in the asynchronous task processing system caused by too many asynchronous tasks being executed simultaneously, thus affecting the operation of the entire asynchronous task processing system.
[0056] In some embodiments, the first-level dimensional rate limiting rule is: the number of concurrent processing operations for asynchronous tasks with the same or similar first-dimensional label information does not exceed a preset number of concurrent processing operations for one-dimensional tasks. For example, if there are asynchronous tasks A, B, and C, and the preset number of concurrent processing operations for one-dimensional tasks is 3, this can also be understood as the preset number of concurrent processing operations for asynchronous tasks being 3. Therefore, the actual number of concurrent processing operations for asynchronous tasks running in the asynchronous task processing system cannot exceed 3. It is understood that the asynchronous task processing system also includes multi-level dimensional rate limiting rules. The multi-level dimensional rate limiting rule is that the number of concurrent processing operations for asynchronous tasks with the same or similar Nth-dimensional label information does not exceed a preset number of concurrent processing operations for multi-dimensional tasks, where N is a positive integer greater than or equal to 2.
[0057] In some embodiments, the primary dimension can be a region dimension, an enterprise dimension, or an IP address dimension, etc., and can be set as needed. Taking the enterprise dimension as the primary dimension as an example, the preset number of concurrent processing of a one-dimensional task does not exceed the number of concurrent processing of the first asynchronous task. In some embodiments, the number of concurrent asynchronous tasks processed in a single region dimension does not exceed the total number of concurrent asynchronous tasks executed by the asynchronous task consumer.
[0058] Please refer to Figure 3 In some embodiments, step S104 includes, but is not limited to, steps S201 to S202:
[0059] Step S201: Based on the number of concurrent processing of the first asynchronous task, determine the number of asynchronous tasks that need to be executed concurrently and the number of asynchronous tasks that need to be stored in the cache middleware for execution.
[0060] Step S202: According to the rate limiting rules of the first-level dimension, if the number of asynchronous tasks with the same or similar first-level label information is processed concurrently exceeds the preset number of concurrent one-level tasks, the excess asynchronous tasks will continue to be stored in the cache middleware to wait for execution, and asynchronous tasks with other types of label information will be added to the concurrently executed asynchronous tasks to obtain the rate limiting sorting result.
[0061] For example, if the asynchronous tasks in the first-level dimension are A, B, C, and D, and the asynchronous tasks in the second-level dimension corresponding to A are A, B, and C, then the rate-limiting sorting result for the asynchronous tasks in the second-level dimension corresponding to A is A and B; the asynchronous tasks in the second-level dimension corresponding to B are D, E, and F, and the sorting result for the asynchronous tasks in the second-level dimension corresponding to B is D and E; the asynchronous tasks in the second-level dimension corresponding to C are G, H, and I, and the sorting result for the asynchronous tasks in the second-level dimension corresponding to C is G and H; and the asynchronous tasks in the second-level dimension corresponding to D are J, K, and L, and the sorting result for the asynchronous tasks in the second-level dimension corresponding to D is J and K. If the number of concurrent processing of the first asynchronous task is 3, according to the first-level label information, the order in which A, B, C, and D enter the asynchronous task processing system is A, B, C, and D. After rate-limiting sorting, the asynchronous tasks that need to be executed concurrently are determined to be A, B, and D. It can be understood that at this time, the asynchronous tasks that have not been executed by the asynchronous task consumers are cached in the cache middleware and await execution. For example, in this embodiment, C, E, F, G, H, I, J, K, and L are cached in the cache middleware and await execution.
[0062] In some embodiments, according to the rate limiting rules of the first-level dimension, if the number of concurrent asynchronous tasks with the same or similar first-level dimension label information exceeds the preset number of concurrent one-dimensional tasks, for example, if asynchronous task A has asynchronous tasks A, B, C, and D with the same or similar first-level dimension label information, and the preset number of concurrent one-dimensional tasks is 2, assuming that A and B are selected to be added to the concurrent asynchronous tasks, then C and D continue to be stored in the cache middleware waiting for execution, thereby obtaining the rate limiting sorting result. Optionally, the same or similar first-level dimension label information can be asynchronous tasks of the same dimension or asynchronous tasks of the same type.
[0063] Understandably, placing asynchronous tasks exceeding the number of concurrent asynchronous tasks into a cache middleware to wait for execution can prevent the simultaneous execution of too many asynchronous tasks, which would exceed the processing capacity of the asynchronous task processing system, causing congestion and lag, and affecting the operation of the entire asynchronous task processing system.
[0064] Please see Figure 4 In some embodiments, the asynchronous task processing system further includes an asynchronous task service, which is used to place the asynchronous tasks divided by the asynchronous task processing system into a cache middleware. In some embodiments, the asynchronous task processing system determines the number of asynchronous tasks that need to be executed concurrently and the number of asynchronous tasks that need to be stored in the cache middleware for execution based on the first asynchronous task concurrent processing limit. After the asynchronous task consumer calls and executes the asynchronous task, the asynchronous task service returns the result of the asynchronous task execution to the server. It is understood that the execution result may be the result of the asynchronous task execution being successful or the result of the asynchronous task execution failing. It is understood that placing asynchronous tasks exceeding the first asynchronous task concurrent processing limit into the cache middleware for execution can avoid the simultaneous execution of too many asynchronous tasks, which would exceed the processing capacity of the asynchronous task processing system, causing congestion and lag in the asynchronous task processing system and affecting the operation of the entire asynchronous task processing system.
[0065] Please see Figure 5 In some embodiments, the caching middleware is configured with a queue, and after step S105, steps S301 to S302 are included, but are not limited to:
[0066] Step S301: The asynchronous task consumer detects that the asynchronous task in the queue has been completed.
[0067] Step S302: Add the waiting asynchronous tasks in the cache middleware to the queue. The waiting asynchronous tasks are the asynchronous tasks that have been scheduled but have not yet been completed.
[0068] In some embodiments, the asynchronous task consumer can also monitor the execution status of asynchronous tasks in real time. When an asynchronous task is completed, the asynchronous task consumer returns the completed asynchronous task to the server and sends the corresponding status information indicating that the asynchronous task has been completed, so that the server can be informed of the execution progress of the asynchronous task in a timely manner.
[0069] Understandably, the caching middleware also includes queues, which are used to sort asynchronous tasks based on their tag information and rate limiting rules. In some embodiments, waiting asynchronous tasks are those that have been scheduled from the server but have not yet been executed. In some embodiments, setting up queues on the caching middleware facilitates the sorting of asynchronous tasks according to requirements, and allows asynchronous task consumers to execute the corresponding asynchronous tasks based on the sorting results.
[0070] Please see Figure 6 In some embodiments, the label information further includes label information of the Nth dimension, where N is a positive integer greater than or equal to 2; after step S104, steps S401 to S402 are also included, but are not limited to:
[0071] Step S401: Obtain the label information of the Nth dimension and the rate limiting rules of the Nth dimension;
[0072] Step S402: Update the rate limiting sorting for asynchronous tasks to obtain the updated rate limiting sorting result; the rate limiting rule for the N-level dimension is that the number of concurrent processing of the same or similar N-level dimension label information does not exceed the preset number of concurrent processing of N-dimensional tasks.
[0073] In some embodiments, the tag information also includes Nth dimension tag information, such as second-dimensional and third-dimensional tag information, which is not specifically limited in this application embodiment. In some embodiments, the Nth dimension tag information can be the order in which all asynchronous tasks in the corresponding Nth dimension enter the asynchronous task processing system. For example, the Nth dimension tag information can also be the estimated processing time information of the N-dimensional asynchronous task, the dimension information of each asynchronous task, the weight information of the asynchronous task, the storage information consumed by the asynchronous task, etc., which is not specifically limited in this application embodiment.
[0074] In some embodiments, the multi-dimensional rate limiting rule is that the number of concurrent processing of asynchronous tasks with the same or similar Nth dimension label information does not exceed the preset number of concurrent processing of multi-dimensional tasks.
[0075] In some embodiments, since N is a positive integer greater than or equal to 2, the caching middleware previously contained a first-dimensional rate-limiting sorting result. This result was obtained by rate-limiting and sorting asynchronous tasks based on the first-dimensional label information and the first-level rate-limiting rules. At this point, multi-level asynchronous tasks were added to the queue for sorting, and the first-dimensional rate-limiting sorting result was updated after the sorting was complete.
[0076] For example, the preset dimension can refer to the dimension of asynchronous tasks. In some embodiments, if asynchronous tasks provide services to various enterprises, then the first dimension of asynchronous tasks can be enterprise task information executed synchronously by the asynchronous processing system; the second dimension (N=2) of asynchronous tasks can be subsidiary task information of each enterprise; the third dimension (N=3) of asynchronous tasks can be department task information of each subsidiary; the fourth dimension (N=4) of asynchronous tasks can be team task information of each department, and so on. It is understandable that dividing asynchronous tasks into dimensions facilitates the asynchronous task processing system to rate-limit asynchronous tasks based on the label information of each dimension. This can solve the problem in some application scenarios where an excessive number of asynchronous tasks for a single user affects the execution of asynchronous tasks for other users. By implementing rate limiting for asynchronous tasks and rate limiting for a specific dimension of asynchronous tasks, the system avoids the problem of a single task taking too long to execute, thus affecting the execution of subsequent tasks. This allows for the reasonable allocation of service resources and improves the execution efficiency of asynchronous tasks.
[0077] Please see Figure 7 In some embodiments, step S105 includes, but is not limited to, steps S501 to S502:
[0078] Step S501: Determine the preset execution queuing strategy; wherein, the execution queuing strategy includes a first-in-first-out queuing strategy or a weighted queuing strategy.
[0079] Step S502: Based on the number of concurrent processing of the first asynchronous task, the rate limiting sorting result, and the preset execution queuing strategy, the asynchronous task consumer is invoked to execute the asynchronous task.
[0080] Understandably, asynchronous task execution systems first determine a preset execution queuing strategy. Optionally, the queuing strategy can be adjusted based on the asynchronous tasks to be executed. Understandably, if the queuing strategy is fixed, then the queuing method cannot be adjusted according to the urgency or configuration of the tasks, potentially affecting the execution progress of asynchronous tasks. Specifically, execution queuing strategies can include first-in-first-out (FIFO) queuing, weighted queuing, random queuing, weighted average queuing, etc.
[0081] Please see Figure 8 In some embodiments, step S105 includes, but is not limited to, steps S601 to S602:
[0082] Step S601: If the queuing strategy is first-in-first-out queuing, then the asynchronous tasks that enter the queue first will be executed first. After the asynchronous tasks that enter the queue first are completed, the asynchronous tasks that enter the queue later will be executed.
[0083] Step S602: If the queuing strategy is weighted queuing, then each time an asynchronous task enters the queue, all asynchronous tasks in the queue are queued according to their task weights. The asynchronous tasks with larger task weights are executed first, followed by the asynchronous tasks with smaller task weights; or the asynchronous tasks with smaller task weights are executed first, followed by the asynchronous tasks with larger task weights.
[0084] Understandably, when using a first-in, first-out (FIFO) queuing strategy, after asynchronous tasks enter the queue, the asynchronous task consumer executes the asynchronous tasks that entered the queue first, and then executes the asynchronous tasks added later. Specifically, in this process, after a new asynchronous task is added, the asynchronous task consumer executes it as the later-added asynchronous task. Using a FIFO queuing strategy to queue asynchronous tasks ensures that each asynchronous task is executed sequentially.
[0085] In some embodiments, asynchronous tasks can be queued according to their priority. Priority here refers to queuing asynchronous tasks based on their urgency. During the execution of an asynchronous task by a consumer, if the asynchronous task processing system receives information from the server indicating that a corresponding asynchronous task requires urgent processing, then that urgent asynchronous task will be processed first. It is understood that after processing the urgent asynchronous tasks, the original queuing strategy can be used to queue and execute the remaining asynchronous tasks, or a new queuing strategy can be formulated. Queuing asynchronous tasks according to their urgency allows for the priority execution of urgent asynchronous tasks, avoiding disruption to their processing.
[0086] In some embodiments, when the queuing strategy is weighted queuing, the asynchronous task processing system can execute asynchronous tasks according to their respective weights. Specifically, queuing can be based on the weights of each asynchronous task. In some embodiments, asynchronous tasks with higher weights can be executed first, where higher weights refer to tasks that are time-consuming and require a lot of resources, followed by asynchronous tasks with lower weights, where lower weights refer to tasks that are faster and consume fewer resources; or asynchronous tasks with lower weights can be executed first, followed by asynchronous tasks with higher weights.
[0087] Understandably, the queuing strategy can also be random queuing. That is, when an asynchronous task enters the queue, the asynchronous task processing system controls the asynchronous task consumer to randomly select one asynchronous task from the queue for execution. Once the asynchronous tasks in the queue are completed, a new asynchronous task is added to the queue for random allocation, employing a random queuing strategy. In some embodiments, random queuing can also add new asynchronous tasks to the queue and re-allocate them for execution while tasks are being executed in the queue. Using a random queuing strategy ensures that each asynchronous task has an equal probability of execution.
[0088] Please see Figure 9 In some embodiments, after step S105, there are steps S701 to S705, among others.
[0089] Step S701: If a single asynchronous task fails to execute, determine whether the number of retries has been exceeded;
[0090] Step S702: If no time limit is reached, call the asynchronous task consumer to re-execute the asynchronous task;
[0091] And / or,
[0092] Step S703: Obtain the preset execution time of the preset asynchronous task;
[0093] Step S704: Determine whether the execution time of each asynchronous task exceeds the preset execution time;
[0094] Step S705: If the preset execution time is exceeded, the execution status of the asynchronous task is determined to be a timeout state.
[0095] In some embodiments, if a single asynchronous task fails to execute, the failed asynchronous task is re-executed. Optionally, the number of re-executions can be 2, 3, 4, etc., and this application embodiment does not impose a specific limitation on this. It is understood that if the number of re-executions of a single asynchronous task exceeds the retry limit, and the asynchronous task still fails to execute, then the corresponding asynchronous task is stored in a cache middleware, and then returned to the server by the cache middleware.
[0096] In some embodiments, if the number of times an asynchronous task that failed to execute has been retried has not exceeded the retry count, the asynchronous task consumer is called to re-execute the asynchronous task until the corresponding asynchronous task is executed successfully or the re-execution time exceeds the retry count. At this point, the corresponding asynchronous task is stored in the cache middleware and then returned to the server by the cache middleware.
[0097] Understandably, retrying an asynchronous task when it fails can eliminate the impact of occasional factors, such as network fluctuations, on its execution.
[0098] In some embodiments, when a single asynchronous task is retried, or when a single asynchronous task is executed for the first time, it is determined whether the cumulative time of the asynchronous task retry or the time of the first execution of a single asynchronous task exceeds a preset execution time. If it exceeds the preset execution time, the execution status of the asynchronous task is determined to be a timeout state.
[0099] Understandably, by setting a preset execution time for asynchronous tasks, asynchronous tasks that fail to execute or take too long to execute can be stopped, thus preventing them from affecting the execution of other asynchronous tasks. In some embodiments, asynchronous tasks that have timed out are stored in a cache middleware and then returned to the server by the cache middleware, or they are stored in the cache middleware and wait for all asynchronous tasks to complete. That is, they are re-executed only when the asynchronous task processing system has no asynchronous tasks being processed.
[0100] Please see Figure 10 In some embodiments, after a single asynchronous task enters the asynchronous task processing system, it enters the cache middleware from the initial state to wait for execution. At this time, if a cancellation instruction is received from the server, the corresponding asynchronous task is cancelled and returned to the server.
[0101] In some embodiments, the asynchronous task consumer calls the relevant asynchronous task to a queue for queuing. During the execution of the asynchronous task by the asynchronous task consumer, if the asynchronous task is executed successfully, it is directly returned to the server; if the asynchronous task fails, it is determined whether the number of times the asynchronous task has been re-executed exceeds the number of retries; if it has not exceeded the number of retries, the asynchronous task consumer is called to re-execute the asynchronous task until the corresponding asynchronous task is executed successfully, or if it still fails after exceeding the number of retries, the corresponding asynchronous task is determined to have failed; or, if the execution time of the asynchronous task re-execution by the asynchronous task consumer exceeds the preset execution time and still fails to execute successfully, the corresponding asynchronous task is determined to have failed.
[0102] In some embodiments, if the execution time of a single task exceeds the preset execution time of an asynchronous task, the execution status of the asynchronous task is determined to be a timeout state.
[0103] Understandably, setting the status of asynchronous tasks executed by asynchronous task consumers to complete, failed, or timed out allows the asynchronous task processing system to know the execution status of asynchronous tasks in real time. In some embodiments, asynchronous tasks that fail or time out can be numbered and stored in a cache middleware. The asynchronous task processing system then decides whether to return to the server based on its settings. This avoids duplicate execution of the corresponding asynchronous task, thus preventing other asynchronous tasks from being executed repeatedly.
[0104] In some embodiments, the caching middleware also includes a cache queue, which temporarily stores asynchronous tasks that failed to be added to the queue or failed to execute after being successfully added to the queue. Setting up the caching middleware allows asynchronous tasks to be stored in the queue according to their execution status, preventing asynchronous task consumers from repeatedly executing asynchronous tasks. In some embodiments, the cache queue can also categorize asynchronous tasks so that the server knows the task dimension to which the failed asynchronous task belongs. In some embodiments, the cache queue can be sorted according to the time when asynchronous tasks entered the cache queue, so that asynchronous task consumers can execute asynchronous tasks in the order they occurred or return them to the server.
[0105] Please refer to Figure 11 For example, the overall execution process of the asynchronous task in this application will be described.
[0106] In some embodiments, the asynchronous task executor first calls the asynchronous task consumer to execute the asynchronous task. The asynchronous task service stores the asynchronous tasks divided by the asynchronous task processing system in the cache middleware. Among them, a portion of the asynchronous tasks are sorted in the queue. After obtaining the sorting result, the asynchronous task executor calls the asynchronous task consumer to execute the asynchronous task according to the queuing strategy.
[0107] Reference Figure 12 In some embodiments, this application proposes an asynchronous task processing system that can implement the above-described asynchronous task processing method. The asynchronous task processing system includes:
[0108] The task request acquisition module 1201 is used to acquire the task request received by the server. The task request includes multiple asynchronous tasks to be processed.
[0109] The asynchronous task partitioning module 1202 is used to partition asynchronous tasks according to preset dimensions and obtain the label information of each asynchronous task. The label information includes at least the first dimension label information.
[0110] The first asynchronous task concurrent processing quantity acquisition module 1203 is used to acquire the preset first asynchronous task concurrent processing quantity;
[0111] The asynchronous task sorting module 1204 is used to sort asynchronous tasks by rate limiting based on the first dimension label information and the rate limiting rules of the first dimension, and obtain the rate limiting sorting result.
[0112] The asynchronous task execution module 1205 is used to call the asynchronous task consumer to execute asynchronous tasks based on the number of concurrent processing of the first asynchronous task and the rate limiting sorting result.
[0113] In some embodiments, task requests are obtained by the server, and the controller classifies the task requests according to the instruction opcode. It is understood that task requests include asynchronous task requests and non-asynchronous task requests. Asynchronous tasks refer to tasks that are separated from the main process for execution, while non-asynchronous tasks refer to tasks executed by the main process. It is understood that after an asynchronous task is completed, it will return to the main process.
[0114] For example, asynchronous tasks are typically time-consuming, resource-intensive, or error-prone. If they are executed by the main process, it will affect other tasks that are normally shorter in duration, consume fewer resources, or are less prone to errors. In some embodiments, there are multiple asynchronous tasks, such as sending emails or instant messages, checking for spam, document processing, audio and video processing, image processing, calling external third-party services, importing / exporting large amounts of data, etc.
[0115] For example, the preset dimension can refer to the dimension of asynchronous tasks. In some embodiments, if asynchronous tasks provide services to various enterprises, then the first dimension of asynchronous tasks can be enterprise task information executed synchronously by the asynchronous processing system; the second dimension (N=2) of asynchronous tasks can be subsidiary task information of each enterprise; the third dimension (N=3) of asynchronous tasks can be department task information of each subsidiary; the fourth dimension (N=4) of asynchronous tasks can be team task information of each department, and so on. It is understandable that dividing asynchronous tasks into dimensions facilitates the asynchronous task processing system to rate-limit asynchronous tasks based on the label information of each dimension. This can solve the problem in some application scenarios where an excessive number of asynchronous tasks for a single user affects the execution of asynchronous tasks for other users. By implementing rate limiting for asynchronous tasks and rate limiting for a specific dimension of asynchronous tasks, the system avoids the problem of a single task taking too long to execute, thus affecting the execution of subsequent tasks. This allows for the reasonable allocation of service resources and improves the execution efficiency of asynchronous tasks.
[0116] In some embodiments, asynchronous tasks are divided according to preset dimensions to obtain tag information for each asynchronous task. This tag information can include information such as the memory size occupied by the asynchronous task, the time the asynchronous task was stored in the cache middleware, the estimated execution time of the asynchronous task, and the category information of the asynchronous task. In some embodiments, the tag information includes at least the first dimension tag information; optionally, the tag information can also include multiple tags from multiple dimensions. Obtaining the tag information of asynchronous tasks facilitates subsequent asynchronous task invocation, saves invocation time, makes the storage of asynchronous tasks more orderly, and ensures efficient execution of asynchronous tasks.
[0117] In some embodiments, the preset first concurrent asynchronous task processing number is the preset number of asynchronous tasks that the asynchronous task processing system can concurrently process. For example, if there are 4 asynchronous tasks, A, B, C, and D, and the preset first concurrent asynchronous task processing number is 3, then the asynchronous task processing system can concurrently process 3 asynchronous tasks. Optionally, the first concurrent asynchronous task processing number can be determined according to the order in which the 4 asynchronous tasks enter the asynchronous task processing system. In this case, the asynchronous tasks concurrently processed by the asynchronous task processing system are A, B, and C.
[0118] In some embodiments, the first dimension label information is the order in which all asynchronous tasks in the first dimension enter the asynchronous task processing system. For example, the first dimension label information may also be the estimated processing time information of a one-dimensional asynchronous task, the dimension information of each asynchronous task, the weight information of the asynchronous task, the storage information consumed by the asynchronous task, etc., and this application embodiment does not impose specific limitations here.
[0119] Understandably, the first-level rate limiting rule limits the concurrent processing capacity of asynchronous tasks in the first dimension. For example, if the first-level asynchronous tasks include A, B, C, and D, and A has A, B, and C asynchronous tasks in its two dimensions, and the first-level rate limiting rule states that the concurrent processing capacity of asynchronous tasks in the first dimension cannot exceed 2, then after applying the first-level rate limiting rule, the concurrent processing capacity of A's asynchronous tasks cannot exceed 2. Subsequently, if the order in which A's two-dimensional asynchronous tasks enter the asynchronous task processing system is A, B, C, then based on the first-dimensional tag information and the first-level rate limiting rule, the asynchronous tasks are rate-limited and sorted, resulting in a rate-limited sorting result of A and B. In some embodiments, if a single user has too many asynchronous tasks, it can affect the execution of asynchronous tasks for other users. By implementing rate limiting for asynchronous tasks, and rate limiting for a specific dimension of asynchronous tasks, we can avoid the problem of a single task taking too long to execute, thus affecting the execution of subsequent tasks. Simultaneously, we can also rationally allocate service resources and improve the execution efficiency of asynchronous tasks.
[0120] In some embodiments, an asynchronous task consumer is invoked to execute asynchronous tasks based on the number of concurrent asynchronous tasks and the rate-limiting sorting result. It is understood that the asynchronous task consumer executes asynchronous tasks under the control of the controller. For example, if there are asynchronous tasks A, B, C, and D in the first-level dimension, and the corresponding second-level asynchronous tasks A, B, and C are A, B, and C, and the rate-limiting sorting result for A's corresponding second-level asynchronous tasks is A and B; the corresponding second-level asynchronous tasks B are D, E, and F, and the sorting result for B's corresponding second-level asynchronous tasks is D and E; the corresponding second-level asynchronous tasks C are G, H, and I, and the sorting result for C's corresponding second-level asynchronous tasks is G and H; and the corresponding second-level asynchronous tasks D are J, K, and L, and the sorting result for D's corresponding second-level asynchronous tasks is J and K. If the number of concurrent asynchronous tasks in the first asynchronous task is 3, based on the first-level label information, the order in which A, B, C, and D enter the asynchronous task processing system is A, B, C, and D. After rate-limiting sorting, it is determined that the asynchronous tasks to be executed by the asynchronous task consumer are A, B, and D. In some embodiments, if a single user has too many asynchronous tasks, it may affect the execution of asynchronous tasks for other users. By implementing rate limiting for asynchronous tasks, or rate limiting for a specific dimension of asynchronous tasks, we can avoid the problem of a single task taking too long to execute, which could affect the execution of subsequent tasks. At the same time, we can also allocate service resources reasonably and improve the execution efficiency of asynchronous tasks.
[0121] In some embodiments, if the asynchronous task execution system detects that the total number of asynchronous tasks does not exceed the concurrent processing limit for asynchronous tasks, it will no longer rate-limit the asynchronous tasks according to the dimensional rate-limiting rules. That is, after dividing the asynchronous tasks and obtaining their tag information, the system obtains the preset concurrent processing limit for asynchronous tasks. Then, without relying on dimensional rate-limiting rules, it directly sorts the asynchronous tasks based on the dimensional tag information, obtains the rate-limiting ranking result, and then calls the asynchronous task consumer to execute the asynchronous tasks based on the concurrent processing limit and the rate-limiting ranking result. It can be understood that when the number of asynchronous tasks does not exceed the concurrent processing limit, rate-limiting is no longer necessary, thus saving server resources, reducing the waiting time of asynchronous tasks, and improving the execution efficiency of asynchronous tasks.
[0122] In some embodiments, the number of concurrent asynchronous tasks can be the number of asynchronous tasks executed in parallel by the asynchronous task processing system. It is understood that limiting the number of concurrent asynchronous tasks can prevent congestion and lag in the asynchronous task processing system caused by too many asynchronous tasks being executed simultaneously, thus affecting the operation of the entire asynchronous task processing system.
[0123] In some embodiments, the first-level dimensional rate limiting rule is: the number of concurrent processing operations for asynchronous tasks with the same or similar first-dimensional label information does not exceed a preset number of concurrent processing operations for one-dimensional tasks. For example, if there are asynchronous tasks A, B, and C, and the preset number of concurrent processing operations for one-dimensional tasks is 3, this can also be understood as the preset number of concurrent processing operations for asynchronous tasks being 3. Therefore, the actual number of concurrent processing operations for asynchronous tasks running in the asynchronous task processing system cannot exceed 3. It is understood that the asynchronous task processing system also includes multi-level dimensional rate limiting rules. The multi-level dimensional rate limiting rule is that the number of concurrent processing operations for asynchronous tasks with the same or similar Nth-dimensional label information does not exceed a preset number of concurrent processing operations for multi-dimensional tasks, where N is a positive integer greater than or equal to 2.
[0124] In some embodiments, the primary dimension can be a region dimension, an enterprise dimension, or an IP address dimension, etc., and can be set as needed. Taking the enterprise dimension as the primary dimension as an example, the preset number of concurrent processing of a one-dimensional task does not exceed the number of concurrent processing of the first asynchronous task. In some embodiments, the number of concurrent asynchronous tasks processed in a single region dimension does not exceed the total number of concurrent asynchronous tasks executed by the asynchronous task consumer.
[0125] The specific implementation of this asynchronous task processing system is basically the same as the specific embodiments of the asynchronous task processing method described above, and will not be repeated here. Subject to meeting the requirements of the embodiments of this application, the asynchronous task processing system may also be equipped with other functional modules to implement the asynchronous task processing method in the above embodiments.
[0126] This application also provides an electronic device, which includes a memory and a processor. The memory stores a computer program, and the processor executes the computer program to implement the above-described asynchronous task processing method. This electronic device can be any smart terminal, including tablet computers, in-vehicle computers, etc.
[0127] Please see Figure 13 , Figure 13 The hardware structure of an electronic device according to another embodiment is illustrated. The electronic device includes:
[0128] The processor 1301 can be implemented using a general-purpose CPU (Central Processing Unit), microprocessor, application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of this application.
[0129] The memory 1302 can be implemented as a read-only memory (ROM), a static storage device, a dynamic storage device, or a random access memory (RAM). The memory 1302 can store the operating system and other applications. When the technical solutions provided in the embodiments of this specification are implemented through software or firmware, the relevant program code is stored in the memory 1302 and is called and executed by the processor 1301 using the asynchronous task processing method of the embodiments of this application.
[0130] The input / output interface 1303 is used to implement information input and output;
[0131] The communication interface 1304 is used to enable communication and interaction between this device and other devices. Communication can be achieved through wired means (such as USB, Ethernet cable, etc.) or wireless means (such as mobile network, WIFI, Bluetooth, etc.).
[0132] Bus 1305 transmits information between various components of the device (e.g., processor 1301, memory 1302, input / output interface 1303, and communication interface 1304);
[0133] The processor 1301, memory 1302, input / output interface 1303 and communication interface 1304 are connected to each other within the device via bus 1305.
[0134] This application also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the above-described asynchronous task processing method.
[0135] Memory, as a non-transitory computer-readable storage medium, can be used to store non-transitory software programs and non-transitory computer-executable programs. Furthermore, memory may include high-speed random access memory, and may also include non-transitory memory, such as at least one disk storage device, flash memory device, or other non-transitory solid-state storage device. In some embodiments, memory may optionally include memory remotely located relative to the processor, and these remote memories can be connected to the processor via a network. Examples of such networks include, but are not limited to, the Internet, intranets, local area networks, mobile communication networks, and combinations thereof.
[0136] The embodiments described in this application are for the purpose of more clearly illustrating the technical solutions of the embodiments of this application, and do not constitute a limitation on the technical solutions provided by the embodiments of this application. As those skilled in the art will know, with the evolution of technology and the emergence of new application scenarios, the technical solutions provided by the embodiments of this application are also applicable to similar technical problems.
[0137] Those skilled in the art will understand that the technical solutions shown in the figures do not constitute a limitation on the embodiments of this application, and may include more or fewer steps than shown, or combine certain steps, or different steps.
[0138] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs.
[0139] Those skilled in the art will understand that all or some of the steps in the methods disclosed above, as well as the functional modules / units in the systems and devices, can be implemented as software, firmware, hardware, or suitable combinations thereof.
[0140] The terms “first,” “second,” “third,” “fourth,” etc. (if present) in the specification and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. 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 comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0141] It should be understood that in this application, "at least one (item)" means one or more, and "more than" means two or more. "And / or" is used to describe the relationship between related objects, indicating that three relationships can exist. For example, "A and / or B" can represent 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 " / " generally indicates that the preceding and following related objects are in an "or" relationship. "At least one (item) of the following" or similar expressions refer to any combination of these items, including any combination of single or plural items. For example, at least one (item) of a, b, or c can represent: 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.
[0142] In the embodiments provided in this application, it should be understood that the disclosed systems and methods can be implemented in other ways. For example, the system embodiments described above are merely illustrative; for instance, the division of the units described above 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 an indirect coupling or communication connection through some interfaces, devices, or units, and may be electrical, mechanical, or other forms.
[0143] The units described above 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.
[0144] Furthermore, 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. The integrated unit can be implemented in hardware or as a software functional unit.
[0145] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes multiple instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned storage medium includes various media capable of storing programs, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0146] The preferred embodiments of the present application have been described above with reference to the accompanying drawings, but this does not limit the scope of the claims of the present application. Any modifications, equivalent substitutions, and improvements made by those skilled in the art without departing from the scope and substance of the embodiments of the present application shall be within the scope of the claims of the present application.
Claims
1. An asynchronous task processing method, characterized by, The method comprises: The task request received by the server comprises a plurality of asynchronous tasks to be processed; According to the preset dimensions, the asynchronous tasks are divided to obtain label information of each asynchronous task, the label information being memory size information occupied by the asynchronous task, time information of the asynchronous task stored in the cache middleware, estimated execution time information of the asynchronous task, and category information of the asynchronous task, the label information comprising first-dimension label information and Nth-dimension label information, N being a positive integer greater than or equal to 2; A preset first asynchronous task concurrent processing quantity is obtained; The asynchronous tasks are sorted according to the first-dimension label information and the first-dimension flow limiting rule to obtain a flow limiting sorting result, and then the Nth-dimension label information and the Nth-dimension flow limiting rule are obtained; the flow limiting sorting result of the asynchronous tasks is updated to obtain an updated flow limiting sorting result; the Nth-dimension flow limiting rule is that the concurrent processing quantity of asynchronous tasks with the same or same type Nth-dimension label information does not exceed a preset Nth-dimension task concurrent processing quantity; According to the first asynchronous task concurrent processing quantity and the flow limiting sorting result, the asynchronous task consumer is called to execute the asynchronous tasks.
2. The asynchronous task processing method according to claim 1, wherein The first-dimension flow limiting rule is that the concurrent processing quantity of asynchronous tasks with the same or same type first-dimension label information does not exceed a preset one-dimension task concurrent processing quantity; According to the first asynchronous task concurrent processing quantity, the number of asynchronous tasks that need to be concurrently executed and the number of asynchronous tasks that need to be stored in the cache middleware for execution are determined; According to the first-dimension flow limiting rule, if the concurrent processing quantity of asynchronous tasks with the same or same type first-dimension label information exceeds the preset one-dimension task concurrent processing quantity, the asynchronous tasks exceeding the one-dimension task concurrent processing quantity are stored in the cache middleware for execution, and asynchronous tasks with other type label information are added to the asynchronous tasks for concurrent execution to obtain the flow limiting sorting result. The cache middleware is provided with a queue, and after the asynchronous task consumer is called to execute the asynchronous tasks according to the first asynchronous task concurrent processing quantity and the flow limiting sorting result, the method further comprises:
3. The asynchronous task processing method of claim 2, wherein, The asynchronous task consumer detects that the asynchronous tasks in the queue have been executed; The asynchronous tasks in the cache middleware for execution are added to the queue, the asynchronous tasks for execution being asynchronous tasks that have been scheduled but not executed. The asynchronous task consumer is called to execute the asynchronous tasks according to the first asynchronous task concurrent processing quantity and the flow limiting sorting result, comprising:
4. The asynchronous task processing method of claim 1, wherein, A preset execution queuing strategy is determined; wherein the execution queuing strategy comprises a first-in-first-out queuing strategy or a weight queuing strategy; The asynchronous task consumer is called to execute the asynchronous tasks according to the first asynchronous task concurrent processing quantity, the flow limiting sorting result, and the preset execution queuing strategy. 5. The asynchronous task processing method of claim 4, wherein, The calling of the asynchronous task consumer to execute the asynchronous task according to the first asynchronous task concurrent processing quantity and the result of the flow limiting sorting comprises: If the execution queuing strategy is first-in-first-out queuing, the asynchronous task first entering the queue is executed first, and after the execution of the asynchronous task first entering the queue is completed, the asynchronous task entering the queue later is executed; If the queuing strategy is weight queuing, when each asynchronous task enters the queue, all the asynchronous tasks in the queue are queued according to task weights, the asynchronous task with a large task weight is executed first, and then the asynchronous task with a small task weight is executed; or the asynchronous task with a small task weight is executed first, and then the asynchronous task with a large task weight is executed.
6. The asynchronous task processing method of claim 1, wherein, After the calling of the asynchronous task consumer to execute the asynchronous task according to the first asynchronous task concurrent processing quantity and the result of the flow limiting sorting, the method further comprises: If a single asynchronous task execution fails, it is judged whether the number of retries is exceeded; If the number of retries is not exceeded, the asynchronous task consumer is called to re-execute the asynchronous task; and / or, a preset execution time of the asynchronous task is obtained; it is judged whether the execution time of each asynchronous task exceeds the preset execution time; if the preset execution time is exceeded, it is judged that the execution state of the asynchronous task is a timeout state.
7. An asynchronous task processing system, characterized by The system comprises: a task request acquisition module configured to acquire a task request received by a server, the task request comprising a plurality of asynchronous tasks to be processed; an asynchronous task division module configured to divide the asynchronous tasks according to a preset dimension to obtain label information of each asynchronous task, the label information comprising memory size information occupied by the asynchronous task, time information of storage of the asynchronous task in a cache middleware, estimated execution time information of the asynchronous task, and category information of the asynchronous task, the label information comprising first dimension label information and Nth dimension label information, N being a positive integer greater than or equal to 2; a first asynchronous task concurrent processing quantity acquisition module configured to acquire a preset first asynchronous task concurrent processing quantity; an asynchronous task sorting module configured to sort the asynchronous tasks according to the first dimension label information and a first-level dimension flow limiting rule to obtain a flow limiting sorting result, and then acquire Nth dimension label information and an Nth-level dimension flow limiting rule; update the flow limiting sorting result of the asynchronous tasks to obtain an updated flow limiting sorting result; the Nth-level dimension flow limiting rule being that the concurrent processing quantity of the same or same type Nth dimension label information does not exceed a preset Nth task concurrent processing quantity; an asynchronous task execution module configured to call an asynchronous task consumer to execute the asynchronous task according to the first asynchronous task concurrent processing quantity and the result of the flow limiting sorting.
8. An electronic device, comprising: The electronic device comprises a memory and a processor, the memory stores a computer program, and the processor implements the asynchronous task processing method of any one of claims 1 to 6 when executing the computer program.
9. A computer readable storage medium, the storage medium having stored thereon a computer program, characterized in that, The computer program is executed by the processor to implement the asynchronous task processing method of any one of claims 1 to 6.
Citation Information
Patent Citations
Real-time task scheduling control method, system and device and readable storage medium
CN111367645A
Concurrent request processing method and device, server and storage medium
CN113342498A