云环境下微服务系统的弹性伸缩方法、系统、介质及设备Elastic scaling method, system, medium and device for microservice system in cloud environment
技术领域technical field
本发明属于软件技术领域,涉及一种伸缩方法和系统,特别是涉及一种云环境下微服务系统的弹性伸缩方法、系统、介质及设备。The invention belongs to the technical field of software, and relates to a scaling method and system, in particular to an elastic scaling method, system, medium and device for a microservice system in a cloud environment.
背景技术Background technique
随着软件规模的扩大以及云计算等新技术的迅猛发展,软件开发者对软件架构的需求越来越高,快速变化的业务需求以及大规模软件的内部复杂性给软件的开发、运维、乃至软件的整个生命周期带来巨大的挑战。软件开发者希望利用云计算的弹性特点,开发灵活、高效的软件系统,但单体式架构等传统的软件开发架构却限制了软件的快速开发以及灵活伸缩。为此,微服务开发风格被提出并被成功应用到许多大规模商业软件系统。基于微服务的软件系统将高耦合的大规模软件拆分成一系列具有独立生命周期的、高内聚、低耦合的服务集合,从而降低软件的内部复杂性、提高了系统的可扩展性,并通过降低服务粒度的方式实现更灵活的伸缩。但微服务之间的独立性也带来了较大的性能损失,需要通过任务调度方法进行弥补。同时,容器化的部署方式以及众多微服务实例的自动伸缩也需要伸缩方法支撑。With the expansion of software scale and the rapid development of new technologies such as cloud computing, software developers have higher and higher requirements for software architecture. Rapidly changing business requirements and the internal complexity of large-scale And even the entire life cycle of the software brings huge challenges. Software developers hope to use the elastic characteristics of cloud computing to develop flexible and efficient software systems, but traditional software development architectures such as monolithic architectures limit the rapid development and flexible scaling of software. To this end, the microservice development style has been proposed and successfully applied to many large-scale commercial software systems. The software system based on microservices splits high-coupling large-scale software into a series of service sets with independent life cycle, high cohesion and low coupling, thereby reducing the internal complexity of the software, improving the scalability of the system, and More flexible scaling is achieved by reducing service granularity. However, the independence between microservices also brings a large performance loss, which needs to be compensated by the task scheduling method. At the same time, the containerized deployment method and the automatic scaling of many microservice instances also require the support of scaling methods.
目前,微服务系统的相关研究尚处于起步阶段,弹性伸缩的研究主要集中于云环境中的任务调度和自动伸缩。云环境中的任务调度侧重于如何在云环境中安排工作流中任务的执行,并利用云环境中即付即用的大量计算资源进行资源伸缩,实现性能和成本的权衡;但大部分研究局限于单个工作流的调度,忽略了多个工作流的同时调度以及持续的工作负载。云环境中的自动伸缩侧重于计算资源的管理,通过建模分析预测请求的响应时间并预测满足性能要求所需的资源量;但这种建模预估的方式不能准确地反映资源实际需求,且这些方法不涉及具体的任务调度方法,而调度方法也会影响资源需求量。此外,微服务的部署以容器为主,通常采用“一个微服务实例一个容器”的策略进行部署,这使得微服务的伸缩实际上是装载有服务实例的容器的伸缩,需要考虑容器和虚拟机的同时伸缩,以及容器到虚拟机的放置问题。At present, the research on microservice systems is still in its infancy, and the research on elastic scaling mainly focuses on task scheduling and automatic scaling in the cloud environment. Task scheduling in the cloud environment focuses on how to arrange the execution of tasks in the workflow in the cloud environment, and use a large number of pay-as-you-go computing resources in the cloud environment to scale resources to achieve a trade-off between performance and cost; however, most studies are limited For the scheduling of a single workflow, the simultaneous scheduling of multiple workflows and the continuous workload are ignored. Automatic scaling in the cloud environment focuses on the management of computing resources, predicting the response time of requests and predicting the amount of resources required to meet performance requirements through modeling and analysis; however, this modeling and estimation method cannot accurately reflect the actual demand for resources. And these methods do not involve a specific task scheduling method, and the scheduling method also affects the resource demand. In addition, the deployment of microservices is mainly based on containers, and the strategy of "one microservice instance and one container" is usually used for deployment, which makes the scaling of microservices actually the scaling of containers loaded with service instances, and needs to consider containers and virtual machines. Simultaneous scaling, and container-to-VM placement issues.
因此,如何提供一种云环境下微服务系统的弹性伸缩方法、系统、介质及设备,以解决现有技术无法准确地反映资源实际需求,且不涉及具体的任务调度方法,而调度方法也会影响资源需求量,且未考虑容器和虚拟机的同时伸缩,以及容器到虚拟机的放置问题等缺陷,实已成为本领域技术人员亟待解决的技术问题。Therefore, how to provide an elastic scaling method, system, medium and device for a microservice system in a cloud environment to solve the problem that the existing technology cannot accurately reflect the actual demand of resources, and does not involve a specific task scheduling method, and the scheduling method will also Defects such as affecting the resource demand, not considering the simultaneous scaling of the container and the virtual machine, and the placement of the container to the virtual machine have become technical problems to be solved urgently by those skilled in the art.
发明内容SUMMARY OF THE INVENTION
鉴于以上所述现有技术的缺点,本发明的目的在于提供一种云环境下微服务系统的弹性伸缩方法、系统、介质及设备,用于解决现有技术无法准确地反映资源实际需求,且不涉及具体的任务调度方法,而调度方法也会影响资源需求量,且未考虑容器和虚拟机的同时伸缩,以及容器到虚拟机的放置问题的问题。In view of the above-mentioned shortcomings of the prior art, the purpose of the present invention is to provide an elastic scaling method, system, medium and device for a micro-service system in a cloud environment, so as to solve the problem that the prior art cannot accurately reflect the actual demand of resources, and It does not involve a specific task scheduling method, and the scheduling method also affects the resource demand, and does not consider the simultaneous scaling of the container and the virtual machine, and the placement of the container to the virtual machine.
为实现上述目的及其他相关目的,本发明一方面提供一种云环境下微服务系统的弹性伸缩方法,所述云环境下微服务系统包括微服务实例层和虚拟机层,每个微服务实例封装于一容器中,并部署于一虚拟机上;所述云环境下微服务系统的弹性伸缩方法包括:监控所述云环境下微服务系统中每个微服务实例的工作属性信息;在所述微服务系统运行前及运行时,确定每种微服务实例的最优性价比容器类型;以任务的工作流和每种微服务实例的最佳性价比容器类型为基础,形成任务的调度方案;读取所述任务的调度方案,以从其中获取新增微服务实例的类型和数量,并将新增微服务实例部署在已租用或新增虚拟机上。In order to achieve the above object and other related objects, the present invention provides an elastic scaling method of a microservice system in a cloud environment, wherein the microservice system in the cloud environment includes a microservice instance layer and a virtual machine layer, and each microservice instance packaged in a container and deployed on a virtual machine; the elastic scaling method of the microservice system in the cloud environment includes: monitoring the work attribute information of each microservice instance in the microservice system in the cloud environment; Before and during the operation of the microservice system, determine the optimal cost-effective container type for each microservice instance; form the task scheduling scheme based on the task workflow and the optimal cost-effective container type for each microservice instance; read The scheduling scheme of the task is obtained to obtain the type and quantity of the newly added microservice instance, and the newly added microservice instance is deployed on the leased or newly added virtual machine.
于本发明的一实施例中,所述每个微服务实例的工作属性信息包括微服务实例的实际响应时间和/或工作流的端对端响应时间。In an embodiment of the present invention, the work attribute information of each microservice instance includes the actual response time of the microservice instance and/or the end-to-end response time of the workflow.
于本发明的一实施例中,所述监控所述云环境下微服务系统中每个微服务实例的工作属性信息的步骤还包括:根据工作流定义的截止时间,判断所述任务是否超时,若超时,存储延迟时间。In an embodiment of the present invention, the step of monitoring the work attribute information of each microservice instance in the microservice system in the cloud environment further includes: judging whether the task times out according to the deadline defined by the workflow, If it times out, store the delay time.
于本发明的一实施例中,在执行确定每种微服务实例的最优性价比容器类型的步骤之前,所述云环境下微服务系统的弹性伸缩方法还包括:计算每个微服务实例的平均执行时间、微服务实例之间的平均数据传输量和通信延迟。In an embodiment of the present invention, before executing the step of determining the optimal cost-effective container type for each microservice instance, the method for elastic scaling of the microservice system in the cloud environment further includes: calculating the average value of each microservice instance. Execution time, average data transfer volume and communication latency between microservice instances.
于本发明的一实施例中,所述确定每种微服务实例的最优性价比容器类型的步骤包括:初始化所有类型的微服务实例对应的容器类型;计算当前的容器类型下工作流的期望完成时间;当所述期望完成时间大于工作流的截止时间,计算当第i种微服务实例对应的容器类型替换成资源量更多、价格更高的类型时的收益比。In an embodiment of the present invention, the step of determining the optimal cost-effective container type for each microservice instance includes: initializing container types corresponding to all types of microservice instances; calculating the expected completion of the workflow under the current container type. time; when the expected completion time is greater than the deadline of the workflow, calculate the benefit ratio when the container type corresponding to the i-th microservice instance is replaced with a type with more resources and a higher price.
于本发明的一实施例中,所述以任务的工作流和每种微服务实例的最优性价比容器类型为基础,形成任务的调度方案的步骤包括:提取每个微服务实例对应的最优性价比容器类型的运行速度,计算工作流中每个任务的排名,并以任务的排名为基础,计算每个任务的子截止时间;当一个调度周期中需要为多个工作流进行调度、且多个工作流之间存在微服务实例竞争时,通过添加统一的入口任务和出口任务,将多个工作流融合成单一工作流;计算所述工作流中每个就绪任务的期望完成时间;所述就绪任务为所有前驱任务已执行完成的任务; 基于每个任务的子截止时间、每个就绪任务的期望完成时间和后续任务数,计算所述就绪任务的调度紧急程度,选取所述调度紧急程度的最小值对应的就绪任务,作为后续调度的对象;遍历所有可执行该任务的微服务实例,判断所述任务是否能够满足所述子截止时间;通过计算任务松弛度来判断所述任务是否能够满足所述子截止时间;当所述任务松弛度为非负数时,表示存在部分微服务实例可在所述子截止时间之前完成该任务,则计算调度所述任务至所述微服务实例上造成的成本增加量,将所述任务调度到最小的成本增加量对应的微服务实例;当所述任务松弛度为负数时,表示所有部分微服务实例不能满足所述子截止时间,则计算在所述子截止时间之前完成任务所需的最小微服务实例计算速度,以根据最小微服务实例计算速度,新建微服务实例;若新建微服务实例,遍历所述已租用虚拟机,选择其中装载有该微服务实例所需容器镜像的虚拟机,则选择其中虚拟机剩余资源量和容器所需资源量差值最小的虚拟机,并将新建微服务实例部署至该虚拟机上;返回所述计算所述工作流中每个就绪任务的期望完成时间的步骤。In an embodiment of the present invention, the step of forming the task scheduling scheme based on the task workflow and the optimal cost-effective container type for each microservice instance includes: extracting the optimal value corresponding to each microservice instance. The running speed of the cost-effective container type, calculates the ranking of each task in the workflow, and calculates the sub-deadline time of each task based on the ranking of the tasks; when multiple workflows need to be scheduled in one scheduling cycle, and many When there is competition for microservice instances among the workflows, by adding unified entry tasks and exit tasks, multiple workflows are integrated into a single workflow; the expected completion time of each ready task in the workflow is calculated; the A ready task is a task that has been executed and completed by all predecessor tasks; based on the sub-deadline of each task, the expected completion time of each ready task and the number of subsequent tasks, the scheduling urgency of the ready task is calculated, and the scheduling urgency is selected. The ready task corresponding to the minimum value of , as the object of subsequent scheduling; traverse all microservice instances that can execute the task, and determine whether the task can meet the sub-deadline; determine whether the task can meet the sub-deadline by calculating the task slack Satisfy the sub-deadline; when the task slack is a non-negative number, it means that there are some microservice instances that can complete the task before the sub-deadline, then calculating and scheduling the task to the microservice instance will cause When the task slack is negative, it means that all some microservice instances cannot meet the sub-deadline, then the task is calculated in the Describe the minimum computing speed of the microservice instance required to complete the task before the deadline, so as to create a new microservice instance according to the minimum computing speed of the microservice instance; if a new microservice instance is created, traverse the leased virtual machine, and select the For the virtual machine of the container image required by the microservice instance, select the virtual machine with the smallest difference between the remaining resources of the virtual machine and the resources required by the container, and deploy the newly created microservice instance on the virtual machine; return to the computing Steps that describe the expected completion time of each ready task in the workflow.
于本发明的一实施例中,所述云环境下微服务系统的弹性伸缩方法还包括:当已租用虚拟机不足以部署所有新增微服务实例时,则租用新虚拟机用于部署剩余未部署的微服务实例;所述租用新虚拟机的类型、数量以及到虚拟机的映射方式通过预存的可变尺寸的装箱问题的方式求解。In an embodiment of the present invention, the elastic scaling method of the microservice system in the cloud environment further includes: when the rented virtual machine is not enough to deploy all newly added microservice instances, renting a new virtual machine for deploying the remaining unused virtual machines. The deployed microservice instance; the type and quantity of the leased new virtual machine and the mapping method to the virtual machine are solved by means of a pre-stored variable size packing problem.
本发明另一方面提供一种云环境下微服务系统的弹性伸缩系统,所述云环境下微服务系统包括微服务实例层和虚拟机层,每个微服务实例封装于一容器中,并部署于一虚拟机上;所述云环境下微服务系统的弹性伸缩系统包括:监控模块,用于监控所述云环境下微服务系统中每个微服务实例的工作属性信息;容器类型确定模块,用于在所述微服务系统运行前及运行时,确定每种微服务实例的最优性价比容器类型;调度方案形成模块,用于以任务的工作流和每种微服务实例的最佳性价比容器类型为基础,形成任务的调度方案;部署模块,用于读取所述任务的调度方案,以从其中获取新增微服务实例的类型和数量,并将新增微服务实例部署在已租用或新增虚拟机上。Another aspect of the present invention provides an elastic scaling system for a microservice system in a cloud environment. The microservice system in the cloud environment includes a microservice instance layer and a virtual machine layer. Each microservice instance is encapsulated in a container and deployed. on a virtual machine; the elastic scaling system of the microservice system in the cloud environment includes: a monitoring module for monitoring the work attribute information of each microservice instance in the microservice system in the cloud environment; a container type determination module, It is used to determine the optimal cost-effective container type for each microservice instance before and during the operation of the microservice system; the scheduling scheme forms a module for the workflow of tasks and the optimal cost-effective container for each microservice instance Based on the type, the scheduling scheme of the task is formed; the deployment module is used to read the scheduling scheme of the task to obtain the type and quantity of the newly added microservice instance, and deploy the newly added microservice instance in the leased or added to the virtual machine.
本发明又一方面提供一种介质,其上存储有计算机程序,该计算机程序被处理器执行时实现所述云环境下微服务系统的弹性伸缩方法。Another aspect of the present invention provides a medium on which a computer program is stored, and when the computer program is executed by a processor, implements the elastic scaling method of the microservice system in the cloud environment.
本发明最后一方面提供一种设备,包括:处理器及存储器;所述存储器用于存储计算机程序,所述处理器用于执行所述存储器存储的计算机程序,以使所述设备执行所述云环境下微服务系统的弹性伸缩方法。A final aspect of the present invention provides an apparatus, comprising: a processor and a memory; the memory is used for storing a computer program, and the processor is used for executing the computer program stored in the memory, so that the apparatus executes the cloud environment The elastic scaling method of the microservice system.
如上所述,本发明所述的云环境下微服务系统的弹性伸缩方法、系统、介质及设备,具 有以下有益效果:As described above, the elastic scaling method, system, medium and device of a microservice system in a cloud environment according to the present invention have the following beneficial effects:
第一,本发明结合任务调度算法与资源伸缩算法,利用任务调度算法获取调度方案并精确计算出系统伸缩所需的资源量,在保证系统性能的同时降低了系统运行的成本。First, the present invention combines the task scheduling algorithm and the resource scaling algorithm, uses the task scheduling algorithm to obtain the scheduling scheme and accurately calculates the amount of resources required for system scaling, thereby reducing system operation costs while ensuring system performance.
第二,本发明针对云环境中以虚拟机为主的资源提供方式,提出了容器和虚拟机的组合伸缩问题,并利用VSBPP求解方法得到成本最优的虚拟机扩展和容器部署方案。Second, the present invention proposes a combined scaling problem of containers and virtual machines for the resource provisioning mode mainly based on virtual machines in cloud environments, and uses the VSBPP solution method to obtain a cost-optimized solution for virtual machine expansion and container deployment.
第三,本发明综合考虑工作流的整体结构,计算每种微服务的最优性价比容器类型,并以此为依据进行截止时间划分,提高了截止时间划分的可靠性,提升了算法的性能。Third, the present invention comprehensively considers the overall structure of the workflow, calculates the optimal cost-effective container type for each microservice, and divides the deadline based on this, which improves the reliability of deadline division and improves the performance of the algorithm.
附图说明Description of drawings
图1显示为本发明的云环境下微服务系统的原理结构示意图。FIG. 1 is a schematic diagram showing the principle structure of the microservice system in the cloud environment of the present invention.
图2A显示为本发明的云环境下微服务系统的弹性伸缩方法于一实施例中的流程示意图。FIG. 2A is a schematic flowchart of an elastic scaling method of a microservice system in a cloud environment according to an embodiment of the present invention.
图2B显示为本发明的云环境下微服务系统的弹性伸缩方法中S22的流程示意图。FIG. 2B is a schematic flowchart of S22 in the elastic scaling method of the microservice system in the cloud environment of the present invention.
图2C显示为本发明的云环境下微服务系统的弹性伸缩方法中S23的流程示意图。FIG. 2C is a schematic flowchart of S23 in the elastic scaling method of the microservice system in the cloud environment of the present invention.
图3显示为本发明的云环境下微服务系统的弹性伸缩系统于一实施例中的原理结构示意图。FIG. 3 is a schematic diagram showing the principle structure of an elastic scaling system of a microservice system in a cloud environment according to an embodiment of the present invention.
元件标号说明Component label description
具体实施方式detailed description
以下通过特定的具体实例说明本发明的实施方式,本领域技术人员可由本说明书所揭露的内容轻易地了解本发明的其他优点与功效。本发明还可以通过另外不同的具体实施方式加 以实施或应用,本说明书中的各项细节也可以基于不同观点与应用,在没有背离本发明的精神下进行各种修饰或改变。需说明的是,在不冲突的情况下,以下实施例及实施例中的特征可以相互组合。The embodiments of the present invention are described below through specific specific examples, and those skilled in the art can easily understand other advantages and effects of the present invention from the contents disclosed in this specification. The present invention can also be implemented or applied through other different specific embodiments, and various details in this specification can also be modified or changed based on different viewpoints and applications without departing from the spirit of the present invention. It should be noted that the following embodiments and features in the embodiments may be combined with each other under the condition of no conflict.
需要说明的是,以下实施例中所提供的图示仅以示意方式说明本发明的基本构想,遂图式中仅显示与本发明中有关的组件而非按照实际实施时的组件数目、形状及尺寸绘制,其实际实施时各组件的型态、数量及比例可为一种随意的改变,且其组件布局型态也可能更为复杂。It should be noted that the drawings provided in the following embodiments are only used to illustrate the basic concept of the present invention in a schematic way, so the drawings only show the components related to the present invention rather than the number, shape and number of components in actual implementation. For dimension drawing, the type, quantity and proportion of each component can be changed at will in actual implementation, and the component layout may also be more complicated.
本发明所述云环境下微服务系统的弹性伸缩方法、系统、介质及设备的技术原理如下:The technical principles of the elastic scaling method, system, medium and device of the microservice system in the cloud environment according to the present invention are as follows:
本发明包括最优性价比容器类型求解、基于任务紧急程度的异构工作流调度、基于VSBPP的容器虚拟机组合伸缩;其中,最优性价比容器类型求解以描述微服务系统结构的工作流为基础,从资源量最少的容器类型开始,依次为每种微服务替换容器类型,并计算容器类型替换造成的收益比,即性能提升量和价格上涨量的比值,选取收益比最高的微服务容器类型进行实际替换,重复此过程直到在某种容器类型方案下微服务系统的性能达到要求,这个容器类型方案即为最优性价比容器类型;基于任务紧急程度的异构工作流调度以描述用户请求结构的工作流以及最优性价比容器类型为基础,计算用户请求中每个任务的子截止时间、预期完成时间和待调度后继任务数量,以这三个值的比值作为任务的调度紧急程度,决定任务调度的先后顺序;按调度先后顺序依次对每个任务进行调度,判断任务在现有服务实例上是否能够满足子截止时间:如果满足,则计算任务在每个满足子截止时间的服务实例上造成的成本增加量,并选取其中成本增加量最小的服务实例进行任务分配;如果不满足,优先创建符合最优性价比容器类型的新容器,在其中部署服务实例并分配任务到该新服务实例上;基于VSBPP的容器虚拟机组合伸缩从调度算法得到的调度方案中得到新增容器的类型和数量,尝试在已租用虚拟机上进行部署,如果已租用虚拟机的资源量不足以部署所有新增容器,则租用一批新虚拟机用于部署剩余未部署容器,新租用虚拟机的类型、数量以及容器到虚拟机的映射方案通过VSBPP求解方法进行求解。本发明综合考虑任务调度算法和资源伸缩算法,通过任务调度算法精确确定需要扩展的资源数量,再通过资源伸缩算法进行成本最优化的伸缩方案求解,保证微服务系统性能,最小化云资源租用成本。The invention includes the optimal cost-effective container type solution, heterogeneous workflow scheduling based on task urgency, and VSBPP-based container virtual machine combination scaling; wherein, the optimal cost-effective container type solution is based on the workflow describing the structure of the microservice system, Starting from the container type with the least amount of resources, replace the container type for each microservice in turn, and calculate the revenue ratio caused by the replacement of the container type, that is, the ratio of the performance improvement and the price increase, and select the microservice container type with the highest revenue ratio. Actual replacement, repeat this process until the performance of the microservice system meets the requirements under a certain container type scheme, which is the optimal cost-effective container type; heterogeneous workflow scheduling based on task urgency to describe the structure of user requests. Based on the workflow and the optimal cost-effective container type, calculate the sub-deadline, expected completion time, and the number of subsequent tasks to be scheduled for each task in the user request, and use the ratio of these three values as the task's scheduling urgency to determine task scheduling. Schedule each task in turn according to the scheduling order, and determine whether the task can meet the sub-deadline on the existing service instance: if it is satisfied, then calculate the task caused by each service instance that meets the sub-deadline. Cost increase, and select the service instance with the smallest cost increase for task allocation; if not satisfied, create a new container that conforms to the optimal cost-effective container type, deploy the service instance in it, and assign tasks to the new service instance; based on VSBPP's container virtual machine combination scaling obtains the type and quantity of newly added containers from the scheduling scheme obtained by the scheduling algorithm, and tries to deploy it on the leased virtual machine. If the resources of the leased virtual machine are not enough to deploy all the new containers, Then a batch of new virtual machines are leased to deploy the remaining un-deployed containers. The type and quantity of newly leased virtual machines and the mapping scheme from containers to virtual machines are solved by the VSBPP solution method. The invention comprehensively considers the task scheduling algorithm and the resource scaling algorithm, accurately determines the number of resources to be expanded through the task scheduling algorithm, and then solves the cost-optimized scaling scheme through the resource scaling algorithm, ensures the performance of the micro-service system, and minimizes the cost of cloud resource rental. .
实施例一Example 1
本实施例提供一种云环境下微服务系统的弹性伸缩方法,所述云环境下微服务系统包括微服务实例层和虚拟机层,每个微服务实例封装于一容器中,并部署于一虚拟机上;所述云环境下微服务系统的弹性伸缩方法包括:This embodiment provides an elastic scaling method for a microservice system in a cloud environment. The microservice system in the cloud environment includes a microservice instance layer and a virtual machine layer, and each microservice instance is packaged in a container and deployed in a On the virtual machine; the elastic scaling method of the microservice system in the cloud environment includes:
监控所述云环境下微服务系统中每个微服务实例的工作属性信息;Monitoring the work attribute information of each microservice instance in the microservice system in the cloud environment;
在所述微服务系统运行前及运行时,确定每种微服务实例的最优性价比容器类型;Before and during the operation of the microservice system, determine the optimal cost-effective container type for each microservice instance;
以任务的工作流和每种微服务实例的最佳性价比容器类型为基础,形成任务的调度方案;Based on the task workflow and the best cost-effective container type for each microservice instance, the task scheduling scheme is formed;
读取所述任务的调度方案,以从其中获取新增微服务实例的类型和数量,并将新增微服务实例部署在已租用或新增虚拟机上。The scheduling scheme of the task is read to obtain the type and quantity of the newly added microservice instance, and the newly added microservice instance is deployed on the leased or newly added virtual machine.
以下将结合图示对本实施例所提供的云环境下微服务系统的弹性伸缩方法进行详细描述。请参阅图1,显示为云环境下微服务系统的原理结构示意图。如图1所示,所述云环境下微服务系统1包括微服务实例层和虚拟机层,每个微服务实例被封装在一个容器中,并被部署到一虚拟机中。在本实施例中,所述微服务系统以工作流的形式表示,并通过有向无环图(Directed Acyclic Graph,DAG)进行描述,多个用户请求将被缓存在工作负载队列中,如图1中的工作流层所示。在某个时刻T,当用户请求进入系统时,会触发系统中某个功能的执行,该用户请求可以被该功能对应的工作流及DAG表示,DAG中的每个顶点表示请求中的一个任务,两个顶点之间的边表示任务之间的依赖关系。The elastic scaling method of the microservice system in the cloud environment provided by this embodiment will be described in detail below with reference to the drawings. Please refer to Figure 1, which shows a schematic diagram of the principle structure of a microservice system in a cloud environment. As shown in FIG. 1 , the microservice system 1 in the cloud environment includes a microservice instance layer and a virtual machine layer, and each microservice instance is encapsulated in a container and deployed in a virtual machine. In this embodiment, the microservice system is represented in the form of workflow and described by a Directed Acyclic Graph (DAG), and multiple user requests will be cached in the workload queue, as shown in the figure The workflow layer in 1 is shown. At a certain time T, when a user requests to enter the system, it will trigger the execution of a function in the system. The user request can be represented by the workflow and DAG corresponding to the function, and each vertex in the DAG represents a task in the request , an edge between two vertices represents a dependency between tasks.
请参阅图2A,显示为云环境下微服务系统的弹性伸缩方法于一实施例中的流程示意图。如图2A所示,所述云环境下微服务系统的弹性伸缩方法具体包括以下几个步骤:Please refer to FIG. 2A , which is a schematic flowchart of an embodiment of an elastic scaling method of a microservice system in a cloud environment. As shown in FIG. 2A , the elastic scaling method of the microservice system in the cloud environment specifically includes the following steps:
S21,监控所述云环境下微服务系统中每个微服务实例的工作属性信息,并根据工作流定义的截止时间,判断所述任务(在本实施例中,所述任务)是否超时,若超时,存储延迟时间。在本实施例中,所述每个微服务实例的工作属性信息包括微服务实例的实际响应时间和/或工作流的端对端响应时间等等信息。将工作流定义的截止时间与微服务实例的实际响应时间相比较,以判断用户请求是否超时。S21: Monitor the work attribute information of each microservice instance in the microservice system in the cloud environment, and determine whether the task (in this embodiment, the task) times out according to the deadline defined by the workflow, and if Timeout, storage delay time. In this embodiment, the work attribute information of each microservice instance includes information such as the actual response time of the microservice instance and/or the end-to-end response time of the workflow. Compare the deadline defined by the workflow with the actual response time of the microservice instance to determine whether the user request timed out.
S22,在所述微服务系统运行前及运行时,确定每种微服务实例的最优性价比容器类型。在本实施例中,当微服务系统需要扩展某种微服务的服务实例数量时,优先选择对应的容器类型,保证性能和成本的最优化。在求解之前,通过S21监控的数据,求出每种类型微服务实例的平均执行时间(每种类型微服务实例的平均执行时间等于每种类型微服务实例多次执行的执行时间之和除以执行次数)以及微服务实例之间的平均数据传输量(微服务实例之间的平均数据传输量等于微服务实例之间多次传输数据所消耗的时间之和除以传输次数)和通信延迟,并在微服务系统运行时进行实时更新。S22, before and during the running of the microservice system, determine the optimal cost-effective container type for each microservice instance. In this embodiment, when the microservice system needs to expand the number of service instances of a certain microservice, the corresponding container type is preferentially selected to ensure the optimization of performance and cost. Before solving, through the data monitored by S21, find the average execution time of each type of microservice instance (the average execution time of each type of microservice instance is equal to the sum of the execution times of multiple executions of each type of microservice instance divided by execution times) and the average data transfer volume between microservice instances (the average data transfer volume between microservice instances is equal to the sum of the time consumed by multiple data transfers between microservice instances divided by the number of transfers) and communication delays, And make real-time updates when the microservice system is running.
请参阅图2B,显示为S22的流程示意图。如图2B所示,所述S22具体包括以下步骤:Please refer to FIG. 2B , which is a schematic flowchart of S22 . As shown in Figure 2B, the S22 specifically includes the following steps:
S221,初始化所有类型的微服务实例对应的容器类型。S221, initialize container types corresponding to all types of microservice instances.
S222,计算当前的容器类型下工作流的期望完成时间。S222: Calculate the expected completion time of the workflow under the current container type.
makespan=max{FT
c} 公式(3)
makespan=max{FT c } Formula (3)
其中,t
p为任务t
c的前驱任务,当前仅当t
c的所有前驱任务完成时t
c才可以执行。data
p,c为任务t
p和t
c之间的平均数据传输量,b为网络带宽,TT
p,c表示任务t
p和t
c之间的数据传输时间,即通信延迟;FT
p表示t
p的完成时间,ET
c表示t
c的平均执行时间。
Among them, t p is the predecessor task of task t c , and currently t c can be executed only when all predecessor tasks of t c are completed. data p,c is the average data transmission amount between tasks t p and t c , b is the network bandwidth, TT p,c represents the data transmission time between tasks t p and t c , that is, the communication delay; FT p represents t The completion time of p , ET c represents the average execution time of t c .
S223,当所述期望完成时间大于工作流的截止时间,计算当第i种微服务实例对应的容器类型替换成资源量更多、价格更高的类型时的收益比。S223, when the expected completion time is greater than the expiration time of the workflow, calculate the revenue ratio when the container type corresponding to the i-th microservice instance is replaced with a type with more resources and a higher price.
公式(4)Formula (4)
其中,duration
i为第i个容器的运行时长,interval为云服务提供商的收费时间单位,取值为云服务提供商提供的虚拟机收费单位时间,price
i为第i个容器的单位价格,单位价格随容器的资源量变化而变化。
Among them, duration i is the running time of the i-th container, interval is the charging time unit of the cloud service provider, the value is the virtual machine charging unit time provided by the cloud service provider, price i is the unit price of the i-th container, The unit price varies with the amount of resources in the container.
所有微服务类型求收益比,得到集合{gain
i}。其中makespan
before、cost
before、makespan
after、cost
after分别表示替换前与替换后的期望完成时间和容器总价格。选取其中最大收益比对应的i,将第i种微服务对应的容器类型进行实际替换,并返回步骤S222。
Calculate the revenue ratio of all microservice types to get the set {gain i }. Among them, makespan before , cost before , makespan after , and cost after represent the expected completion time and total container price before and after replacement, respectively. The i corresponding to the maximum revenue ratio is selected, the container type corresponding to the i-th microservice is actually replaced, and the process returns to step S222.
计算收益比gain
i时,容器总价格cost取决于容器的单价和容器的运行时长。替换后容器的单价增加,但容器的运行时长降低,所以可能存在如下情况:
When calculating the revenue ratio gain i , the total cost of the container depends on the unit price of the container and the running time of the container. After the replacement, the unit price of the container increases, but the running time of the container decreases, so the following situations may exist:
(1)替换后成本降低,则选取cost差值作为gain
i;
(1) cost is reduced after replacement, then select cost difference as gain i ;
(2)替换后成本不变,则选取makespan差值作为gain
i。
(2) The cost remains unchanged after replacement, and the difference of makespan is selected as gain i .
如果期望完成时间满足工作流的截止时间,则算法停止,当前每种微服务对应的容器类型即为最优性价比容器类型。If the expected completion time meets the deadline of the workflow, the algorithm stops, and the container type corresponding to each microservice is the optimal cost-effective container type.
S23,以任务的工作流和每种微服务实例的最佳性价比容器类型为基础,形成任务的调度方案。S23, a task scheduling scheme is formed based on the task workflow and the best cost-effective container type for each microservice instance.
请参阅图2C,显示为S23的流程示意图。如图2C所示,所述S23包括以下步骤:Please refer to FIG. 2C , which is a schematic flowchart of S23 . As shown in Figure 2C, the S23 includes the following steps:
S231,提取每个微服务实例对应的最优性价比容器类型的运行速度,计算工作流中每个 任务的排名,并以任务的排名为基础,计算每个任务的子截止时间。S231, extracting the running speed of the optimal cost-effective container type corresponding to each microservice instance, calculating the ranking of each task in the workflow, and calculating the sub-deadline time of each task based on the ranking of the tasks.
在本实施例中,根据公式(6)计算工作流中每个任务的排名rank。In this embodiment, the rank of each task in the workflow is calculated according to formula (6).
其中,任务t
j为任务t
i的后继任务,ET
*
i为t
i在最优性价比容器类型上的执行时间,TT
i,j为t
i与t
j之间的数据传输时间。rank的物理含义为:在无任务排队时间的情况下,任务t
i开始执行到整个工作流完成执行的期望时间。
Among them, task t j is the successor task of task t i , ET * i is the execution time of t i on the optimal cost-effective container type, and TT i,j is the data transmission time between t i and t j . The physical meaning of rank is: in the absence of task queuing time, the expected time from the start of task t i to the completion of the entire workflow.
根据其物理含义,以任务的rank为基础,计算每个任务的子截止时间,即每个任务被允许的最晚完成时间。如果一个任务不能在它的子截止时间之前执行完成,则可以认为这个任务所属的工作流将超时:According to its physical meaning, based on the rank of the task, the sub-deadline of each task is calculated, that is, the latest allowed completion time of each task. If a task cannot be executed before its child deadlines, it can be considered that the workflow to which this task belongs will time out:
其中,subdeadline
i为任务t
i的子截止时间,cpLength为工作流的关键路径长度,即整个工作流完成执行的期望时间,deadline为整个工作流的截止时间。
Among them, subdeadline i is the sub-deadline of task t i , cpLength is the critical path length of the workflow, that is, the expected time to complete the execution of the entire workflow, and deadline is the deadline of the entire workflow.
S232,当一个调度周期中需要为多个工作流进行调度、且多个工作流之间存在微服务实例竞争时,通过添加统一的入口任务和出口任务,即一个工作流中无前驱任务或者无后继任务的两类特殊任务,将多个工作流融合成单一工作流。S232, when multiple workflows need to be scheduled in one scheduling cycle, and there is competition for microservice instances among multiple workflows, by adding unified entry tasks and exit tasks, that is, there is no predecessor task or no predecessor task in one workflow. Two types of special tasks for successor tasks, which combine multiple workflows into a single workflow.
S233,计算所述工作流中每个就绪任务的期望完成时间;所述就绪任务为所有前驱任务已执行完成的任务。特别地,没有前驱任务的入口任务一定是每个工作流中最先执行的任务。期望完成时间的计算公式如下:S233: Calculate the expected completion time of each ready task in the workflow; the ready task is a task that has been executed and completed by all predecessor tasks. In particular, an entry task without a predecessor task must be the first task executed in each workflow. The formula for calculating the expected completion time is as follows:
其中,XFT(t
c)为就绪任务t
c的期望完成时间,I
i,j表示第i种微服务的第j个微服务实例,EFT(t
c,I
i,j)和ET(t
c,I
i,j)分别表示任务t
c在微服务实例I
i,j上的最早完成时间和执行时间,w
c为任务t
c的计算量,s
i,j为微服务实例I
i,j的处理速度,avail(I
i,j)为微服务实例I
i,j的可用时间,AFT(t
p)为任务t
p的实际完成时间。期望完成时间即为所有微服务实例中最早完成时间的最小值。需要注意的是,任务t
c只有在其对应类型的微服务的服务实例上才可以执行。
Among them, XFT(t c ) is the expected completion time of the ready task t c , I i,j represents the jth microservice instance of the ith microservice, EFT(t c ,I i,j ) and ET(t c , I i,j ) represent the earliest completion time and execution time of the task t c on the microservice instance I i, j , respectively, w c is the calculation amount of the task t c , and si, j is the microservice instance I i, j The processing speed of , avail(I i,j ) is the available time of the microservice instance I i,j , and AFT(t p ) is the actual completion time of the task t p . The expected completion time is the minimum value of the earliest completion time among all microservice instances. It should be noted that the task t c can only be executed on the service instance of its corresponding type of microservice.
S234,基于每个任务的子截止时间、每个就绪任务的期望完成时间和后续任务数,计算所述就绪任务的调度紧急程度,选取所述调度紧急程度的最小值对应的就绪任务,作为后续调度的对象。S234, based on the sub-deadline time of each task, the expected completion time of each ready task, and the number of subsequent tasks, calculate the scheduling urgency of the ready task, and select the ready task corresponding to the minimum value of the scheduling urgency, as a follow-up Scheduled object.
在本实施例中,根据公式(11)计算所述就绪任务的调度紧急程度:In this embodiment, the scheduling urgency of the ready task is calculated according to formula (11):
其中,hop(t
i)为任务t
i的待调度后续任务数,就绪任务的待调度后继任务数定义为从该任务到出口任务的最大路径长度。当调度紧急程度的值越小时,任务的期望完成时间越接近于子截止时间,后续等待调度的任务数量也越多,该任务也需要优先进行调度。
Among them, hop(t i ) is the number of subsequent tasks to be scheduled for task t i , and the number of subsequent tasks to be scheduled for a ready task is defined as the maximum path length from the task to the exit task. When the value of the scheduling urgency is smaller, the expected completion time of the task is closer to the sub-deadline time, and the number of subsequent tasks waiting to be scheduled is also greater, and the task also needs to be scheduled first.
选取调度紧急程度值最小的就绪任务,作为后续调度的对象。Select the ready task with the smallest scheduling urgency value as the object of subsequent scheduling.
S235,对待调度任务,遍历所有可执行该任务的微服务实例,判断所述任务是否能够满足所述子截止时间;通过计算任务松弛度来判断所述任务是否能够满足所述子截止时间。S235: For the scheduled task, traverse all microservice instances that can execute the task, and determine whether the task can meet the sub-deadline; and determine whether the task can meet the sub-deadline by calculating the task slack.
在本实施例中,根据公式(12)计算任务松弛度:In this embodiment, the task slack is calculated according to formula (12):
Laxity(t
c,I
i,j)=subdeadlin e
c-EFT(t
c,I
i,j) 公式(12)
Laxity(t c ,I i,j )=subdeadline c -EFT(t c ,I i,j ) Equation (12)
Laxity(t
c,I
i,j)物理含义为:当任务t
c被调度到实例I
i,j上时,其子截止时间和最早完成时间之间的差值。
The physical meaning of Laxity(t c ,I i,j ) is: when the task t c is scheduled to the instance I i,j , the difference between its sub-deadline time and the earliest completion time.
当所述任务松弛度Laxity(t
c,I
i,j)为非负数时,表示存在部分微服务实例可在所述子截止时间之前完成该任务,则计算调度所述任务至所述微服务实例上造成的成本增加量incrCost
i,
j,将所述任务调度到最小的成本增加量对应的微服务实例。
When the task laxity Laxity(t c , I i, j ) is a non-negative number, it means that there are some microservice instances that can complete the task before the sub-deadline, then the task is calculated and scheduled to the microservice The cost increase caused by the instance incrCost i, j , schedule the task to the microservice instance corresponding to the minimum cost increase.
在本实施例中,成本增加量incrCost
i,j的计算公式如下:
In this embodiment, the calculation formula of the cost increase incrCost i,j is as follows:
incrCost
i,j=cost′-cost 公式(13)
incrCost i,j = cost′-cost formula (13)
其中,cost和cost’分别表示任务t
c被调度到服务实例I
i,j之前和之后的成本,duration
x为第x个虚拟机的租用时长,interval为云服务提供商的收费时间单位,price
x为第x个虚拟机的单位价格。
Among them, cost and cost' represent the cost before and after the task t c is scheduled to the service instance I i,j respectively, duration x is the rental duration of the xth virtual machine, interval is the charging time unit of the cloud service provider, price x is the unit price of the xth virtual machine.
当所述任务松弛度为负数时,表示所有部分微服务实例满足所述子截止时间,则计算在所述子截止时间之前完成任务所需的最小微服务实例计算速度minSpeed,以根据最小微服务实例计算速度,则新建微服务实例。When the task slack is a negative number, it means that all some microservice instances meet the sub-deadline, and then calculate the minimum microservice instance computing speed minSpeed required to complete the task before the sub-deadline, so as to calculate the minimum microservice instance calculation speed minSpeed according to the minimum microservice Instance computing speed, create a new microservice instance.
在本实施例中,根据公式(15)计算在所述子截止时间之前完成任务所需的最小微服务实例计算速度minSpeed:In this embodiment, the minimum microservice instance computing speed minSpeed required to complete the task before the sub-deadline is calculated according to formula (15):
其中,IT(I
*
i,j)为一个新服务实例的创建时间,并按以下策略进行选择:
Among them, IT(I * i,j ) is the creation time of a new service instance, and is selected according to the following strategies:
(1)当minSpeed大于可获取的虚拟机类型的最大处理速度,则根据公式(9)计算该任务在现有微服务实例上可以达到的最早完成时间,以及新建一个具有最大处理速度的服务实例并且任务在该实例上执行所能达到的最早完成时间(包括新服务实例的创建时间),取两种方案中最早完成时间更小的方案;(1) When minSpeed is greater than the maximum processing speed of the available virtual machine type, calculate the earliest completion time that the task can achieve on the existing microservice instance according to formula (9), and create a new service instance with the maximum processing speed. And the earliest completion time (including the creation time of the new service instance) that the task can execute on this instance, whichever is shorter in the two schemes;
(2)当minSpeed小于该任务对应的微服务的最优性价比容器类型的处理速度,则新建一个最优性价比容器并部署微服务实例,将任务调度到该微服务实例;(2) When minSpeed is less than the processing speed of the optimal cost-effective container type of the microservice corresponding to the task, create a new optimal cost-effective container and deploy the microservice instance, and schedule the task to the microservice instance;
(3)minSpeed处于可获取的虚拟机类型的最大处理速度与该任务对应的微服务的最优性价比容器类型的处理速度之间时,则新建一个处理速度稍大于minSpeed的容器并部署服务实例,将任务调度到该实例上。(3) When minSpeed is between the maximum processing speed of the available virtual machine type and the processing speed of the optimal cost-effective container type of the microservice corresponding to the task, create a new container with a processing speed slightly higher than minSpeed and deploy the service instance, Schedule tasks to this instance.
S236,若新建微服务实例,遍历所述已租用虚拟机,选择其中装载有该微服务实例所需容器镜像的虚拟机,则选择其中虚拟机剩余资源量和容器所需资源量差值最小的虚拟机,并将新建微服务实例部署至该虚拟机上;同时,重新调整该任务的预期完成时间。如果已租用虚拟机中没有服务实例所需的容器镜像,则将该服务实例加入集合newIns中,由容器虚拟机组合伸缩模块进行部署(在本实施例中,被提前部署的新建服务实例不再参加容器虚拟机组合伸缩模块的部署)。返回S233,即返回所述计算所述工作流中每个就绪任务的期望完成时间的步骤。S236, if a new microservice instance is created, traverse the leased virtual machines, select the virtual machine loaded with the container image required by the microservice instance, and select the one with the smallest difference between the remaining resources of the virtual machine and the resources required by the container. virtual machine, and deploy the new microservice instance to the virtual machine; at the same time, readjust the expected completion time of the task. If there is no container image required by the service instance in the rented virtual machine, the service instance is added to the set newIns and deployed by the container virtual machine combined with the scaling module (in this embodiment, the new service instance deployed in advance is no longer Participate in the deployment of the container virtual machine combination scaling module). Returning to S233, that is, returning to the step of calculating the expected completion time of each ready task in the workflow.
S24,读取所述任务的调度方案,以从其中获取新增微服务实例的类型和数量,并将新增微服务实例部署在已租用或新增虚拟机上。S24: Read the scheduling scheme of the task to obtain the type and quantity of the newly added microservice instance therefrom, and deploy the newly added microservice instance on the leased or newly added virtual machine.
具体地,读取所述任务的调度方案,获取未部署的新服务实例集合newIns,从其中获取新增的服务实例以及其对应的容器类型,并根据容器所需的资源量进行升序排列。按照排序结果,依次新增服务实例部署到已租用虚拟机上,选择的依据是Best Fit原则,即选择虚拟机剩余资源量和容器所需资源量差值最小的虚拟机。Specifically, the scheduling scheme of the task is read, the undeployed new service instance set newIns is obtained, the newly added service instances and their corresponding container types are obtained therefrom, and they are arranged in ascending order according to the amount of resources required by the containers. According to the sorting results, new service instances are added to the leased virtual machines in turn. The selection is based on the Best Fit principle, that is, the virtual machine with the smallest difference between the remaining resources of the virtual machine and the resources required by the container is selected.
当已租用虚拟机不足以部署所有新增微服务实例时,则租用新虚拟机用于部署剩余未部署的微服务实例;所述租用新虚拟机的类型、数量以及到虚拟机的映射方式通过预存的可变尺寸的装箱问题(variable-sized bin pack problem,VSBPP)的方式求解。其中,新增的服务实 例即为VSBPP中的物品,可租用的虚拟机类型即为不同容量的箱子。When the leased virtual machines are not enough to deploy all the newly added microservice instances, the new virtual machines are leased to deploy the remaining undeployed microservice instances; the type and quantity of the leased new virtual machines and the mapping method to the virtual machines are determined by The pre-stored variable-sized bin pack problem (VSBPP) is solved. Among them, the newly added service instances are items in VSBPP, and the types of virtual machines that can be rented are boxes of different capacities.
在本实施例中,利用FFDLS算法、IFFD算法等VSBPP求解算法进行求解所述租用新虚拟机的类型、数量以及到虚拟机的映射方式。In this embodiment, a VSBPP solving algorithm such as the FFDLS algorithm and the IFFD algorithm is used to solve the type and quantity of the leased new virtual machine and the mapping method to the virtual machine.
具体地,VSBPP求解算法中的目标函数为新增虚拟机的租用费用最小。云环境中提供的虚拟机常根据租用的时间单位数量,如Amazon EC2的虚拟机以小时收费,未满一小时部分按一小时收费,所以租用费用计算公式如公式(16)所示:Specifically, the objective function in the VSBPP solution algorithm is to minimize the rental cost of the newly added virtual machine. The virtual machines provided in the cloud environment are often based on the number of time units leased. For example, the virtual machine of Amazon EC2 is charged by the hour, and the part less than one hour is charged by one hour. Therefore, the rental fee calculation formula is shown in formula (16):
其中,duration
i为第i个虚拟机的租用时长,interval为云服务提供商的收费时间单位,price
i为第i个虚拟机的单位价格。
Among them, duration i is the rental duration of the ith virtual machine, interval is the charging time unit of the cloud service provider, and price i is the unit price of the ith virtual machine.
在获取到预存的可变尺寸的装箱问题的解后,对每个新租用虚拟机计算剩余资源量,即虚拟机所拥有的资源总量减去被服务实例占用的资源量,并按照该虚拟机上的新增服务实例的所需资源量占比,将剩余资源量按比例分配给新增服务实例。After obtaining the solution of the pre-stored variable-size bin packing problem, calculate the remaining resource amount for each newly leased virtual machine, that is, the total amount of resources owned by the virtual machine minus the amount of resources occupied by the service instance, and according to this The proportion of the required resources of the newly added service instances on the virtual machine, and the remaining resources are allocated to the newly added service instances in proportion.
本实施例所述云环境下微服务系统的弹性伸缩方法具有以下有益效果:The elastic scaling method of the microservice system in the cloud environment described in this embodiment has the following beneficial effects:
第一,本实施例结合任务调度算法与资源伸缩算法,利用任务调度算法获取调度方案并精确计算出系统伸缩所需的资源量,在保证系统性能的同时降低了系统运行的成本。First, this embodiment combines the task scheduling algorithm and the resource scaling algorithm, uses the task scheduling algorithm to obtain the scheduling scheme and accurately calculates the amount of resources required for system scaling, which reduces system operation costs while ensuring system performance.
第二,本实施例针对云环境中以虚拟机为主的资源提供方式,提出了容器和虚拟机的组合伸缩问题,并利用VSBPP求解方法得到成本最优的虚拟机扩展和容器部署方案。Second, this embodiment proposes a combined scaling problem of containers and virtual machines for the resource provisioning method based on virtual machines in a cloud environment, and uses the VSBPP solution method to obtain a cost-optimized solution for virtual machine expansion and container deployment.
第三,本实施例综合考虑工作流的整体结构,计算每种微服务的最优性价比容器类型,并以此为依据进行截止时间划分,提高了截止时间划分的可靠性,提升了算法的性能。Third, this embodiment comprehensively considers the overall structure of the workflow, calculates the optimal cost-effective container type for each microservice, and divides the deadline based on this, which improves the reliability of deadline division and improves the performance of the algorithm. .
本实施例还提供一种介质(亦称为计算机可读存储介质),其上存储有计算机程序,该计算机程序被处理器执行时实现上述云环境下微服务系统的弹性伸缩方法。This embodiment also provides a medium (also referred to as a computer-readable storage medium) on which a computer program is stored, and when the computer program is executed by a processor, implements the above-mentioned elastic scaling method of a microservice system in a cloud environment.
本领域普通技术人员可以理解计算机可读存储介质为:实现上述各方法实施例的全部或部分步骤可以通过计算机程序相关的硬件来完成。前述的计算机程序可以存储于一计算机可读存储介质中。该程序在执行时,执行包括上述各方法实施例的步骤;而前述的存储介质包括:ROM、RAM、磁碟或者光盘等各种可以存储程序代码的介质。Those of ordinary skill in the art can understand that the computer-readable storage medium means that all or part of the steps of implementing the above method embodiments can be completed by hardware related to computer programs. The aforementioned computer program may be stored in a computer-readable storage medium. When the program is executed, the steps including the above method embodiments are executed; and the foregoing storage medium includes: ROM, RAM, magnetic disk or optical disk and other media that can store program codes.
本实施例再提供一种云环境下微服务系统的弹性伸缩系统,所述云环境下微服务系统包括微服务实例层和虚拟机层,每个微服务实例封装于一容器中,并部署于一虚拟机上;所述云环境下微服务系统的弹性伸缩系统包括:This embodiment further provides an elastic scaling system for a microservice system in a cloud environment. The microservice system in the cloud environment includes a microservice instance layer and a virtual machine layer. Each microservice instance is encapsulated in a container and deployed on On a virtual machine; the elastic scaling system of the microservice system in the cloud environment includes:
监控模块,用于监控所述云环境下微服务系统中每个微服务实例的工作属性信息;a monitoring module for monitoring the work attribute information of each microservice instance in the microservice system in the cloud environment;
容器类型确定模块,用于在所述微服务系统运行前及运行时,确定每种微服务实例的最 优性价比容器类型;A container type determination module, used to determine the optimal cost-effective container type for each microservice instance before and during the operation of the microservice system;
调度方案形成模块,用于以任务的工作流和每种微服务实例的最佳性价比容器类型为基础,形成任务的调度方案;The scheduling scheme forming module is used to form the scheduling scheme of the task based on the workflow of the task and the best cost-effective container type for each microservice instance;
部署模块,用于读取所述任务的调度方案,以从其中获取新增微服务实例的类型和数量,并将新增微服务实例部署在已租用或新增虚拟机上。The deployment module is used for reading the scheduling scheme of the task, so as to obtain the type and quantity of the newly added microservice instance, and deploy the newly added microservice instance on the leased or newly added virtual machine.
以下将结合图示对本实施例所提供的云环境下微服务系统的弹性伸缩系统进行详细描述。请参阅图3,显示为云环境下微服务系统的弹性伸缩系统于一实施例中的原理结构示意图。如图3所示,所述云环境下微服务系统的弹性伸缩系统3包括监控模块31、容器类型确定模块32、调度方案形成模块33及部署模块34。The elastic scaling system of the microservice system in the cloud environment provided by this embodiment will be described in detail below with reference to the drawings. Please refer to FIG. 3 , which is a schematic diagram showing the principle structure of an elastic scaling system of a microservice system in a cloud environment in an embodiment. As shown in FIG. 3 , the elastic scaling system 3 of the microservice system in the cloud environment includes a monitoring module 31 , a container type determination module 32 , a scheduling scheme forming module 33 and a deployment module 34 .
所述监控模块31用于监控所述云环境下微服务系统中每个微服务实例的工作属性信息,并根据工作流定义的截止时间,判断所述任务(在本实施例中,所述任务)是否超时,若超时,存储延迟时间。在本实施例中,所述每个微服务实例的工作属性信息包括微服务实例的实际响应时间和/或工作流的端对端响应时间等信息。将工作流定义的截止时间与微服务实例的实际响应时间相比较,以判断用户请求是否超时。The monitoring module 31 is used to monitor the work attribute information of each microservice instance in the microservice system in the cloud environment, and judge the task according to the deadline defined by the workflow (in this embodiment, the task ) whether it times out, if it times out, store the delay time. In this embodiment, the work attribute information of each microservice instance includes information such as the actual response time of the microservice instance and/or the end-to-end response time of the workflow. Compare the deadline defined by the workflow with the actual response time of the microservice instance to determine whether the user request timed out.
与所述监控模块31耦合的所述容器类型确定模块32用于在所述微服务系统运行前及运行时,确定每种微服务实例的最优性价比容器类型。The container type determination module 32 coupled with the monitoring module 31 is configured to determine the optimal cost-effective container type for each microservice instance before and during the operation of the microservice system.
在本实施例中,当微服务系统需要扩展某种微服务的服务实例数量时,优先选择对应的容器类型,保证性能和成本的最优化。所述容器类型确定模块32在求解之前,通过所述监控模块31监控的数据,求出每种类型微服务实例的平均执行时间(每种类型微服务实例的平均执行时间等于每种类型微服务实例多次执行的执行时间之和除以执行次数)以及微服务实例之间的平均数据传输量(微服务实例之间的平均数据传输量等于微服务实例之间多次传输数据所消耗的时间之和除以传输次数)和通信延迟,并在微服务系统运行时进行实时更新。In this embodiment, when the microservice system needs to expand the number of service instances of a certain microservice, the corresponding container type is preferentially selected to ensure the optimization of performance and cost. Before solving, the container type determination module 32 obtains the average execution time of each type of microservice instance through the data monitored by the monitoring module 31 (the average execution time of each type of microservice instance is equal to the average execution time of each type of microservice instance). The sum of the execution time of multiple executions of the instance divided by the number of executions) and the average data transfer volume between microservice instances (the average data transfer volume between microservice instances is equal to the time it takes to transfer data multiple times between microservice instances) The sum divided by the number of transfers) and communication latency, and updated in real-time as the microservice system runs.
具体地,所述容器类型确定模块32用于初始化所有类型的微服务实例对应的容器类型;计算当前的容器类型下工作流的期望完成时间;当所述期望完成时间大于工作流的截止时间,分别计算当第i种微服务实例对应的容器类型替换成资源量更多、价格更高的类型时的收益比。如果期望完成时间满足工作流的截止时间,则所述容器类型确定模块32停止,当前每种微服务对应的容器类型即为最优性价比容器类型。Specifically, the container type determination module 32 is used to initialize the container types corresponding to all types of microservice instances; calculate the expected completion time of the workflow under the current container type; when the expected completion time is greater than the expiration time of the workflow, Calculate the revenue ratio when the container type corresponding to the i-th microservice instance is replaced with a type with more resources and a higher price. If the expected completion time meets the deadline of the workflow, the container type determination module 32 stops, and the container type corresponding to each microservice currently is the optimal cost-effective container type.
与所述监控模块31和所述容器类型确定模块32耦合的调度方案形成模块33用于以任务的工作流和每种微服务实例的最佳性价比容器类型为基础,形成任务的调度方案。The scheduling scheme forming module 33 coupled with the monitoring module 31 and the container type determining module 32 is configured to form the scheduling scheme of the task based on the workflow of the task and the best cost-effective container type for each microservice instance.
具体地,所述调度方案形成模块33用于提取每个微服务实例对应的最优性价比容器类型 的运行速度,计算工作流中每个任务的排名,并以任务的排名为基础,计算每个任务的子截止时间;当一个调度周期中需要为多个工作流进行调度、且多个工作流之间存在微服务实例竞争时,通过添加统一的入口任务和出口任务,将多个工作流融合成单一工作流;计算所述工作流中每个就绪任务的期望完成时间;所述就绪任务为所有前驱任务已执行完成的任务;基于每个任务的子截止时间、每个就绪任务的期望完成时间和后续任务数,计算所述就绪任务的调度紧急程度,选取所述调度紧急程度的最小值对应的就绪任务,作为后续调度的对象;遍历所有可执行该任务的微服务实例,判断所述任务是否能够满足所述子截止时间;通过计算任务松弛度来判断所述任务是否能够满足所述子截止时间;当所述任务松弛度为非负数时,表示存在部分微服务实例可在所述子截止时间之前完成该任务,则计算调度所述任务至所述微服务实例上造成的成本增加量,将所述任务调度到最小的成本增加量对应的微服务实例;当所述任务松弛度为负数时,表示所有部分微服务实例满足所述子截止时间,则计算在所述子截止时间之前完成任务所需的最小微服务实例计算速度,以根据最小微服务实例计算速度,则新建微服务实例;若新建微服务实例,遍历所述已租用虚拟机,选择其中装载有该微服务实例所需容器镜像的虚拟机,则选择其中虚拟机剩余资源量和容器所需资源量差值最小的虚拟机,并将新建微服务实例部署至该虚拟机上;返回计算所述工作流中每个就绪任务的期望完成时间。Specifically, the scheduling scheme forming module 33 is used to extract the running speed of the optimal cost-effective container type corresponding to each microservice instance, calculate the ranking of each task in the workflow, and calculate the ranking of each task based on the ranking of the tasks. The sub-deadline of the task; when multiple workflows need to be scheduled in a scheduling cycle and there is competition for microservice instances among multiple workflows, the multiple workflows can be integrated by adding unified entry tasks and exit tasks into a single workflow; calculate the expected completion time of each ready task in the workflow; the ready task is the completed task of all predecessor tasks; based on the sub-deadline of each task, the expected completion time of each ready task time and the number of subsequent tasks, calculate the scheduling urgency of the ready task, and select the ready task corresponding to the minimum value of the scheduling urgency as the object of subsequent scheduling; traverse all microservice instances that can execute the task, and determine the Whether the task can meet the sub-deadline; determine whether the task can meet the sub-deadline by calculating the task slack; when the task slack is a non-negative number, it means that there are some microservice instances that can be used in the If the task is completed before the sub-deadline, the cost increase caused by scheduling the task to the microservice instance is calculated, and the task is scheduled to the microservice instance corresponding to the minimum cost increase; when the task slackness When it is a negative number, it means that all the microservice instances meet the sub-deadline time, then calculate the minimum microservice instance computing speed required to complete the task before the sub-deadline time, and then create a new microservice instance according to the minimum microservice instance computing speed. Service instance; if a new microservice instance is created, traverse the leased virtual machine, select the virtual machine loaded with the container image required by the microservice instance, and select the smallest difference between the remaining resources of the virtual machine and the resources required by the container. and deploys the newly created microservice instance on the virtual machine; returns and calculates the expected completion time of each ready task in the workflow.
分别与所述容器类型确定模块32和调度方案形成模块33耦合的部署模块34用于读取所述任务的调度方案,以从其中获取新增微服务实例的类型和数量,并将新增微服务实例部署在已租用虚拟机上。当已租用虚拟机不足以部署所有新增微服务实例时,则租用新虚拟机用于部署剩余未部署的微服务实例;所述租用新虚拟机的类型、数量以及到虚拟机的映射方式通过预存的可变尺寸的装箱问题(variable-sized bin pack problem,VSBPP)的方式求解。其中,新增的服务实例即为VSBPP中的物品,可租用的虚拟机类型即为不同容量的箱子。The deployment module 34, which is respectively coupled with the container type determination module 32 and the scheduling scheme forming module 33, is used to read the scheduling scheme of the task, so as to obtain the type and number of newly added microservice instances from it, and to add the newly added microservices. Service instances are deployed on leased virtual machines. When the leased virtual machines are not enough to deploy all the newly added microservice instances, the new virtual machines are leased to deploy the remaining undeployed microservice instances; the type and quantity of the leased new virtual machines and the mapping method to the virtual machines are determined by The pre-stored variable-sized bin pack problem (VSBPP) is solved. Among them, the newly added service instances are items in VSBPP, and the types of virtual machines that can be rented are boxes of different capacities.
具体地,所述部署模块34利用FFDLS算法、IFFD算法等VSBPP求解算法进行求解所述租用新虚拟机的类型、数量以及到虚拟机的映射方式。在获取到预存的可变尺寸的装箱问题的解后,对每个新租用虚拟机计算剩余资源量,即虚拟机所拥有的资源总量减去被服务实例占用的资源量,并按照该虚拟机上的新增服务实例的所需资源量占比,将剩余资源量按比例分配给新增服务实例。Specifically, the deployment module 34 uses VSBPP solving algorithms such as the FFDLS algorithm and the IFFD algorithm to solve the type and quantity of the leased new virtual machine and the mapping method to the virtual machine. After obtaining the solution of the pre-stored variable-size bin packing problem, calculate the remaining resource amount for each newly leased virtual machine, that is, the total amount of resources owned by the virtual machine minus the amount of resources occupied by the service instance, and according to this The proportion of the required resources of the newly added service instances on the virtual machine, and the remaining resources are allocated to the newly added service instances in proportion.
在本实施例中,所述云环境下微服务系统的弹性伸缩系统3中监控模块31、容器类型确定模块32、调度方案形成模块33及部署模块34中具体计算过程如云环境下微服务系统的弹性伸缩方法中所描述的一样,此处不再赘述。In this embodiment, the specific computing processes in the monitoring module 31 , the container type determination module 32 , the scheduling scheme forming module 33 and the deployment module 34 in the elastic scaling system 3 of the microservice system in the cloud environment are as in the microservice system in the cloud environment. It is the same as that described in the elastic scaling method of , and will not be repeated here.
需要说明的是,应理解以上系统的各个模块的划分仅仅是一种逻辑功能的划分,实际实现时可以全部或部分集成到一个物理实体上,也可以物理上分开。且这些模块可以全部以软件通过处理元件调用的形式实现,也可以全部以硬件的形式实现,还可以部分模块通过处理元件调用软件的形式实现,部分模块通过硬件的形式实现。例如:x模块可以为单独设立的处理元件,也可以集成在上述系统的某一个芯片中实现。此外,x模块也可以以程序代码的形式存储于上述系统的存储器中,由上述系统的某一个处理元件调用并执行以上x模块的功能。其它模块的实现与之类似。这些模块全部或部分可以集成在一起,也可以独立实现。这里所述的处理元件可以是一种集成电路,具有信号的处理能力。在实现过程中,上述方法的各步骤或以上各个模块可以通过处理器元件中的硬件的集成逻辑电路或者软件形式的指令完成。以上这些模块可以是被配置成实施以上方法的一个或多个集成电路,例如:一个或多个特定集成电路(Application Specific Integrated Circuit,简称ASIC),一个或多个微处理器(Digital Singnal Processor,简称DSP),一个或者多个现场可编程门阵列(Field Programmable Gate Array,简称FPGA)等。当以上某个模块通过处理元件调度程序代码的形式实现时,该处理元件可以是通用处理器,如中央处理器(Central Processing Unit,简称CPU)或其它可以调用程序代码的处理器。这些模块可以集成在一起,以片上系统(System-on-a-chip,简称SOC)的形式实现。It should be noted that it should be understood that the division of each module of the above system is only a division of logical functions, and may be fully or partially integrated into a physical entity in actual implementation, or may be physically separated. And these modules can all be implemented in the form of software calling through processing elements, or all of them can be implemented in hardware, and some modules can be implemented in the form of calling software through processing elements, and some modules can be implemented in hardware. For example, the x module may be a separately established processing element, or may be integrated in a certain chip of the above-mentioned system to be implemented. In addition, the x module can also be stored in the memory of the above-mentioned system in the form of program code, and is called by a certain processing element of the above-mentioned system to execute the function of the above-mentioned x module. The implementation of other modules is similar. All or part of these modules can be integrated together or implemented independently. The processing element described here may be an integrated circuit with signal processing capability. In the implementation process, each step of the above-mentioned method or each of the above-mentioned modules can be completed by an integrated logic circuit of hardware in the processor element or an instruction in the form of software. The above modules may be one or more integrated circuits configured to implement the above methods, such as: one or more specific integrated circuits (Application Specific Integrated Circuit, ASIC for short), one or more microprocessors (Digital Singnal Processor, DSP for short), one or more Field Programmable Gate Arrays (FPGA for short), etc. When one of the above modules is implemented in the form of a processing element scheduler code, the processing element may be a general-purpose processor, such as a central processing unit (Central Processing Unit, CPU for short) or other processors that can call program codes. These modules can be integrated together and implemented in the form of a System-on-a-chip (SOC for short).
实施例二 Embodiment 2
本实施例提供一种设备,所述设备包括:处理器、存储器、收发器、通信接口或/和系统总线;存储器和通信接口通过系统总线与处理器和收发器连接并完成相互间的通信,存储器用于存储计算机程序,通信接口用于和其他设备进行通信,处理器和收发器用于运行计算机程序,使设备执行如上所述云环境下微服务系统的弹性伸缩方法的各个步骤。This embodiment provides a device, the device includes: a processor, a memory, a transceiver, a communication interface or/and a system bus; the memory and the communication interface are connected to the processor and the transceiver through the system bus and complete mutual communication, The memory is used to store the computer program, the communication interface is used to communicate with other devices, the processor and the transceiver are used to run the computer program, so that the device executes each step of the elastic scaling method of the microservice system in the cloud environment as described above.
上述提到的系统总线可以是外设部件互连标准(Peripheral Component Interconnect,简称PCI)总线或扩展工业标准结构(Extended Industry Standard Architecture,简称EISA)总线等。该系统总线可以分为地址总线、数据总线、控制总线等。为便于表示,图中仅用一条粗线表示,但并不表示仅有一根总线或一种类型的总线。通信接口用于实现数据库访问装置与其他设备(如客户端、读写库和只读库)之间的通信。存储器可能包含随机存取存储器(Random Access Memory,简称RAM),也可能还包括非易失性存储器(non-volatile memory),例如至少一个磁盘存储器。The system bus mentioned above may be a Peripheral Component Interconnect (PCI for short) bus or an Extended Industry Standard Architecture (EISA for short) bus or the like. The system bus can be divided into address bus, data bus, control bus and so on. For ease of presentation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus. The communication interface is used to realize the communication between the database access device and other devices (such as client, read-write library and read-only library). The memory may include random access memory (Random Access Memory, RAM for short), and may also include non-volatile memory (non-volatile memory), such as at least one disk storage.
上述的处理器可以是通用处理器,包括中央处理器(Central Processing Unit,简称CPU)、网络处理器(Network Processor,简称NP)等;还可以是数字信号处理器(Digital Signal Processing,简称DSP)、专用集成电路(Application Specific Integrated Circuit,简称ASIC)、现场可编程门阵列(Field Programmable Gate Array,简称FPGA)或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件。The above-mentioned processor may be a general-purpose processor, including a central processing unit (Central Processing Unit, referred to as CPU), a network processor (Network Processor, referred to as NP), etc.; may also be a digital signal processor (Digital Signal Processing, referred to as DSP) , Application Specific Integrated Circuit (ASIC), Field Programmable Gate Array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, and discrete hardware components.
本发明所述的云环境下微服务系统的弹性伸缩方法的保护范围不限于本实施例列举的步骤执行顺序,凡是根据本发明的原理所做的现有技术的步骤增减、步骤替换所实现的方案都包括在本发明的保护范围内。The protection scope of the elastic scaling method of the microservice system in the cloud environment according to the present invention is not limited to the execution sequence of the steps listed in this embodiment. All solutions are included in the protection scope of the present invention.
本发明还提供一种云环境下微服务系统的弹性伸缩系统,所述云环境下微服务系统的弹性伸缩系统可以实现本发明所述的云环境下微服务系统的弹性伸缩方法,但本发明所述的云环境下微服务系统的弹性伸缩方法的实现装置包括但不限于本实施例列举的云环境下微服务系统的弹性伸缩系统的结构,凡是根据本发明的原理所做的现有技术的结构变形和替换,都包括在本发明的保护范围内。The present invention also provides an elastic scaling system for a microservice system in a cloud environment. The elastic scaling system for a microservice system in a cloud environment can implement the elastic scaling method for a microservice system in a cloud environment described in the present invention. The implementation device of the elastic scaling method of the microservice system in the cloud environment includes but is not limited to the structure of the elastic scaling system of the microservice system in the cloud environment enumerated in this embodiment. The structural deformation and replacement are all included in the protection scope of the present invention.
综上所述,本发明所述云环境下微服务系统的弹性伸缩方法、系统、介质及设备具有以下有益效果:To sum up, the elastic scaling method, system, medium and device of a microservice system in a cloud environment according to the present invention have the following beneficial effects:
第一,本发明结合任务调度算法与资源伸缩算法,利用任务调度算法获取调度方案并精确计算出系统伸缩所需的资源量,在保证系统性能的同时降低了系统运行的成本。First, the present invention combines the task scheduling algorithm and the resource scaling algorithm, uses the task scheduling algorithm to obtain the scheduling scheme and accurately calculates the amount of resources required for system scaling, thereby reducing system operation costs while ensuring system performance.
第二,本发明针对云环境中以虚拟机为主的资源提供方式,提出了容器和虚拟机的组合伸缩问题,并利用VSBPP求解方法得到成本最优的虚拟机扩展和容器部署方案。Second, the present invention proposes a combined scaling problem of containers and virtual machines for the resource provisioning mode mainly based on virtual machines in cloud environments, and uses the VSBPP solution method to obtain a cost-optimized solution for virtual machine expansion and container deployment.
第三,本发明综合考虑工作流的整体结构,计算每种微服务的最优性价比容器类型,并以此为依据进行截止时间划分,提高了截止时间划分的可靠性,提升了算法的性能。本发明有效克服了现有技术中的种种缺点而具高度产业利用价值。Third, the present invention comprehensively considers the overall structure of the workflow, calculates the optimal cost-effective container type for each microservice, and divides the deadline based on this, which improves the reliability of deadline division and improves the performance of the algorithm. The invention effectively overcomes various shortcomings in the prior art and has high industrial utilization value.
上述实施例仅例示性说明本发明的原理及其功效,而非用于限制本发明。任何熟悉此技术的人士皆可在不违背本发明的精神及范畴下,对上述实施例进行修饰或改变。因此,举凡所属技术领域中具有通常知识者在未脱离本发明所揭示的精神与技术思想下所完成的一切等效修饰或改变,仍应由本发明的权利要求所涵盖。The above-mentioned embodiments merely illustrate the principles and effects of the present invention, but are not intended to limit the present invention. Anyone skilled in the art can modify or change the above embodiments without departing from the spirit and scope of the present invention. Therefore, all equivalent modifications or changes made by those with ordinary knowledge in the technical field without departing from the spirit and technical idea disclosed in the present invention should still be covered by the claims of the present invention.