Task scheduling method and device, electronic equipment and computer readable storage medium

By introducing a dual queue structure and dynamic priority adjustment mechanism in the task scheduling system, the problem that task scheduling methods under high concurrency cannot take into account fairness and efficiency, and the efficiency and fairness of task processing are achieved.

CN119440778AInactive Publication Date: 2025-02-14WISDOM FOOTPRINT DATA TECH CO LTD

Patent Information

Application Number
CN202510046312.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-01-13
Publication Date
2025-02-14
Estimated Expiration
Not applicable · inactive patent

Smart Images

  • Figure CN119440778A_ABST
    Figure CN119440778A_ABST
Patent Text Reader

Abstract

The invention provides a task scheduling method and device, electronic equipment and a computer readable storage medium, and relates to the technical field of computers. The method comprises the following steps: adjusting the current priority of each task to be scheduled in a main queue according to the current resource load; under the condition that the priority adjustment frequency corresponding to the to-be-scheduled task reaches a preset frequency and the duration of the to-be-scheduled task entering the main queue exceeds a first preset duration, the to-be-scheduled task is stored in a retention queue as a retention task; for the detention tasks with overlong waiting time in the detention queue, the detention tasks are added into the main queue again after the priorities are adjusted, so that the tasks are scheduled to be dequeued and executed according to the dynamically adjusted priority sequence, the tasks with high priorities can be executed as soon as possible, and the situation that the tasks with low priorities cannot be processed for a long time can be avoided; the efficiency and the fairness of task processing are considered under the condition of high concurrency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a task scheduling method, device, electronic device and computer-readable storage medium. Background Art

[0002] When processing natural language problems based on the LLaMA (Large Language Model Meta AI) model, frequent interactions with customers will generate a large number of request tasks waiting to be executed. In an asynchronous high-concurrency environment, many systems (such as distributed systems, microservice architectures, etc.) use queues to manage task scheduling. Especially when performing asynchronous processing, the scheduling efficiency and response time of tasks are very critical.

[0003] However, traditional queues, such as FIFO (First Input First Output) queues or priority queues, have certain defects: In high-concurrency situations, when multiple tasks arrive at the FIFO queue at the same time, some tasks in the queue may not be processed for a long time due to queuing, causing queue congestion and increased latency; although priority queues can give priority to urgent tasks, if there are too many high-priority tasks, low-priority tasks may not be processed for a long time, causing starvation.

[0004] Therefore, existing queue-based task scheduling methods cannot balance fairness and efficiency under high concurrency conditions. Summary of the invention

[0005] In view of this, an object of the present invention is to provide a task scheduling method, device, electronic device and computer-readable storage medium to solve the problem that the existing task scheduling method cannot take into account both fairness and efficiency under high concurrency conditions.

[0006] In order to achieve the above purpose, the technical solution adopted by the embodiment of the present invention is as follows: In a first aspect, the present invention provides a task scheduling method, the method comprising: Adjust the current priority of each task to be scheduled in the main queue according to the current resource load; When the number of priority adjustments corresponding to any task to be scheduled in the main queue reaches a preset number and the time for the task to be scheduled to enter the main queue exceeds a first preset time, the task to be scheduled is stored in the retention queue as a retained task; When the time for any stranded task in the stranded queue to enter the stranded queue exceeds a second preset time, the current priority of the stranded task is adjusted according to the stranded time of the stranded task; the stranded time is the difference between the time when the stranded task enters the main queue and the current time; The retained tasks with adjusted priorities are stored again in the main queue as tasks to be scheduled; The tasks to be scheduled in the main queue are scheduled according to the order of their current priorities.

[0007] In an optional implementation manner, adjusting the current priority of each to-be-scheduled task in the main queue according to the current resource load includes: Determine a load adjustment factor according to the current resource load; wherein, when the current resource load is greater than or equal to a preset value, the corresponding load adjustment factor is a negative number; when the current resource load is less than the preset value, the corresponding load adjustment factor is a positive number; Determine a customer impact factor according to the customer level of each task to be scheduled in the main queue; the customer impact factor is proportional to the customer level; Determine an access frequency factor according to the number of accesses of each of the tasks to be scheduled within a set period; the access frequency factor is proportional to the number of accesses; The current priority of each of the tasks to be scheduled is adjusted according to the load adjustment factor, the customer impact factor corresponding to each of the tasks to be scheduled, and the access frequency factor corresponding to each of the tasks to be scheduled.

[0008] In an optional implementation, adjusting the current priority of each of the tasks to be scheduled according to the load adjustment factor, the customer impact factor corresponding to each of the tasks to be scheduled, and the access frequency factor corresponding to each of the tasks to be scheduled includes: According to the formula The current priority of each task to be scheduled is adjusted; wherein, represents the adjusted priority of the task to be scheduled, Indicates the current priority of the task to be scheduled, represents the load adjustment factor, represents the customer impact factor corresponding to the task to be scheduled, Indicates the access frequency factor corresponding to the task to be scheduled.

[0009] In an optional implementation manner, adjusting the current priority of the stranded task according to the stranded duration of the stranded task includes: Calculate the product of the detention time of the detention task and the preset growth coefficient; The product is added to the current priority of the stranded task to obtain the adjusted priority of the stranded task.

[0010] In an optional implementation, after scheduling each to-be-scheduled task in the main queue according to the order of the current priority of each to-be-scheduled task in the main queue, the method further includes: When there are multiple tasks to be scheduled with the same priority, the scheduling order of the multiple tasks to be scheduled is determined according to the task types, task sizes and / or estimated execution times of the multiple tasks to be scheduled.

[0011] In an optional embodiment, the method further comprises: When each task to be scheduled enters the main queue for the first time, the initial priority of the task to be scheduled is calculated according to the task type, task size and estimated execution time of the task to be scheduled.

[0012] In an optional implementation manner, the calculating the initial priority of the task to be scheduled according to the task type, task size and estimated execution time of the task to be scheduled includes: Converting the task type of the task to be scheduled according to a preset task type conversion function, and multiplying the obtained task type conversion value by a preset task type weight to obtain a first product; Converting the task size of the task to be scheduled according to a preset task size conversion function, and multiplying the obtained task size conversion value by a preset task size weight to obtain a second product; Converting the estimated execution time of the task to be scheduled according to a preset execution time conversion function, and multiplying the obtained execution time conversion value by a preset execution time weight to obtain a third product; The first product, the second product and the third product are added together to obtain the initial priority of the task to be scheduled.

[0013] In a second aspect, the present invention provides a task scheduling device, the device comprising: The priority adjustment module is used to adjust the current priority of each task to be scheduled in the main queue according to the current resource load; A queue management module, configured to store any to-be-scheduled task in the main queue as a stranded task in the stranded queue when the number of priority adjustments corresponding to any to-be-scheduled task in the main queue reaches a preset number and the length of time the to-be-scheduled task enters the main queue exceeds a first preset length of time; The priority adjustment module is further configured to adjust the current priority of the stranded task according to the stranded duration of the stranded task when the duration of time that any stranded task in the stranded queue enters the stranded queue exceeds a second preset duration; the stranded duration is the difference between the time when the stranded task enters the main queue and the current time; The queue management module is further used to store the stranded tasks after priority adjustment back into the main queue as tasks to be scheduled; The task scheduling module is used to schedule the tasks to be scheduled in the main queue according to the order of their current priorities.

[0014] In a third aspect, the present invention provides an electronic device comprising a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein the computer program, when executed by the processor, implements the steps of the task scheduling method described in any one of the aforementioned embodiments.

[0015] In a fourth aspect, the present invention provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of the task scheduling method as described in any one of the aforementioned embodiments.

[0016] The task scheduling method, device, electronic device and computer-readable storage medium provided by the embodiments of the present invention include adjusting the current priority of each task to be scheduled in the main queue according to the current resource load; when the number of priority adjustments corresponding to any task to be scheduled in the main queue reaches a preset number and the time for the task to be scheduled to enter the main queue exceeds a first preset time, the task to be scheduled is stored in the retained queue as a stranded task; when the time for any stranded task in the retained queue to enter the retained queue exceeds a second preset time, the current priority of the stranded task is adjusted according to the retention time of the stranded task; the retention time is the difference between the time when the stranded task enters the main queue and the current time; the stranded task with the adjusted priority is stored again in the main queue as a task to be scheduled; and each task to be scheduled in the main queue is scheduled according to the order of the current priorities of each task to be scheduled in the main queue. The embodiment of the present invention dynamically adjusts the priority of each task to be scheduled based on the resource load situation. For stranded tasks with too long waiting time, they will be re-added to the main queue after the priority is adjusted. In this way, tasks are scheduled out of the queue for execution in the order of the dynamically adjusted priority, which can not only ensure that high-priority tasks are executed as soon as possible, but also avoid that low-priority tasks cannot be processed for a long time, thereby achieving a balance between efficiency and fairness in task processing under high concurrency.

[0017] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, preferred embodiments are given below and described in detail with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for use in the embodiments are briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present invention and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without creative work.

[0019] Figure 1 A first schematic flow chart of a task scheduling method provided by an embodiment of the present invention is shown; Figure 2 A second flow chart of the task scheduling method provided by an embodiment of the present invention is shown; Figure 3 A third flow chart of the task scheduling method provided by an embodiment of the present invention is shown; Figure 4 A fourth flow chart of the task scheduling method provided by an embodiment of the present invention is shown; Figure 5 A first functional module diagram of a task scheduling device provided by an embodiment of the present invention is shown; Figure 6 A second functional module diagram of the task scheduling device provided by an embodiment of the present invention is shown; Figure 7 A block diagram of an electronic device provided by an embodiment of the present invention is shown.

[0020] Icons: 100 - electronic device; 110 - memory; 120 - processor; 130 - communication module; 600 - task scheduling device; 610 - priority adjustment module; 620 - queue management module; 630 - task scheduling module; 640 - initial priority calculation module. DETAILED DESCRIPTION

[0021] The following will be combined with the accompanying drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Generally, the components of the embodiments of the present invention described and shown in the drawings here can be arranged and designed in various different configurations.

[0022] Therefore, the following detailed description of the embodiments of the present invention provided in the accompanying drawings is not intended to limit the scope of the invention claimed for protection, but merely represents selected embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without making creative work are within the scope of protection of the present invention.

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

[0024] In the existing queue-based task scheduling methods, in the case of high concurrency, when multiple tasks arrive at the queue at the same time, some tasks in the queue may not be processed for a long time due to queuing, causing queue congestion and increased delay; although the priority queue can give priority to urgent tasks, if the number of high-priority tasks is too large, it may cause low-priority tasks to be unable to be processed for a long time, causing starvation.

[0025] Based on this, an embodiment of the present invention proposes a task scheduling method, device, electronic device and computer-readable storage medium, which dynamically adjusts the priority of each task to be scheduled based on the resource load situation. For stranded tasks with too long waiting time, they will also be rejoined to the main queue after adjusting the priority. In this way, tasks are scheduled out of the queue for execution in the order of the dynamically adjusted priority, which can not only ensure that high-priority tasks are executed as soon as possible, but also avoid low-priority tasks from being unable to be processed for a long time, thereby achieving both efficiency and fairness in task processing under high concurrency.

[0026] Hereinafter, various embodiments of the present invention will be described in detail with reference to the accompanying drawings.

[0027] Please refer to Figure 1 , is a flow chart of a task scheduling method provided by an embodiment of the present invention. It should be noted that the task scheduling method of the present invention is not based on Figure 1And the following specific order is limited. It should be understood that in other embodiments, the order of some steps in the task scheduling method of the present invention can be interchanged according to actual needs, or some steps therein can be omitted or deleted. The task scheduling method can be applied to electronic devices such as automobiles, laptops, tablets, PCs (Personal Computers), servers, etc. Specifically, it can be implemented in a distributed system or microservice architecture, and the scheduling and priority adjustment logic of tasks can be handled by a central scheduler (Scheduler); the central scheduler can communicate with the back-end service through the API to dynamically adjust the priority and execution status of the task. The following will describe Figure 1 The specific process shown is described in detail.

[0028] Step S101, adjusting the current priority of each task to be scheduled in the main queue according to the current resource load.

[0029] In this embodiment, the electronic device can monitor the system resource load in real time, mainly including CPU load (CPU usage), memory load (memory usage ratio), I / O load (disk and network I / O usage), etc., and then dynamically adjust the current priority of each task to be scheduled in the main queue according to the current resource load.

[0030] For example, under high load conditions, the priority of high-priority tasks in the main queue can be lowered to reduce the scheduling frequency of these high-priority tasks, and the priority of low-priority tasks can be increased to ensure that resources are fairly allocated; under low load conditions, the priority of high-priority tasks can be increased to speed up the processing rate of these high-priority tasks and improve the system throughput.

[0031] Step S102: When the priority adjustment times corresponding to any task to be scheduled in the main queue reaches a preset number and the time for the task to be scheduled to enter the main queue exceeds a first preset time, the task to be scheduled is stored in the retention queue as a retained task.

[0032] In this embodiment, the preset number of times and the first preset time can be set according to actual needs. For example, the preset number of times can be set to 5 times, and the first preset time can be set to 15 seconds. When the task to be scheduled enters the main queue for more than 15 seconds and has not been executed after 5 priority adjustments, the task to be scheduled will be transferred to the retention queue.

[0033] Step S103, when the time for any stranded task in the stranded queue to enter the stranded queue exceeds the second preset time, the current priority of the stranded task is adjusted according to the stranded time of the stranded task; the stranded time is the difference between the time when the stranded task enters the main queue and the current time.

[0034] In this embodiment, the second preset duration can be set according to actual needs. For a stranded task that stays in the stranded queue for more than a certain time (the second preset duration), the priority can be adjusted according to the stranded duration, thereby increasing the priority of the stranded task to avoid task blocking. Step S104, storing the stranded task with the adjusted priority back into the main queue as a task to be scheduled.

[0035] In this embodiment, whenever the priority of a stranded task in the stranded queue changes, the stranded task will be reinserted into the main queue, ensuring that the tasks to be scheduled in the main queue are always sorted according to the current priority.

[0036] In this embodiment, in order to effectively realize the dynamic adjustment of task priority, a dual queue structure (i.e., main queue + retention queue) is used to manage tasks. The main queue is used to store all tasks entering the queue, and the tasks are sorted according to priority; the retention queue is used to store low-priority tasks that have not been executed for a long time; for tasks in the retention queue, the system will dynamically increase their priority to ensure that they are not "starved to death". Whenever the priority of a task in the retention queue changes, it will be reinserted into the main queue to ensure that the tasks in the main queue are always sorted according to the current priority.

[0037] Step S105 , scheduling the tasks to be scheduled in the main queue according to the order of their current priorities.

[0038] In this embodiment, based on the dynamic adjustment result of the priority of each task to be scheduled, tasks can be selected from the main queue for execution in order of priority according to the current priority of each task to be scheduled, and tasks to be scheduled with a high current priority will be executed first.

[0039] It can be seen that the task scheduling method provided by the embodiment of the present invention adjusts the current priority of each task to be scheduled in the main queue according to the current resource load; when the number of priority adjustments corresponding to any task to be scheduled in the main queue reaches a preset number and the time for the task to be scheduled to enter the main queue exceeds the first preset time, the task to be scheduled is stored in the retained queue as a retained task; when the time for any retained task in the retained queue to enter the retained queue exceeds the second preset time, the current priority of the retained task is adjusted according to the retention time of the retained task; the retention time is the difference between the time when the retained task enters the main queue and the current time; the retained task after priority adjustment is stored again in the main queue as a task to be scheduled; and each task to be scheduled in the main queue is scheduled according to the order of their current priorities. The embodiment of the present invention dynamically adjusts the priority of each task to be scheduled based on the resource load situation. For stranded tasks with too long waiting time, they will be re-added to the main queue after the priority is adjusted. In this way, tasks are scheduled out of the queue for execution in the order of the dynamically adjusted priority, which can not only ensure that high-priority tasks are executed as soon as possible, but also avoid that low-priority tasks cannot be processed for a long time, thereby achieving a balance between efficiency and fairness in task processing under high concurrency.

[0040] In one embodiment, see Figure 2 Before step S101, the task scheduling method provided by the embodiment of the present invention may further include: Step S201, when each task to be scheduled enters the main queue for the first time, the initial priority of the task to be scheduled is calculated according to the task type, task size and estimated execution time of the task to be scheduled.

[0041] That is to say, when each task to be scheduled enters the main queue for the first time, an initial priority is calculated based on its metadata (such as task type, task size, and estimated execution time). When each task to be scheduled makes its first priority adjustment, it is adjusted based on the initial priority, and subsequent priority adjustments are made based on the priority after the previous adjustment.

[0042] Among them, task types can include computationally intensive, query, etc.; task size can be expressed by the amount of resources, data or storage space required for the task; the estimated execution time directly affects the priority of the task; the longer the execution time, the lower the priority of the task, so that short-time tasks can be executed as quickly as possible, thereby improving system throughput.

[0043] In one embodiment, step S201 may specifically include: converting the task type of the task to be scheduled according to a preset task type conversion function, and multiplying the obtained task type conversion value by a preset task type weight to obtain a first product; converting the task size of the task to be scheduled according to a preset task size conversion function, and multiplying the obtained task size conversion value by a preset task size weight to obtain a second product; converting the estimated execution time of the task to be scheduled according to a preset execution time conversion function, and multiplying the obtained execution time conversion value by a preset execution time weight to obtain a third product; adding the first product, the second product and the third product to obtain the initial priority of the task to be scheduled.

[0044] In this embodiment, the initial priority of the task to be scheduled can be expressed as: initial priority = .

[0045] Among them, T represents the task type, S represents the task size, and T exec Indicates the estimated execution time; is the preset task type weight, is the preset task size weight, is the preset execution time weight, , , The influence of various factors (task type, task size, estimated execution time) on the final priority can be controlled, and the + + =1 (the sum of weights is 1, maintaining fairness); Indicates the task type conversion value; Indicates the task size conversion value; Indicates the execution time conversion value.

[0046] In this embodiment, the task type conversion value Functions can be converted according to preset task types By converting the task type, we can get = ;in, It can characterize the impact of task type on priority and is a constant. For example, for computationally intensive tasks, , the corresponding task type conversion value is 0.6; for query tasks, , the corresponding task type conversion value is 0.4.

[0047] Task size conversion value Functions can be converted according to preset task sizes The task size is converted to ;in, A logarithmic function can be used, for example ,The task size is logarithmically transformed so that the larger the task, the priority increases, but the increase gradually slows down as the task size increases, thus compressing the impact of the task size and preventing overly large tasks from dominating the priority.

[0048] Execution time conversion value The estimated execution time can be converted according to the preset execution time conversion function, that is, = (T exec );in, (T exec ) is usually inversely proportional to the execution time, you can set (T exec ) That is, the longer the execution time of the task, the lower the priority. This is used to reduce the priority of long-time tasks and ensure that short-time tasks can also be executed first.

[0049] In this embodiment, , , It can be adjusted continuously according to the actual application scenario. In practical applications, historical data is usually used to adjust these weights in order to maximize the efficiency of the system.

[0050] In one example, you can set ,Task type has a certain impact on priority, and computationally intensive tasks usually take priority;,setting , the task size affects the priority to a certain extent (the impact of task size is moderate); setting ,The impact of execution time is usually in the opposite direction, the longer the time, the lower the priority (the impact of execution time is expected to be smaller).

[0051] Assume that the following tasks to be scheduled enter the main queue for the first time: Task 1: Spark computing task (T), size 300MB (S), estimated execution time 30 seconds (T exec ); Task 2: Spark computing task (T), size 100MB (S), estimated execution time 10 seconds (T exec ); Task 3: Query task (T), size 50MB (S), estimated execution time 3 seconds (T exec ); Task 4: Query task (T), size 400MB (S), estimated execution time 20 seconds (T exec ).

[0052] For task 1, the task type conversion value is 0.6 and the task size conversion value is , the execution time conversion value is , then the initial priority of task 1 = 0.5×0.6+0.3× +0.2× .

[0053] For Task 2, the task type conversion value is 0.6 and the task size conversion value is , the execution time conversion value is , then the initial priority of task 2 = 0.5×0.6+0.3× +0.2× .

[0054] For task 3, the task type conversion value is 0.4 and the task size conversion value is , the execution time conversion value is , then the initial priority of task 3 = 0.5×0.4+0.3× +0.2× .

[0055] For task 4, the task type conversion value is 0.4 and the task size conversion value is , the execution time conversion value is , then the initial priority of task 4 = 0.5×0.4+0.3× +0.2× .

[0056] The priority relationship among Task 1, Task 2, Task 3 and Task 4 is: Task 1>Task 4>Task 2>Task 3. Task 1 has the highest priority because its task type is computationally intensive. Although Task 4 is a query task, its task size is larger than Task 2, resulting in a higher priority. Task 4 has a lower priority than Task 1, reflecting that the impact of task type on priority is more obvious. At the same time, it can be seen that task size is not the dominant factor, because Task 4 is larger than Task 1, but Task 1 has a higher priority than Task 4.

[0057] In actual applications, when selecting tasks from the main queue for scheduling in order of priority, there may be multiple tasks with the same priority. Based on this, please refer to Figure 3 After step S105, the task scheduling method provided by the embodiment of the present invention may further include: Step S301 : when there are multiple tasks to be scheduled with the same priority, determining the scheduling order of the multiple tasks to be scheduled according to the task types, task sizes and / or estimated execution times of the multiple tasks to be scheduled.

[0058] In this embodiment, the scheduling order of multiple tasks to be scheduled with the same priority level can be determined based on the task type. For example, computationally intensive tasks can be set to be scheduled and executed before I / O intensive tasks because computationally intensive tasks may occupy more CPU resources. The scheduling order of multiple tasks to be scheduled with the same priority level can also be determined based on the task size. For example, small tasks can be set to be executed first to reduce the system load and complete them quickly. The scheduling order of multiple tasks to be scheduled with the same priority level can also be determined based on the estimated execution time of the tasks. For example, tasks with a shorter estimated execution time can be executed first to improve system throughput.

[0059] It is understandable that in this embodiment, the scheduling order of multiple tasks to be scheduled with the same priority can be determined based on one or more of the task type, task size, and expected execution time. For example, for multiple tasks to be scheduled with the same priority, the scheduling order can be determined first according to the task type of each task to be scheduled; then, for the tasks to be scheduled with the same task type, the scheduling order can be determined according to the task size; finally, for the tasks to be scheduled with the same task type and the same task size, the scheduling order can be determined according to the expected execution time of the task.

[0060] In one embodiment, see Figure 4 , the above step S101 specifically includes: Step S1011, determining a load adjustment factor according to the current resource load; wherein, when the current resource load is greater than or equal to a preset value, the corresponding load adjustment factor is a negative number; when the current resource load is less than the preset value, the corresponding load adjustment factor is a positive number.

[0061] In this embodiment, when the current resource load is greater than or equal to the preset value, it indicates that the current resource load is high, and a negative load adjustment factor can be used to lower the task priority; when the current resource load is less than the preset value, it indicates that the current resource load is low, and a positive load adjustment factor can be used to increase the task priority.

[0062] For example, if the current resource load is greater than or equal to 80%, it indicates that the current resource load is high, and the corresponding load adjustment factor is determined to be -0.1; if the current resource load is less than 80%, it indicates that the current resource load is low, and the corresponding load adjustment factor is determined to be +0.1.

[0063] Step S1012, determining a customer impact factor according to the customer level of each task to be scheduled in the main queue; the customer impact factor is proportional to the customer level.

[0064] In this embodiment, when the task to be scheduled is not from a VIP customer, the customer level can be considered to be 0, or the default customer impact factor is 0, which does not affect the initial priority; when the task to be scheduled is from a VIP customer, the customer impact factor can be calculated according to the customer level of the VIP customer (VIP level). For example, the customer impact factor can be set to 0.1×customer level; when the customer level is 1, the customer impact factor is 0.1; when the customer level is 2, the customer impact factor is 0.2; when the customer level is 3, the customer impact factor is 0.3.

[0065] Step S1013, determining an access frequency factor according to the number of accesses of each to-be-scheduled task within a set period; the access frequency factor is proportional to the number of accesses.

[0066] In this embodiment, the setting period can be set according to actual needs, such as 1 day, 1 week, etc. Generally speaking, tasks that are frequently requested recently represent more access possibilities in the future, and thus have higher priorities. Therefore, the higher the recent access frequency (number of accesses within the setting period) of the task to be scheduled, the larger the corresponding access frequency factor should be, which can be calculated in proportion, i.e., access frequency factor = k1 × number of accesses, where k1 is the weight parameter of the number of accesses, which is used to control the impact of the number of accesses on the priority.

[0067] For example, the number of visits corresponding to the task to be scheduled is 10 times, and k1=0.02, then the visit frequency factor = 0.02×10=0.2.

[0068] Step S1014: adjusting the current priority of each task to be scheduled according to the load adjustment factor, the customer impact factor corresponding to each task to be scheduled, and the access frequency factor corresponding to each task to be scheduled.

[0069] In one implementation, step S1014 specifically includes: according to the formula Adjust the current priority of each task to be scheduled; Indicates the adjusted priority of the task to be scheduled. Indicates the current priority of the task to be scheduled. represents the load adjustment factor, represents the customer impact factor corresponding to the task to be scheduled, Indicates the access frequency factor corresponding to the task to be scheduled.

[0070] Assuming that the current resource load of the system is high, the corresponding load adjustment factor is ; The current priority of Task 1 is 1.1, the customer level is 1, and the number of recent visits is 10; The current priority of Task 2 is 1.0, the customer level is 3, and the number of recent visits is 10; The current priority of Task 3 is 1.1, the customer level is 0, and the number of recent visits is 50; The adjusted priority of Task 1 = 1.1 × (1-0.1 + 0.1 × 1 + 0.02 × 10) 1.32; Task 2 adjusted priority = 1.0 × (1-0.1 + 0.1 × 3 + 0.02 × 10) 1.4; Task 3 adjusted priority = 1.1×(1-0.1+0.1×0+0.02×50) 2.09. Task 2 had a lower priority before adjustment, but because of the higher customer level, it took the lead after dynamic adjustment; although Task 3 was not from VIP customers, it received a higher priority due to the high number of recent visits.

[0071] In one embodiment, in the above step S103, the current priority of the stranded task is adjusted according to the stranded duration of the stranded task, specifically including: calculating the product of the stranded duration of the stranded task and a preset growth coefficient; adding the product to the current priority of the stranded task to obtain the adjusted priority of the stranded task.

[0072] In this embodiment, the adjusted priority of the stranded task can be expressed as: adjusted priority = current priority + f (detention duration), where f (detention duration) is a function based on the detention duration; the longer the task waits in the queue, the higher its adjusted priority is, which is a positive proportional relationship, so this embodiment adopts an exponential function, that is, f (detention duration) = k2 × detention duration, k2 represents the growth coefficient, which can be understood as how much the priority increases per second. According to practical experience, k2 can be set to 0.05.

[0073] For example, there are tasks 1 and 2 in the detention queue. The current priority of task 1 is 1 and the detention time is 20 seconds; the current priority of task 2 is 1 and the detention time is 30 seconds; then the adjusted priority of task 1 = 1 + 0.05 × 20 = 2, and the adjusted priority of task 2 = 1 + 0.05 × 30 = 2.5. Since the detention time of task 2 is longer, its adjusted priority is higher.

[0074] It can be seen that the task scheduling method provided by the embodiment of the present invention can dynamically adjust the priority of tasks according to the current resource load, ensure that high-priority tasks can be completed as soon as possible, avoid long waiting times, and improve system throughput; and automatically adjust the priority of tasks according to the current resource load, so as to reasonably utilize the computing resources of the cluster and prevent a single type of task from overwhelming system resources, thereby achieving reasonable allocation of resources and load balancing; for low-priority tasks that have not been processed for a long time, their priority will gradually increase, ensuring that low-priority tasks will not be "starved to death" due to too many high-priority tasks. In this way, the system can ensure that high-priority tasks respond quickly, and avoid low-priority tasks from not being executed for a long time, thereby better balancing the fairness and efficiency of task processing.

[0075] In this embodiment, the execution status of the task (such as actual execution time, execution results, etc.) can also be obtained according to the set period. When it is determined that some tasks have not been completed on time or the load is too high, the scheduling strategy will be further optimized by adjusting the priority of the task.

[0076] It should be noted that in the actual execution of the task, a parallel execution method can be adopted. For example, Task 1 can be divided into three steps: 1, 2, and 3. There is no dependency between Step 1 and Step 2, so Step 1 and Step 2 can be executed at the same time; Step 3 needs to associate the results of Step 1 and Step 2 (there is a dependency), so it is necessary to wait until Step 1 and Step 2 are executed before Step 3 can be executed to avoid resource conflicts or execution order errors, that is, each task can be executed in parallel; assuming that Task 2 can be divided into three steps: a, b, and c, then in the actual execution, Step 1 of Task 1 and Step a of Task 2 may be executed at the same time, that is, different tasks can also be executed in parallel.

[0077] In order to execute the corresponding steps in the above embodiments and various possible methods, a method for implementing a task scheduling device is provided below. Figure 5 , which is a functional module diagram of a task scheduling device 600 provided in an embodiment of the present invention. It should be noted that the basic principle and technical effects of the task scheduling device 600 provided in this embodiment are the same as those of the above embodiments. For the sake of brief description, for parts not mentioned in this embodiment, reference can be made to the corresponding contents in the above embodiments. The task scheduling device 600 includes: a priority adjustment module 610, a queue management module 620 and a task scheduling module 630.

[0078] The priority adjustment module 610 is used to adjust the current priority of each task to be scheduled in the main queue according to the current resource load.

[0079] It can be understood that the priority adjustment module 610 can execute the above step S101.

[0080] The queue management module 620 is used to store the to-be-scheduled task as a stranded task in the stranded queue when the number of priority adjustments corresponding to any to-be-scheduled task in the main queue reaches a preset number and the time for the to-be-scheduled task to enter the main queue exceeds a first preset time.

[0081] It can be understood that the queue management module 620 can execute the above step S102.

[0082] The priority adjustment module 610 is also used to adjust the current priority of the stranded task according to the stranded time of any stranded task in the stranded queue when the time for which the stranded task enters the stranded queue exceeds the second preset time; the stranded time is the difference between the time when the stranded task enters the main queue and the current time.

[0083] It can be understood that the priority adjustment module 610 can also execute the above step S103.

[0084] The queue management module 620 is further used to store the stranded tasks after priority adjustment back into the main queue as tasks to be scheduled.

[0085] It can be understood that the queue management module 620 can also execute the above step S104.

[0086] The task scheduling module 630 is used to schedule the tasks to be scheduled in the main queue according to the order of their current priorities.

[0087] It can be understood that the task scheduling module 630 can also execute the above step S105.

[0088] Optionally, the priority adjustment module 610 is specifically used to determine a load adjustment factor based on the current resource load; wherein, when the current resource load is greater than or equal to a preset value, the corresponding load adjustment factor is a negative number; when the current resource load is less than a preset value, the corresponding load adjustment factor is a positive number; the customer impact factor is determined according to the customer level of each task to be scheduled in the main queue; the customer impact factor is proportional to the customer level; the access frequency factor is determined according to the number of visits of each task to be scheduled within a set period; the access frequency factor is proportional to the number of visits; the current priority of each task to be scheduled is adjusted according to the load adjustment factor, the customer impact factor corresponding to each task to be scheduled and the access frequency factor corresponding to each task to be scheduled.

[0089] It can be understood that the priority adjustment module 610 can also execute the above steps S1011 to S1014.

[0090] Optionally, the priority adjustment module 610 is further configured to adjust the priority according to the formula Adjust the current priority of each task to be scheduled; Indicates the adjusted priority of the task to be scheduled. Indicates the current priority of the task to be scheduled. represents the load adjustment factor, represents the customer impact factor corresponding to the task to be scheduled, Indicates the access frequency factor corresponding to the task to be scheduled.

[0091] Optionally, the priority adjustment module 610 is further specifically configured to calculate the product of the detention duration of the stranded task and a preset growth coefficient; and add the product to the current priority of the stranded task to obtain the adjusted priority of the stranded task.

[0092] Optionally, the task scheduling module 630 is further configured to determine a scheduling order of the multiple tasks to be scheduled according to their task types, task sizes and / or estimated execution times when there are multiple tasks to be scheduled with the same priority.

[0093] It can be understood that the task scheduling module 630 can also execute the above step S301.

[0094] Optionally, see Figure 6 The task scheduling device 600 provided in the embodiment of the present invention may also include an initial priority calculation module 640, which is used to calculate the initial priority of the task to be scheduled according to the task type, task size and estimated execution time of the task to be scheduled when each task to be scheduled enters the main queue for the first time.

[0095] It can be understood that the initial priority calculation module 640 can execute the above step S201.

[0096] Optionally, the initial priority calculation module 640 is specifically used to convert the task type of the task to be scheduled according to a preset task type conversion function, and multiply the obtained task type conversion value by a preset task type weight to obtain a first product; convert the task size of the task to be scheduled according to a preset task size conversion function, and multiply the obtained task size conversion value by a preset task size weight to obtain a second product; convert the estimated execution time of the task to be scheduled according to a preset execution time conversion function, and multiply the obtained execution time conversion value by a preset execution time weight to obtain a third product; add the first product, the second product and the third product to obtain the initial priority of the task to be scheduled.

[0097] It can be seen that the task scheduling device provided by the embodiment of the present invention includes a priority adjustment module, a queue management module and a task scheduling module. The priority adjustment module is used to adjust the current priority of each task to be scheduled in the main queue according to the current resource load; the queue management module is used to store the task to be scheduled as a stranded task in the stranded queue when the number of priority adjustments corresponding to any task to be scheduled in the main queue reaches a preset number and the time for the task to be scheduled to enter the main queue exceeds the first preset time; the priority adjustment module is also used to adjust the current priority of the stranded task according to the stranded time of the stranded task when the time for any stranded task in the stranded queue to enter the stranded queue exceeds the second preset time; the stranded time is the difference between the time when the stranded task enters the main queue and the current time; the queue management module is also used to store the stranded task after the priority adjustment as the task to be scheduled in the main queue again; the task scheduling module is used to schedule each task to be scheduled in the main queue according to the order of the current priorities of each task to be scheduled in the main queue. The embodiment of the present invention dynamically adjusts the priority of each task to be scheduled based on the resource load situation. For stranded tasks with too long waiting time, they will be re-added to the main queue after the priority is adjusted. In this way, tasks are scheduled out of the queue for execution in the order of the dynamically adjusted priority, which can not only ensure that high-priority tasks are executed as soon as possible, but also avoid that low-priority tasks cannot be processed for a long time, thereby achieving a balance between efficiency and fairness in task processing under high concurrency.

[0098] Please refer to Figure 7 , is a block diagram of an electronic device 100 provided in an embodiment of the present invention. The electronic device 100 includes a memory 110, a processor 120, and a communication module 130. The memory 110, the processor 120, and the communication module 130 are electrically connected to each other directly or indirectly to achieve data transmission or interaction. For example, these components can be electrically connected to each other through one or more communication buses or signal lines.

[0099] The memory 110 is used to store programs or data. The memory 110 may be, but is not limited to, a random access memory (RAM), a read only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), etc.

[0100] The processor 120 is used to read / write data or programs stored in the memory 110 and execute corresponding functions. For example, when the computer program stored in the memory 110 is executed by the processor 120, the task scheduling method disclosed in the above embodiments can be implemented.

[0101] The communication module 130 is used to establish a communication connection between the electronic device 100 and other devices through a network, and to send and receive data through the network.

[0102] It should be understood that Figure 7 The structure shown is only a schematic diagram of the structure of the electronic device 100. The electronic device 100 may also include Figure 7 More or fewer components as shown, or with Figure 7 Different configurations shown. Figure 7 Each component shown in the figure can be implemented by hardware, software or a combination thereof.

[0103] An embodiment of the present invention further provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by the processor 120, the task scheduling method disclosed in the above embodiments is implemented.

[0104] In several embodiments provided in the present application, it should be understood that the disclosed devices and methods can also be implemented in other ways. The device embodiments described above are merely schematic. For example, the flowcharts and block diagrams in the accompanying drawings show the possible architecture, functions and operations of the devices, methods and computer program products according to multiple embodiments of the present invention. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of a code, and the module, a program segment or a part of a code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, and the combination of boxes in the block diagram and / or flowchart can be implemented with a dedicated hardware-based system that performs a specified function or action, or can be implemented with a combination of dedicated hardware and computer instructions.

[0105] In addition, the functional modules in the various embodiments of the present invention may be integrated together to form an independent part, or each module may exist independently, or two or more modules may be integrated to form an independent part.

[0106] If the functions are implemented in the form of software function modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for enabling a computer device (which can be a personal computer, server, or network device, etc.) to perform all or part of the steps of the methods described in various embodiments of the present invention. The aforementioned storage media include: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, and other media that can store program codes.

[0107] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. A task scheduling method, characterized in that: The method comprises: Adjust the current priority of each task to be scheduled in the main queue according to the current resource load; When the number of priority adjustments corresponding to any task to be scheduled in the main queue reaches a preset number and the time for the task to be scheduled to enter the main queue exceeds a first preset time, the task to be scheduled is stored in the retention queue as a retained task; When the time for any stranded task in the stranded queue to enter the stranded queue exceeds a second preset time, the current priority of the stranded task is adjusted according to the stranded time of the stranded task; the stranded time is the difference between the time when the stranded task enters the main queue and the current time; The retained tasks with adjusted priorities are stored again in the main queue as tasks to be scheduled; The tasks to be scheduled in the main queue are scheduled according to the order of their current priorities.

2. The task scheduling method according to claim 1, characterized in that: The step of adjusting the current priority of each task to be scheduled in the main queue according to the current resource load includes: Determine a load adjustment factor according to the current resource load; wherein, when the current resource load is greater than or equal to a preset value, the corresponding load adjustment factor is a negative number; when the current resource load is less than the preset value, the corresponding load adjustment factor is a positive number; Determine a customer impact factor according to the customer level of each task to be scheduled in the main queue; the customer impact factor is proportional to the customer level; Determine an access frequency factor according to the number of accesses of each of the tasks to be scheduled within a set period; the access frequency factor is proportional to the number of accesses; The current priority of each of the tasks to be scheduled is adjusted according to the load adjustment factor, the customer impact factor corresponding to each of the tasks to be scheduled, and the access frequency factor corresponding to each of the tasks to be scheduled.

3. The task scheduling method according to claim 2, characterized in that: The adjusting the current priority of each of the tasks to be scheduled according to the load adjustment factor, the customer impact factor corresponding to each of the tasks to be scheduled, and the access frequency factor corresponding to each of the tasks to be scheduled includes: According to the formula The current priority of each task to be scheduled is adjusted; wherein, represents the adjusted priority of the task to be scheduled, represents the current priority of the task to be scheduled, represents the load adjustment factor, represents the customer impact factor corresponding to the task to be scheduled, Indicates the access frequency factor corresponding to the task to be scheduled.

4. The task scheduling method according to claim 1, characterized in that: The adjusting the current priority of the stranded task according to the stranded duration of the stranded task includes: Calculate the product of the detention time of the detention task and the preset growth coefficient; The product is added to the current priority of the stranded task to obtain the adjusted priority of the stranded task.

5. The task scheduling method according to claim 1, characterized in that: After scheduling the tasks to be scheduled in the main queue according to the order of their current priorities, the method further includes: When there are multiple tasks to be scheduled with the same priority, the scheduling order of the multiple tasks to be scheduled is determined according to the task types, task sizes and / or estimated execution times of the multiple tasks to be scheduled.

6. The task scheduling method according to any one of claims 1 to 5, characterized in that: The method further comprises: When each task to be scheduled enters the main queue for the first time, the initial priority of the task to be scheduled is calculated according to the task type, task size and estimated execution time of the task to be scheduled.

7. The task scheduling method according to claim 6, characterized in that: The calculating the initial priority of the task to be scheduled according to the task type, task size and estimated execution time of the task to be scheduled includes: Converting the task type of the task to be scheduled according to a preset task type conversion function, and multiplying the obtained task type conversion value by a preset task type weight to obtain a first product; Converting the task size of the task to be scheduled according to a preset task size conversion function, and multiplying the obtained task size conversion value by a preset task size weight to obtain a second product; Converting the estimated execution time of the task to be scheduled according to a preset execution time conversion function, and multiplying the obtained execution time conversion value by a preset execution time weight to obtain a third product; The first product, the second product and the third product are added together to obtain the initial priority of the task to be scheduled.

8. A task scheduling device, characterized in that: The device comprises: The priority adjustment module is used to adjust the current priority of each task to be scheduled in the main queue according to the current resource load; A queue management module, configured to store any to-be-scheduled task in the main queue as a stranded task in the stranded queue when the number of priority adjustments corresponding to any to-be-scheduled task in the main queue reaches a preset number and the length of time the to-be-scheduled task enters the main queue exceeds a first preset length of time; The priority adjustment module is further configured to adjust the current priority of the stranded task according to the stranded duration of the stranded task when the duration of time that any stranded task in the stranded queue enters the stranded queue exceeds a second preset duration; the stranded duration is the difference between the time when the stranded task enters the main queue and the current time; The queue management module is further used to store the stranded tasks after priority adjustment back into the main queue as tasks to be scheduled; The task scheduling module is used to schedule the tasks to be scheduled in the main queue according to the order of their current priorities.

9. An electronic device, characterized in that: The method comprises a processor, a memory and a computer program stored in the memory and executable on the processor, wherein the computer program, when executed by the processor, implements the steps of the task scheduling method according to any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the task scheduling method according to any one of claims 1 to 7 are implemented.

Citation Information

Patent Citations

  • Task scheduling method and device based on multi-factor cooperation and storage medium

    CN112035236A

  • Job scheduling method and device, computer equipment and storage medium

    CN118277062A

  • Workload scheduling using queues with different priorities

    US20240118920A1

Cited By

  • High-speed rail business channel ticket checking service method based on data transmission

    CN120031343A

  • Real-time scheduling method and system based on Wayland protocol

    CN120743484A

  • Data-driven scheduling method for task operation optimization in intelligent computing center

    CN120849047A

  • A data-driven scheduling method for task execution optimization in an intelligent computing center

    CN120849047B