Task processing method
By splitting the asynchronous scheduling tasks in financial business operations into multiple subtasks, and pulling these subtasks from the database when the instance device is idle for processing, the problem of too long task processing caused by limited number of threads is solved, and more efficient task processing is achieved.
Patent Information
- Application Number
- CN202411598181.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-08
- Publication Date
- 2025-02-28
AI Technical Summary
In financial business operations, asynchronous scheduling tasks are limited in number of threads due to resource limitations, and they cannot efficiently process a large number of complex tasks, resulting in too long processing.
By splitting the target tasks into multiple subtasks and inserting these subtasks into a preset database, when there are idle threads in the instance device, the subtasks are pulled from the database for processing until all subtasks are completed.
This method can increase the number of instance devices that process tasks, share the pressure of a single instance, reduce task processing time, and improve task processing efficiency.
Smart Images

Figure CN119537010A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a task processing method. Background Art
[0002] Asynchronous scheduling tasks are very common task operations in backend application services. The purpose is to asynchronously and parallelly process multiple tasks under a business operation so that the business operation can be processed quickly and responded to in a timely manner, such as processing financial business operations. The implementation scheme of asynchronous scheduling tasks basically uses the multi-threading method in the thread pool under the application instance that currently receives the business request to complete asynchronous scheduling.
[0003] This method can achieve the desired purpose when the task volume is small and the processing is not complicated. However, due to the resource limitations of the instance (CPU, memory, etc.), the thread pool size can only be set within a reasonable range, so the number of threads is limited. When the task volume corresponding to the financial business operation is large and the processing is complex, a large number of tasks need to queue up and wait for the thread to be idle before processing, resulting in the entire financial business operation processing taking too long.
[0004] Therefore, there is an urgent need for a method to improve the efficiency of financial business processing to reduce processing time. Summary of the invention
[0005] The main purpose of the embodiments of the present application is to provide a task processing method and device, an electronic device and a storage medium, aiming to improve the efficiency of task processing.
[0006] To achieve the above-mentioned purpose, a first aspect of an embodiment of the present application proposes a task processing method, which is applied to a first example device, and the method includes:
[0007] In some embodiments, a business operation request is received, where the business operation request is used to request processing of a target task of a target business.
[0008] In some embodiments, in response to the business operation request, the target task is split to obtain a plurality of first subtasks associated with the target business.
[0009] In some embodiments, the multiple first subtasks are inserted into a preset database. In the preset database, each of the multiple first subtasks is used as a task to be processed, and when there is an idle thread in the target instance device, the target instance device pulls the task to be processed from the preset database, and processes the task to be processed based on the idle thread until the task to be processed in the preset database is processed, so as to complete the processing of the target task, and the target instance device includes at least one second instance device.
[0010] In some embodiments, if the first instance device has an idle thread, the to-be-processed task is pulled from the preset database, and the pulled to-be-processed task is processed based on the idle thread.
[0011] In combination with the first aspect, in a possible implementation manner, the step of pulling the to-be-processed tasks from the preset database includes:
[0012] Obtaining a first idle thread number of the first instance device, rounding the quotient of the first idle thread number of the first instance device and the initial thread number to obtain a first target pull number; the initial thread number is a preset number of threads initially allocated to a new subtask;
[0013] Pulling a first target from the preset database pulls a plurality of tasks to be processed.
[0014] In combination with the first aspect, in a possible implementation manner, the above-mentioned processing of the pulled tasks to be processed based on the idle thread includes:
[0015] Allocate the corresponding initial number of threads to each newly pulled task to be processed;
[0016] Process each pending task based on the assigned thread.
[0017] In combination with the first aspect, in a possible implementation manner, after the allocated thread processes each to-be-processed task, the following steps are included:
[0018] When the second subtask is executed and a new idle thread is released, the number of second idle threads of the first instance device and the first remaining execution time of each second subtask in the first instance device are obtained; wherein the second subtask is the subtask being processed by the first instance device;
[0019] Allocating the released idle threads to the second subtasks based on the number of the second idle threads and the first remaining execution time of each second subtask;
[0020] The second subtask is processed based on the allocated thread.
[0021] In combination with the first aspect, in a possible implementation manner, allocating the released idle thread to the second subtask based on the number of the second idle threads and the first remaining execution time of each second subtask includes:
[0022] Determine a first number of threads to be added for each of the second subtasks based on a first remaining execution time of each of the second subtasks; wherein the first number of threads to be added is the number of threads required to be added for the second subtask;
[0023] Calculate the sum of the first number of threads to be added of each of the second subtasks to obtain a first target number of threads;
[0024] Determine the first number of threads to be allocated for each of the second subtasks based on the second number of idle threads and the first target number of threads; wherein the first number of threads to be allocated is the number of threads actually allocated to the second subtask;
[0025] According to the first number of threads to be allocated of each of the second subtasks, the released idle threads are allocated to the second subtasks.
[0026] In combination with the first aspect, in a possible implementation manner, determining the first number of threads to be allocated for each of the second subtasks based on the second number of idle threads and the first target number of threads includes:
[0027] If the second number of idle threads is greater than or equal to the first target number of threads, determining the first number of threads to be allocated for each of the second subtasks to be the corresponding first number of threads to be added;
[0028] If the second number of idle threads is less than the first target number of threads, the ratio between the first numbers of threads to be added is obtained, and the number of first threads to be allocated for each second subtask is determined according to the ratio and the second number of idle threads.
[0029] To achieve the above-mentioned purpose, a second aspect of an embodiment of the present application proposes a task processing method, which is applied to a second example device, and the method includes:
[0030] In some embodiments, when the existence of an idle thread is detected, pending tasks are pulled from a preset database, wherein the pending tasks in the preset database include multiple first subtasks inserted by a first instance device, the first subtask is a subtask associated with a target business, and the multiple first subtasks are obtained by splitting the target task by the first instance device in response to a business operation request, and the business operation request is used to request processing of the target task of the target business; the second instance device is an instance device other than the first instance device.
[0031] In some embodiments, when the to-be-processed task is pulled, the to-be-processed task is processed based on the idle thread.
[0032] In conjunction with the second aspect, in a possible implementation, the step of pulling the to-be-processed tasks from the preset database includes:
[0033] Obtaining the third idle thread number of the second instance device, rounding the quotient of the third idle thread number of the second instance device and the initial thread number to obtain a second target pull number; the initial thread number is a preset number of threads initially allocated to the new subtask;
[0034] Pulling a second target from the preset database pulls a plurality of tasks to be processed.
[0035] In conjunction with the second aspect, in a possible implementation manner, the processing of the to-be-processed task based on the idle thread includes:
[0036] Allocate the corresponding initial number of threads to each newly pulled task to be processed;
[0037] Process each pending task based on the assigned thread.
[0038] In conjunction with the second aspect, in a possible implementation, after the allocated thread processes each to-be-processed task, the following steps are performed:
[0039] When the third subtask is executed and a new idle thread is released, the number of fourth idle threads of the second instance device and the second remaining execution time of each third subtask in the second instance device are obtained; wherein the third subtask is the subtask being processed by the second instance device;
[0040] Allocating the released idle thread to the third subtask based on the fourth number of idle threads and the second remaining execution time of each third subtask;
[0041] The third subtask is processed based on the allocated thread.
[0042] In combination with the second aspect, in a possible implementation manner, allocating the released idle thread to the third subtask based on the fourth number of idle threads and the second remaining execution time of each third subtask includes:
[0043] Determine a second number of threads to be added for each of the third subtasks based on the second remaining execution time of each of the third subtasks; wherein the second number of threads to be added is the number of threads required to be added for the third subtask;
[0044] Calculate the sum of the second number of threads to be added of each of the third subtasks to obtain a second target number of threads;
[0045] Based on the fourth number of idle threads and the second target number of threads, determining the second number of threads to be allocated for each of the third subtasks; wherein the second number of threads to be allocated is the number of threads actually allocated to the third subtask;
[0046] According to the number of second threads to be allocated of each of the third subtasks, the released idle threads are allocated to the third subtasks.
[0047] In combination with the second aspect, in a possible implementation manner, determining the number of second threads to be allocated for each of the third subtasks based on the fourth number of idle threads and the second target number of threads includes:
[0048] If the fourth number of idle threads is greater than or equal to the second target number of threads, determining the second number of threads to be allocated for each of the third subtasks to be the corresponding second number of threads to be added;
[0049] If the fourth number of idle threads is less than the second target number of threads, the ratio between the second numbers of threads to be added is obtained, and the number of second threads to be allocated for each third subtask is determined according to the ratio and the fourth number of idle threads.
[0050] To achieve the above-mentioned purpose, a third aspect of an embodiment of the present application provides a task processing device, which may include at least one instance device of a first instance device and a second instance device, or include the first instance device and at least one second instance device;
[0051] If the task processing device includes a first instance device, the task processing device includes:
[0052] The request receiving module is used to receive a business operation request, wherein the business operation request is used to request processing of a target task of a target business.
[0053] The request response module is used to respond to the business operation request and split the target task to obtain multiple first subtasks associated with the target business.
[0054] The task insertion module is used to insert the multiple first subtasks into a preset database, wherein in the preset database, each of the multiple first subtasks is used as a task to be processed.
[0055] The first task processing module is used to pull the to-be-processed tasks from the preset database if there are idle threads in the first instance device, and process the pulled to-be-processed tasks based on the idle threads.
[0056] And when there is an idle thread in the target instance device, the target instance device pulls the pending tasks from the preset database and processes the pending tasks based on the idle thread until the pending tasks in the preset database are processed to complete the processing of the target tasks, and the target instance device includes at least one second instance device.
[0057] If the task processing device includes a second instance device, the task processing device includes:
[0058] A task pulling module is used to pull pending tasks from a preset database when an idle thread is detected, wherein the pending tasks in the preset database include multiple first subtasks inserted by a first instance device, the first subtask is a subtask associated with a target business, and the multiple first subtasks are obtained by splitting the target task by the first instance device in response to a business operation request, and the business operation request is used to request processing of the target task of the target business; the second instance device is an instance device other than the first instance device.
[0059] The second task processing module processes the task to be processed based on the idle thread when the task to be processed is pulled.
[0060] To achieve the above-mentioned purpose, the fourth aspect of an embodiment of the present application proposes an electronic device, which includes a memory and a processor, the memory stores a computer program, and the processor implements the method described in the first aspect and / or the second aspect when executing the computer program.
[0061] To achieve the above objectives, the fifth aspect of an embodiment of the present application proposes a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, it implements the method described in the first aspect and / or the second aspect.
[0062] The present application proposes a task processing method and device, an electronic device, and a storage medium, which splits the current target task into multiple subtasks through a first instance device, and inserts multiple first subtasks into a preset database, and the target instance device and the first instance device pull the first subtask from the preset database for processing, wherein the target instance includes at least one second instance device. In this way, more instance devices for processing tasks can be added to share the pressure of overcrowding of a single instance due to a small number of instances, and reduce the task processing time. BRIEF DESCRIPTION OF THE DRAWINGS
[0063] Figure 1 is an optional flowchart of a task processing method applied to a first example device provided in an embodiment of the present application;
[0064] Figure 2 yes Figure 1 Flow chart of step S104 in FIG.
[0065] Figure 3 yes Figure 1Flow chart of step S104 in FIG.
[0066] Figure 4 yes Figure 3 Flow chart of the steps after step S302 in FIG.
[0067] Figure 5 yes Figure 4 Flow chart of step S402 in FIG.
[0068] Figure 6 yes Figure 4 Flow chart of the steps after step S402 in FIG.
[0069] Figure 7 is an optional flow chart of a task processing method applied to a second example device;
[0070] Figure 8 yes Figure 7 Flow chart of step S701 in FIG.
[0071] Fig. 9 yes Figure 7 Flowchart of step S702 in FIG.
[0072] Fig.10 yes Fig. 9 Flow chart of the steps after step S902 in FIG. 1 ;
[0073] Fig.11 yes Fig.10 Flow chart of step S111 in FIG.
[0074] Fig.12 yes Fig.10 Flow chart of the steps after step S111 in;
[0075] Fig.13 is a structural diagram of a first example of a task processing device provided in an embodiment of the present application;
[0076] Fig.14 is a structural diagram of a second example of a task processing device provided in an embodiment of the present application;
[0077] Fig.15 It is a schematic diagram of the hardware structure of the electronic device provided in the embodiment of the present application. DETAILED DESCRIPTION
[0078] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0079] It should be noted that, although the functional modules are divided in the device schematic diagram and the 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 above drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.
[0080] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein are only for the purpose of describing the embodiments of this application and are not intended to limit this application.
[0081] The embodiments of the present application provide a task processing method, device, electronic device and storage medium, aiming to improve task processing efficiency.
[0082] The task processing method and device, electronic device and storage medium provided in the embodiments of the present application are specifically described through the following embodiments. First, the task processing method in the embodiments of the present application is described.
[0083] The embodiments of the present application can acquire and process relevant data based on artificial intelligence technology. Among them, artificial intelligence (AI) is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results.
[0084] AI basic technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing technology, operation / interaction systems, mechatronics, etc. AI software technologies mainly include computer vision technology, robotics technology, biometrics technology, speech processing technology, natural language processing technology, and machine learning / deep learning.
[0085] The task processing method provided in the embodiment of the present application relates to the field of data processing technology. The task processing method provided in the embodiment of the present application can be applied to a terminal, can be applied to a server side, or can be software running in a terminal or a server side. In some embodiments, the terminal can be a smart phone, a tablet computer, a laptop computer, a desktop computer, etc.; the server side can be configured as an independent physical server, or can be configured as a server cluster or a distributed system composed of multiple physical servers, and can also be configured as a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms; the software can be an application that implements the task processing method, etc., but is not limited to the above forms.
[0086] The present application can be used in many general or special computer system environments or configurations. For example: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, distributed computing environments including any of the above systems or devices, etc. The present application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present application can also be practiced in distributed computing environments, in which tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media including storage devices.
[0087] The embodiment of the present application provides a task processing method applied to a first instance device and a task processing method applied to a second instance device. The first instance device and the second instance device are different instance devices.
[0088] Figure 1 is an optional flowchart of a task processing method applied to a first example device provided in an embodiment of the present application. Figure 1 The method may include but is not limited to steps S101 to S103.
[0089] Step S101: receiving a business operation request.
[0090] Step S102: In response to the business operation request, split the target task to obtain a plurality of first subtasks associated with the target business.
[0091] Step S103, inserting the plurality of first subtasks into a preset database;
[0092] Step S104: If the first instance device has an idle thread, then pull the to-be-processed tasks from the preset database, and process the pulled to-be-processed tasks based on the idle thread.
[0093] The first instance device is the first instance device to receive the business operation request, the business operation request is used to request processing of the target task of the target business, the target business is the business to be executed currently, and can be a financial business, such as a banking business, and the first subtask is a subtask obtained by splitting the target task. Task splitting is to split the current task into smaller and easier to manage tasks.
[0094] In step S102 of some embodiments, when splitting the task, each subtask can be clearly defined, including the name of the subtask, the content of the task, and the output result of the task, and the subtasks are arranged according to the priority of the subtasks to obtain multiple first subtasks associated with the target business. For example, the task is split into 5 subtasks (including subtask A, subtask B, subtask C, subtask D, and subtask F), and the priority of each subtask is determined according to the name of the subtask, the content of the task, and the output result of the task. If the priorities of the 5 subtasks are subtask A, subtask B, subtask C, subtask D, and subtask F, the subtasks are arranged as subtask A, subtask B, subtask C, subtask D, and subtask F.
[0095] The preset database is a database for storing the first subtasks. In step S103 of some embodiments, the first instance device is connected to the preset database and outputs the arranged multiple first subtasks to the preset database for storage.
[0096] In the preset database, the status of each newly inserted first subtask is set to be processed, so that each first subtask is used as a task to be processed.
[0097] In a possible implementation, after inserting multiple first subtasks into a preset database, determine whether to expand the second instance device. If not, only the first instance device is used to process the first subtasks. If necessary, expand the second instance device, which is an instance device other than the first instance device. In the case where there are idle threads in the target instance device, the target instance device pulls the pending tasks from the preset database, and processes the pending tasks based on the idle threads until the pending tasks in the preset database are processed, so as to complete the processing of the target tasks. The target instance device includes at least one second instance device.
[0098] Specifically, it is possible to determine whether to expand a new instance device by calculating the thread usage of the current existing instance device. For example, when the thread usage of the first instance device exceeds a preset usage threshold, the first and second instance devices are expanded. When the thread usage of the first, second and first instance devices both exceed the preset usage threshold, the third instance device is expanded, and so on. Wherein, thread usage = number of threads being executed / maximum number of threads configured for the instance device.
[0099] In steps S101 to S104 shown in the embodiment of the present application, since the underlying resources (CPU, memory, etc.) of a single instance device are limited, a single instance device cannot infinitely expand its hardware resources vertically. Therefore, by splitting the target task into multiple subtasks and having multiple instance devices perform asynchronous processing on the multiple subtasks, the processing pressure of a single instance device can be reduced. Using multiple instance devices to perform asynchronous processing on multiple subtasks can speed up task processing and improve task processing efficiency.
[0100] See also Figure 2 In some embodiments, step S104 may include but is not limited to steps S201 to S202:
[0101] Step S201, obtaining the first idle thread number of the first instance device, rounding the quotient of the first idle thread number of the first instance device and the initial thread number to obtain a first target pull number.
[0102] Step S202: Pull a first target and a plurality of tasks to be processed from the preset database.
[0103] The first idle thread number is the number of idle threads currently in the first instance device, where the idle thread is an unused thread, and the initial thread number is the number of threads initially allocated to a new subtask, which can be preset according to demand. The first target pull number is the number of pending tasks that can be processed by the current first instance device, which can be understood as the number of additional pending tasks that can be processed while ensuring the processing speed of the subtask currently being processed by the first instance device, which can be determined according to the rules formulated in this embodiment.
[0104] In step S201 of some embodiments, by identifying threads that have not executed subtasks, the first idle thread number of the first instance device is obtained, and the quotient of the first idle thread number of the first instance device and the initial thread number is calculated. Since the first target pull number is a quantitative value, which is a positive integer, when the first idle thread number and the initial thread number are not a multiple relationship, a decimal may be obtained. Therefore, in this embodiment, the quotient of the first idle thread number of the first instance device and the initial thread number is rounded to obtain the first target pull number.
[0105] In order to process subtasks more efficiently, in this embodiment, the quotient of the first idle thread number and the initial thread number of the first instance device is rounded down to obtain the first target pull number. For example, the first idle thread number is 10, the initial thread number is 3, and the quotient of 10 divided by 3 is approximately equal to 3.3, then the first target pull number is 3.
[0106] In step S202 of some embodiments, the status of the first subtask that has not been pulled from the preset database is pending. When the pending task is pulled from the preset database, the status of the pending task is modified to being processed, and the pending task is pulled into the task waiting queue of the first instance device to wait for the allocation of a thread.
[0107] The task waiting queue is used to store pending tasks waiting for the thread to be assigned. Putting the pending tasks into the task waiting queue of the second instance device can be regarded as a successful pull.
[0108] In a possible implementation manner, the first subtasks may be pulled in sequence according to the arrangement order of the first subtasks.
[0109] It should be noted that the number of first subtasks stored in the preset database is not necessarily greater than the first target pulling number. If the number of first subtasks that have not been pulled in the preset database is less than the first target pulling number, all pending tasks can be pulled from the preset database to the task waiting queue of the first instance device.
[0110] Step S201-step S202 determines the first target pull number based on the first idle thread number and the initial thread number of the first instance device, and can pull an appropriate number of tasks to be processed while ensuring the current task processing speed of the first instance device, thereby ensuring the efficiency of subsequent task processing.
[0111] In addition, by pulling and processing the tasks to be processed in order according to their priority, urgent subtasks can be processed first.
[0112] See also Figure 3 In some embodiments, step S104 may include but is not limited to steps S301 to S302:
[0113] Step S301 , allocating threads of the corresponding initial number of threads to each newly pulled task to be processed.
[0114] Step S302: Process each to-be-processed task based on the assigned thread.
[0115] In step S301 of some embodiments, for example, if the initial number of threads may be 1, then a corresponding thread is allocated to each newly pulled task to be processed.
[0116] In step S302 of some embodiments, threads to which each task to be processed is assigned are used to process the corresponding task to be processed respectively.
[0117] Step S301-Step S302 allocates the number of threads equal to the initial number of threads to each newly pulled task to be processed, and uses the allocated threads to process each task to be processed. Since the number of newly pulled tasks to be processed is based on the first number of idle threads and the initial number of threads, it is possible to fully utilize the threads of the current first instance device without wasting thread resources, and process as many tasks to be processed as possible while ensuring efficiency.
[0118] See also Figure 4 In some embodiments, step S302 may include but is not limited to steps S401 to S403:
[0119] Step S401, when the second subtask is executed and a new idle thread is released, the number of second idle threads of the first instance device and the first remaining execution time of each second subtask in the first instance device are obtained.
[0120] Step S402: allocating the released idle threads to the second subtasks based on the number of the second idle threads and the first remaining execution time of each second subtask.
[0121] Step S403: Process the second subtask based on the allocated thread.
[0122] The above-mentioned second number of idle threads is the number of idle threads of the current first instance device, the above-mentioned second subtask is the subtask being processed by the first instance device, the above-mentioned first remaining execution time is the current remaining execution time of the second subtask, and the first remaining execution time is the time required to complete the execution of the second subtask. For example, the subtasks being processed by the first instance device include subtask A, subtask B and subtask C, then subtask A, subtask B and subtask C are all second subtasks. If subtask A still has 50s to be processed in the current state, then the first remaining execution time of subtask A is 50s.
[0123] In step S401 of some embodiments, the number of second idle threads of the first instance device is obtained by identifying threads that have not executed subtasks, and the first remaining execution time of each second subtask is obtained by identifying the time required for each second subtask to be executed.
[0124] In step S402 of some embodiments, the number of new threads allocated to each second subtask is calculated by the number of second idle threads and the first remaining execution time of each second subtask, and the released idle threads are allocated to each second subtask based on the number of new threads.
[0125] In step S403 of some embodiments, the second subtask is processed based on the allocated new thread and the existing thread to speed up the processing of the second subtask.
[0126] Step S401-step S402 can speed up the processing of the second subtask by further adding a new thread to the second subtask, thereby preventing the processing time of the second subtask from being too long.
[0127] See also Figure 5 In some embodiments, step S402 may include but is not limited to steps S501 to S504:
[0128] Step S501: determining a first number of threads to be added for each of the second subtasks based on a first remaining execution time of each of the second subtasks.
[0129] Step S502: Calculate the sum of the first number of threads to be added of each of the second subtasks to obtain a first target number of threads.
[0130] Step S503: determining the first number of threads to be allocated for each of the second subtasks based on the second number of idle threads and the first target number of threads.
[0131] Step S504: Allocate the released idle threads to the second subtasks according to the first number of threads to be allocated of each of the second subtasks.
[0132] The first number of threads to be added is the number of threads required to be added for the second subtask, which can be understood as the number of new threads allocated to the second subtask determined according to the rules set in this embodiment in order to reduce the current first remaining execution time and speed up the processing progress.
[0133] In step S501 of some embodiments, a correspondence between a preset duration range and a number of threads may be established, and the first number of threads to be added for each second subtask may be obtained by obtaining the number of threads corresponding to the preset duration range in which each first remaining execution duration is located. For example, in units of seconds, the number of threads corresponding to the preset duration range [0, 50) is 0, the number of threads corresponding to the preset duration range [50, 100) is 1, the number of threads corresponding to the preset duration range [100-150) is 2, and so on. If the first remaining execution duration of the second subtask A is 60s and the corresponding number of threads is 1, then the first number of threads to be added for the second subtask A is 1.
[0134] In step S502 of some embodiments, for example, the second subtask includes subtask A, subtask B and subtask C, and the first numbers of threads to be added corresponding to subtask A, subtask B and subtask C are 2, 6 and 4 respectively, then the first target number of threads is 2+6+4=12.
[0135] The first number of threads to be allocated is the number of newly added threads that can actually be allocated to the second subtask.
[0136] In step S503 of some embodiments, if the second number of idle threads is greater than or equal to the first target number of threads, each second subtask can be allocated threads corresponding to the first number of threads to be added. Therefore, if the second number of idle threads is greater than or equal to the first target number of threads, the first number of threads to be allocated for each second subtask is determined to be the corresponding first number of threads to be added.
[0137] If the second number of idle threads is less than the first target number of threads, the idle threads cannot be allocated to each second subtask with the first number of threads to be added respectively. Therefore, if the second number of idle threads is less than the first target number of threads, the ratio between the first numbers of threads to be added is calculated, and the number of first threads to be allocated for each second subtask is determined according to the ratio and the second number of idle threads, that is, the second number of idle threads is divided to each second subtask according to the ratio.
[0138] Specifically, if the multiple of the second idle thread number and the ratio is greater than or equal to 1, the first number of threads to be allocated for each second subtask is determined according to the ratio. The multiple of the second idle thread number and the ratio can be obtained by calculating the sum of the minimum ratios of the first numbers of threads to be added for each second subtask, and then calculating the quotient of the sum of the second idle thread number and the minimum ratio.
[0139] For example, the second number of idle threads is 10, and the second subtask includes subtask A, subtask B and subtask C. The first numbers of threads to be added of subtask A, subtask B and subtask C are 2, 6 and 4 respectively. Then the minimum ratio is 2:6:4=1:3:2, 1, 3 and 2 are the values of each item of the minimum ratio respectively, and the sum of each item of the minimum ratio is 1+3+2=6. The quotient of the second number of idle threads and the sum of each item of the minimum ratio is calculated, and the multiple of the second number of idle threads and the ratio is 10÷6≈1.7, 1.7>1, so the multiple of the second number of idle threads and the ratio is greater than 1.
[0140] The method for determining the first number of threads to be allocated for each second subtask may be: round down the multiple value of the sum of the second idle thread number and the minimum ratio to obtain the target multiple, for example, if the multiple of the sum of the second idle thread number and the minimum ratio is 1.7, then the target multiple is 1. Finally, the product of the target multiple and the minimum ratio is respectively determined as the first number of threads to be allocated for the corresponding second subtask, for example, the second subtask includes subtask A, subtask B and subtask C, and the first number of threads to be added for subtask A, subtask B and subtask C are 2, 6 and 4 respectively, then the minimum ratio is 1:3:2, and the target multiple is 1, then the first number of threads to be allocated for subtask A, subtask B and subtask C are 1×1=1, 1×3=3, and 1×2=2 respectively.
[0141] For another example, if the second number of idle threads is 17, the second subtask includes subtask A, subtask B and subtask C, and the first number of threads to be added for subtask A, subtask B and subtask C are 4, 12 and 8 respectively, then the minimum ratio is 1:3:2, and the multiple of the sum of the second number of idle threads and the minimum ratio is 17÷6≈2.83, then the target multiple is 2, and the first number of threads to be allocated for subtask A, subtask B and subtask C are 2×1=2, 2×3=6, and 2×2=4 respectively.
[0142] If the multiple of the second idle thread number and the ratio is less than 1, the first number of threads to be allocated of the second subtask with the highest proportion is determined to be the second idle thread number, and the first number of threads to be allocated of other second subtasks except the second subtask with the highest proportion is zero.
[0143] For example, if the second number of idle threads is 4, the second subtask includes subtask A, subtask B and subtask C, the first number of threads to be added for subtask A, subtask B and subtask C are 2, 6 and 4 respectively, the minimum ratio is 2:6:4=1:3:2, and the multiple of the sum of the second number of idle threads and the minimum ratio is 4÷6≈0.67. Subtask B has the highest proportion, then the first number of threads to be allocated for subtask A, subtask B and subtask C are 0, 4 and 0 respectively.
[0144] In step S504 of some embodiments, the threads of the first number of threads to be allocated are allocated to the corresponding second subtask. For example, the second subtask includes subtask A, subtask B and subtask C, and the first number of threads to be allocated for subtask A, subtask B and subtask C are 1, 3 and 2 respectively. Then, 1 new thread is allocated to subtask A, 3 new threads are allocated to subtask B, and 2 new threads are allocated to subtask C.
[0145] Steps S501 to S504 balance the processing progress of each subtask and improve the effective utilization of the thread by reasonably allocating the released idle threads to each second subtask.
[0146] See also Figure 6 In some embodiments, step S402 may further include but is not limited to step S601:
[0147] Step S601, if there are still idle threads left after the released idle threads are assigned to the second subtask, and there are still pending tasks that have not been pulled in the preset database, then re-execute the step of pulling the pending tasks from the preset database and processing the pulled pending tasks based on the idle threads.
[0148] In step S601 of some embodiments, the third target pull number is obtained by calculating the quotient of the first remaining idle thread number and the initial thread number, and rounding down the quotient of the first remaining idle thread number and the initial thread number, where the first remaining idle thread number is the number of unassigned threads after the released idle threads are assigned to the second subtask, and the third target pull number is the number of additional subtasks that the first instance device can currently process.
[0149] Pull a new third target and several pending tasks from the preset database. For example, if the third target pull number is 3, then pull 3 new pending tasks from the preset database to the task waiting queue of the first instance device, and loop through steps S301-S302, S401-S403, S501-S504 and S601 until all pending tasks in the preset database are pulled.
[0150] It should be noted that, since the number of pending tasks in the preset database is limited, when the number of pending tasks remaining in the preset database that have not been pulled is not necessarily exactly greater than the second target pull number, if the number of pending tasks remaining in the preset database that have not been pulled is less than the second target pull number, all the remaining pending tasks that have not been pulled are pulled from the preset database, and all the remaining pending tasks that have not been pulled are pulled into the task waiting queue of the first instance device. For example, if the second target pull number is 5 and the number of pending tasks remaining in the preset database that have not been pulled is 3, then the remaining 3 pending tasks that have not been pulled in the preset database are finally pulled.
[0151] The task processing method of the first example device is described above, and the task processing method of the second example device is described in detail below.
[0152] Figure 7is an optional flowchart of a task processing method applied to a second example device provided in an embodiment of the present application. Figure 7 The method may include but is not limited to steps S701 to S702.
[0153] Step S701: when it is detected that there is an idle thread, pull the to-be-processed tasks from the preset database.
[0154] Step S702: When the task to be processed is pulled, the task to be processed is processed based on the idle thread.
[0155] In step S701 of some embodiments, when there is an idle thread in the second instance device, the second instance device sequentially pulls the tasks to be processed from the preset database in the order in which the tasks to be processed are arranged.
[0156] The tasks to be processed may be pulled to the task waiting queue of the second instance device.
[0157] Change the status of the pending task to be pulled to processing. If the status change fails, it means that the pending task to be pulled has been pulled by other instance devices, and there is no need to pull the pending task again. If the status of the pending task to be pulled is changed to processing failure, skip the current pending task to be pulled, pull the next pending task, and so on. The pending task can be placed in the task waiting queue of the second instance device as a successful pull.
[0158] For example, the first subtask in the preset database is arranged as subtask A and subtask B. First, if the status of subtask A is modified to failure in processing, subtask A will not be pulled, and the next subtask B will be pulled. If the status of subtask B is modified to success in processing, subtask B will be pulled to the task waiting queue of the second instance device.
[0159] In step S702 of some embodiments, the tasks to be processed are processed by allocating idle threads to the tasks to be processed.
[0160] Step S701-step S702 can share the pressure of task processing of the first instance device by pulling the first subtask from the preset database for processing, so as to speed up the progress of task processing.
[0161] See also Figure 8 In some embodiments, step S701 may include but is not limited to steps S801 to S803:
[0162] Step S801, obtaining the third idle thread number of the second instance device, rounding the quotient of the third idle thread number of the second instance device and the initial thread number to obtain a second target pull number.
[0163] Step S802: Pull a second target and a plurality of tasks to be processed from the preset database.
[0164] The third number of idle threads is the number of idle threads currently in the second instance device. The second target pull number is the number of pending tasks that can be processed by the current second instance device, which can be understood as the number of additional pending tasks that can be processed while ensuring the processing speed of the subtask currently being processed by the second instance device.
[0165] In step S801 of some embodiments, the third idle thread number of the second instance device is obtained by identifying threads that have not executed subtasks, and the quotient of the third idle thread number of the second instance device and the initial thread number is calculated. Since the second target pull number is a quantitative value, which is a positive integer, when the third idle thread number and the initial thread number are not a multiple, a decimal may be obtained. Therefore, in this embodiment, the quotient of the third idle thread number of the first instance device and the initial thread number is rounded to obtain the second target pull number.
[0166] In order to process subtasks more efficiently, in this embodiment, the quotient of the third idle thread number and the initial thread number of the second instance device is rounded down to obtain the second target pull number. For example, the third idle thread number is 10, the initial thread number is 3, and the quotient of 10 divided by 3 is approximately equal to 3.3, so the second target pull number is 3.
[0167] In step S802 of some embodiments, if the status of the pending task to be pulled is changed to failed in processing, the current pending task to be pulled is skipped, and the next pending task is pulled, and so on, until the second target is pulled to pull a number of pending tasks to the task waiting queue of the second instance device. For example, the second target pull number is 3, and the first subtask in the preset database is arranged as subtask A, subtask B, subtask C, subtask D and subtask F, among which subtask A and subtask B have been pulled, and the three pending tasks pulled are subtask C, subtask D and subtask F.
[0168] If the number of pending tasks that have not been pulled in the preset database is less than the second target pull number, then all pending tasks that have not been pulled in the preset database can be pulled. For example, if the second target pull number is 3, and the first subtask in the preset database is arranged as subtask A, subtask B, subtask C, subtask D, and subtask F, among which subtask A, subtask B, and subtask C have been pulled, then the pending tasks pulled are subtask D and subtask F to the task waiting queue of the second instance device.
[0169] Step S801-step S802 determines the second target pull number based on the third idle thread number and the initial thread number of the second instance device, and can pull an appropriate number of pending tasks for processing while ensuring the current task processing speed of the second instance device, thereby ensuring processing efficiency.
[0170] In addition, by pulling and processing the tasks to be processed in order according to their priority, urgent subtasks can be processed first.
[0171] See also Fig. 9 In some embodiments, step S702 may include but is not limited to steps S901 to S902:
[0172] Step S901 : Allocate a corresponding initial number of threads to each newly-pulled task to be processed.
[0173] Step S902: Process each to-be-processed task based on the assigned thread.
[0174] In step S901 of some embodiments, for example, if the initial number of threads may be 1, then a corresponding thread is allocated to each newly pulled task to be processed.
[0175] In step S902 of some embodiments, threads to which each task to be processed is assigned are used to process the corresponding task to be processed respectively.
[0176] Step S901-Step S902 allocates the number of threads equal to the initial number of threads to each newly pulled task to be processed, and uses the allocated threads to process each task to be processed. Since the number of newly pulled tasks to be processed is obtained based on the third number of idle threads and the initial number of threads, it is possible to fully utilize the threads of the current second instance device without wasting thread resources, and process as many tasks to be processed as possible while ensuring efficiency.
[0177] See also Fig.10 In some embodiments, step S902 may include but is not limited to steps S110 to S112:
[0178] Step S110, when the third subtask is executed and a new idle thread is released, the fourth number of idle threads of the second instance device and the second remaining execution time of each third subtask in the second instance device are obtained.
[0179] Step S111: allocating the released idle threads to the third subtasks based on the fourth number of idle threads and the second remaining execution time of each third subtask.
[0180] Step S112: Process the third subtask based on the allocated thread.
[0181] The fourth number of idle threads is the number of idle threads of the current second instance device, the third subtask is the subtask being processed by the second instance device, the second remaining execution time is the current remaining execution time of the third subtask, and the remaining execution time is the time required to complete the execution of the third subtask. For example, the subtasks being processed by the second instance device include subtask A, subtask B and subtask C, then subtask A, subtask B and subtask C are all the third subtask. If subtask A still has 50s to be processed in the current state, then the second remaining execution time of subtask A is 50s.
[0182] In step S110 of some embodiments, the number of fourth idle threads of the second instance device is obtained by identifying threads that have not executed subtasks, and the second remaining execution time of each third subtask is obtained by identifying the time required for completion of each third subtask.
[0183] In step S111 of some embodiments, the number of new threads allocated to each third subtask is calculated by the fourth number of idle threads and the second remaining execution time of each third subtask, and the released idle threads are allocated to each third subtask based on the number of new threads.
[0184] In step S112 of some embodiments, the third subtask is processed based on the allocated new thread and the existing thread to speed up the processing of the third subtask.
[0185] Steps S110 to S112 can speed up the processing of the third subtask by further adding a new thread to the third subtask, thereby preventing the processing time of the third subtask from being too long.
[0186] See also Fig.11 In some embodiments, step S111 may include but is not limited to steps S120 to S123:
[0187] Step S120: determining a second number of threads to be added for each of the third subtasks based on a second remaining execution time of each of the third subtasks.
[0188] Step S121, calculating the sum of the second number of threads to be added of each of the third subtasks to obtain a second target number of threads.
[0189] Step S122: determining the number of second threads to be allocated for each of the third subtasks based on the fourth number of idle threads and the second target number of threads.
[0190] Step S123: allocating the released idle threads to the third subtasks according to the number of second threads to be allocated of each of the third subtasks.
[0191] The second number of threads to be added is the number of threads required to be added for the third subtask, which can be understood as the number of new threads that can be allocated to the third subtask determined according to the rules set in this embodiment in order to reduce the current second remaining execution time and speed up the processing progress.
[0192] In step S120 of some embodiments, a correspondence between a preset duration range and a number of threads may be established, and the second number of threads to be added for each third subtask may be obtained by obtaining the number of threads corresponding to the preset duration range in which each second remaining execution duration is located. For example, in units of seconds, the number of threads corresponding to the preset duration range [0, 50) is 0, the number of threads corresponding to the preset duration range [50, 100) is 1, the number of threads corresponding to the preset duration range [100-150) is 2, and so on. If the second remaining execution duration of the third subtask A is 60s and the corresponding number of threads is 1, then the second number of threads to be added for the third subtask A is 1.
[0193] In step S121 of some embodiments, for example, the third subtask includes subtask A, subtask B and subtask C, and the second numbers of threads to be added corresponding to subtask A, subtask B and subtask C are 2, 6 and 4 respectively, then the second target number of threads is 2+6+4=12.
[0194] The second number of threads to be allocated is the number of newly added threads that can actually be allocated to the third subtask.
[0195] In step S122 of some embodiments, if the fourth number of idle threads is greater than or equal to the second target number of threads, each third subtask can be allocated threads corresponding to the second number of threads to be added. Therefore, if the fourth number of idle threads is greater than or equal to the second target number of threads, the second number of threads to be allocated for each third subtask is determined to be the corresponding second number of threads to be added.
[0196] If the fourth number of idle threads is less than the second target number of threads, the idle threads cannot be allocated to each third subtask respectively with the second number of threads to be added. Therefore, if the fourth number of idle threads is less than the second target number of threads, the ratio between the second numbers of threads to be added is calculated, and the number of second threads to be allocated for each third subtask is determined according to the ratio and the fourth number of idle threads, that is, the current idle threads are divided into each third subtask according to the ratio.
[0197] Specifically, if the multiple of the fourth idle thread number and the ratio is greater than or equal to 1, the number of second threads to be allocated for each third subtask is determined according to the ratio. The multiple of the fourth idle thread number and the ratio can be obtained by calculating the sum of the minimum ratios of the second threads to be added for each third subtask and then calculating the quotient of the sum of the fourth idle thread number and the minimum ratio.
[0198] For example, the number of the fourth idle threads is 10, the third subtask includes subtask A, subtask B and subtask C, and the second numbers of threads to be added of subtask A, subtask B and subtask C are 2, 6 and 4 respectively. Then the minimum ratio is 2:6:4=1:3:2, 1, 3, 2 are the values of each item of the minimum ratio respectively, and the sum of each item of the minimum ratio is 1+3+2=6. The quotient of the fourth idle thread number and the sum of each item of the minimum ratio is calculated, and the multiple of the fourth idle thread number and the ratio is 10÷6≈1.7, 1.7>1, therefore, the multiple of the fourth idle thread number and the ratio is greater than 1.
[0199] The method for determining the number of second threads to be allocated for each third subtask may be: round down the multiple value of the sum of the fourth idle thread number and the items of the minimum ratio to obtain the target multiple, for example, the multiple of the sum of the fourth idle thread number and the items of the minimum ratio is 1.7, and the target multiple is 1. Finally, the product of the target multiple and the items of the minimum ratio is respectively determined as the number of second threads to be allocated for the corresponding third subtask, for example, the third subtask includes subtask A, subtask B and subtask C, and the number of second threads to be added for subtask A, subtask B and subtask C are 2, 6 and 4 respectively, then the minimum ratio is 1:3:2, and the target multiple is 1, then the number of second threads to be allocated for subtask A, subtask B and subtask C is 1×1=1, 1×3=3, 1×2=2 respectively.
[0200] For another example, if the number of the fourth idle threads is 17, the third subtask includes subtask A, subtask B and subtask C, and the second number of threads to be added for subtask A, subtask B and subtask C are 4, 12 and 8 respectively, then the minimum ratio is 1:3:2, and the multiple of the sum of the fourth number of idle threads and the minimum ratio is 17÷6≈2.83, then the target multiple is 2, and the second number of threads to be allocated for subtask A, subtask B and subtask C are 2×1=2, 2×3=6, and 2×2=4 respectively.
[0201] If the multiple of the fourth idle thread number and the ratio is less than 1, the second number of threads to be allocated of the third subtask with the highest proportion is determined to be the fourth idle thread number, and the second number of threads to be allocated of other third subtasks except the third subtask with the highest proportion is zero.
[0202] For example, if the number of the fourth idle threads is 4, the third subtask includes subtask A, subtask B and subtask C, the second number of threads to be added for subtask A, subtask B and subtask C are 2, 6 and 4 respectively, and the minimum ratio is 2:6:4=1:3:2. The multiple of the sum of the fourth number of idle threads and the minimum ratio is 4÷6≈0.67. Subtask B has the highest proportion. Then the second number of threads to be allocated for subtask A, subtask B and subtask C are 0, 4 and 0 respectively.
[0203] In step S123 of some embodiments, the threads of the second number of threads to be allocated are allocated to the corresponding third subtask.
[0204] Steps S120 to S123 balance the processing progress of each subtask and improve the effective utilization rate of the thread by reasonably allocating the released idle threads to each third subtask.
[0205] See also Fig.12 In some embodiments, step S111 may further include but is not limited to step S130:
[0206] Step S130, if there are still idle threads left after the released idle threads are assigned to the third subtask, and there are still pending tasks that have not been pulled out in the preset database, then the step of pulling the pending tasks from the preset database is re-executed, and when the pending tasks are pulled out, the step of processing the pending tasks based on the idle threads is performed.
[0207] In step S130 of some embodiments, the quotient of the second number of remaining idle threads and the initial number of threads is calculated, and the quotient of the second number of remaining idle threads and the initial number of threads is rounded down to obtain a fourth target pull number. The second number of remaining idle threads is the number of threads that are not allocated after the released idle threads are allocated to the third subtask, and the fourth target pull number is the number of subtasks that can be additionally processed by the second instance device.
[0208] Pull a new fourth target and several pending tasks from the preset database. For example, if the fourth target pull number is 3, then pull 3 new pending tasks from the preset database to the task waiting queue of the second instance device, and loop through steps S901 to S902, S110-S112, S120-S123 and S130 until all pending tasks in the preset database are pulled.
[0209] It should be noted that, since the number of pending tasks in the preset database is limited, when the number of pending tasks remaining in the preset database that have not been pulled is not necessarily exactly greater than the fourth target pull number, if the number of pending tasks remaining in the preset database that have not been pulled is less than the fourth target pull number, all the remaining pending tasks that have not been pulled can be pulled from the preset database. For example, if the fourth target pull number is 5 and the number of pending tasks remaining in the preset database that have not been pulled is 3, then the remaining 3 pending tasks that have not been pulled in the preset database are finally pulled to the task waiting queue of the second instance device.
[0210] The embodiment of the present application splits the current target task into multiple subtasks through the first instance device, and inserts multiple first subtasks into the preset database, and the target instance device and the first instance device pull the first subtask from the preset database for processing, wherein the target instance includes at least one second instance device. In this way, more instance devices for processing tasks can be added to share the pressure of overcrowding of a single instance due to a small number of instances, and reduce the task processing time.
[0211] The embodiment of the present application also provides a task processing device, which can implement the above-mentioned task processing method. The device can include at least one instance device of the first instance device and the second instance device, or include the first instance device and at least one second instance device;
[0212] See also Fig.13 , if the device includes the first example device, the device includes:
[0213] The request receiving module 131 is used to receive a business operation request, where the business operation request is used to request processing of a target task of a target business.
[0214] The request response module 132 is used to split the target task in response to the business operation request to obtain multiple first subtasks associated with the target business.
[0215] The task inserting module 133 is used to insert the plurality of first subtasks into a preset database, wherein in the preset database, each of the plurality of first subtasks is used as a task to be processed.
[0216] The first task processing module 134 is configured to pull tasks to be processed from the preset database if there are idle threads in the first instance device, and process the pulled tasks to be processed based on the idle threads.
[0217] And when there is an idle thread in the target instance device, the target instance device pulls the pending tasks from the preset database and processes the pending tasks based on the idle thread until the pending tasks in the preset database are processed to complete the processing of the target tasks, and the target instance device includes at least one second instance device.
[0218] The specific implementation of the device is basically the same as the specific implementation of the task processing method applied to the first example device, and will not be repeated here.
[0219] See also Fig.14 , if the device includes the second example device, the device includes:
[0220] The task pulling module 141 is used to pull pending tasks from a preset database when an idle thread is detected, wherein the pending tasks in the preset database include multiple first subtasks inserted by a first instance device, the first subtask is a subtask associated with a target business, and the multiple first subtasks are obtained by splitting the target task by the first instance device in response to a business operation request, and the business operation request is used to request processing of the target task of the target business; the second instance device is an instance device other than the first instance device.
[0221] The second task processing module 142 processes the task to be processed based on the idle thread when the task to be processed is pulled.
[0222] The specific implementation of the device is basically the same as the specific implementation of the task processing method applied to the second example device, and will not be repeated here.
[0223] The embodiment of the present application also provides an electronic device, the electronic device includes a memory and a processor, the memory stores a computer program, and the processor implements the above-mentioned task processing method when executing the computer program. The electronic device can be any intelligent terminal including a tablet computer, a car computer, etc.
[0224] See also Fig.15 , Fig.15 The hardware structure of an electronic device of another embodiment is illustrated, and the electronic device includes:
[0225] The processor 150 may be implemented by a general-purpose CPU (Central Processing Unit), a microprocessor, an application-specific integrated circuit (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 the present application;
[0226] The memory 151 can be implemented in the form of a read-only memory (ROM), a static storage device, a dynamic storage device, or a random access memory (RAM). The memory 151 can store an operating system and other application programs. When the technical solution provided in the embodiment of this specification is implemented by software or firmware, the relevant program code is stored in the memory 151, and the processor 150 calls and executes the task processing method of the embodiment of this application;
[0227] Input / output interface 152, used to implement information input and output;
[0228] Communication interface 153, used to realize communication interaction between the device and other devices, which can be realized through wired mode (such as USB, network cable, etc.) or wireless mode (such as mobile network, WI FI, Bluetooth, etc.);
[0229] A bus 154 that transmits information between the various components of the device (e.g., the processor 150, the memory 151, the input / output interface 152, and the communication interface 153);
[0230] The processor 150 , the memory 151 , the input / output interface 152 and the communication interface 153 are connected to each other in communication within the device via the bus 154 .
[0231] An embodiment of the present application also provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the above-mentioned task processing method is implemented.
[0232] The memory, as a non-transient computer-readable storage medium, can be used to store non-transient software programs and non-transient computer executable programs. In addition, the memory may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some embodiments, the memory may optionally include a memory remotely disposed relative to the processor, and these remote memories may be connected to the processor via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0233] The task processing method and device, electronic device and storage medium provided by the embodiment of the present application split the current target task into multiple subtasks through the first instance device, and insert multiple first subtasks into a preset database, and the target instance device and the first instance device pull the first subtask from the preset database for processing, wherein the target instance includes at least one second instance device. In this way, the number of instance devices used to process tasks can be increased, sharing the pressure of overcrowding of a single instance due to a small number of instances, and reducing the task processing time.
[0234] The embodiments described in the embodiments of the present application are intended to more clearly illustrate the technical solutions of the embodiments of the present application and do not constitute a limitation on the technical solutions provided in the embodiments of the present application. Those skilled in the art will appreciate that with the evolution of technology and the emergence of new application scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.
[0235] Those skilled in the art will appreciate that the technical solutions shown in the figures do not constitute a limitation on the embodiments of the present application, and may include more or fewer steps than shown in the figures, or a combination of certain steps, or different steps.
[0236] The device embodiments described above are merely illustrative, and the units described as separate components may or may not be physically separated, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0237] Those skilled in the art will appreciate that all or some of the steps in the methods disclosed above, and the functional modules / units in the systems and devices may be implemented as software, firmware, hardware, or a suitable combination thereof.
[0238] The terms "first", "second", "third", "fourth", etc. (if any) in the specification of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0239] It should be understood that in the present application, "at least one (item)" means one or more, and "plurality" means two or more. "And / or or" is used to describe the association relationship of associated objects, indicating that three relationships may exist. For example, "A and / or or B" can mean: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural. The character " / " generally indicates that the associated objects before and after are in an "or" relationship. "At least one of the following items" or similar expressions refers to any combination of these items, including any combination of single items or plural items. For example, at least one of a, b or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or multiple.
[0240] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the above units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0241] The units described above as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0242] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0243] If the integrated unit is implemented in the form of 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 the present application is essentially 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, and the computer software product is stored in a storage medium, including multiple instructions to enable a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, referred to as ROM), random access memory (Random Access Memory, referred to as RAM), disk or optical disk and other media that can store programs.
[0244] The preferred embodiments of the present invention are described above with reference to the accompanying drawings, but the scope of the rights of the present invention is not limited thereto. Any modification, equivalent substitution and improvement made by a person skilled in the art without departing from the scope and essence of the present invention should be within the scope of the rights of the present invention.
Claims
1. A task processing method, characterized in that: Applied to the first example device, the method includes: Receiving a business operation request, wherein the business operation request is used to request processing of a target task of a target business; In response to the business operation request, split the target task to obtain a plurality of first subtasks associated with the target business; inserting the plurality of first subtasks into a preset database, Wherein, in the preset database, each of the plurality of first subtasks is taken as a task to be processed; If the first instance device has an idle thread, pulling the to-be-processed task from the preset database, and processing the pulled to-be-processed task based on the idle thread; And when there is an idle thread in the target instance device, the target instance device pulls the pending tasks from the preset database and processes the pending tasks based on the idle thread until the pending tasks in the preset database are processed to complete the processing of the target tasks, and the target instance device includes at least one second instance device.
2. The method according to claim 1, characterized in that The step of extracting the to-be-processed tasks from the preset database includes: Obtaining a first idle thread number of the first instance device, rounding the quotient of the first idle thread number of the first instance device and the initial thread number to obtain a first target pull number; the initial thread number is a preset number of threads initially allocated to a new subtask; Pulling a first target from the preset database pulls a plurality of tasks to be processed.
3. The method according to claim 1, characterized in that The processing of the pulled tasks to be processed based on the idle thread includes: Allocate the corresponding initial number of threads to each newly pulled task to be processed; Process each pending task based on the assigned thread; After the allocated threads process each task to be processed, the following steps are performed: When the second subtask is executed and a new idle thread is released, the number of second idle threads of the first instance device and the first remaining execution time of each second subtask in the first instance device are obtained; wherein the second subtask is the subtask being processed by the first instance device; Allocating the released idle threads to the second subtasks based on the number of the second idle threads and the first remaining execution time of each second subtask; The second subtask is processed based on the allocated thread.
4. The method according to claim 3, characterized in that The allocating the released idle thread to the second subtask based on the second number of idle threads and the first remaining execution time of each second subtask includes: Determine a first number of threads to be added for each of the second subtasks based on a first remaining execution time of each of the second subtasks; wherein the first number of threads to be added is the number of threads required to be added for the second subtask; Calculate the sum of the first number of threads to be added of each of the second subtasks to obtain a first target number of threads; Determine the first number of threads to be allocated for each of the second subtasks based on the second number of idle threads and the first target number of threads; wherein the first number of threads to be allocated is the number of threads actually allocated to the second subtask; According to the first number of threads to be allocated of each of the second subtasks, the released idle threads are allocated to the second subtasks.
5. The method according to claim 4, characterized in that The determining, based on the second number of idle threads and the first target number of threads, of the first to-be-allocated threads of each of the second subtasks includes: If the second number of idle threads is greater than or equal to the first target number of threads, determining the first number of threads to be allocated for each of the second subtasks to be the corresponding first number of threads to be added; If the second number of idle threads is less than the first target number of threads, the ratio between the first numbers of threads to be added is obtained, and the number of first threads to be allocated for each second subtask is determined according to the ratio and the second number of idle threads.
6. A task processing method, characterized in that: Applied to the second example device, the method includes: In the case where an idle thread is detected, a task to be processed is pulled from a preset database, wherein the task to be processed in the preset database includes a plurality of first subtasks inserted by a first instance device, the first subtask is a subtask associated with a target business, and the plurality of first subtasks are obtained by splitting the target task by the first instance device in response to a business operation request, and the business operation request is used to request processing of the target task of the target business; the second instance device is an instance device other than the first instance device; When the to-be-processed task is pulled, the to-be-processed task is processed based on the idle thread.
7. The method according to claim 6, characterized in that The step of pulling the pending tasks from the preset database includes: Obtaining the third idle thread number of the second instance device, rounding the quotient of the third idle thread number of the second instance device and the initial thread number to obtain a second target pull number; the initial thread number is a preset number of threads initially allocated to the new subtask; Pulling a second target from the preset database pulls a plurality of tasks to be processed.
8. The method according to claim 6, characterized in that The processing of the pending tasks based on the idle thread includes: Allocate the corresponding initial number of threads to each newly pulled task to be processed; Process each pending task based on the assigned thread; After the allocated threads process each task to be processed, the following steps are performed: When the third subtask is executed and a new idle thread is released, the number of fourth idle threads of the second instance device and the second remaining execution time of each third subtask in the second instance device are obtained; wherein the third subtask is the subtask being processed by the second instance device; Allocating the released idle thread to the third subtask based on the fourth number of idle threads and the second remaining execution time of each third subtask; The third subtask is processed based on the allocated thread.
9. The method according to claim 8, characterized in that The allocating the released idle thread to the third subtask based on the fourth number of idle threads and the second remaining execution time of each third subtask includes: Determine a second number of threads to be added for each of the third subtasks based on the second remaining execution time of each of the third subtasks; wherein the second number of threads to be added is the number of threads required to be added for the third subtask; Calculate the sum of the second number of threads to be added of each of the third subtasks to obtain a second target number of threads; Based on the fourth number of idle threads and the second target number of threads, determining the second number of threads to be allocated for each of the third subtasks; wherein the second number of threads to be allocated is the number of threads actually allocated to the third subtask; According to the number of second threads to be allocated of each of the third subtasks, the released idle threads are allocated to the third subtasks.
10. The method according to claim 9, characterized in that The determining, based on the fourth number of idle threads and the second target number of threads, the number of second threads to be allocated for each of the third subtasks includes: If the fourth number of idle threads is greater than or equal to the second target number of threads, determining the second number of threads to be allocated for each of the third subtasks to be the corresponding second number of threads to be added; If the fourth number of idle threads is less than the second target number of threads, the ratio between the second numbers of threads to be added is obtained, and the number of second threads to be allocated for each third subtask is determined according to the ratio and the fourth number of idle threads.