CN113778617A - Container horizontal expansion method and device, electronic equipment and storage medium - Google Patents

Container horizontal expansion method and device, electronic equipment and storage medium Download PDF

Info

Publication number
CN113778617A
CN113778617A CN202110916250.XA CN202110916250A CN113778617A CN 113778617 A CN113778617 A CN 113778617A CN 202110916250 A CN202110916250 A CN 202110916250A CN 113778617 A CN113778617 A CN 113778617A
Authority
CN
China
Prior art keywords
task processing
task
processing unit
processing units
tasks
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202110916250.XA
Other languages
Chinese (zh)
Inventor
柳恒建
杨军
陈挺
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Wanyi Technology Co Ltd
Original Assignee
Wanyi Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Wanyi Technology Co Ltd filed Critical Wanyi Technology Co Ltd
Priority to CN202110916250.XA priority Critical patent/CN113778617A/en
Publication of CN113778617A publication Critical patent/CN113778617A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45533Hypervisors; Virtual machine monitors
    • G06F9/45558Hypervisor-specific management and integration aspects
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5061Partitioning or combining of resources
    • G06F9/5077Logical partitioning of resources; Management or configuration of virtualized resources
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/546Message passing systems or structures, e.g. queues
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45533Hypervisors; Virtual machine monitors
    • G06F9/45558Hypervisor-specific management and integration aspects
    • G06F2009/4557Distribution of virtual machine instances; Migration and load balancing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45533Hypervisors; Virtual machine monitors
    • G06F9/45558Hypervisor-specific management and integration aspects
    • G06F2009/45595Network integration; Enabling network access in virtual machine instances
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/50Indexing scheme relating to G06F9/50
    • G06F2209/5011Pool
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/54Indexing scheme relating to G06F9/54
    • G06F2209/548Queue

Abstract

The application relates to a container horizontal stretching method, a container horizontal stretching device, electronic equipment and a storage medium. The horizontal telescopic method of the container comprises the following steps: detecting the number of tasks in a task queue; calculating the number of expected task processing units by using the number of tasks; and adding or deleting task processing units in a task processing unit pool based on the number of the expected task processing units, wherein the task processing units are used for processing the tasks in the task queue. Each task is processed by a task processing unit, and the capacity expansion and the capacity reduction of the number of the task processing units are effectively carried out according to the service requirements.

Description

Container horizontal expansion method and device, electronic equipment and storage medium
Technical Field
The application relates to the field of cloud technology platforms, in particular to a method and a device for horizontally stretching and retracting a container, electronic equipment and a storage medium.
Background
Kubernetes, K8s for short, is an open source for managing containerized applications on multiple hosts in a cloud platform, and provides a mechanism for application deployment, planning, updating, and maintenance. The goal of Kubernetes is to make deployment containerized applications simple and efficient. The basic unit of Kubernetes resource scheduling is a container group (Pod), and Kubernetes can automatically increase or decrease the copy number of the container group according to the usage amount of a CPU or a memory, so that capacity expansion or capacity reduction scheduling is realized.
The Horizontal expansion and contraction (HPA) of the container can dynamically expand and contract the number of copies of the container group according to the utilization rate of a Central Processing Unit (CPU) or a memory, so as to reduce the pressure of each container group. When the load of the container group reaches a certain threshold value, more new copies can be generated according to the capacity expansion strategy to share the pressure, and when the use of the container group is idle, the number of copies can be automatically reduced after the container group is stably idle for a period of time. The utilization rate of the CPU and the memory cannot represent the actual service requirement, and for applications with high load but low utilization rate of the CPU and the memory, the CPU and the memory cannot be effectively scaled according to the CPU and the memory index.
Disclosure of Invention
In view of the above-mentioned shortcomings of the prior art, the present application aims to provide a method, an apparatus, an electronic device and a storage medium for horizontally extending and retracting a container, which aims to solve the problem that the container cannot be effectively extended and retracted according to a CPU and a memory index.
In a first aspect, an embodiment of the present application provides a method for horizontally telescoping a container, including:
detecting the number of tasks in a task queue;
calculating the number of expected task processing units by using the number of tasks;
and adding or deleting task processing units in a task processing unit pool based on the number of the expected task processing units, wherein the task processing units are used for processing the tasks in the task queue.
In the embodiment of the application, the number of uncompleted tasks is recorded by using the task queue, the task processing units are added or deleted by taking the number of uncompleted tasks as an index, and dynamic capacity expansion and capacity reduction of the number of the task processing units are realized, so that each task is processed by the task processing unit, and the capacity expansion and capacity reduction of the number of the task processing units are effectively carried out according to business requirements.
In one possible embodiment, the method further comprises:
receiving a task to be processed;
putting the task to be processed into the task queue;
dispatching the task to be processed into a target task processing unit, wherein the target task processing unit belongs to a first task processing unit set, and the first task processing unit set comprises task processing units which are not overloaded in the task processing unit pool;
and after the target task processing unit finishes the task to be processed, deleting the task to be processed from the task queue.
In the embodiment of the application, the task processing unit which is not overloaded in the task processing unit pool is determined as the target task processing unit, the task to be processed is allocated to the target task processing unit, and the target task processing unit processes the task to be processed. The problem of unbalanced task number processed by the task processing unit is solved, and the utilization efficiency of the task processing unit is improved.
In one possible implementation, the target task processing unit is a task processing unit with a smaller number of tasks being processed in the first set of task processing units.
In the embodiment of the application, the task processing unit with the smaller number of tasks being processed in the first task processing unit set is determined as the target task processing unit, the task to be processed is assigned to the target task processing unit, and the target task processing unit processes the task to be processed. The problem of unbalanced task number processed by the task processing units is solved, the situations that the concurrence of old task processing units is large and the concurrence of newly expanded task processing units is small are avoided, and the utilization efficiency of the task processing units is improved.
In one possible embodiment, the detecting the number of tasks in the task queue includes:
detecting the number of tasks in a task queue at a first frequency, wherein the first frequency is positively correlated with the change rate of the number of tasks in the task queue.
In the embodiment of the present application, the frequency of detecting the number of tasks in the task queue may be controlled according to the change rate of the number of tasks in the task queue, so as to control the frequency of expanding and contracting the number of task processing units. The larger the change rate of the number of tasks in the task queue is, the higher the capacity expansion or capacity reduction frequency of the number of task processing units is, the horizontal expansion delay of the container can be adjusted according to the task requirements, and the horizontal expansion efficiency of the container is improved.
In one possible embodiment, the adding or deleting task processing units in the task processing unit pool based on the desired number of task processing units includes:
determining the number of actual task processing units in the task processing unit pool;
calculating the difference between the actual task processing unit number and the expected task processing unit number to obtain a difference number;
deleting the task processing units of the difference number under the condition that the number of the actual task processing units is larger than the number of the expected task processing units;
and under the condition that the number of the actual task processing units is less than the number of the expected task processing units, newly adding the task processing units with the difference number.
In one possible embodiment, the method further comprises:
detecting the state of a first task processing unit, wherein the first task processing unit is any task processing unit in a task processing unit pool;
and under the condition that the state of the first task processing unit is abnormal, creating a second task processing unit, wherein the second task processing unit is used for processing the task which is being processed by the first task processing unit.
In the embodiment of the application, the state of the first task processing unit is detected, and when the state of the first task processing unit is abnormal, the second task processing unit is created, and the task being processed by the first task processing unit is transferred to the second task processing unit, so that each task in the task queue can be executed normally.
In a second aspect, an embodiment of the present application provides a horizontal telescopic device for a container, including:
the first detection unit is used for detecting the number of tasks in the task queue;
a calculating unit for calculating the number of expected task processing units by using the number of tasks;
and the telescopic unit is used for adding or deleting task processing units in a task processing unit pool based on the number of the expected task processing units, and the task processing units are used for executing the tasks in the task queue.
In one embodiment, the above container horizontal telescopic device further includes:
the receiving unit is used for receiving the tasks to be processed;
the enqueuing unit is used for putting the tasks to be processed into the task queue;
the dispatching unit is used for dispatching the tasks to be processed to target task processing units, the target task processing units belong to a first task processing unit set, and the first task processing unit set comprises task processing units which are not overloaded in the task processing unit pool;
and the dequeuing unit is used for deleting the tasks to be processed from the task queue after the target task processing unit finishes the tasks to be processed.
In one embodiment, the container horizontal telescopic device further comprises:
the second detection unit is used for detecting the state of a first task processing unit, and the first task processing unit is any task processing unit in the task processing unit pool;
the creating unit is used for creating a second task processing unit under the condition that the state of the first task processing unit is abnormal, and the second task processing unit is used for processing the task being processed by the first task processing unit.
In one embodiment, the first detecting unit is configured to detect the number of tasks in the task queue at a first frequency, and the first frequency is positively correlated to a rate of change of the number of tasks in the task queue.
In the embodiment of the present application, each unit in the provided apparatus may be respectively or entirely combined into one or several other units to form the apparatus, or some unit(s) therein may be further split into multiple units with smaller functions to form the apparatus, which may achieve the same operation without affecting the achievement of the technical effect of the embodiment of the present application. The units are divided based on logic functions, and in practical application, the functions of one unit can be realized by a plurality of units, or the functions of a plurality of units can be realized by one unit.
In a third aspect, an embodiment of the present application provides a container horizontal telescoping system, including:
the task queue is used for recording the number of uncompleted tasks;
the task processing unit pool is used for managing task processing units, and the task processing units are used for processing tasks in the task queues;
the telescopic controller is used for detecting the number of tasks in the task queue and calculating the number of expected task processing units by using the number of tasks; and adding or deleting task processing units in a task processing unit pool based on the number of the expected task processing units, wherein the task processing units are used for processing the tasks in the task queue.
In a fourth aspect, an embodiment of the present application provides an electronic device, including a processor and a memory, where the memory is used to store one or more programs, where the one or more programs are configured to be executed by the processor, and the program includes instructions for performing some or all of the steps described in the first aspect of the embodiment of the present application.
In a fifth aspect, embodiments of the present application provide a computer-readable storage medium storing a computer program comprising program instructions that, when executed by a processor, cause the processor to perform some or all of the steps as described in the first aspect of embodiments of the present application.
In the embodiment of the application, the number of uncompleted tasks is recorded by using the task queue, the task processing units are added or deleted by taking the number of uncompleted tasks as an index, and dynamic capacity expansion and capacity reduction of the number of the task processing units are realized, so that each task is processed by the task processing unit, and the capacity expansion and capacity reduction of the number of the task processing units are effectively carried out according to business requirements.
Drawings
Fig. 1 is a schematic flow chart of a method for horizontally telescoping a container according to an embodiment of the present disclosure;
fig. 2 is a schematic flowchart of a task scheduling method according to an embodiment of the present application;
fig. 3 is a schematic structural diagram of a horizontal telescopic device for a container according to an embodiment of the present disclosure;
fig. 4 is a schematic structural diagram of a horizontal telescopic system of a container according to an embodiment of the present disclosure;
fig. 5 is a schematic structural diagram of an electronic device according to an embodiment of the present application.
Detailed Description
To facilitate an understanding of the present application, the present application will now be described more fully with reference to the accompanying drawings. Preferred embodiments of the present application are given in the accompanying drawings. This application may, however, be embodied in many different forms and should not be construed as limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete.
The terms "first," "second," and the like in the description and claims of the present application and in the above-described drawings are used for distinguishing between different objects and not for describing a particular order. Furthermore, the terms "include" and "have," as well as any variations thereof, are intended to cover non-exclusive inclusions. For example, a process, method, system, article, or apparatus that comprises a list of steps or elements is not limited to only those steps or elements listed, but may alternatively include other steps or elements not listed, or inherent to such process, method, article, or apparatus.
Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein in the description of the present application is for the purpose of describing particular embodiments only and is not intended to be limiting of the application.
Kubernetes, K8s for short, is an open source for managing containerized applications on multiple hosts in a cloud platform, and provides a mechanism for application deployment, planning, updating, and maintenance. The goal of Kubernetes is to make deployment containerized applications simple and efficient. The basic unit of Kubernetes resource scheduling is a container group (Pod), and Kubernetes can automatically increase or decrease the copy number of the container group according to the usage amount of a CPU or a memory, so that capacity expansion or capacity reduction scheduling is realized.
The Horizontal expansion and contraction (HPA) of the container can dynamically expand and contract the number of copies of the container group according to the utilization rate of a Central Processing Unit (CPU) or a memory, so as to reduce the pressure of each container group. When the load of the container group reaches a certain threshold value, more new copies can be generated according to the capacity expansion strategy to share the pressure, and when the use of the container group is idle, the number of copies can be automatically reduced after the container group is stably idle for a period of time. The utilization rate of the CPU and the memory cannot represent the actual service requirement, and for applications with high load but low utilization rate of the CPU and the memory, the CPU and the memory cannot be effectively scaled according to the CPU and the memory index. Moreover, the HPA scaling delay is high, and it is not suitable for faster scaling by default 30S.
After the copy of the container group is dynamically expanded, the client needs to access through a copy Service address (hereinafter referred to as Service), and the Service needs to schedule a task request sent by the client. And (3) scheduling by using a rotation training strategy by default, for example, there are 2 copies, namely copy 1 and copy 2, under Service, and there are three tasks, namely task 1, task 2 and task 3, wherein according to the rotation training strategy, task 1 is assigned to copy 1 for processing, task 2 is assigned to copy 2 for processing, and task 3 is assigned to copy 1 for processing. The situation of uneven distribution is easy to occur when scheduling is carried out according to the round-robin strategy, so that the concurrency of old copies is large, the concurrency of newly expanded copies is small, and the utilization efficiency of the copies is reduced.
Based on this, the present application intends to provide a solution to the above technical problem, the details of which will be explained in the following embodiments.
Referring to fig. 1, fig. 1 is a schematic flow chart illustrating a method for horizontally extending and retracting a container according to an embodiment of the present disclosure. As shown in fig. 1, the horizontal telescoping method of the container includes the following steps.
101, detecting the number of tasks in the task queue.
Specifically, the task queue records uncompleted tasks of the application, where the uncompleted tasks include an unallocated task and an allocated and processing task, that is, a queue element in the task queue is an uncompleted task. The number of tasks in the task queue is the number of uncompleted tasks. The number of the tasks which are not processed can be obtained by monitoring the number of the tasks in the task queue.
Further, the detecting the number of tasks in the task queue may include the following steps:
detecting the number of tasks in a task queue at a first frequency, wherein the first frequency is positively correlated with the change rate of the number of tasks in the task queue.
In the embodiment of the application, the number of tasks in the task queue may be periodically detected, so that the capacity expansion or the capacity reduction of the number of task processing units is periodically performed according to the number of tasks in the task queue. The expansion or contraction delay of the number of the task processing units can be controlled by controlling the frequency of detecting the number of the tasks in the task queue. The first frequency is positively correlated with the change rate of the number of tasks in the task queue, that is, the greater the change rate of the number of tasks in the task queue, the higher the frequency of detecting the number of tasks in the task queue. The change rate of the number of the tasks in the task queue is related to the instantaneous concurrency of the task request, and when the instantaneous concurrency of the task request is larger, the change rate of the number of the tasks in the task queue is larger. The first frequency is positively correlated with the change rate of the number of tasks in the task queue, namely the first frequency is positively correlated with the instantaneous concurrency of the task requests. The first frequency may be determined by detecting an instantaneous concurrency of task requests by the application and detecting a number of tasks in the task queue at the first frequency.
In the embodiment of the present application, the frequency of detecting the number of tasks in the task queue may be controlled according to the change rate of the number of tasks in the task queue, so as to control the frequency of expanding and contracting the number of task processing units. The larger the change rate of the number of tasks in the task queue is, the higher the capacity expansion or capacity reduction frequency of the number of task processing units is, the horizontal expansion delay of the container can be adjusted according to the task requirements, and the horizontal expansion efficiency of the container is improved.
And 102, calculating the number of expected task processing units by using the number of tasks.
Specifically, the task processing units are configured to process tasks in the task queue, and each task processing unit may process a plurality of tasks at the same time. The number of task processing units is expected to be the number of task processing units required to process the tasks in the task queue. In order to avoid an excessive load on the task processing units, an upper limit on the number of tasks that can be processed by each task processing unit may be set. Firstly, determining the upper limit of the number of tasks which can be processed by each task processing unit, and then dividing the number of tasks in the task queue by the upper limit of the number of tasks which can be processed by each task processing unit to obtain the number of expected task processing units. Under the condition that the upper limit of the number of tasks which can be processed by each task processing unit is different, the upper limit of the number of tasks which can be processed by each task processing unit is detected, the upper limit of the average number of tasks which can be processed by the task processing units is calculated, and the number of tasks in the task queue is divided by the upper limit of the average number of tasks which can be processed by the task processing units to obtain the number of expected task processing units.
For example, it is assumed that the task processing units can process n tasks on average, and when the number of tasks in the task queue is m, m/n task processing units are required to process the tasks in the task queue, and the number of task processing units is expected to be m/n. When m/n is not an integer, 1-bit integer fetching is required. For example, when the number of tasks in the task queue is 7 and the task processing unit is set to be capable of processing 3 tasks on average, it is desirable that the number of task processing units is 3, i.e., it is desirable that 3 task processing units are required to process the 7 tasks.
And 103, adding or deleting task processing units in the task processing unit pool based on the number of the expected task processing units.
Specifically, from the viewpoint of operation and deployment, an application may include a plurality of task processing units (instances), and the task processing unit pool refers to a collection of the plurality of task processing units included in the application. After the number of the expected task processing units is determined, adding or deleting the task processing units in the task processing unit pool, so that the number of the task processing units in the task processing unit pool is equal to the number of the expected task processing units.
In this embodiment of the present application, the task processing unit may be a container group (Pod) in kubernets, and the task processing unit pool may be a deployment set (deployment) in kubernets. In kubernets, Pod is the minimum unit of work of kubernets, and represents a deployment unit, which may be understood as a single instance of an application in kubernets, and may be composed of a single container or a small number of containers tightly coupled and sharing resources, and kubernets manages the number of copies of Pod through a deployment set (deployment).
Specifically, when cluster management is performed on task processing containers Pod in a task processing unit pool by using Kubernetes, elastic expansion management can be performed on the containers based on core indexes and custom indexes. The general core indexes include nodes, Central Processing Units (CPUs) of Pod, memories, and the like. In the embodiment of the application, the flexible expansion and contraction management can be performed on the container based on the self-defined index of the number of uncompleted tasks. In an embodiment, the definition of the custom index may be implemented in an internal program of the quantitycalc-metrics container, and the specific implementation is that the quantitycalc-metrics container reads the index file in the volume of the shared storage volume, and converts the file content of the index file into a prometheus index format. And then elastic expansion and contraction management of the container is carried out according to a corresponding prometheus index, so that the number of Pod copies is added or deleted by Kubernets through a deployment set (deployment). The pointer file in the shared storage volume is modified by the task processing container Pod. When a task is newly added for processing, the content of the index file is increased by 1, and otherwise, the content of the index file is decreased by 1. For example, when the content of the index file is 0000, and a new task is added to the task processing container Pod, if the content of the index file plus 1 is 0001, 0001 is written into the index file, and if the task is completed, the content of the index file is 0001, and if the content of the index file minus 1 is 0000, 0000 is written into the index file. In this embodiment, the quantityc-metrics container and the task processing container Pod are independent of each other, and stability and maintainability are better.
Optionally, adding or deleting task processing units in the task processing unit pool based on the number of the desired task processing units may include the following steps:
(11) determining the number of actual task processing units in the task processing unit pool;
(12) calculating the difference between the actual task processing unit number and the expected task processing unit number to obtain a difference number;
(13) deleting the task processing units of the difference number under the condition that the number of the actual task processing units is larger than the number of the expected task processing units;
(14) and under the condition that the number of the actual task processing units is less than the number of the expected task processing units, newly adding the task processing units with the difference number.
In the embodiment of the application, the number of the task processing units which need to be newly added or deleted in the task processing unit pool is determined by calculating the difference between the actual number of the task processing units in the task processing unit pool and the expected number of the task processing units. Deleting the task processing units with the difference number under the condition that the number of the actual task processing units is larger than that of the expected task processing units; and under the condition that the number of the actual task processing units is less than that of the expected task processing units, newly adding a difference number of task processing units.
In the case where the actual number of task processing units is greater than the desired number of task processing units, the poor number of task processing units is deleted. Before deleting the poor number of task processing units, in order to ensure the safety of data, the configuration of safety capacity reduction is required. Before deleting the task processing unit, detecting whether the task processed by the task processing unit is completed, if the task in the task processing unit is not completed, waiting for the task processing unit to complete the task and then deleting the task, and not distributing a new task to the task processing unit. For example, assuming that the number of desired task processing units is 10 and the number of actual task processing units is 15, 5 task processing units are deleted from the task processing unit pool.
And under the condition that the number of the actual task processing units is less than that of the expected task processing units, newly adding a difference number of task processing units. Before adding the task processing units with the difference quantity, whether the quantity of the expected task processing units is larger than the threshold value of the quantity of the task processing units needs to be judged. The threshold value of the number of task processing units is the maximum number of task processing units contained in the task processing unit pool. And under the condition that the number of the expected task processing units is smaller than the threshold value of the number of the task processing units, newly adding a difference number of task processing units. And under the condition that the number of the expected task processing units is larger than the threshold value of the number of the task processing units, calculating the difference between the actual number of the task processing units and the threshold value of the number of the task processing units, wherein the number of the newly added task processing units is the difference between the actual number of the task processing units and the threshold value of the number. For example, assuming that the number of desired task processing units is 10, the threshold number of task processing units is 7, and the actual task processing unit is 5, 2 task processing units are newly added to the task processing unit pool.
In the embodiment of the application, the number of uncompleted tasks is recorded by using the task queue, the task processing units are added or deleted by taking the number of uncompleted tasks as an index, and dynamic capacity expansion and capacity reduction of the number of the task processing units are realized, so that each task is processed by the task processing unit, and the capacity expansion and capacity reduction of the number of the task processing units are effectively carried out according to business requirements.
Furthermore, after the number of the task processing units is reduced or expanded based on the number of the tasks in the task queue, the container horizontal scaling method further includes scheduling the received tasks so that the tasks can be processed by the corresponding task processing units. Referring to fig. 2, fig. 2 is a flowchart illustrating a task scheduling method according to an embodiment of the present disclosure. As shown in fig. 2, the task scheduling method includes the following steps.
And 201, receiving a task to be processed.
Specifically, a task request sent by a client based on business needs is received, and a corresponding task to be processed is generated.
202, putting the task to be processed into a task queue.
Specifically, after receiving the task to be processed, the task to be processed is put into a task queue, and the processing state of the task to be processed is recorded by the task queue.
And 203, dispatching the task to be processed to the target task processing unit.
Specifically, the target task processing unit belongs to a first task processing unit set, and the first task processing unit set includes task processing units that are not overloaded in the task processing unit pool.
In the embodiment of the present application, the task processing units in the task processing unit pool may be divided into an overload task processing unit and a non-overload task processing unit according to the load condition of the task processing unit. The first task processing unit set comprises non-overloaded task processing units in the task processing unit pool. The first task processing unit set may be a set of all non-overloaded task processing units in the task processing unit pool, or may be a set of some non-overloaded task processing units in the task processing unit pool. The target task processing unit is any task processing unit in the first task processing unit set.
And under the condition that the number of the task processing units in the task processing unit pool is 0, delaying the dispatching of the tasks to be processed until the number of the task processing units in the task processing unit pool is not 0, determining a target task processing unit, dispatching the tasks to be processed to the target task processing unit, and enabling the target task processing unit to process the tasks to be processed.
Optionally, the target task processing unit is a task processing unit with a smaller number of tasks being processed in the first task processing unit set.
Specifically, the task processing unit with the smaller number of tasks being processed in the first task processing unit set may be a task processing unit with a smaller number of tasks being processed in the first task processing unit set than the first threshold. The first threshold may be set according to the number of tasks that can be processed by the task processing unit, such as setting the first threshold to one-half of the number of tasks that can be processed by the task processing unit. The first task processing unit set may be further divided into a light-loaded task processing unit set and a heavy-loaded task processing unit set according to the load conditions of the task processing units. The set of light-load task processing units is a set of task processing units with the number of tasks being processed less than a first threshold, and the set of heavy-load task processing units is a set of task processing units with the number of tasks being processed greater than the first threshold. The target task processing unit may be any one of a set of light-load task processing units.
Preferably, the target task processing unit is a task processing unit with the least number of tasks being processed in the first task processing unit set. The task processing units in the first task processing unit set may be sorted according to the number of tasks being processed by the task processing units, and one task processing unit with the least number of tasks being processed in one task processing unit set is determined as the target task processing unit.
After the target task processing unit is determined, the task to be processed is dispatched to the target task processing unit, and the target task processing unit processes the task to be processed.
Furthermore, after the task to be processed is dispatched to the target task processing unit, the method also comprises the step of detecting the processing state of the task to be processed. And under the condition that the processing state of the task to be processed is abnormal, re-assigning the task to be processed to the target task processing unit, and if the target task processing unit still cannot process the task to be processed, assigning the task to be processed to a second target task processing unit, wherein the second target task processing unit is any task processing unit except the target task processing unit in the first task processing set.
In the embodiment of the application, the task processing unit with the smaller number of tasks being processed in the first task processing unit set is determined as the target task processing unit, the task to be processed is assigned to the target task processing unit, and the target task processing unit processes the task to be processed. The problem of unbalanced task number processed by the task processing units is solved, the situations that the concurrence of old task processing units is large and the concurrence of newly expanded task processing units is small are avoided, and the utilization efficiency of the task processing units is improved.
And 204, after the target task processing unit finishes the task to be processed, deleting the task to be processed from the task queue.
Specifically, since the tasks that are not completed by the application are recorded in the task queue, after the target task processing unit completes the task to be processed, the task to be processed needs to be deleted from the task queue.
In the embodiment of the application, the task processing unit which is not overloaded in the task processing unit pool is determined as the target task processing unit, the task to be processed is allocated to the target task processing unit, and the target task processing unit processes the task to be processed. The problem of unbalanced task number processed by the task processing unit is solved, and the utilization efficiency of the task processing unit is improved.
Further, the horizontal telescopic method of the container further comprises the following steps:
(21) detecting the state of a first task processing unit, wherein the first task processing unit is any task processing unit in a task processing unit pool;
(22) and under the condition that the state of the first task processing unit is abnormal, creating a second task processing unit, wherein the second task processing unit is used for processing the task which is being processed by the first task processing unit.
Specifically, the state of a first task processing unit is detected, where the first task processing unit is any task processing unit in a task processing unit pool. And under the condition that the first task processing unit has abnormal state (such as process exit) and cannot process the task, creating a second task processing unit, transferring the task in the first task processing unit to the second task processing unit, and processing the task processed by the first task processing unit by the second task processing unit. After the task being processed in the first task processing unit is transferred to the second task processing unit, the first task processing unit is deleted from the task processing unit pool.
In the embodiment of the application, the state of the first task processing unit is detected, and when the state of the first task processing unit is abnormal, the second task processing unit is created, and the task being processed by the first task processing unit is transferred to the second task processing unit, so that each task in the task queue can be executed normally.
Referring to fig. 3, fig. 3 is a schematic structural diagram of a horizontal telescopic device for a container according to an embodiment of the present disclosure. As shown in fig. 3, the container horizontal telescopic device 300 includes a first detecting unit 301, a calculating unit 302, and a telescopic unit 303.
The first detection unit 301 is configured to detect the number of tasks in the task queue.
The calculating unit 302 is configured to calculate the number of expected task processing units by using the number of tasks;
the scaling unit 303 is configured to add or delete task processing units in a task processing unit pool based on the number of the expected task processing units, where the task processing units are configured to process tasks in the task queue.
In the embodiment of the application, the number of uncompleted tasks is recorded by using the task queue, the task processing units are added or deleted by taking the number of uncompleted tasks as an index, and dynamic capacity expansion and capacity reduction of the number of the task processing units are realized, so that each task is processed by the task processing unit, and the capacity expansion and capacity reduction of the number of the task processing units are effectively carried out according to business requirements.
In one possible embodiment, the container horizontal telescoping device 300 further comprises a receiving unit 304, an enqueuing unit 305, a dispatching unit 306, and a dequeuing unit 307.
The receiving unit 304 is configured to receive a task to be processed.
The enqueue unit 305 is configured to place the to-be-processed task into the task queue.
The dispatch unit 306 may be configured to dispatch the task to be processed to the target task processing unit.
The dequeuing unit 307 is configured to delete the to-be-processed task from the task queue after the target task processing unit completes the to-be-processed task.
In the embodiment of the application, the task processing unit which is not overloaded in the task processing unit pool is determined as the target task processing unit, the task to be processed is allocated to the target task processing unit, and the target task processing unit processes the task to be processed. The problem of unbalanced task number processed by the task processing unit is solved, and the utilization efficiency of the task processing unit is improved.
In a possible embodiment, the container horizontal telescopic device 300 further comprises:
a second detecting unit 308, configured to detect a state of a first task processing unit, where the first task processing unit is any task processing unit in the task processing unit pool;
a creating unit 309, configured to create a second task processing unit when the state of the first task processing unit is abnormal, where the second task processing unit is configured to process a task being processed by the first task processing unit.
In the embodiment of the application, the state of the first task processing unit is detected, and when the state of the first task processing unit is abnormal, the second task processing unit is created, and the task being processed by the first task processing unit is transferred to the second task processing unit, so that each task in the task queue can be executed normally.
In a possible implementation manner, the first detecting unit 301 is configured to detect the number of tasks in the task queue at a first frequency, where the first frequency is positively correlated to a change rate of the number of tasks in the task queue.
In the embodiment of the present application, the frequency of detecting the number of tasks in the task queue may be controlled according to the change rate of the number of tasks in the task queue, so as to control the frequency of expanding and contracting the number of task processing units. The larger the change rate of the number of tasks in the task queue is, the higher the capacity expansion or capacity reduction frequency of the number of task processing units is, the horizontal expansion delay of the container can be adjusted according to the task requirements, and the horizontal expansion efficiency of the container is improved.
Referring to fig. 4, fig. 4 is a schematic structural diagram of a horizontal telescopic system of a container according to an embodiment of the present disclosure. As shown in FIG. 4, the container horizontal scaling system 400 includes a task queue 401, a pool of task processing units 402, and a scaling controller 403.
The task queue 401 is used for recording the number of uncompleted tasks.
The task processing unit pool 402 is configured to manage task processing units, where the task processing units are configured to process tasks in the task queue;
the scaling controller 403 is configured to detect the number of tasks in the task queue, and calculate the number of expected task processing units by using the number of tasks; and adding or deleting task processing units in a task processing unit pool based on the number of the expected task processing units, wherein the task processing units are used for processing the tasks in the task queue.
Optionally, the container horizontal telescoping system 400 further includes a gateway 404, configured to receive a task to be processed; putting the task to be processed into the task queue; dispatching the task to be processed into a target task processing unit, wherein the target task processing unit belongs to a first task processing unit set, and the first task processing unit set comprises task processing units which are not overloaded in the task processing unit pool; and after the target task processing unit finishes the task to be processed, deleting the task to be processed from the task queue.
In the embodiment of the application, the number of uncompleted tasks is recorded by using the task queue, the task processing units are added or deleted by taking the number of uncompleted tasks as an index, and dynamic capacity expansion and capacity reduction of the number of the task processing units are realized, so that each task is processed by the task processing unit, and the capacity expansion and capacity reduction of the number of the task processing units are effectively carried out according to business requirements.
Referring to fig. 5, fig. 5 is a schematic structural diagram of an electronic device according to an embodiment of the present disclosure, and as shown in fig. 5, the electronic device 500 includes a processor 501 and a memory 502. The processor 501 and the memory 502 may be connected to each other by a communication bus 503. The communication bus 503 may be a Peripheral Component Interconnect (PCI) bus, an Extended Industry Standard Architecture (EISA) bus, or the like. The communication bus 503 may be divided into an address bus, a data bus, a control bus, and the like. For ease of illustration, only one thick line is shown in FIG. 5, but this is not intended to represent only one bus or type of bus. The memory 502 is used for storing a computer program comprising program instructions, and the processor 501 is configured for calling the program instructions, the program comprising instructions for performing some or all of the steps of the methods shown in fig. 1 and 2.
The processor 501 may be a general purpose Central Processing Unit (CPU), a microprocessor, an Application-Specific Integrated Circuit (ASIC), or one or more Integrated circuits for controlling the execution of programs according to the above schemes.
The Memory 502 may be a Read-Only Memory (ROM) or other type of static storage device that can store static information and instructions, a Random Access Memory (RAM) or other type of dynamic storage device that can store information and instructions, an Electrically Erasable Programmable Read-Only Memory (EEPROM), a Compact Disc Read-Only Memory (CD-ROM) or other optical Disc storage, optical Disc storage (including Compact Disc, laser Disc, optical Disc, digital versatile Disc, blu-ray Disc, etc.), magnetic disk storage media or other magnetic storage devices, or any other medium that can be used to carry or store desired program code in the form of instructions or data structures and that can be accessed by a computer, but is not limited to these. The memory may be self-contained and coupled to the processor via a bus. The memory may also be integral to the processor.
The electronic device 500 may further include a communication interface including a Universal Serial Bus (USB) interface, which may be used to connect an external storage medium.
In addition, the electronic device 500 may further include general components such as an antenna, which will not be described in detail herein.
Embodiments of the present application also provide a computer-readable storage medium, where the computer-readable storage medium stores a computer program for electronic data exchange, and the computer program enables a computer to execute some or all of the steps of any one of the container horizontal scaling methods described in the method embodiments shown in fig. 1 and fig. 2.
It should be understood that the application of the present application is not limited to the above examples, and that modifications or changes may be made by those skilled in the art based on the above description, and all such modifications and changes are intended to fall within the scope of the appended claims.

Claims (10)

1. A method of horizontally telescoping a container, comprising:
detecting the number of tasks in a task queue;
calculating the number of expected task processing units by using the number of tasks;
and adding or deleting task processing units in a task processing unit pool based on the number of the expected task processing units, wherein the task processing units are used for processing the tasks in the task queue.
2. The method of claim 1, further comprising:
receiving a task to be processed;
putting the task to be processed into the task queue;
dispatching the task to be processed into a target task processing unit, wherein the target task processing unit belongs to a first task processing unit set, and the first task processing unit set comprises task processing units which are not overloaded in the task processing unit pool;
and after the target task processing unit finishes the task to be processed, deleting the task to be processed from the task queue.
3. The method of claim 2, wherein the target task processing unit is a task processing unit of the first set of task processing units that is processing a smaller number of tasks.
4. The method of claim 2, further comprising:
detecting the state of a first task processing unit, wherein the first task processing unit is any task processing unit in a task processing unit pool;
and under the condition that the state of the first task processing unit is abnormal, creating a second task processing unit, wherein the second task processing unit is used for processing the task which is being processed by the first task processing unit.
5. The method of claim 1, wherein detecting the number of tasks in the task queue comprises:
detecting the number of tasks in a task queue at a first frequency, wherein the first frequency is positively correlated with the change rate of the number of tasks in the task queue.
6. The method of claim 1, wherein adding or deleting task processing units from a pool of task processing units based on the desired number of task processing units comprises:
determining the number of actual task processing units in the task processing unit pool;
calculating the difference between the actual task processing unit number and the expected task processing unit number to obtain a difference number;
deleting the task processing units of the difference number under the condition that the number of the actual task processing units is larger than the number of the expected task processing units;
and under the condition that the number of the actual task processing units is less than the number of the expected task processing units, newly adding the task processing units with the difference number.
7. A horizontal telescopic device for a container, comprising:
the first detection unit is used for detecting the number of tasks in the task queue;
a calculating unit for calculating the number of expected task processing units by using the number of tasks;
and the telescopic unit is used for adding or deleting task processing units in a task processing unit pool based on the number of the expected task processing units, and the task processing units are used for executing the tasks in the task queue.
8. A container horizontal retraction system, comprising:
the task queue is used for recording the number of uncompleted tasks;
the task processing unit pool is used for managing task processing units, and the task processing units are used for processing tasks in the task queues;
the telescopic controller is used for detecting the number of tasks in the task queue and calculating the number of expected task processing units by using the number of tasks; and adding or deleting task processing units in a task processing unit pool based on the number of the expected task processing units, wherein the task processing units are used for processing the tasks in the task queue.
9. An electronic device comprising a processor and a memory for storing one or more programs configured for execution by the processor, the programs comprising instructions for performing the method of any of claims 1-7.
10. A computer-readable storage medium, characterized in that the computer-readable storage medium stores a computer program comprising program instructions which, when executed by a processor, cause the processor to carry out the method according to any one of claims 1 to 7.
CN202110916250.XA 2021-08-10 2021-08-10 Container horizontal expansion method and device, electronic equipment and storage medium Pending CN113778617A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110916250.XA CN113778617A (en) 2021-08-10 2021-08-10 Container horizontal expansion method and device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110916250.XA CN113778617A (en) 2021-08-10 2021-08-10 Container horizontal expansion method and device, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
CN113778617A true CN113778617A (en) 2021-12-10

Family

ID=78837202

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110916250.XA Pending CN113778617A (en) 2021-08-10 2021-08-10 Container horizontal expansion method and device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN113778617A (en)

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6449614B1 (en) * 1999-03-25 2002-09-10 International Business Machines Corporation Interface system and method for asynchronously updating a share resource with locking facility
CN109471733A (en) * 2018-11-22 2019-03-15 郑州云海信息技术有限公司 A kind of resource control method and device
CN111078386A (en) * 2019-12-30 2020-04-28 北京奇艺世纪科技有限公司 Control method and control device of distributed scheduling system

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6449614B1 (en) * 1999-03-25 2002-09-10 International Business Machines Corporation Interface system and method for asynchronously updating a share resource with locking facility
CN109471733A (en) * 2018-11-22 2019-03-15 郑州云海信息技术有限公司 A kind of resource control method and device
CN111078386A (en) * 2019-12-30 2020-04-28 北京奇艺世纪科技有限公司 Control method and control device of distributed scheduling system

Similar Documents

Publication Publication Date Title
CN107241281B (en) Data processing method and device
US20160378570A1 (en) Techniques for Offloading Computational Tasks between Nodes
US20130239119A1 (en) Dynamic Processor Mapping for Virtual Machine Network Traffic Queues
CN112269641B (en) Scheduling method, scheduling device, electronic equipment and storage medium
CN105373429A (en) Task scheduling method, device and system
CN102906726A (en) Co-processing accelerating method, device and system
CN111966453B (en) Load balancing method, system, equipment and storage medium
CN105117285B (en) A kind of nonvolatile memory method for optimizing scheduling based on mobile virtual system
CN105491150A (en) Load balance processing method based on time sequence and system
CN107291544A (en) Method and device, the distributed task scheduling execution system of task scheduling
CN104539708A (en) Capacity reduction method, device and system for cloud platform resources
CN112162835A (en) Scheduling optimization method for real-time tasks in heterogeneous cloud environment
CN114385353A (en) Resource scheduling method and device, electronic equipment and storage medium
CN111104227A (en) Resource control method and device of K8s platform and related components
CN112600761A (en) Resource allocation method, device and storage medium
CN109597674B (en) Shared virtual resource pool share scheduling method and system
Shu-Jun et al. Optimization and research of hadoop platform based on fifo scheduler
CN111104203B (en) Virtual machine decentralized scheduling method and device, electronic equipment and storage medium
CN107797870A (en) A kind of cloud computing data resource dispatching method
CN113778617A (en) Container horizontal expansion method and device, electronic equipment and storage medium
CN102696257B (en) Method and device for implementing temperature balance among multiple physical servers
CN114237902A (en) Service deployment method and device, electronic equipment and computer readable medium
CN113886091A (en) Virtual machine migration method, system, equipment and storage medium
CN114390104A (en) Process forensics system, method, apparatus, computer device and medium
CN110096364B (en) Cloud server computing set control method and system

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination