Container Resource Scheduling Method, Device, Electronic Device and Storage Medium
By calculating the number of free paths of the sandbox and the proportion of used time slices in the container, and dynamically dispatching code requests, the waste and idle problems in container resource scheduling are solved, and the efficient and stable operation of the system is achieved.
Patent Information
- Application Number
- CN202510324840.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-19
- Publication Date
- 2025-07-22
- Estimated Expiration
- 2045-03-19
AI Technical Summary
In the prior art, container resource scheduling is difficult to allocate reasonably, resulting in waste or idle resources, and it is impossible to effectively prevent malicious code from affecting system stability.
By calculating the proportion of free paths of the container and the proportion of used time slices of the sandbox in the container, determining the priority information of the container, dynamically scheduling code operation requests, and combining the Linux user isolation mechanism to achieve sandbox isolation.
It improves resource utilization, avoids local overload or idleness, ensures long-term fairness and stability of the system, and prevents malicious code from being affected.
Smart Images

Figure CN119829221B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data processing, and in particular, to a container resource scheduling method, device, electronic device, and storage medium. Background Art
[0002] With the continuous development of computer technology, in modern computing systems, it has become increasingly common to allow users to submit and execute custom code, or code generated by large models, to the cloud for rapid execution. However, malicious users may trigger the generation of unsafe execution paths by submitting obfuscated code, thereby affecting system stability.
[0003] In related technologies, container technology is usually used to isolate the execution environment to prevent system damage caused by malicious code. However, the resources consumed by the code submitted by different users are completely different and difficult to estimate. How to reasonably schedule container resources has become an urgent problem in the industry. Summary of the Invention
[0004] The present invention provides a container resource scheduling method, device, electronic device, and storage medium to solve the problem of how to reasonably schedule container resources in the prior art.
[0005] The present invention provides a container resource scheduling method, including:
[0006] When receiving a code running request, calculate the proportion of the idle paths of the sandbox and the proportion of the used time slices of the sandbox for each container according to the idle path number and the used time slice information of the sandbox of each container; wherein, each of the containers includes a plurality of sandboxes;
[0007] Determine the priority information of each container according to the proportion of the idle paths of the sandbox and the proportion of the used time slices of the sandbox of each container, so as to perform container resource scheduling for the code running request according to the priority information.
[0008] According to the container resource scheduling method provided by the present invention, determining the priority information of each container according to the proportion of the idle paths of the sandbox and the proportion of the used time slices of the sandbox of each container includes:
[0009] Obtain the path weight information of each container according to the product of the proportion of the idle paths of the sandbox of the container and the path coefficient;
[0010] Obtain the time slice weight information of each container according to the product of the proportion of the used time slices of the sandbox of the container and the time slice coefficient;
[0011] Obtain the priority information of each container according to the sum of the path weight information and the time slice weight information of each container;
[0012] Among them, the number coefficient is associated with the number of usage paths of the sandboxes of each container, and the time slice coefficient is associated with the used time slice information of the sandboxes of each container.
[0013] Before the step of obtaining the priority information of each container according to the sum of the product of the ratio of the idle path number of the sandbox of the container and the number coefficient, and the product of the ratio of the used time slice of the sandbox of the container and the time slice coefficient, the method further includes:
[0014] Determine the number coefficient according to the ratio of the total number of usage paths of the sandboxes of each container to the total maximum available path number of the sandboxes of each container;
[0015] Determine the time slice coefficient according to the ratio of the total used time slice information of the sandboxes of each container to the total maximum time slice information of the sandboxes of each container.
[0016] According to a container resource scheduling method provided by the present invention, the calculating the ratio of the idle path number of the sandbox of each container and the ratio of the used time slice of the sandbox of each container according to the idle path number of the sandbox of each container and the used time slice information of the sandbox includes:
[0017] Determine the ratio of the idle path number of the sandbox of each container according to the ratio of the idle path number of the sandbox of each container to the total idle path number of the sandboxes; the total idle path number of the sandboxes is obtained by summing up the idle path numbers of the sandboxes of each container;
[0018] Determine the ratio of the used time slice information of the sandbox of each container according to the ratio of the used time slice information of the sandbox of each container to the total used time slice information of the sandboxes; among them, the total used time slice information of the sandboxes is obtained by summing up the used time slice information of the sandboxes of each container.
[0019] According to a container resource scheduling method provided by the present invention, the container resource scheduling of the code running request according to the priority information includes:
[0020] Schedule any idle sandbox in the container corresponding to the target priority information to the code running request for code running;
[0021] Among them, the target priority information is the maximum value among the priority information.
[0022] Before the step of scheduling any idle sandbox in the container corresponding to the target priority information to the code running request for code running, the method further includes:
[0023] In the case of multiple target priority information, the target priority information with the largest number of idle paths in the sandbox is used as the final target priority information.
[0024] According to a container resource scheduling method provided by the present invention, the sandboxes in the containers use the Linux user isolation mechanism to achieve mutual isolation between different sandboxes in the same container.
[0025] The present invention also provides a container resource scheduling device, including:
[0026] A calculation module, configured to calculate the ratio of the number of idle paths in the sandbox of each container and the ratio of the used time slices in the sandbox according to the number of idle paths in the sandbox and the used time slice information of the sandbox of each container when receiving a code running request; wherein, each of the containers includes multiple sandboxes;
[0027] A scheduling module, configured to determine the priority information of each container according to the ratio of the number of idle paths in the sandbox of each container and the ratio of the used time slices in the sandbox, so as to perform container resource scheduling for the code running request according to the priority information.
[0028] According to a container resource scheduling device provided by the present invention, the device is further configured to:
[0029] Obtain the path weight information of each container according to the product of the ratio of the number of idle paths in the sandbox of the container and the path coefficient;
[0030] Obtain the time slice weight information of each container according to the product of the ratio of the used time slices in the sandbox of the container and the time slice coefficient;
[0031] Obtain the priority information of each container according to the sum of the path weight information and the time slice weight information of each container;
[0032] Wherein, the path coefficient is associated with the number of paths used by the sandboxes of each container, and the time slice coefficient is associated with the used time slice information of the sandboxes of each container.
[0033] According to a container resource scheduling device provided by the present invention, the device is further configured to:
[0034] Determine the path coefficient according to the ratio of the total number of paths used by the sandboxes of each container to the total maximum available number of paths of the sandboxes of each container;
[0035] Determine the time slice coefficient according to the ratio of the total used time slice information of the sandboxes of each container to the total maximum time slice information of the sandboxes of each container.
[0036] According to a container resource scheduling device provided by the present invention, the device is further configured to:
[0037] Determine the proportion of the free sandbox paths of each container based on the ratio of the free sandbox paths of each container to the total sum of the free sandbox paths of all containers; the total sum of the free sandbox paths is obtained by summing up the free sandbox paths of each container.
[0038] Determine the proportion of the used time slice information of the sandbox of each container based on the ratio of the used time slice information of the sandbox of each container to the total sum of the used time slice information of the sandbox; wherein, the total sum of the used time slice information of the sandbox is obtained by summing up the used time slice information of the sandbox of each container.
[0039] According to a container resource scheduling device provided by the present invention, the device is further configured to:
[0040] Schedule any free sandbox in the container corresponding to the target priority information to the code running request for code running.
[0041] Wherein, the target priority information is the maximum value among all the priority information.
[0042] According to a container resource scheduling device provided by the present invention, the device is further configured to:
[0043] In the case where there are multiple target priority information, use the target priority information with the largest number of free sandbox paths as the final target priority information.
[0044] According to a container resource scheduling device provided by the present invention, the device is further configured to: The sandboxes in the container use the Linux user isolation mechanism to achieve mutual isolation between different sandboxes in the same container.
[0045] The present invention also provides an electronic device, including a memory, a processor, and a computer program stored on the memory and executable on the processor, wherein when the processor executes the computer program, it implements the container resource scheduling method as described in any one of the above.
[0046] The present invention also provides a non-transitory computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, it implements the container resource scheduling method as described in any one of the above.
[0047] The present invention also provides a computer program product, including a computer program, and when the computer program is executed by a processor, it implements the container resource scheduling method as described in any one of the above.
[0048] The container resource scheduling method, device, electronic device, and storage medium provided by the present invention can solve the problems of local overload or idleness caused by static resource allocation through the calculation of the proportion of idle paths in the sandbox, realize the dynamic selection of containers with sufficient resources, and improve resource utilization. Through the calculation of the proportion of used time slices in the sandbox, the starvation problem caused by uneven historical loads can be solved. Through the adjustment of time slice weights, long-term fairness can be guaranteed. Combining the priority information calculated from the proportion of idle paths in the sandbox and the proportion of used time slices in the sandbox can reasonably balance the container loads, avoid some containers exhausting resources prematurely or remaining idle for a long time, and effectively perform container resource scheduling. BRIEF DESCRIPTION OF THE DRAWINGS
[0049] To more clearly illustrate the technical solutions in the present invention or the prior art, the following will briefly introduce the drawings required for the description of the embodiments or the prior art. Obviously, the drawings in the following description are some embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings.
[0050] Figure 1 It is a flowchart of the container resource scheduling method provided by the present invention;
[0051] Figure 2 It is the overall architecture of the distributed code running sandbox provided by the embodiment of the present invention;
[0052] Figure 3 It is a schematic diagram of the system scheduling process provided by the present invention;
[0053] Figure 4 It is a schematic diagram of the structure of the container resource scheduling device provided by the present invention;
[0054] Figure 5 It is a schematic diagram of the structure of the electronic device provided by the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0055] To make the objectives, technical solutions, and advantages of the present invention clearer, the following will clearly and completely describe the technical solutions in the present invention in conjunction with the drawings in the present invention. Obviously, the described embodiments are some, but not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts fall within the scope of protection of the present invention.
[0056] In the related art, when performing container resource scheduling, the user request User is scheduled to a relatively idle container Container. There are enough idle sandbox CodeBoxes in the Container to allocate to the user request. It is required that the Container has sufficient computing power to run the code. To prevent the occurrence of starved Containers.
[0057] First, the scheduler Scheduler traverses the Containers to select idle Containers where Idle(i)>0; = filter ( ,i => >0); Traverse Select The smallest And allocate it to User; = Min( , i => ).
[0058] After the above steps, it is possible to select an idle sandbox ( ) and have sufficient time slices to run the user's code. However, in this method, there will be a scenario where the CodeBox of a certain Container has been allocated completely, but its time slices are still idle. A new User may be scheduled to a Container with idle paths but very few remaining time slices, resulting in increased time consumption. Therefore, the algorithm needs to be optimized.
[0059] When the Scheduler schedules, it cannot know how many time slices the code running requires. It can only record the time consumption of the code that is already running. Therefore, the information on the time slices already used by the sandbox and the idle paths of the sandbox can be combined to make a joint selection.
[0060] Figure 1 is a schematic flowchart of the container resource scheduling method provided by the present invention. As Figure 1 shown, the method includes the following:
[0061] Step 110, in the case of receiving a code running request, calculate the proportion of the idle paths of the sandbox and the proportion of the time slices already used by the sandbox for each container according to the information on the idle paths of the sandbox and the time slices already used by the sandbox of each container; wherein, each of the containers includes a plurality of sandboxes;
[0062] In the present invention, the code running request may specifically refer to a code running request uploaded by a user or a code running request for code automatically generated by a large model.
[0063] In the present invention, the number of idle sandbox paths refers to the number of sandbox execution paths in a container that are currently not being used to execute code.
[0064] Each container contains multiple sandboxes. The system periodically or in real-time counts the number of sandboxes in which code is running (occupied) and the number of sandboxes in which code is not running (idle). For example, if a container has 10 sandboxes, and 3 of them are executing code while 7 are not in use, then the number of idle sandbox paths is 7.
[0065] In the present invention, the information on the time slices used by the sandbox represents the time resources consumed by the code running in the sandbox. A time slice is a time unit used for task scheduling in an operating system. The system divides the CPU time into several time slices and allocates them to the code execution in each sandbox in turn. Each sandbox is allocated a certain number of time slices each time it runs code. When the execution time of the code exceeds this time slice, the system will pause the execution of this code and switch to running other code.
[0066] In the present invention, the system records the total number of time slices consumed by each sandbox since its creation. For example, if a certain sandbox has run code 5 times since its creation, and each time it runs, it uses 10ms, 15ms, 5ms, 20ms, and 8ms of time slices respectively, then the total time slices used by this sandbox is 10 + 15 + 5 + 20 + 8 = 58ms.
[0067] In the present invention, by calculating the proportion of the number of idle sandbox paths and the proportion of the time slices used by the sandbox, the current resource usage and load level of each container can be understood. A high proportion of the number of idle sandbox paths indicates that there are more available sandbox resources in the container, and more code execution requests can be processed simultaneously; while a high proportion of the time slices used by the sandbox indicates that the sandbox resources of this container are already relatively busy and have consumed a large number of time slices within a certain period, and it may take some time to process new code tasks. These data provide an important basis for subsequent container resource scheduling, helping to reasonably allocate code execution requests and improve the overall resource utilization rate and performance of the system.
[0068] Step 120: Determine the priority information of each container according to the proportion of the number of idle sandbox paths and the proportion of the time slices used by the sandbox in each container, so as to perform container resource scheduling for the code execution requests according to the priority information.
[0069] In the present invention, by calculating the priority information of each container, it helps the scheduling system better understand the resource status and load conditions of each container, thereby optimizing the scheduling strategy and improving the overall performance and response speed of the system.
[0070] In the present invention, the scheduling system selects containers with high priorities to execute code running requests according to the calculated priority information. Containers with high priorities usually have a higher proportion of idle paths in the sandbox and a lower proportion of used time slices in the sandbox, which means they have more available resources and lower loads and can respond to code running requests faster.
[0071] Therefore, containers with high priorities will be preferentially selected to execute code running requests, thus achieving efficient utilization of resources and load balancing.
[0072] In the present invention, by calculating the proportion of idle paths in the sandbox, the problem of local overload or idleness caused by static resource allocation can be solved, dynamic selection of containers with sufficient resources can be achieved, and resource utilization can be improved. By calculating the proportion of used time slices in the sandbox, the starvation problem caused by uneven historical loads can be solved. Through adjustment of time slice weights, long-term fairness can be ensured. Combining the priority information calculated from the proportion of idle paths in the sandbox and the proportion of used time slices in the sandbox can reasonably balance the loads of containers, avoid some containers exhausting resources prematurely or being idle for a long time, and effectively perform container resource scheduling.
[0073] Optionally, determining the priority information of each container according to the proportion of idle paths in the sandbox and the proportion of used time slices in the sandbox of each container includes:
[0074] Obtaining the path weight information of each container according to the product of the proportion of idle paths in the sandbox of the container and the path coefficient;
[0075] Obtaining the time slice weight information of each container according to the product of the proportion of used time slices in the sandbox of the container and the time slice coefficient;
[0076] Obtaining the priority information of each container according to the sum of the path weight information and the time slice weight information of each container;
[0077] Wherein, the path coefficient is associated with the number of paths used in the sandbox of each container, and the time slice coefficient is associated with the information of used time slices in the sandbox of each container.
[0078] In the present invention, the path coefficient is associated with the number of paths used in the sandbox of each container and is used to adjust the weight of the proportion of idle paths in the sandbox in priority calculation. For example, when the number of paths used in the sandbox of some containers in the system is large, the path coefficient can be adjusted to balance resource allocation between different containers.
[0079] In the present invention, the time slice coefficient is associated with the sandbox used time slice information of each container, and is used to adjust the weight of the sandbox used time slice ratio in the priority calculation. For example, if a container has a large number of sandbox used time slices, it may mean that the tasks of the container are more urgent or take longer to execute. The time slice coefficient can help the system better prioritize these tasks.
[0080] More specifically, computing containers Priority information .
[0081] - b
[0082] Among them, combined with the proportion of idle roads and time slice consumption ratio The weights are calculated comprehensively, among which, is the number of idle paths, The sandbox used time slice information. i is the container number, n is the total number of containers in the system, is the path coefficient, and b is the time slice coefficient.
[0083] In the present invention, the path coefficient and the time slice coefficient can be set to fixed values, for example, both are set to 1, or can be dynamically adjusted according to the device conditions.
[0084] In the present invention, by comprehensively considering the proportion of idle paths in the sandbox and the proportion of used time slices in the sandbox, and combining the path coefficient and the time slice coefficient to determine the priority, resources can be allocated more reasonably and the utilization of resources can be improved. The determination of priority information can help the scheduling system better understand the resource status and load conditions of each container, thereby optimizing the scheduling strategy and improving the overall performance and response speed of the system.
[0085] Optionally, before the step of obtaining the priority information of each container according to the product of the sandbox idle path ratio of the container and the path coefficient, and the sum of the product of the sandbox used time slice ratio of the container and the time slice coefficient, the step further includes:
[0086] Determine the path coefficient according to the ratio of the sum of the number of paths used by the sandboxes of each container to the sum of the maximum number of paths available for the sandboxes of each container;
[0087] The time slice coefficient is determined according to the ratio of the sum of the sandbox used time slice information of each container to the sum of the maximum time slice information of each container.
[0088] In the present invention, the total number of sandbox usage paths of all containers is counted , and the total sum of the maximum available paths of the sandboxes of all containers , calculate the path coefficient, specifically:
[0089] = 1 +
[0090] In the present invention, the total sum of the used time slices of the sandboxes of all containers is counted , and the total sum of the maximum time slices of all containers , calculate the time slice coefficient, specifically:
[0091] b = 1 +
[0092] In the present invention, through these two coefficients, the system can more accurately measure the resource usage of each container, so that when calculating the priority, the idle resources and load status of the container can be comprehensively considered to achieve a more intelligent resource scheduling.
[0093] Optionally, calculating the proportion of the idle paths of the sandbox of each container and the proportion of the used time slices of the sandbox according to the idle path number of the sandbox of each container and the information of the used time slices of the sandbox includes:
[0094] Determine the proportion of the idle paths of the sandbox of each container according to the ratio of the idle path number of the sandbox of each container to the total sum of the idle path numbers of the sandboxes; the total sum of the idle path numbers of the sandboxes is obtained by summing up the idle path numbers of the sandboxes of each container;
[0095] Determine the proportion of the used time slice information of the sandbox of each container according to the ratio of the used time slice information of the sandbox of each container to the total sum of the used time slice information of the sandboxes; wherein, the total sum of the used time slice information of the sandboxes is obtained by summing up the used time slice information of the sandboxes of each container.
[0096] In the present invention, the idle path number of the sandbox of each container: refers to the number of sandboxes that are not currently being used in each container. For example, if container A has 10 sandboxes and 3 of them are running code, then its idle path number of the sandbox is 7. For example, there are containers A, B, and C, and their idle path numbers of the sandboxes are 7, 5, and 3 respectively, then the total sum of the idle path numbers of the sandboxes is 7 + 5 + 3 = 15.
[0097] In the present invention, divide the idle path number of the sandbox of each container by the total sum of the idle path numbers of the sandboxes to obtain the proportion of the idle path number of the sandbox of each container. For example, the proportion of the idle path number of the sandbox of container A is 7 / 15, the proportion of container B is 5 / 15, and the proportion of container C is 3 / 15.
[0098] In the present invention, the used time slice information of each container's sandbox: refers to the number of time slices that the sandbox in each container has used. For example, the used time slice of the sandbox in container A is 100 ms, that in container B is 80 ms, and that in container C is 50 ms.
[0099] The sum of the used time slice information is the total obtained by adding up the used time slice information of all containers' sandboxes. For example, the sum of the used time slice information of the sandboxes in containers A, B, and C is 100 + 80 + 50 = 230 ms. Dividing the used time slice information of each container's sandbox by the sum of the used time slice information of all sandboxes, we get the proportion of the used time slice information of each container's sandbox. For example, the proportion of the used time slice information of the sandbox in container A is 100 / 230, that in container B is 80 / 230, and that in container C is 50 / 230.
[0100] In the present invention, by calculating the proportion of the idle paths of each container's sandbox and the proportion of the used time slices of the sandbox, we can understand the relative usage of each container in the overall resources, providing a basis for subsequent resource scheduling.
[0101] Optionally, performing container resource scheduling for the code running request according to the priority information includes:
[0102] Scheduling any idle sandbox in the container corresponding to the target priority information to the code running request for code running;
[0103] Wherein, the target priority information is the maximum value among all the priority information.
[0104] In the present invention, the system will select the maximum value from the priority information of all containers as the target priority information. For example, if the priorities of three containers are 80, 90, and 75 respectively, then the target priority information is 90.
[0105] In the present invention, the system allocates the code running request to the container with the target priority information. Assuming that the priority of container B is 90, the system will select container B to process the code running request.
[0106] There are multiple sandboxes in container B, and some of them are in an idle state. The scheduling system will select one of these idle sandboxes and allocate it to the code running request. For example, there are sandboxes 1, 2, and 3 in container B, and sandbox 2 is idle. The system will schedule sandbox 2 to the code running request.
[0107] In the present invention, the code running request is executed in the scheduled sandbox. For example, the user-submitted code is run in sandbox 2.
[0108] In the present invention, by allocating the code execution request to the container with the highest priority, it is ensured that the code can be executed as soon as possible, improving the response speed of the system. The priority scheduling mechanism can make a reasonable allocation according to the resource usage and load status of the container, avoiding resource waste and task backlog.
[0109] Optionally, before scheduling any idle sandbox in the container corresponding to the target priority information to the code execution request for code execution, the method further includes:
[0110] In the case of multiple pieces of target priority information, the target priority information with the largest number of idle sandbox paths is used as the final target priority information.
[0111] In the present invention, for containers with the same priority information, the current number of idle sandbox paths of each of them is counted respectively. The number of idle sandbox paths of these containers is compared to find the container with the largest number of idle sandbox paths. The priority information of the container with the largest number of idle sandbox paths is used as the final target priority information for scheduling the code execution request.
[0112] A container with a large number of idle sandbox paths indicates that there are more idle sandbox resources available for code execution. Selecting such a container can make more efficient use of system resources and avoid resource waste.
[0113] For example, there are three containers A, B, and C in the system, and their priority information is all 90. The number of idle sandbox paths of container A is 5, the number of idle sandbox paths of container B is 8, and the number of idle sandbox paths of container C is 3. According to the above steps, the number of idle sandbox paths of container B is the largest, so its priority information is used as the final target priority information, and the code execution request is scheduled to container B.
[0114] In the present invention, by reasonably allocating resources, the overall stability and reliability of the system can be improved, ensuring that the code execution request can be processed in a timely manner.
[0115] Optionally, the sandboxes in the container use the Linux user isolation mechanism to achieve mutual isolation between different sandboxes in the same container.
[0116] Figure 2 For the overall architecture of the distributed code execution sandbox provided by the embodiments of the present invention, as Figure 2 shown, each container contains multiple "code sandboxes" inside. The code sandbox is an isolated environment for executing user code. They achieve mutual isolation through the Linux user isolation mechanism, ensuring that the code execution in each sandbox does not interfere with each other and does not affect the security of the container or the physical machine.
[0117] In the present invention, the Linux user isolation mechanism: The code running in the sandbox executes with a specific Linux user identity, which has lower permissions in the system and cannot perform critical operations on the host. Moreover, different sandboxes are isolated from each other using Linux user identities, ensuring that the code execution environments within each sandbox are relatively independent, further enhancing the security of user data and code execution in a multi-tenant environment and preventing malicious code from escalating permissions or interfering with each other through user identities.
[0118] Multiple environments are isolated in each container, and each environment is provided to only one user at a time to ensure the isolation of the user environment. The containers run on physical machines and are scheduled by K8s.
[0119] Figure 3 Schematic diagram of the system scheduling process provided by the present invention, as Figure 3 shown, including: The user submits a code running request to the system, and the scheduler Scheduler receives the user's code running request and schedules the request to a suitable container according to the resource status of the system.
[0120] Moreover, the scheduler Scheduler receives the status report Report of the container regularly or in real time, including information such as the number of idle paths and used time slices of the sandboxes in the container. The scheduler decides which container's sandbox to allocate the user's code running request to based on the received status report.
[0121] Each container Container contains multiple code sandboxes CodeBox, and the code sandboxes CodeBox are used to execute the user's code. There are multiple code sandboxes in each container, and multiple code running requests can be processed simultaneously.
[0122] More specifically, user User1 submits a code running request to the scheduler, the scheduler receives the user's request, and queries the status information of the container. The container reports information such as the number of idle paths and used time slices of its internal sandboxes to the scheduler regularly.
[0123] The scheduler calculates the priority of each container based on the status information of the container, and the scheduler allocates the user's code running request to the idle sandbox in the container with the highest priority; the selected sandbox receives the code running request and executes the user's code.
[0124] In the present invention, through the intelligent scheduling of the scheduler, the code running request can be allocated to the most suitable container and sandbox, improving the resource utilization rate and response speed of the system.
[0125] The container resource scheduling device provided by the present invention will be described below. The container resource scheduling device described below can be correspondingly referred to the container resource scheduling method described above.
[0126] Figure 4 Schematic structural diagram of the container resource scheduling device provided by the present invention, as Figure 4 shown, including:
[0127] The calculation module 410 is configured to calculate the ratio of the idle paths of the sandbox of each container and the ratio of the used time slices of the sandbox according to the idle path number of the sandbox and the used time slice information of the sandbox of each container when receiving a code running request; wherein, each of the containers includes a plurality of sandboxes;
[0128] The scheduling module 420 is configured to determine the priority information of each container according to the ratio of the idle paths of the sandbox of each container and the ratio of the used time slices of the sandbox, so as to perform container resource scheduling for the code running request according to the priority information.
[0129] According to a container resource scheduling device provided by the present invention, the device is further configured to:
[0130] Obtain the path weight information of each container according to the product of the ratio of the idle paths of the sandbox of the container and the path coefficient;
[0131] Obtain the time slice weight information of each container according to the product of the ratio of the used time slices of the sandbox of the container and the time slice coefficient;
[0132] Obtain the priority information of each container according to the sum of the path weight information and the time slice weight information of each container;
[0133] Wherein, the path coefficient is associated with the number of paths used by the sandboxes of each container, and the time slice coefficient is associated with the used time slice information of the sandboxes of each container.
[0134] According to a container resource scheduling device provided by the present invention, the device is further configured to:
[0135] Determine the path coefficient according to the ratio of the total number of paths used by the sandboxes of each container to the total maximum available path number of the sandboxes of each container;
[0136] Determine the time slice coefficient according to the ratio of the total used time slice information of the sandboxes of each container to the total maximum time slice information of the sandboxes of each container.
[0137] According to a container resource scheduling device provided by the present invention, the device is further configured to:
[0138] Determine the ratio of the idle paths of the sandbox of each container according to the ratio of the idle paths of the sandbox of each container to the total number of idle paths of the sandbox; the total number of idle paths of the sandbox is obtained by summing the idle paths of the sandboxes of each container;
[0139] Determine the proportion of the used time slice information of the sandbox of each container according to the ratio of the used time slice information of the sandbox of each container to the total sum of the used time slice information of the sandbox; wherein, the total sum of the used time slice information of the sandbox is obtained by summing up the used time slice information of the sandboxes of each container.
[0140] According to a container resource scheduling device provided by the present invention, the device is further configured to:
[0141] Schedule any idle sandbox in the container corresponding to the target priority information to the code running request for code running;
[0142] Wherein, the target priority information is the maximum value among all the priority information.
[0143] According to a container resource scheduling device provided by the present invention, the device is further configured to:
[0144] In the case of multiple target priority information, take the target priority information with the largest number of idle sandbox paths as the final target priority information.
[0145] According to a container resource scheduling device provided by the present invention, the device is further configured to: The sandboxes in the container use the Linux user isolation mechanism to achieve mutual isolation between different sandboxes in the same container.
[0146] In the present invention, through the calculation of the proportion of the number of idle sandbox paths, the problem of local overload or idleness caused by static resource allocation can be solved, and containers with sufficient resources can be dynamically selected to improve resource utilization. Through the calculation of the proportion of used time slices of the sandbox, the starvation problem caused by uneven historical loads can be solved. Through the adjustment of time slice weights, long-term fairness can be guaranteed. Combining the priority information calculated from the proportion of the number of idle sandbox paths and the proportion of used time slices of the sandbox can reasonably balance the container load, avoid some containers from exhausting resources prematurely or being idle for a long time, and effectively perform container resource scheduling.
[0147] Figure 5 It is a schematic structural diagram of an electronic device provided by the present invention, as Figure 5As shown in the figure, the electronic device may include: a processor 510, a communications interface 520, a memory 530, and a communication bus 540. Among them, the processor 510, the communications interface 520, and the memory 530 complete communication with each other through the communication bus 540. The processor 510 may call the logical instructions in the memory 530 to execute the container resource scheduling method, which includes: when receiving a code running request, calculating the proportion of the free paths of the sandbox of each container and the proportion of the used time slices of the sandbox according to the free path number of the sandbox of each container and the information of the used time slices of the sandbox; wherein, each of the containers includes a plurality of sandboxes;
[0148] Determine the priority information of each of the containers according to the proportion of the free paths of the sandbox of each of the containers and the proportion of the used time slices of the sandbox, so as to perform container resource scheduling for the code running request according to the priority information.
[0149] In addition, when the logical instructions in the above-mentioned memory 530 are implemented in the form of software functional units and sold or used as an independent product, they may be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or a part of this technical solution, may be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in various embodiments of the present invention. The foregoing storage medium includes: various media such as a USB flash drive, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a magnetic disk, or an optical disc that can store program codes.
[0150] On the other hand, the present invention also provides a computer program product. The computer program product includes a computer program. The computer program can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the container resource scheduling method provided by the above-mentioned various methods. The method includes: when receiving a code running request, calculating the proportion of the free paths of the sandbox of each container and the proportion of the used time slices of the sandbox according to the free path number of the sandbox of each container and the information of the used time slices of the sandbox; wherein, each of the containers includes a plurality of sandboxes;
[0151] Determine the priority information of each of the containers according to the proportion of the free paths of the sandbox of each of the containers and the proportion of the used time slices of the sandbox, so as to perform container resource scheduling for the code running request according to the priority information.
[0152] In another aspect, the present invention further provides a non-transitory computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, it implements a container resource scheduling method provided by the above-mentioned various methods. The method includes: when receiving a code running request, calculating the proportion of free paths of the sandbox of each container and the proportion of used time slices of the sandbox according to the free path number of the sandbox of each container and the used time slice information of the sandbox; wherein, each of the containers includes a plurality of sandboxes.
[0153] Determine the priority information of each container according to the proportion of free paths of the sandbox of each container and the proportion of used time slices of the sandbox, so as to perform container resource scheduling for the code running request according to the priority information.
[0154] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place, or may be distributed to multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the solution of this embodiment. Those of ordinary skill in the art can understand and implement it without creative labor.
[0155] Through the description of the above embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on such an understanding, the above technical solutions, in essence, or the part that contributes to the prior art can be embodied in the form of a software product. The computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disc, etc., and includes several instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0156] Finally, it should be noted that: the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that: they can still modify the technical solutions described in the foregoing embodiments, or perform equivalent replacements for some of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of each embodiment of the present invention.
Claims
1. A container resource scheduling method, characterized in that Including: Upon receiving a code execution request, calculate the proportion of idle paths and the proportion of used time slices of the sandbox for each container based on the number of idle paths and the used time slice information of the sandbox for each container; wherein, each of the containers includes multiple sandboxes; Determine the priority information for each of the containers based on the proportion of idle paths and the proportion of used time slices of the sandbox for each of the containers, so as to perform container resource scheduling for the code execution request according to the priority information; Among them, determining the priority information for each of the containers based on the proportion of idle paths and the proportion of used time slices of the sandbox for each of the containers includes: Obtain the path weight information for each container according to the product of the proportion of idle paths of the sandbox of the container and the path coefficient; Obtain the time slice weight information for each container according to the product of the proportion of used time slices of the sandbox of the container and the time slice coefficient; Obtain the priority information for each container according to the sum of the path weight information and the time slice weight information for each container; Among them, the path coefficient is associated with the number of paths used by the sandboxes of each container, and the time slice coefficient is associated with the used time slice information of the sandboxes of each container.
2. The container resource scheduling method according to claim 1, wherein Before the step of obtaining the priority information for each of the containers according to the sum of the product of the proportion of idle paths of the sandbox of the container and the path coefficient, and the product of the proportion of used time slices of the sandbox of the container and the time slice coefficient, it further includes: Determine the path coefficient according to the ratio of the total number of paths used by the sandboxes of each container to the total maximum available paths of the sandboxes of each container; Determine the time slice coefficient according to the ratio of the total used time slice information of the sandboxes of each container to the total maximum time slice information of each container.
3. The container resource scheduling method according to claim 1, wherein, The calculating the proportion of idle paths and the proportion of used time slices of the sandbox for each container based on the number of idle paths and the used time slice information of the sandbox for each container includes: Determine the proportion of idle paths of the sandbox for each container according to the ratio of the number of idle paths of the sandbox of each container to the total number of idle paths of the sandboxes; the total number of idle paths of the sandboxes is obtained by summing the number of idle paths of the sandboxes of each container; Determine the proportion of the used time slice information of the sandbox for each container according to the ratio of the used time slice information of the sandbox of each container to the total used time slice information of the sandboxes; wherein, the total used time slice information of the sandboxes is obtained by summing the used time slice information of the sandboxes of each container.
4. The container resource scheduling method according to claim 1, wherein, Performing container resource scheduling for the code execution request according to the priority information includes: Schedule any idle sandbox in the container corresponding to the target priority information to the code execution request for code execution; Among them, the target priority information is the maximum value among the priority information.
5. The container resource scheduling method according to claim 4, wherein Before the step of scheduling any idle sandbox in the container corresponding to the target priority information to the code execution request for code execution, the method further includes: In the case where there are multiple target priority information, use the target priority information with the largest number of idle paths of the sandbox as the final target priority information.
6. The container resource scheduling method according to claim 1, wherein The sandbox in the container uses the Linux user isolation mechanism to achieve mutual isolation between different sandboxes in the same container.
7. A container resource scheduling device, characterized in that Including: A calculation module, configured to, when receiving a code running request, calculate the proportion of the idle paths of the sandbox in each container and the proportion of the used time slices of the sandbox according to the idle path numbers of the sandboxes in each container and the information of the used time slices of the sandboxes; wherein, each of the containers includes a plurality of sandboxes; A scheduling module, configured to determine the priority information of each of the containers according to the proportion of the idle paths of the sandbox in each of the containers and the proportion of the used time slices of the sandbox, so as to perform container resource scheduling for the code running request according to the priority information; Wherein, the device is further configured to: Determine the priority information of each of the containers according to the proportion of the idle paths of the sandbox in each of the containers and the proportion of the used time slices of the sandbox, including: Obtain the path weight information of each container according to the product of the proportion of the idle paths of the sandbox in the container and the path coefficient; Obtain the time slice weight information of each container according to the product of the proportion of the used time slices of the sandbox in the container and the time slice coefficient; Obtain the priority information of each container according to the sum of the path weight information and the time slice weight information of each container; Wherein, the path coefficient is associated with the number of paths used by the sandboxes of each container, and the time slice coefficient is associated with the information of the used time slices of the sandboxes of each container.
8. An electronic device, comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the container resource scheduling method according to any one of claims 1 to 6.
9. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the container resource scheduling method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Task execution method, system and device for resource dynamic allocation and storage medium
CN117707777A
Cluster node classification method and device, storage medium and processor
CN119167147A