A resource allocation method and device, computer equipment and storage medium
By dynamically adjusting the resource thresholds and task attributes of virtual partitions, the problem of unfair resource allocation is solved, achieving fair and reasonable resource allocation and improving user experience.
Patent Information
- Application Number
- CN202210999939.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-19
- Publication Date
- 2025-12-12
- Estimated Expiration
- 2042-08-19
AI Technical Summary
In resource allocation, some recipients occupy too many resources for a long time, resulting in insufficient resources for other recipients. Existing technologies, which use manually determined allocation ratios, lead to unfair resource allocation.
By determining the resource threshold, task attributes, and current resource usage of virtual partitions, resource allocation is dynamically adjusted to ensure fair and reasonable resource thresholds. Partitions to be allocated and those to be allocated resources are selected, and resource allocation is optimized based on task demand and historical execution time.
It achieves fair and reasonable allocation of resources, reduces resource waste, and improves user experience and allocation accuracy.
Smart Images

Figure CN115357386B_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of computer technology, and more specifically, to a resource allocation method, apparatus, computer equipment, and storage medium. Background Technology
[0002] When allocating resources (such as allocating resources to various departments within an enterprise), it often happens that some allocation objects (such as departments, groups, virtual partitions, etc.) occupy too many resources for too long, while other allocation objects have insufficient resources and can only wait for a long time for the allocation objects to use up their occupied resources before they can use them.
[0003] In related technologies, total resources are typically allocated according to a manually determined ratio. However, because the tasks performed by each allocation object and the resources required for each task change in real time, this method often results in some allocation objects having insufficient resources while others have excessive resources. Therefore, how to allocate resources fairly has become an urgent problem to be solved. Summary of the Invention
[0004] This disclosure provides at least one resource allocation method, apparatus, computer device, and storage medium.
[0005] In a first aspect, embodiments of this disclosure provide a resource allocation method, including:
[0006] Determine the resource information of multiple virtual partitions, wherein the resource information includes the resource threshold of the virtual partition, the task attributes of each task executed in the virtual partition, and the current resource usage of the virtual partition;
[0007] Based on the resource information of each virtual partition, determine the partitions to be allocated among the multiple virtual partitions and the number of resources to be allocated corresponding to the partitions to be allocated; and based on the resource thresholds and the current number of resources occupied by the multiple virtual partitions, determine the resource allocation partitions among the multiple virtual partitions.
[0008] The resources of the resource allocation partition are allocated to the partition to be allocated according to the number of resources to be allocated.
[0009] In the method, the to-be-allocated partition and the to-be-allocated resource quantity corresponding to the to-be-allocated partition in the plurality of virtual partitions can be determined based on the resource threshold of the virtual partition, the task attribute of each task executed in the virtual partition, and the current occupied resource quantity of the virtual partition, so that the virtual partition with a smaller current occupied resource quantity can be ensured to be the to-be-allocated partition. In addition, the resource allocation partition in the plurality of virtual partitions can be determined based on the resource threshold and the current occupied resource quantity of the plurality of virtual partitions, so that the virtual partition with a larger current occupied resource quantity can be ensured to be the resource allocation partition. Finally, the resource of the resource allocation partition is allocated to the to-be-allocated partition by using the to-be-allocated resource quantity, so that the resource allocation partition can appropriately allocate excessive resources to the to-be-allocated partition, thereby achieving fair resource allocation.
[0010] In a possible implementation, the method further includes determining the resource threshold of the plurality of virtual partitions according to the following method, which includes:
[0011] determining preset weights of the plurality of virtual partitions and total allocated resources corresponding to the plurality of virtual partitions;
[0012] determining initial resource thresholds corresponding to the plurality of virtual partitions based on the preset weights of the plurality of virtual partitions and the total allocated resources corresponding to the plurality of virtual partitions;
[0013] determining the resource threshold of the plurality of virtual partitions based on the initial resource threshold, the task attribute of each task executed in the virtual partition, and the current occupied resource quantity of the virtual partition.
[0014] In this way, because the resource threshold is determined according to the preset weight, the total allocated resource, and the task attribute, and the total allocated resource and the task attribute can change according to the change of the task in the virtual partition, the resource threshold of each virtual partition can dynamically change according to the execution status of the task in each virtual partition, thereby making the resource threshold more fair and reasonable.
[0015] In a possible implementation, the task attribute includes a task running state of each task executed in the virtual partition and a resource demand quantity corresponding to each task.
[0016] The determining the to-be-allocated partition in the plurality of virtual partitions based on the resource information of each virtual partition includes:
[0017] determining a first candidate partition containing a to-be-executed task;
[0018] In a case where a sum of a resource requirement amount of any to-be-executed task of any first candidate partition and a current occupied resource amount of the first candidate partition does not exceed a resource threshold of the first candidate partition, the first candidate partition is determined as the to-be-allocated partition.
[0019] By using this method, the to-be-allocated partition that can receive resources can be screened by the resource threshold, so that the virtual partition of the task with a larger resource requirement amount cannot receive resources as the to-be-allocated partition, and the situation that the virtual partition occupies more resources is reduced to a certain extent.
[0020] In a possible implementation, the determining, based on the resource threshold and the current occupied resource amount of each of the plurality of virtual partitions, of a resource allocation partition from the plurality of virtual partitions includes:
[0021] determining a second candidate partition whose current occupied resource amount exceeds the resource threshold;
[0022] determining the resource allocation partition based on the second candidate partition.
[0023] By using this method, the virtual partition that occupies too many resources can be accurately screened by the resource threshold, and the virtual partition that occupies too many resources is determined as the resource allocation partition, so that the fairness of resource allocation is improved.
[0024] In a possible implementation, the determining, based on the second candidate partition, of the resource allocation partition includes:
[0025] in a case where there are a plurality of second candidate partitions, determining, for any second candidate partition, a target ratio of the current occupied resource amount of the second candidate partition to the resource threshold;
[0026] determining the resource allocation partition based on the target ratio.
[0027] By using this method, the candidate partition with the highest excess degree of excess occupied resources can be determined as the resource allocation partition, so that the rationality and fairness of resource allocation are improved.
[0028] In a possible implementation, the determining of the to-be-allocated resource amount corresponding to the to-be-allocated partition includes:
[0029] determining a first target task from the to-be-executed tasks of the to-be-allocated partition;
[0030] determining the to-be-allocated resource amount based on a resource requirement amount in a task attribute corresponding to the first target task.
[0031] By using the method, the resource can be accurately obtained according to the actual resource requirement of the first target task, and the resource allocation accuracy is improved.
[0032] In a possible implementation, the determining of the first target task from the tasks to be executed in the to-be-allocated partition comprises:
[0033] determining a first candidate task from the tasks to be executed in the to-be-allocated partition, wherein a sum of a resource requirement of the first candidate task and the current occupied resource quantity does not exceed the resource threshold of the to-be-allocated partition.
[0034] determining the first target task from the first candidate task based on a task attribute of the first candidate task.
[0035] By using the method, the current occupied resource of the to-be-allocated partition can be ensured to not exceed the resource threshold after the resource is allocated to the first target task, so that the to-be-allocated partition is prevented from obtaining excessive resources, and the fairness and rationality of the resource allocation are improved.
[0036] In a possible implementation, the allocating of the resource of the resource allocation partition to the to-be-allocated partition comprises:
[0037] determining a second target task to be released in the resource allocation partition based on a task attribute of each task executed in the resource allocation partition and the to-be-allocated resource quantity.
[0038] allocating a resource occupied by the second target task to the to-be-allocated partition.
[0039] By using the method, the second target task suitable for allocating the resource can be determined according to the task attribute and the to-be-allocated resource quantity.
[0040] In a possible implementation, the task attribute of the task comprises a historical execution time, a resource requirement, and a resource occupation permission.
[0041] The determining of the second target task to be released in the resource allocation partition based on the task attribute of each task executed in the resource allocation partition and the to-be-allocated resource quantity comprises:
[0042] determining a second candidate task being executed in the resource allocation partition and having a target permission as a resource occupation permission.
[0043] determining the second target task based on a historical execution time, a resource requirement of the second candidate task, and the to-be-allocated resource quantity.
[0044] Using this method, since the second target task has already performed calculations using the occupied resources for a period of time before the resources are allocated, the previously calculated content is difficult to save after the occupied resources are allocated to the partition to be allocated. Therefore, prioritizing tasks with shorter historical execution times as the second target task can reduce the waste of computing resources.
[0045] In one possible implementation, after determining the partitions to be allocated among the plurality of virtual partitions, and before allocating the resources of the resource allocation partition to the partitions to be allocated according to the number of resources to be allocated, the method further includes:
[0046] The time it takes for the partition to be allocated to meet the preset conditions exceeds a preset time.
[0047] The preset conditions include:
[0048] The partition to be allocated has tasks to be executed, and the current amount of resources occupied by the partition to be allocated is less than the resource threshold of the partition to be allocated.
[0049] This method reduces the frequency of resource changes by setting a preset duration, improving the user experience. Furthermore, the preset conditions ensure that the partition to be allocated always receives allocated resources until the preset conditions are met for a period exceeding the preset duration, thus ensuring a fairer resource allocation.
[0050] In one possible implementation, after determining the partitions to be allocated among the plurality of virtual partitions and the number of resources to be allocated corresponding to the partitions to be allocated, the method further includes:
[0051] Determine the number of idle resources in the plurality of virtual partitions;
[0052] If the number of idle resources is not less than the number of resources to be allocated, the idle resources are allocated to the partition to be allocated.
[0053] This approach allows partitions awaiting allocation to prioritize the use of idle resources when such resources are available, reducing changes to currently used resources and improving the user experience.
[0054] In one possible implementation, after allocating the resources of the resource allocation partition to the partition to be allocated according to the number of resources to be allocated, the method further includes:
[0055] Determine whether the virtual partition, after obtaining allocated resources, meets the preset conditions;
[0056] If so, the quantity of resources to be allocated and the resource allocation partition are re-determined, and resources are re-allocated to the virtual partition after the allocation of resources.
[0057] By using this method, the virtual partition currently occupying too few resources can be allocated multiple times to improve the fairness of resource allocation.
[0058] In a second aspect, the present disclosure also provides a resource allocation apparatus, comprising:
[0059] A first determining module configured to determine resource information of a plurality of virtual partitions, wherein the resource information comprises resource thresholds of the virtual partitions, task attributes of tasks executed in the virtual partitions, and current occupied resource quantities of the virtual partitions;
[0060] A second determining module configured to determine, based on the resource information of each virtual partition, a to-be-allocated partition in the plurality of virtual partitions and a to-be-allocated resource quantity corresponding to the to-be-allocated partition, and determine, based on the resource thresholds and the current occupied resource quantities of the plurality of virtual partitions, a resource allocation partition in the plurality of virtual partitions;
[0061] An allocating module configured to allocate resources of the resource allocation partition to the to-be-allocated partition according to the to-be-allocated resource quantity.
[0062] In a possible implementation, the first determining module is further configured to determine the resource thresholds of the plurality of virtual partitions according to the following method:
[0063] Determine preset weights of the plurality of virtual partitions and total allocated resource quantities corresponding to the plurality of virtual partitions;
[0064] Determine initial resource thresholds corresponding to each virtual partition based on the preset weights of the plurality of virtual partitions and the total allocated resource quantities corresponding to the plurality of virtual partitions;
[0065] Determine the resource thresholds of the plurality of virtual partitions based on the initial resource thresholds, the task attributes of tasks executed in the virtual partitions, and the current occupied resource quantities of the virtual partitions.
[0066] In a possible implementation, the task attributes comprise task running states of tasks executed in the virtual partitions and resource demand quantities corresponding to the tasks.
[0067] The second determining module, when determining the to-be-allocated partition in the plurality of virtual partitions based on the resource information of each virtual partition, is configured to:
[0068] Determine a first candidate partition containing a to-be-executed task;
[0069] For any first candidate partition, if the sum of the resource requirements of any task to be executed in the first candidate partition and the current occupied resources of the first candidate partition does not exceed the resource threshold of the first candidate partition, the first candidate partition is determined as the partition to be allocated.
[0070] In one possible implementation, the second determining module, when determining the resource allocation partition among the plurality of virtual partitions based on the resource thresholds and the current amount of resources occupied by the plurality of virtual partitions, is used to:
[0071] Identify a second candidate partition whose current resource usage exceeds the resource threshold;
[0072] The resource allocation partition is determined based on the second candidate partition.
[0073] In one possible implementation, the second determining module, when determining the resource allocation partition based on the second candidate partition, is configured to:
[0074] When there are multiple second candidate partitions, for any second candidate partition, determine the target ratio of the current occupied resources of that second candidate partition to the resource threshold.
[0075] Based on the target ratio, the resource allocation partition is determined.
[0076] In one possible implementation, the second determining module, when determining the number of resources to be allocated corresponding to the partition to be allocated, is used to:
[0077] Determine the first target task among the tasks to be executed in the partition to be allocated;
[0078] The quantity of resources to be allocated is determined based on the resource requirement in the task attributes corresponding to the first target task.
[0079] In one possible implementation, the second determining module, when determining the first target task among the tasks to be executed in the partition to be allocated, is used to:
[0080] Among the tasks to be executed in the partition to be allocated, the first candidate task is determined whose resource requirement and the sum of the currently occupied resources do not exceed the resource threshold of the partition to be allocated.
[0081] Based on the task attributes of the first candidate task, the first target task is determined from the first candidate task.
[0082] In one possible implementation, the allocation module, when allocating resources from the resource allocation partition to the partition to be allocated according to the number of resources to be allocated, is used to:
[0083] determine a second target task to be released in the resource allocation partition based on the task attributes of the tasks executed in the resource allocation partition and the number of resources to be allocated;
[0084] allocate resources occupied by the second target task to the to-be-allocated partition.
[0085] In a possible implementation, the task attributes of the tasks include historical execution time, resource demand, and resource occupation authority.
[0086] The second determining module is configured to:
[0087] determine a second candidate task being executed in the resource allocation partition and having a resource occupation authority as the target authority;
[0088] determine the second target task based on the historical execution time, the resource demand of the second candidate task, and the number of resources to be allocated.
[0089] In a possible implementation, after determining the to-be-allocated partition in the plurality of virtual partitions, and before allocating the resources of the resource allocation partition to the to-be-allocated partition according to the number of resources to be allocated, the second determining module is further configured to:
[0090] determine that the to-be-allocated partition satisfies a preset condition for a time period exceeding a preset time period;
[0091] The preset condition includes:
[0092] the to-be-allocated partition has a task to be executed, and a current occupied resource quantity of the to-be-allocated partition is less than a resource threshold of the to-be-allocated partition.
[0093] In a possible implementation, after determining the to-be-allocated partition in the plurality of virtual partitions and the number of resources to be allocated corresponding to the to-be-allocated partition, the second determining module is further configured to:
[0094] determine an idle resource quantity in the plurality of virtual partitions;
[0095] in a case where the idle resource quantity is not less than the number of resources to be allocated, allocate the idle resources to the to-be-allocated partition.
[0096] In a possible implementation, after allocating the resources of the resource allocation partition to the to-be-allocated partition according to the number of resources to be allocated, the allocating module is further configured to:
[0097] determine whether the virtual partition after obtaining the allocated resources meets the preset condition;
[0098] If yes, the number of resources to be allocated and the resource allocation partition are re-determined, and resource allocation is performed again for the virtual partition after obtaining the allocated resources.
[0099] In a third aspect, the embodiments of the present disclosure further provide a computer device, comprising a processor, a memory and a bus, the memory stores machine readable instructions executable by the processor, when the computer device is running, the processor and the memory communicate through the bus, and the machine readable instructions are executed by the processor to perform the steps of the above-mentioned first aspect or any possible implementation manner of the first aspect.
[0100] In a fourth aspect, the embodiments of the present disclosure further provide a computer readable storage medium, the computer readable storage medium stores a computer program, and the computer program is executed by the processor to perform the steps of the above-mentioned first aspect or any possible implementation manner of the first aspect.
[0101] The effects of the above-mentioned resource allocation device, computer device and computer readable storage medium are described in the above-mentioned resource allocation method, which will not be repeated here.
[0102] It should be understood that the above general description and the following detailed description are only exemplary and explanatory, but not limiting the technical solutions of the present disclosure.
[0103] In order to make the above-mentioned purposes, features and advantages of the present disclosure more obvious and easy to understand, the following preferred embodiments are specifically described with the attached drawings, as follows. BRIEF DESCRIPTION OF DRAWINGS
[0104] The drawings incorporated into the specification and forming a part of the specification, show embodiments consistent with the present disclosure, and together with the specification, serve to explain the technical solutions of the present disclosure.
[0105] In order to more clearly illustrate the technical solutions of the embodiments of the present disclosure, the following will briefly introduce the drawings needed to be used in the embodiments, the drawings incorporated into the specification and forming a part of the specification, show embodiments consistent with the present disclosure, and together with the specification, serve to explain the technical solutions of the present disclosure. It should be understood that the following drawings only show some embodiments of the present disclosure, and therefore should not be regarded as a limitation on the scope, and for those skilled in the art, other related drawings can also be obtained without creative labor.
[0106] Figure 1 A flow chart of a resource allocation method provided by the embodiments of the present disclosure is shown;
[0107] Figure 2 An architecture schematic diagram of a resource allocation apparatus provided by an embodiment of the present disclosure is shown.
[0108] Figure 3 A structure schematic diagram of a computer device provided by an embodiment of the present disclosure is shown. DETAILED DESCRIPTION
[0109] To make the objectives, technical solutions and advantages of the embodiments of the present disclosure clearer, the technical solutions in the embodiments of the present disclosure will be described clearly and completely below with reference to the drawings in the embodiments of the present disclosure. Obviously, the described embodiments are only part of the embodiments of the present disclosure, rather than all the embodiments. The components of the embodiments of the present disclosure described and shown in the drawings herein can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present disclosure provided in the drawings is not intended to limit the scope of the claimed present disclosure, but only represents selected embodiments of the present disclosure. Based on the embodiments of the present disclosure, all other embodiments obtained by those skilled in the art without creative work fall within the scope of protection of the present disclosure.
[0110] In resource allocation (such as resource allocation to various departments within an enterprise), it is often the case that some allocation objects (such as departments, groups, virtual partitions, etc.) occupy too many resources for too long a time, while other allocation objects are short of resources and can only wait for a long time before using the resources occupied by the some allocation objects.
[0111] In the related art, the total resources are usually allocated according to the allocation ratio determined manually, but since the tasks performed by each allocation object and the resources required by each task are real-time changes, using this method often results in the case that some allocation objects are short of resources while other allocation objects have too many resources. Therefore, how to allocate resources fairly becomes a problem to be solved urgently.
[0112] Based on the above research, the present disclosure provides a resource allocation method, device, computer equipment and storage medium, which can determine a to-be-allocated partition in a plurality of virtual partitions and a to-be-allocated resource quantity corresponding to the to-be-allocated partition based on the resource threshold of the virtual partition, the task attribute of each task executed in the virtual partition, and the current occupied resource quantity of the virtual partition, so as to ensure that the virtual partition with a smaller current occupied resource quantity can be used as the to-be-allocated partition. In addition, the resource allocation partition in the plurality of virtual partitions can be determined based on the resource threshold and the current occupied resource quantity of the plurality of virtual partitions, so as to ensure that the virtual partition with a larger current occupied resource quantity can be used as the resource allocation partition. Finally, the resource of the resource allocation partition is allocated to the to-be-allocated partition through the determined to-be-allocated resource quantity, so that the resource allocation partition can appropriately allocate too much resource to the to-be-allocated partition, thereby realizing fair resource allocation.
[0113] It should be noted that similar reference numerals and letters refer to like items in the drawings, and thus once an item is defined in one drawing, it need not be further defined and explained in subsequent drawings.
[0114] The term "and / or" herein is merely used to describe an associated relationship, which means that there can be three relationships, for example, A and / or B can mean that A exists alone, A and B exist together, and B exists alone. In addition, the term "at least one" herein means any one of a plurality or any combination of at least two of a plurality, for example, including at least one of A, B, and C can mean including any one or more elements selected from the set consisting of A, B, and C.
[0115] In order to facilitate the understanding of the present embodiment, first, a resource allocation method disclosed by the present embodiment is introduced in detail, and the execution subject of the resource allocation method provided by the present embodiment is generally a computer equipment with certain computing capability, for example, a server. In some possible implementation manners, the resource allocation method can be realized by a processor calling computer readable instructions stored in a memory.
[0116] Referring to FIG. 1, Figure 1 The method includes steps 101-103, wherein:
[0117] Step 101, determine the resource information of a plurality of virtual partitions, wherein the resource information includes the resource threshold of the virtual partition, the task attribute of each task executed in the virtual partition, and the current occupied resource quantity of the virtual partition;
[0118] Step 102, determining a to-be-allocated partition in the plurality of virtual partitions and a to-be-allocated resource quantity corresponding to the to-be-allocated partition based on resource information of each virtual partition; and determining a resource allocation partition in the plurality of virtual partitions based on resource threshold values and current occupied resource quantities of the plurality of virtual partitions;
[0119] Step 103, allocating resources of the resource allocation partition to the to-be-allocated partition according to the to-be-allocated resource quantity.
[0120] The following is a detailed description of the above steps:
[0121] For step 101,
[0122] Specifically, the resources can be devices, such as graphics processing units (GPUs) and central processing units (CPUs).
[0123] The virtual partition (VPar) can be used to execute at least one task by occupied resources. In actual applications, one virtual partition can correspond to a department, a team, or the like.
[0124] The task can exemplarily be a computer project (such as image processing and data analysis). The resource threshold value of the virtual partition is a limit of resources that can be occupied by the virtual partition, such as 5 GPUs. The resource threshold value can limit the maximum quantity of resources that can be occupied by each virtual partition.
[0125] The task attribute can include at least one of the following: a task running state of each task executed in the virtual partition, a resource demand quantity corresponding to each task, a historical execution time of each task, and a resource occupation permission of each task.
[0126] The task running state can include a to-be-executed state and an executing state, a task in the executing state is an executing task, a task in the to-be-executed state is a to-be-executed task, the resource requirement of any task represents the number of resources required for executing the task, for example, the resource requirement of task A is 2, the historical execution time of any task represents the total execution time of the task since the task is created, for example, task A is created on January 1 and executed for 3 hours, and executed for 2 hours on January 3, so the historical execution time of task A is 5 hours, and the resource occupation permission of each task can exemplarily include an unallocable permission and an allocable permission, and can also be divided into a first-level permission, a second-level permission and a third-level permission according to the level of the permission. By setting the resource occupation permission, it can be limited which tasks can allocate resources and which tasks can receive resources, and the resources occupied by some important tasks (such as the protected task in the following) are protected to prevent being preempted by other tasks.
[0127] The current occupied resource quantity of the virtual partition represents the number of resources being used by the virtual partition (i.e., the total amount of resources being used by the tasks in the virtual partition), for example, the executing tasks in the virtual partition A include task 1, task 2 and task 3, the resource requirement of task 1 is 1, the resource requirement of task 2 is 2, and the resource requirement of task 3 is 3, so the current occupied resource quantity of the virtual partition A is 6.
[0128] Here, since the resources being used by the protected task do not participate in the allocation of resources (here, referring to the re-allocation of the currently occupied resources), when the protected task with the resource occupation permission being the unallocable permission is included in each task executing in the virtual partition, the current occupied resource quantity of the virtual partition does not include the resources being used by the protected task, and continuing the above example, if task 3 is the protected task, the current occupied resource quantity of the virtual partition is the sum of the resource requirements of task 1 and task 2, which is 3.
[0129] In a possible implementation, when determining the resource threshold of the plurality of virtual partitions, the preset weights of the plurality of virtual partitions and the total number of allocated resources corresponding to the plurality of virtual partitions can be determined first, and then the resource threshold of the plurality of virtual partitions is determined based on the preset weights of the plurality of virtual partitions, the total number of allocated resources corresponding to the plurality of virtual partitions, the task attributes of each task executing in the virtual partition, and the current occupied resource quantity of the virtual partition.
[0130] The preset weights of the plurality of virtual partitions can be artificially preset, or the preset weights can be determined according to the number of tasks of each virtual partition, the size (such as the number of people in the department corresponding to the virtual partition) of each virtual partition, and the budget of each virtual partition.
[0131] Since the protected tasks do not participate in resource allocation, the total number of allocated resources corresponding to the plurality of virtual partitions is the total sum of resources of the plurality of virtual partitions minus the resource requirement of the protected tasks in the plurality of virtual partitions; for example, if the total sum of resources of a cluster (i.e., the total sum of resources of all virtual partitions under the cluster) is 10, there are 2 virtual partitions in the cluster: virtual partition A and virtual partition B, the resource requirement of the protected task in virtual partition A is 1, and the resource requirement of the protected task in virtual partition B is 2, then the total number of allocated resources of the cluster is 10-1-2=7.
[0132] Here, it should be noted that the tasks of each virtual partition are actively submitted by the user end of each virtual partition, and the total sum of resources of the plurality of virtual partitions is constant, but since the protected tasks submitted by each virtual partition can change, the total number of allocated resources corresponding to the plurality of virtual partitions can be dynamically changed, and the current occupied resources of the plurality of virtual partitions are also dynamically changed with the creation, cancellation of tasks, and changes in task running state, and accordingly, the resource threshold of each virtual partition is also a dynamically changing value.
[0133] The following is a specific implementation method for determining the resource threshold of the plurality of virtual partitions, which is divided into steps A1-A5.
[0134] A1, the resource possession ratio of the plurality of virtual partitions can be determined based on the preset weights of the plurality of virtual partitions, and then the initial resource threshold of the plurality of virtual partitions is determined based on the resource possession ratio of the plurality of virtual partitions and the total number of allocated resources.
[0135] Specifically, for any virtual partition, the resource possession ratio can be the preset weight of the virtual partition divided by the sum of the preset weights of other virtual partitions, and when determining the initial resource threshold, the resource possession ratio can be multiplied by the total number of allocated resources.
[0136] For example, if there are 3 virtual partitions in a cluster: virtual partition A, virtual partition B, and virtual partition C, the preset weight of virtual partition A is 1, the preset weight of virtual partition B is 2, and the preset weight of virtual partition C is 0, then the resource possession ratio of virtual partition A is The resource possession ratio of virtual partition B is The resource possession ratio of virtual partition C is 0÷(1+2+0)=0. If the total number of allocated resources of the cluster is 18, then the initial resource threshold of virtual partition A is The initial resource threshold of virtual partition B is The initial resource threshold of virtual partition C is 18x0=0.
[0137] A2, determining the to-be-determined resource threshold of the plurality of virtual partitions based on the initial resource threshold and the sum of the resource demands of the plurality of virtual partitions; wherein the sum of the resource demands is the sum of the resource demands of the tasks other than the protected tasks executed in the virtual partitions.
[0138] Specifically, for any virtual partition, the sum of the resource demands of the virtual partition can be determined first, and in the case where the initial resource threshold of the virtual partition is greater than or equal to the sum of the resource demands of the virtual partition, the sum of the resource demands of the virtual partition is taken as the to-be-determined resource threshold of the virtual partition; in the case where the initial resource threshold of the virtual partition is less than the sum of the resource demands of the virtual partition, the initial resource threshold of the virtual partition is taken as the to-be-determined resource threshold of the virtual partition.
[0139] Here, if there is no case where the initial resource threshold of a virtual partition is greater than or equal to the sum of the resource demands of the virtual partition, the to-be-determined resource threshold can be directly taken as the resource threshold of each virtual partition, and if there is, after determining the to-be-determined resource threshold once according to the above steps, since the initial resource threshold of a part of the virtual partitions is greater than the sum of the resource demands, there is some idle resources, and the sum of the resource demands of another part of the virtual partitions can be greater than the initial resource threshold, so the resource demands of this part of the virtual partitions cannot be met, and therefore the idle resources can be allocated again.
[0140] A3, for each virtual partition whose initial resource threshold is greater than or equal to the sum of the resource demands, the difference between the initial resource threshold and the sum of the resource demands of each virtual partition is taken as the idle resource quantity.
[0141] A4, for each virtual partition whose initial resource threshold is less than the sum of the resource demands (hereinafter referred to as a target virtual partition), the initial resource threshold and the sum of the resource demands of the target virtual partition are determined again.
[0142] Specifically, when the initial resource threshold of the target virtual partition is determined again, the resource possession ratio of the target virtual partition can be determined again based on the preset weight of the target virtual partition, i.e. for any target virtual partition, the preset weight of the target virtual partition is divided by the sum of the preset weights of the other target virtual partitions, and then the determined resource possession ratio is multiplied by the idle resource quantity to obtain the determined initial resource threshold of the target virtual partition.
[0143] When the sum of the resource demands is determined again, for any target virtual partition, the difference between the sum of the resource demands and the initial resource threshold (here, the initial resource threshold determined before the initial resource threshold is determined again in A4) is taken as the determined sum of the resource demands.
[0144] A5, compare the sum of the re-determined initial resource threshold and the re-determined resource demand of each target virtual partition, and detect whether there is a virtual partition whose initial resource threshold is greater than the sum of the resource demands.
[0145] If yes, return to execute the step of A2;
[0146] If no, for any virtual partition, add the to-be-determined resource threshold of the virtual partition to obtain the resource threshold of the virtual partition. Here, when the initial resource threshold of any virtual partition is greater than or equal to the sum of the resource demands, the resource threshold of the virtual partition can be calculated.
[0147] For example, there are three virtual partitions in a cluster: virtual partition 1, virtual partition 2 and virtual partition 3. If the initial resource threshold of virtual partition 1 is 6 and the sum of the resource demands is 5, the to-be-determined resource threshold of virtual partition 1 is 5; the initial resource threshold of virtual partition 2 is 12 and the sum of the resource demands is 10, the to-be-determined resource threshold of virtual partition 2 is 10; the initial resource threshold of virtual partition 3 is 0 and the sum of the resource demands is 4, the to-be-determined resource threshold of virtual partition 3 is 0.
[0148] Continuing the above example, the initial resource thresholds of virtual partition 1 and virtual partition 2 are greater than the sum of the resource demands, the number of idle resources of virtual partition 1 is 6-5=1, the number of idle resources of virtual partition 2 is 12-10=2, and the number of idle resources of the cluster is 1+2=3. The to-be-determined resource threshold of virtual partition 3 is 0, so the sum of the resource demands of virtual partition 3 is 4-0=4. (Here, since only virtual partition 3 still needs to determine the to-be-determined resource threshold, the initial resource threshold of virtual partition 3 does not need to be calculated, and the idle resources can be directly allocated to virtual partition 3.) Since the number of idle resources 3 is less than the sum of the resource demands 4 of virtual partition 3, all the 3 resources are allocated to virtual partition 3, and the resource threshold of virtual partition 1 is finally 5, the resource threshold of virtual partition 2 is 10, and the resource threshold of virtual partition 3 is 3.
[0149] By using this method, since the resource threshold is determined according to the preset weight, the total number of allocated resources and the task attribute, and the total number of allocated resources and the task attribute can change according to the change of the tasks in the virtual partition, the resource threshold of each virtual partition will also dynamically change with the execution status of the tasks in each virtual partition, so that the resource threshold can be more fair and reasonable.
[0150] In a possible implementation, the total number of allocated resources of the plurality of virtual partitions changes due to the task condition changes (such as task completion resource release, task cancellation, task creation) of the plurality of virtual partitions, and thus the resource threshold changes. Therefore, the resource threshold of the plurality of virtual partitions can be re-determined every preset time (such as 30 seconds) to update the resource threshold of the plurality of virtual partitions in real time.
[0151] For step 102,
[0152] The to-be-allocated partition is a partition receiving resources, the resource-allocable partition is a partition sending resources, and the resource allocation partition is used to allocate part of the resources being used to the to-be-allocated partition, so that the resources of a virtual partition occupying too many resources can be allocated to a virtual partition occupying fewer resources.
[0153] Here, the resource allocation partition can be at least one, that is, resources of multiple resource allocation partitions can be allocated to the same to-be-allocated partition.
[0154] In a possible implementation, when the task attribute includes the task running state of each task executed by the virtual partition and the resource demand amount corresponding to each task, when the to-be-allocated partition in the plurality of virtual partitions is determined based on the resource information of each virtual partition, a first candidate partition containing a to-be-executed task can be first determined, and then for any first candidate partition, if the sum of the resource demand amount of any to-be-executed task in the first candidate partition and the current occupied resource amount of the first candidate partition does not exceed the resource threshold of the first candidate partition, the first candidate partition is determined as the to-be-allocated partition.
[0155] Specifically, since the to-be-allocated partition is a virtual partition with insufficient resources, the to-be-allocated partition includes at least one to-be-executed task waiting for resources, and thus a first candidate partition containing a to-be-executed task can be first determined. Then, in order to limit the amount of resources that each partition can obtain through the resource threshold and prevent each partition from obtaining too many resources, it is necessary to make the current occupied resource of each partition still not exceed the resource threshold after obtaining resources, and thus the sum of the resource demand amount of any to-be-executed task in the first candidate partition and the current occupied resource amount of the first candidate partition can be calculated, and if the sum does not exceed the resource threshold of the first candidate partition, the first candidate partition is determined as the to-be-allocated partition.
[0156] If a virtual partition allocates fewer resources, but the virtual partition does not contain a to-be-executed task, it indicates that the currently allocated resources of the virtual partition are sufficient for the resource partition, and thus the virtual partition can not be used as a to-be-allocated partition.
[0157] For any first candidate partition, the resource requirement of each to-be-executed task in the first candidate partition can be sequentially summed with the current occupied resource, and in a case where any sum result does not exceed the resource threshold of the first candidate partition, the first candidate partition is determined as the to-be-allocated partition. Alternatively, the to-be-executed task with the minimum resource requirement in the first candidate partition can be determined first, and if the sum of the resource requirement of the to-be-executed task with the minimum resource and the current occupied resource of the first candidate partition does not exceed the resource threshold of the first candidate partition, the first candidate partition is taken as the to-be-allocated partition.
[0158] For example, the first candidate partition A includes three to-be-executed tasks, the resource requirement of the to-be-executed task 1 is 10, the resource requirement of the to-be-executed task 2 is 5, the resource requirement of the to-be-executed task 3 is 20, the current occupied resource of the first candidate partition A is 40, and the resource threshold of the first candidate partition A is 45. Since 40+5=45, the first candidate partition A can be determined as the to-be-allocated partition. The first candidate partition B includes two to-be-executed tasks, the resource requirement of the to-be-executed task 4 is 20, the resource requirement of the to-be-executed task 5 is 30, the current occupied resource of the first candidate partition B is 50, and the resource threshold of the first candidate partition B is 60. Since 50+20>60 and 50+30>60, the first candidate partition B cannot be determined as the to-be-allocated partition.
[0159] By using this method, the to-be-allocated partition that can receive resources can be screened through the resource threshold, so that the virtual partition of the task with a larger resource requirement cannot receive resources as the to-be-allocated partition, and the situation that the virtual partition occupies more resources is reduced to a certain extent.
[0160] In actual application, due to the frequent change of the resource threshold of the plurality of virtual partitions, the change of the current occupied resource quantity, and the change of the to-be-executed task, the to-be-allocated partition and the resource allocation partition will frequently change, or in other words, before the resource is allocated to a virtual partition again, the resource of the virtual partition itself is enough for the virtual partition to use (for example, some tasks are completed, and then there are idle resources), so that the resource is allocated based on the frequently changed to-be-allocated partition and resource allocation partition, which leads to the same resource frequently changing the virtual partition and the executed task, so that each task can only use the resource for a very short time, and thus cannot be completed.
[0161] Therefore, in order to reduce the frequency of resource change, in a possible implementation, after the to-be-allocated partition in the plurality of virtual partitions is determined, before the resource of the resource allocation partition is allocated to the to-be-allocated partition according to the to-be-allocated resource quantity, it can also be determined that the to-be-allocated partition satisfies the preset condition for more than a preset time length.
[0162] Specifically, for any virtual partition, after determining that the virtual partition is a to-be-allocated partition, the virtual partition can be timed, and whether the virtual partition meets the preset condition can be detected in real time. When it is detected that the virtual partition does not meet the preset condition, the timing is stopped, and the virtual partition is no longer used as a to-be-allocated partition. If the virtual partition always meets the preset condition and the timing exceeds the preset time length, the resources of the resource allocation partition can be allocated to the virtual partition according to the number of to-be-allocated resources.
[0163] Here, it should be noted that the resource allocation partition can be determined when the to-be-allocated partition is determined, or can be determined after the time length during which the to-be-allocated partition meets the preset condition exceeds the preset time length.
[0164] During the timing process, since the resource threshold of the to-be-allocated partition and the current occupied resource quantity can change in real time, the to-be-allocated partition can no longer need to receive resources before the timing reaches the preset time length. Therefore, the to-be-allocated partition that still needs to receive resources can be screened out through the preset condition. In a possible implementation, the preset condition can include that the to-be-allocated partition has a to-be-executed task, and the current occupied resource quantity of the to-be-allocated partition is less than the resource threshold of the to-be-allocated partition. In this way, it can be ensured that the to-be-allocated partition includes a to-be-executed task that needs to be allocated resources, and the current occupied resource quantity of the to-be-allocated partition is less than the resource threshold, thereby improving the fairness of resource allocation.
[0165] In another possible implementation, the preset condition can include that the to-be-allocated partition has a to-be-executed task, and the sum of the resource requirement quantity of any to-be-executed task of the to-be-allocated partition and the current occupied resource quantity of the to-be-allocated partition does not exceed the resource threshold of the to-be-allocated partition.
[0166] Here, when setting the preset time length, if the preset time length is longer, the frequency of resource allocation is lower, and if the preset time length is shorter, the frequency of resource allocation is higher. Therefore, the frequency of resource change can be regulated by adjusting the preset time length.
[0167] In a possible implementation, when it is detected that the number of resource allocations within a preset time is higher than a first preset number, the preset time length is reduced; and when it is detected that the number of resource allocations within a preset time is lower than a second preset number, the preset time length is increased. When the preset time length is reduced or increased, the current preset time length can be added or subtracted according to a preset time length (such as 30 minutes).
[0168] By adopting the method, the frequency of resource change can be reduced by setting the preset time length, and the user experience is improved, and the preset condition can be used to ensure that the to-be-allocated partition always needs to receive the allocated resource before the time length meeting the preset condition exceeds the preset time length, so that the resource allocation is more fair.
[0169] In a possible implementation, when determining the to-be-allocated resource quantity corresponding to the to-be-allocated partition, a first target task in the to-be-executed task of the to-be-allocated partition can be determined first, and then the to-be-allocated resource quantity can be determined based on the resource requirement quantity in the task attribute corresponding to the first target task.
[0170] Specifically, the to-be-allocated partition includes at least one to-be-executed task, so a first target task to be allocated can be selected from the at least one to-be-executed task first, and then the resource requirement quantity of the first target task is used as the to-be-allocated resource quantity to request the resource allocation partition for resources with the to-be-allocated resource quantity.
[0171] In this way, the resource can be accurately obtained according to the actual resource requirement quantity of the first target task for use of the first target task, and the accuracy of resource allocation is improved.
[0172] In a possible implementation, the to-be-allocated partition can preferentially use the unoccupied resource without preoccupying the resource being used by other tasks, that is, after the to-be-allocated partition in the plurality of virtual partitions and the to-be-allocated resource quantity corresponding to the to-be-allocated partition are determined, the idle resource quantity in the plurality of virtual partitions can be determined first, and the idle resource is allocated to the to-be-allocated partition in a case where the idle resource quantity is not less than the to-be-allocated resource quantity.
[0173] The idle resource is an unoccupied resource, and after any task is completed, the resource occupied by the task during execution is released to become the idle resource. Specifically, the idle resource quantity in the plurality of virtual partitions can be detected in real time, and the idle resource is allocated to the to-be-allocated partition in a case where the idle resource quantity is not less than the to-be-allocated resource quantity.
[0174] In a possible implementation, in a case where there are a plurality of to-be-allocated partitions, the idle resource can be allocated to the to-be-allocated partition with the longest waiting time, where the waiting time is the time for which the to-be-allocated partition is not allocated with the resource after being determined, and the waiting time can be exemplarily the time length for which the to-be-allocated partition meets the preset condition.
[0175] In another possible implementation, if the number of to-be-allocated resources of each to-be-allocated partition is greater than the number of idle resources, the number of idle resources gradually increases as the resources occupied by each task are released, and the number of idle resources can be compared with the number of to-be-allocated resources of each to-be-allocated partition in real time. When the number of to-be-allocated resources of any to-be-allocated partition is not greater than the number of idle resources, the idle resources are allocated to the to-be-allocated partition.
[0176] In this way, the to-be-allocated partition can be preferentially allocated with the idle resources in the case of idle resources, and the change of the resources in use is reduced, thereby improving user experience.
[0177] In a possible application scenario, if the resource requirement of a to-be-executed task in a to-be-allocated partition is 50, the current number of occupied resources is 10, and the resource threshold is 15, if the to-be-executed task is not screened in the to-be-allocated partition, and the resource is directly obtained according to the to-be-executed task, the current number of occupied resources of the to-be-allocated partition will become 60 after the resource is received, which is far more than the resource threshold, which is obviously unreasonable.
[0178] Therefore, in a possible implementation, when the first target task in the to-be-executed task of the to-be-allocated partition is determined, a first candidate task in the to-be-executed task of the to-be-allocated partition, for which the sum of the resource requirement and the current number of occupied resources does not exceed the resource threshold of the to-be-allocated partition, can be determined first. Then, the first target task is determined from the first candidate task based on the task attribute of the first candidate task.
[0179] Specifically, for any to-be-allocated partition, the sum of the resource requirement and the current number of occupied resources of each to-be-executed task in the to-be-allocated partition can be calculated in sequence, and the calculation result is compared with the resource threshold of the to-be-allocated partition. In the case that the sum of the resource requirement and the current number of occupied resources of any to-be-executed task does not exceed the resource threshold of the to-be-allocated partition, the to-be-executed task is taken as the first target task.
[0180] Alternatively, the sum of the resource requirement and the current number of occupied resources of all to-be-executed tasks in the to-be-allocated partition can be calculated, and the calculation result is compared with the resource threshold of the to-be-allocated partition. The to-be-executed task, for which the calculation result is less than the resource threshold and the corresponding resource requirement is the largest (or the smallest), is taken as the first target task.
[0181] For example, a to-be-allocated partition contains three to-be-executed tasks, the resource requirement of the to-be-executed task 1 is 10, the resource requirement of the to-be-executed task 2 is 5, the resource requirement of the to-be-executed task 3 is 3, the current occupied resource quantity of the to-be-allocated partition is 10, and the resource threshold is 15. The to-be-executed tasks whose sum of resource requirement and current occupied resource quantity is less than the resource threshold can be determined to include the to-be-executed task 2 and the to-be-executed task 3. The resource requirement of the to-be-executed task 2 is the largest, and therefore, the to-be-executed task 2 is taken as the first target task.
[0182] In this way, it can be ensured to some extent that the current occupied resource of the to-be-allocated partition will not exceed the resource threshold after the first target task is allocated with resources, so that the to-be-allocated partition is prevented from obtaining excessive resources, and the fairness and rationality of resource allocation are improved.
[0183] In a possible implementation, when the resource allocation partition is determined based on the resource threshold and the current occupied resource quantity of the plurality of virtual partitions, candidate partitions whose current occupied resource quantity exceeds the resource threshold can be determined first, and then the resource allocation partition is determined based on the candidate partitions.
[0184] Specifically, in order to enable a virtual partition that occupies excessive resources to allocate the excessive resources to other virtual partitions, the current occupied resource quantity of each virtual partition can be compared with the resource threshold. When the current occupied resource quantity of any virtual partition exceeds the resource threshold, it indicates that the virtual partition occupies excessive resources, and therefore, the virtual partition can be taken as a candidate partition. If there is only one candidate partition, the candidate partition can be directly taken as the resource allocation partition.
[0185] In this way, a virtual partition that occupies excessive resources can be accurately screened out based on the resource threshold, and the virtual partition that occupies excessive resources is taken as the resource allocation partition, so that the fairness of resource allocation is improved.
[0186] In a possible implementation, when the resource allocation partition is determined based on the candidate partitions, if there are multiple candidate partitions, the target proportion of the current occupied resource quantity and the resource threshold of any candidate partition can be determined, and then the resource allocation partition is determined based on the target proportion.
[0187] Specifically, the target proportion of each candidate partition can be calculated first, and then the candidate partition with the largest target proportion can be selected as the resource allocation partition. For example, if the current occupied resource of candidate partition 1 is 6, the resource threshold is 5, the current occupied resource of candidate partition 2 is 15, the resource threshold is 10, and the current occupied resource of candidate partition 3 is 25, the resource threshold is 20, the target proportion of candidate partition 1 is 1.2, the target proportion of candidate partition 2 is 1.5, and the target proportion of candidate partition 3 is 1.25. Therefore, candidate partition 2 with the largest target proportion is selected as the resource allocation partition.
[0188] By using this method, the candidate partition with the highest excess degree of excess occupied resource can be selected as the resource allocation partition, thereby improving the rationality and fairness of resource allocation.
[0189] Alternatively, after the target proportion of each candidate partition is calculated, the candidate partition with the largest target proportion and exceeding the preset threshold can be selected as the resource allocation partition. In this way, in the case that the excess degrees of multiple candidate partitions are small, the multiple candidate partitions can not be selected as the resource allocation partition, thereby reducing the frequency of resource changes.
[0190] In another possible implementation, when the resource allocation partition is determined based on the candidate partitions, in the case that there are multiple candidate partitions, the target difference value between the current occupied resource quantity and the resource threshold of any candidate partition can be determined, and then the candidate partition with the largest target difference value can be selected as the resource allocation partition.
[0191] By using this method, the candidate partition with the largest excess occupied resource can be selected as the resource allocation partition, thereby improving the rationality and fairness of resource allocation.
[0192] In a possible implementation, if the allocable resource (e.g., the resource for executing a task with a target permission) in any of the to-be-allocated partitions is less than the to-be-allocated resource quantity after the to-be-allocated partition is determined, more resource allocation partitions can be determined according to the above method until the allocable resource in the resource allocation partition is not less than the to-be-allocated resource quantity, or multiple resource allocation partitions can be determined at the same time according to the above method.
[0193] Specifically, when the resource allocation partition is determined based on the candidate partitions, in the case that there are multiple candidate partitions, the target proportion of the current occupied resource quantity and the resource threshold of any candidate partition can be determined, and then at least one resource allocation partition can be determined based on the target proportion.
[0194] For step 103,
[0195] Specifically, the resources in the resource allocation partition are allocated to the to-be-allocated partition according to the to-be-allocated resource quantity.
[0196] Since the resource allocation partition contains at least one executing task, it is necessary to determine which task to release the resource allocation of, and in a possible implementation, when the resources in the resource allocation partition are allocated to the to-be-allocated partition according to the to-be-allocated resource quantity, a second target task to be released in the resource allocation partition can be determined based on the task attributes of the tasks executing in the resource allocation partition and the to-be-allocated resource quantity, and then the resources occupied by the second target task are allocated to the to-be-allocated partition. The resources occupied by the second target task are the resource requirement quantity of the second target task.
[0197] In this way, the second target task suitable for allocating resources can be determined according to the task attributes and the to-be-allocated resource quantity.
[0198] In a possible implementation, when the task attributes of the tasks include historical execution time, resource requirement quantity, and resource occupation authority, when the second target task to be released in the resource allocation partition is determined based on the task attributes of the tasks executing in the resource allocation partition and the to-be-allocated resource quantity, a second candidate task executing in the resource allocation partition and having a target authority as the resource occupation authority can be determined first, and then the second target task is determined based on the historical execution time, resource requirement quantity of the second candidate task, and the to-be-allocated resource quantity.
[0199] Specifically, the task running states and authorities of the tasks in the resource allocation partition can be detected first, and a second candidate task having a task running state of an executing state and a target authority as the resource occupation authority is screened out. The target authority can include an authority of allocating resources. For example, the target authority can be the above-described allocatable authority, and a protected task having an unallocatable authority cannot be used as the second target task.
[0200] When there is only one second candidate task, the second candidate task can be directly used as the second target task, and when there are at least two second candidate tasks, the second candidate tasks can be sorted according to the historical execution time from short to long, and at least one second candidate task having a resource requirement quantity capable of reaching the to-be-allocated resource quantity and having the shortest historical execution time is used as the second target task according to the to-be-allocated resource quantity.
[0201] For example, the resource allocation partition A includes five second candidate tasks. After the five second candidate tasks are sorted according to the historical execution time, the five second candidate tasks and the corresponding historical execution time and resource requirement are respectively: "task 1, 1 hour, 1", "task 2, 2 hours, 2", "task 3, 3 hours, 3", "task 4, 1 day, 4", and "task 5, 2 days, 5". If the number of the to-be-allocated resources is 2, the resource requirement of the task 1 and the task 2 with the shortest historical execution time is 3 in total, which satisfies the number of the to-be-allocated resources. Therefore, the task 1 and the task 2 are taken as the second target tasks. If the number of the to-be-allocated resources is 5, the task 1, the task 2 and the task 3 are taken as the second target tasks.
[0202] In this way, because the second target tasks have been calculated for a period of time by using the occupied resources before the resources are allocated, it is difficult to save the previously calculated content after the occupied resources are allocated to the to-be-allocated partition. Therefore, the task with a shorter historical execution time is taken as the second target task, which can reduce the waste of the computing resources.
[0203] In a possible implementation, in a case where there are multiple to-be-allocated partitions, the resources of the resource allocation partition can be allocated to the to-be-allocated partition with the longest waiting time.
[0204] Here, in a case where there are multiple to-be-allocated partitions, the present solution does not limit how to determine the to-be-allocated partition to which the resources are preferentially allocated.
[0205] In a possible manner, in a case where the resources of the resource allocation partition are less than the number of the to-be-allocated resources, the resources of the resource allocation partition can be allocated to the to-be-allocated partition after waiting until the resources of the resource allocation partition are not less than the number of the to-be-allocated resources. Here, the resources of the resource allocation partition can be the sum of the resources that can be allocated in multiple resource allocation partitions.
[0206] In a possible implementation, after the resources of the resource allocation partition are allocated to the to-be-allocated partition according to the number of the to-be-allocated resources, it can be determined whether the virtual partition after the resources are allocated satisfies the preset condition. If yes, the number of the to-be-allocated resources and the resource allocation partition are re-determined, and the resource allocation is performed again for the virtual partition after the resources are allocated.
[0207] Specifically, since the to-be-allocated partition includes at least one to-be-executed task, after the to-be-allocated partition is allocated with resources, the virtual partition after being allocated with resources still has the possibility to meet the preset condition, where the preset condition can be that the virtual partition has a to-be-executed task, and a current occupied resource quantity of the virtual partition is less than a resource threshold of the virtual partition; or the virtual partition has a to-be-executed task, and a sum of a resource requirement quantity of any to-be-executed task of the virtual partition and the current occupied resource quantity of the virtual partition does not exceed the resource threshold of the to-be-allocated partition.
[0208] After it is detected that the virtual partition after being allocated with resources still meets the preset condition, the to-be-allocated resource quantity and the resource allocation partition can be re-determined according to the method described above, and resources of the re-determined resource allocation partition are allocated to the virtual partition according to the re-determined to-be-allocated resource quantity.
[0209] By using this method, the virtual partition with too few currently occupied resources can be allocated multiple times, so as to improve the fairness of resource allocation.
[0210] The resource allocation method provided in the embodiments of the present disclosure can determine a to-be-allocated partition in multiple virtual partitions and a to-be-allocated resource quantity corresponding to the to-be-allocated partition based on a resource threshold of the virtual partition, a task attribute of each task executed in the virtual partition, and a current occupied resource quantity of the virtual partition, so as to ensure that the virtual partition with a smaller current occupied resource quantity can be the to-be-allocated partition. The resource allocation method can also determine a resource allocation partition in the multiple virtual partitions based on the resource threshold and the current occupied resource quantity of the multiple virtual partitions, so as to ensure that the virtual partition with a larger current occupied resource quantity can be the resource allocation partition. Finally, resources of the resource allocation partition are allocated to the to-be-allocated partition through the determined to-be-allocated resource quantity, so that the resource allocation partition can appropriately allocate too many resources to the to-be-allocated partition, thereby achieving fair resource allocation.
[0211] Those skilled in the art can understand that the writing order of each step in the above method of the specific implementation manner does not mean a strict execution order and does not constitute any limitation on the implementation process. The specific execution order of each step should be determined by its function and possible inherent logic.
[0212] Based on the same inventive concept, the embodiments of the present disclosure also provide a resource allocation apparatus corresponding to the resource allocation method. Since the principle of solving problems by the apparatus in the embodiments of the present disclosure is similar to the above-mentioned resource allocation method, the implementation of the apparatus can be referred to the implementation of the method, and the repeated parts will not be described herein.
[0213] Reference Figure 2As shown, an architecture schematic diagram of a resource allocation apparatus provided by an embodiment of the present disclosure is shown, and the apparatus comprises a first determining module 201, a second determining module 202, and an allocation module 203.
[0214] The first determining module 201 is configured to determine resource information of a plurality of virtual partitions, wherein the resource information comprises resource thresholds of the virtual partitions, task attributes of tasks executed in the virtual partitions, and current occupied resource quantities of the virtual partitions.
[0215] The second determining module 202 is configured to determine, based on the resource information of each virtual partition, a to-be-allocated partition in the plurality of virtual partitions and a to-be-allocated resource quantity corresponding to the to-be-allocated partition, and determine, based on the resource thresholds and the current occupied resource quantities of the plurality of virtual partitions, a resource allocation partition in the plurality of virtual partitions.
[0216] The allocation module 203 is configured to allocate resources of the resource allocation partition to the to-be-allocated partition according to the to-be-allocated resource quantity.
[0217] In a possible implementation, the first determining module 201 is further configured to determine the resource thresholds of the plurality of virtual partitions according to the following method:
[0218] determine preset weights of the plurality of virtual partitions and total allocated resource quantities corresponding to the plurality of virtual partitions;
[0219] determine initial resource thresholds corresponding to each virtual partition based on the preset weights of the plurality of virtual partitions and the total allocated resource quantities corresponding to the plurality of virtual partitions;
[0220] determine the resource thresholds of the plurality of virtual partitions based on the initial resource thresholds, the task attributes of tasks executed in the virtual partitions, and the current occupied resource quantities of the virtual partitions.
[0221] In a possible implementation, the task attributes comprise task running states of tasks executed in the virtual partitions and resource demand quantities corresponding to the tasks.
[0222] When determining the to-be-allocated partition in the plurality of virtual partitions based on the resource information of each virtual partition, the second determining module 202 is configured to:
[0223] determine a first candidate partition containing to-be-executed tasks;
[0224] for any first candidate partition, if a sum of a resource demand quantity of any to-be-executed task in the first candidate partition and a current occupied resource quantity of the first candidate partition does not exceed a resource threshold of the first candidate partition, the first candidate partition is determined as the to-be-allocated partition.
[0225] In a possible implementation, the second determining module 202, when determining the resource allocation partition from the second candidate partition, is configured to:
[0226] determine a second candidate partition whose current occupied resource quantity exceeds the resource threshold.
[0227] determine the resource allocation partition based on the second candidate partition.
[0228] In a possible implementation, the second determining module 202, when determining the resource allocation partition based on the second candidate partition, is configured to:
[0229] when there are multiple second candidate partitions, determine, for any second candidate partition, a target ratio of the current occupied resource quantity of the second candidate partition to the resource threshold.
[0230] determine the resource allocation partition based on the target ratio.
[0231] In a possible implementation, the second determining module 202, when determining the to-be-allocated resource quantity corresponding to the to-be-allocated partition, is configured to:
[0232] determine a first target task in the to-be-executed tasks of the to-be-allocated partition.
[0233] determine the to-be-allocated resource quantity based on a resource requirement in a task attribute corresponding to the first target task.
[0234] In a possible implementation, the second determining module 202, when determining the first target task in the to-be-executed tasks of the to-be-allocated partition, is configured to:
[0235] determine a first candidate task in the to-be-executed tasks of the to-be-allocated partition, whose sum of a corresponding resource requirement and the current occupied resource quantity does not exceed the resource threshold of the to-be-allocated partition.
[0236] determine the first target task from the first candidate task based on a task attribute of the first candidate task.
[0237] In a possible implementation, the allocating module 203, when allocating the resources of the resource allocation partition to the to-be-allocated partition according to the to-be-allocated resource quantity, is configured to:
[0238] determine a second target task to be released in the resource allocation partition based on a task attribute of each task executed in the resource allocation partition and the to-be-allocated resource quantity.
[0239] allocating resources occupied by the second target task to the to-be-allocated partition.
[0240] In a possible implementation, the task attribute of the task includes a historical execution time, a resource requirement amount, and a resource occupation permission.
[0241] The second determining module 202 is configured to, when determining the second target task to be released from the resource allocation partition based on the task attribute of each task executed in the resource allocation partition and the to-be-allocated resource amount, determine the second target task based on the historical execution time, the resource requirement amount, and the to-be-allocated resource amount of the second candidate task.
[0242] determine a second candidate task being executed in the resource allocation partition and having a resource occupation permission as the target permission.
[0243] determine the second target task based on the historical execution time, the resource requirement amount, and the to-be-allocated resource amount of the second candidate task.
[0244] In a possible implementation, after determining the to-be-allocated partition in the plurality of virtual partitions, and before allocating the resources of the resource allocation partition to the to-be-allocated partition according to the to-be-allocated resource amount, the second determining module 202 is further configured to:
[0245] determine that the to-be-allocated partition satisfies the preset condition for a time period exceeding a preset time period.
[0246] The preset condition includes:
[0247] the to-be-allocated partition has a to-be-executed task, and a current occupied resource amount of the to-be-allocated partition is less than a resource threshold of the to-be-allocated partition.
[0248] In a possible implementation, after determining the to-be-allocated partition in the plurality of virtual partitions and the to-be-allocated resource amount corresponding to the to-be-allocated partition, the second determining module 202 is further configured to:
[0249] determine an idle resource amount in the plurality of virtual partitions.
[0250] in a case where the idle resource amount is not less than the to-be-allocated resource amount, allocate the idle resource to the to-be-allocated partition.
[0251] In a possible implementation, after allocating the resources of the resource allocation partition to the to-be-allocated partition according to the to-be-allocated resource amount, the allocating module 203 is further configured to:
[0252] determine whether the virtual partition after obtaining the allocated resource satisfies the preset condition.
[0253] If yes, the to-be-allocated resource quantity and the resource allocation partition are re-determined, and resource allocation is performed again for the virtual partition after the to-be-allocated resource is obtained.
[0254] The description of the processing flow of each module in the device and the interaction flow between the modules can refer to the related description in the above method embodiments, and will not be described in detail here.
[0255] Based on the same technical concept, the embodiment of the disclosure also provides a computer device. Referring to Figure 3 As shown in the structure schematic diagram of the computer device 300 provided by the embodiment of the disclosure, the computer device 300 includes a processor 301, a memory 302, and a bus 303. The memory 302 is used to store execution instructions, including an internal memory 3021 and an external memory 3022. The internal memory 3021 is also called an internal storage, and is used to temporarily store operation data in the processor 301 and exchange data with the external memory 3022 such as a hard disk. The processor 301 exchanges data with the external memory 3022 through the internal memory 3021. When the computer device 300 is running, the processor 301 and the memory 302 communicate through the bus 303, so that the processor 301 executes the following instructions:
[0256] determining resource information of a plurality of virtual partitions, wherein the resource information includes a resource threshold of the virtual partition, a task attribute of each task executed in the virtual partition, and a current occupied resource quantity of the virtual partition;
[0257] based on the resource information of each virtual partition, determining a to-be-allocated partition in the plurality of virtual partitions and a to-be-allocated resource quantity corresponding to the to-be-allocated partition, and based on the resource threshold and the current occupied resource quantity of the plurality of virtual partitions, determining a resource allocation partition in the plurality of virtual partitions;
[0258] allocating resources of the resource allocation partition to the to-be-allocated partition according to the to-be-allocated resource quantity.
[0259] The embodiment of the disclosure also provides a computer readable storage medium, which stores a computer program. When the computer program is run by a processor, the steps of the resource allocation method described in the above method embodiments are executed. The storage medium can be a volatile or non-volatile computer readable storage medium.
[0260] The embodiment of the disclosure also provides a computer program product, which carries a program code. The instructions included in the program code can be used to execute the steps of the resource allocation method described in the above method embodiments. For details, please refer to the above method embodiments, which will not be described here.
[0261] The computer program product can be implemented by hardware, software or a combination thereof. In an optional embodiment, the computer program product is embodied in a computer storage medium. In another optional embodiment, the computer program product is embodied in a software product, such as a software development kit (SDK) or the like.
[0262] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the system and device described above can refer to the corresponding process in the foregoing method embodiments, which will not be repeated here. In several embodiments provided in the present disclosure, it should be understood that the disclosed system, device and method can be implemented in other ways. The device embodiments described above are merely schematic, for example, the division of the units is only a logical function division, and actual implementation can have another division manner, for example, a plurality of units or components can be combined or integrated into another system, or some features can be omitted or not executed. In addition, the coupling or direct coupling or communication connection between the units shown or discussed can be indirect coupling or communication connection through some communication interfaces, devices or units, which can be electrical, mechanical or other forms.
[0263] The units described as separate components can or can not be physically separate, and the components shown as units can or can not be physical units, that is, they can be located in one place, or can be distributed on a plurality of network units. According to actual needs, part or all of the units can be selected to achieve the purpose of the embodiment scheme.
[0264] In addition, the functional units in each embodiment of the present disclosure can be integrated in one processing unit, or each unit can exist physically, or two or more units can be integrated in one unit.
[0265] If the functions are implemented in the form of software function units and sold or used as independent products, they can be stored in a nonvolatile computer readable storage medium executable by a processor. Based on this understanding, the technical solutions of the present disclosure essentially or the parts that contribute to the prior art or parts of the technical solutions can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes a number of instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present disclosure. The aforementioned storage medium includes: a U disk, a mobile hard disk, a read-only memory (Read-Only Memory, ROM), a random access memory (Random Access Memory, RAM), a magnetic disk or an optical disk, and various media that can store program codes.
[0266] Finally, it should be noted that the above-described embodiments are merely specific embodiments of the present disclosure, used to illustrate the technical solutions of the present disclosure, and are not limiting. The protection scope of the present disclosure is not limited thereto, and although the present disclosure has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that any person skilled in the art can make modifications or easily think of changes to the technical solutions described in the foregoing embodiments within the technical scope disclosed by the present disclosure, or make equivalent replacements to some of the technical features; and these modifications, changes or replacements do not cause the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present disclosure, and should be covered within the protection scope of the present disclosure. Therefore, the protection scope of the present disclosure should be subject to the protection scope of the claims.
[0267] If the technical solutions of the present application involve personal information, the product applying the technical solutions of the present application has clearly informed the personal information processing rules before processing the personal information, and has obtained the personal independent consent. If the technical solutions of the present application involve sensitive personal information, the product applying the technical solutions of the present application has obtained the personal independent consent before processing the sensitive personal information, and at the same time meets the requirement of "explicit consent". For example, at the personal information collection device such as camera, a clear and prominent sign is set to inform that the personal information collection range has been entered and the personal information will be collected. If the individual voluntarily enters the collection range, it is considered to agree to collect the personal information; or on the device for processing personal information, the personal information processing rules are informed through obvious signs / information, and the personal authorization is obtained through pop-up information or by uploading personal information by the individual. The personal information processing rules can include personal information processor, personal information processing purpose, processing method and personal information type, etc.
Claims
1. A resource allocation method, characterized by, The method comprises: determining resource information of a plurality of virtual partitions, wherein the resource information comprises resource thresholds of the virtual partitions, task attributes of tasks executed in the virtual partitions, and current occupied resource quantities of the virtual partitions; determining, based on the resource information of each virtual partition, a to-be-allocated partition in the plurality of virtual partitions and a to-be-allocated resource quantity corresponding to the to-be-allocated partition; and determining, based on the resource thresholds and the current occupied resource quantities of the plurality of virtual partitions, a resource allocation partition in the plurality of virtual partitions; allocating resources of the resource allocation partition to the to-be-allocated partition according to the to-be-allocated resource quantity. The method further comprises determining the resource thresholds of the plurality of virtual partitions according to the following method, which comprises: determining preset weights of the plurality of virtual partitions and total allocated resource quantities corresponding to the plurality of virtual partitions; determining initial resource thresholds corresponding to each virtual partition based on the preset weights of the plurality of virtual partitions and the total allocated resource quantities corresponding to the plurality of virtual partitions; 2. The method of claim 1, wherein, determining the resource thresholds of the plurality of virtual partitions based on the initial resource thresholds, task attributes of tasks executed in the virtual partitions, and the current occupied resource quantities of the virtual partitions. The task attributes comprise task running states of tasks executed in the virtual partitions and resource demand quantities corresponding to the tasks. The method further comprises determining, based on the resource information of each virtual partition, the to-be-allocated partition in the plurality of virtual partitions, which comprises: determining a first candidate partition containing a to-be-executed task; 3. The method according to claim 1 or 2, characterized in that, for any first candidate partition, if a sum of a resource demand quantity of any to-be-executed task in the first candidate partition and a current occupied resource quantity of the first candidate partition does not exceed a resource threshold of the first candidate partition, the first candidate partition is determined as the to-be-allocated partition. The method further comprises determining, based on the second candidate partition, the resource allocation partition, which comprises: in a case where there are a plurality of second candidate partitions, for any second candidate partition, determining a target proportion of the current occupied resource quantity and the resource threshold of the second candidate partition; based on the target proportion, determining the resource allocation partition.
4. The method of claim 1, wherein, The method further comprises determining the to-be-allocated resource quantity corresponding to the to-be-allocated partition, which comprises: determining a first target task in to-be-executed tasks of the to-be-allocated partition; based on a resource demand quantity in task attributes corresponding to the first target task, determining the to-be-allocated resource quantity.
5. The method according to claim 1 or 2, characterized in that, The method further comprises determining the first target task in to-be-executed tasks of the to-be-allocated partition, which comprises: determining a first candidate task in to-be-executed tasks of the to-be-allocated partition, for which a sum of a corresponding resource demand quantity and the current occupied resource quantity does not exceed a resource threshold of the to-be-allocated partition; based on task attributes of the first candidate task, determining the first target task from the first candidate task.
6. The method of claim 5, wherein, 7. The method according to claim 1 or 2, characterized in that, The method further comprises: determining the second target task based on the task attribute of each task being executed in the resource allocation partition and the to-be-allocated resource quantity; and allocating the resource occupied by the second target task to the to-be-allocated partition.
8. The method of claim 7, wherein, The task attribute of the task comprises a historical execution time, a resource demand quantity, and a resource occupation permission. The method further comprises: determining a second candidate task being executed in the resource allocation partition and having a resource occupation permission being the target permission; determining the second target task based on the historical execution time, the resource demand quantity of the second candidate task, and the to-be-allocated resource quantity.
9. The method of claim 1 or 2, wherein, The method further comprises: determining that the to-be-allocated partition satisfies a preset condition for a time period exceeding a preset time period; The preset condition comprises: the to-be-allocated partition has a to-be-executed task, and a current occupied resource quantity of the to-be-allocated partition is less than a resource threshold of the to-be-allocated partition.
10. The method of claim 1 or 2, wherein, The method further comprises: determining an idle resource quantity in the plurality of virtual partitions; allocating the idle resource to the to-be-allocated partition if the idle resource quantity is not less than the to-be-allocated resource quantity.
11. The method of claim 9, wherein, The method further comprises: determining whether the virtual partition after obtaining the allocated resource satisfies the preset condition; if yes, re-determining the to-be-allocated resource quantity and the resource allocation partition, and performing resource allocation for the virtual partition after obtaining the allocated resource again.
12. A resource allocation apparatus, characterized by comprising: The method further comprises: a first determining module configured to determine resource information of a plurality of virtual partitions, wherein the resource information comprises a resource threshold of the virtual partition, a task attribute of each task being executed in the virtual partition, and a current occupied resource quantity of the virtual partition; a second determining module configured to determine a to-be-allocated partition in the plurality of virtual partitions and a to-be-allocated resource quantity corresponding to the to-be-allocated partition based on the resource information of each virtual partition, and determine a resource allocation partition in the plurality of virtual partitions based on the resource threshold and the current occupied resource quantity of the plurality of virtual partitions; an allocating module configured to allocate resources of the resource allocation partition to the to-be-allocated partition according to the to-be-allocated resource quantity; The second determining module is configured to: determine a second candidate partition whose current occupied resource quantity exceeds the resource threshold when determining the resource allocation partition in the plurality of virtual partitions based on the resource threshold and the current occupied resource quantity of the plurality of virtual partitions. determine the resource allocation partition based on the second candidate partition.
13. A computer device, comprising: comprising: a processor, a memory and a bus, the memory stores machine readable instructions executable by the processor, when the computer device runs, the processor communicates with the memory through the bus, the machine readable instructions are executed by the processor to execute the steps of the resource allocation method in any one of claims 1 to 11.
14. A computer-readable storage medium, characterized in that, The computer readable storage medium stores a computer program, and the computer program is executed by the processor to execute the steps of the resource allocation method in any one of claims 1 to 11.
Citation Information
Patent Citations
Resource dynamic adjustment method and device and multi-core operating system
CN104714845A
Task scheduling method, computer equipment and storage medium
CN112328378A