Transverse capacity expansion and contraction method and system, electronic equipment and storage medium
By combining node-based and centralized decision-making, the number of microservice replicas and resource allocation are dynamically adjusted, solving the problems of resource exhaustion and scaling failure in existing technologies, and achieving efficient horizontal scaling.
Patent Information
- Application Number
- CN202511727774.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-24
- Publication Date
- 2026-02-10
AI Technical Summary
Existing horizontal auto-scaling mechanisms cannot exceed preset replica limits, leading to resource exhaustion in microservices during sudden loads, causing response delays and service interruptions. Furthermore, centralized architectures suffer from data processing delays, while distributed architectures lack coordination, resulting in scaling failures.
By collecting operational metrics of microservices from various nodes, calculating the target number of replicas, and combining centralized and distributed decision-making, the number of microservice replicas and resource allocation are dynamically adjusted to prioritize the needs of microservices with insufficient resources, while reclaiming redundant resources and avoiding resource contention.
It enables efficient scaling up and down when resources are limited, ensuring normal business operation, avoiding resource depletion and scaling failure, and improving resource utilization efficiency.
Smart Images

Figure CN121501508A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of resource management, and particularly relates to a horizontal scaling method and system, an electronic device and a storage medium. BACKGROUND
[0002] Current microservice architecture is widely used due to its agility, reusability and elastic expansion capability. Compared with the traditional monolithic architecture, microservices split complex applications into multiple independently deployed lightweight service units, so that the development team can independently design, deploy and update service modules, significantly improving software delivery speed and system reliability. However, the distributed nature of microservices also introduces the core challenge of dynamic resource management, that is, real-time adjustment of computing resources is needed to maintain service quality.
[0003] Current horizontal automatic scaling mechanisms mainly use centralized architecture or distributed architecture to adjust resources. The current horizontal automatic scaling mechanism mainly allocates the total resource quantity of the system in advance, sets the replica limit value of each microservice, and ensures that the scaling is within the total resource quantity. Then, by monitoring specific indicators of microservices, when the indicators exceed the preset threshold, the number of replicas of the microservice is increased or decreased according to the set proportion within the range of exceeding the replica limit value of the microservice. The centralized architecture relies on a single controller to collect global data and make decisions to achieve the scaling of each microservice. The distributed architecture realizes the horizontal automatic scaling mechanism by each node to scale the microservices belonging to it.
[0004] However, the current method is limited by the preset replica limit value, so when a sudden load causes resource demand to exceed the upper limit, the horizontal automatic scaling mechanism cannot break through this limit, causing the microservice to be in a resource depletion state, causing response delay, service interruption and even business loss. Therefore, it cannot efficiently utilize resources. In addition, the centralized architecture relies on the center to collect and make decisions, so there are problems such as data processing delay. The distributed architecture lacks coordination due to independent decision-making, which can easily cause resource competition and other problems, resulting in scaling failure. SUMMARY
[0005] Based on the deficiencies of the prior art, the present application provides a horizontal scaling method and system, an electronic device and a storage medium to solve the problems.
[0006] In order to achieve the above purpose, the present application provides the following technical solutions:
[0007] The first aspect of the present application provides a horizontal scaling method, comprising:
[0008] The operation metrics of each microservice are collected from each node, and the target number of replicas for each microservice is calculated using the operation metrics of the microservice and a preset threshold.
[0009] The scaling decision for the microservice is determined by comparing the target number of replicas with the current number of replicas.
[0010] If the target number of replicas of each microservice is not greater than its maximum number of replicas, then the scaling decision is executed according to the target number of replicas of the microservice to which it belongs.
[0011] If the target number of replicas of any microservice is greater than its maximum number of replicas, the central node calculates the replica gap and resource gap, or the replica redundancy and resource redundancy of the microservice based on the difference between the target number of replicas and the maximum number of replicas of each microservice.
[0012] The system iterates through each microservice with insufficient resources in descending order of resource gap. Based on the current total available resources and the replica gap of the microservice, it analyzes the updated replica count and resource limit of the microservice after resource allocation, and updates the current total available resources.
[0013] According to the order of redundancy gap from smallest to largest, for each microservice with excess resources, based on the current total idle resources and the replica redundancy of the microservice, analyze the updated replica number and resource limit of the microservice after resource reclamation, and update the current total idle resources.
[0014] The scaling decisions for each microservice are updated by comparing the target number of replicas and the updated number of replicas. The maximum number of replicas and the target number of replicas for each microservice are also updated using the resource limit and the updated number of replicas for each microservice.
[0015] Each node executes its updated scaling decision based on the updated target number of replicas of its respective microservice.
[0016] Optionally, in the above-described horizontal scaling method, the step of collecting the operational metrics of each microservice from each node and calculating the target number of replicas for each microservice using the operational metrics of the microservices and a preset threshold includes:
[0017] The current number of replicas, current CPU utilization, preset threshold, and maximum number of replicas of the microservice to which each node belongs are collected respectively.
[0018] Multiply the current number of replicas of the microservice by the ratio of the current CPU utilization to a preset threshold, and round the result up to obtain the target number of replicas of the microservice.
[0019] Optionally, in the above-described horizontal scaling method, determining the scaling decision by comparing the target number of replicas and the current number of replicas of the microservice includes:
[0020] If the target number of replicas of the microservice is greater than its current number of replicas, a scaling up or down decision is generated.
[0021] If the target number of replicas of the microservice is less than its current number of replicas, a scaling-up / scaling decision is generated.
[0022] If the target number of replicas of the microservice is equal to its current number of replicas, then a scaling decision without scaling is generated.
[0023] Optionally, in the above-described horizontal scaling method, the step of calculating the replica gap and resource gap, or the replica redundancy and resource redundancy of the microservice by the central node based on the difference between the target replica number and the maximum replica number of each microservice includes:
[0024] The central node determines whether the target number of replicas for each microservice is greater than its maximum number of replicas.
[0025] If the target number of replicas of the microservice is greater than its maximum number of replicas, then the target number of replicas of the microservice is subtracted from its maximum number of replicas to obtain the replica gap of the microservice.
[0026] Multiply the replica gap of the microservice by the resource requirement of a single replica to obtain the resource gap of the microservice.
[0027] If the target number of replicas of the microservice is not greater than its maximum number of replicas, then the maximum number of replicas of the microservice is subtracted from its target number of replicas to obtain the replica redundancy of the microservice.
[0028] Multiply the replica gap of the microservice by the resource requirement of a single replica to obtain the resource redundancy of the microservice.
[0029] Optionally, in the above-described horizontal scaling method, the step of traversing each microservice with insufficient resources in descending order of resource gap, analyzing the updated replica count and resource limit of the microservice after resource allocation based on the current total idle resources and the replica gap of the microservice, and updating the current total idle resources, includes:
[0030] The current total amount of idle resources is initialized to the sum of the resource redundancy of each of the microservices with excess resources;
[0031] Iterate through each of the microservices with insufficient resources in descending order of resource gap;
[0032] The current total amount of free resources is divided by the resource requirement of a single replica, and the result is taken as the current number of replicas that can be allocated.
[0033] If the current number of allocable replicas is not less than the replica gap of the microservice, the updated number of replicas and the resource limit of the microservice are set to the target number of replicas of the microservice.
[0034] If the current allocable replica count is less than the replica gap of the microservice, and not less than 1, the updated replica count of the microservice is set to the sum of the integer part of the current allocable replica count and the maximum replica count of the microservice, and the resource limit of the microservice is set to the updated replica count of the microservice.
[0035] If the current number of allocable replicas is less than 1, then the updated number of replicas and the resource limit of the microservice are set to the maximum number of replicas of the microservice.
[0036] Multiply the difference between the updated number of replicas of the microservice and its maximum number of replicas by the single replica resource requirement to obtain the used resources of the microservice;
[0037] Subtract the used resources of the microservice from the current total idle resources.
[0038] Optionally, in the above-described horizontal scaling method, the step of analyzing the updated replica count and resource limit of each microservice with excess resources in ascending order of redundancy gap, based on the current total idle resources and the replica redundancy of the microservice, and updating the current total idle resources, includes:
[0039] Iterate through the microservices with excess resources in ascending order of redundancy gaps;
[0040] The current total amount of free resources is divided by the resource requirement of a single replica, and the result is taken as the current number of reclaimable replicas;
[0041] If the current number of recyclable replicas is not less than the replica redundancy of the microservice, the resource limit of the microservice is set to the maximum number of replicas of the microservice, and the updated number of replicas of the microservice is set to the target number of replicas of the microservice.
[0042] If the current number of reclaimable replicas is less than the replica redundancy of the microservice and not less than 1, the resource limit of the microservice is set to the sum of the integer part of the current number of reclaimable replicas and the target number of replicas of the microservice, and the updated number of replicas of the microservice is set to the target number of replicas of the microservice.
[0043] If the current number of recyclable replicas is less than 1, then the updated number of replicas and the resource limit of the microservice are set to the target number of replicas of the microservice.
[0044] Multiply the difference between the maximum number of replicas of the microservice and its resource limit by the resource requirement per replica to obtain the reclaimed resources of the microservice;
[0045] Add the current total idle resources to the reclaimed resources of the microservice.
[0046] Optionally, in the above-described horizontal scaling method, updating the scaling decisions for each microservice by comparing the target number of replicas and the updated number of replicas for each microservice includes:
[0047] For each of the microservices, if the updated number of replicas of the microservice is consistent with the target number of replicas, the scaling up / down decision of the microservice is maintained.
[0048] If the number of replicas of the microservice after the update is greater than the maximum number of replicas and less than the target number of replicas, then the scaling decision for updating the microservice is to scale up.
[0049] If the number of replicas of the microservice after the update is not greater than the maximum number of replicas, then the scaling decision for updating the microservice is no scaling.
[0050] A second aspect of this application provides a system for horizontal scaling, comprising:
[0051] The target calculation unit is used to collect the operation metrics of the microservices belonging to each node, and use the operation metrics of the microservices and preset thresholds to calculate the target number of replicas of each microservice.
[0052] The decision-making unit is used to determine the scaling-up / scaling decision of the microservice by comparing the target number of replicas with the current number of replicas.
[0053] The first scaling unit is used to execute scaling decisions according to the target replica count of each microservice when the target replica count of each microservice is not greater than its maximum replica count.
[0054] The resource analysis unit is used to calculate the replica gap and resource gap of each microservice, or the replica redundancy and resource redundancy of each microservice, by means of the central node, when the target number of replicas of any microservice is greater than its maximum number of replicas.
[0055] The resource allocation unit is used to traverse each of the microservices with insufficient resources in descending order of resource gap, analyze the updated number of replicas and the resource limit of the microservice after resource allocation based on the current total idle resources and the replica gap of the microservice, and update the current total idle resources.
[0056] The resource reclamation unit is used to analyze the updated number of replicas and the resource limit of each microservice with excess resources in ascending order of redundancy gap, based on the current total idle resources and the replica redundancy of the microservice, and update the current total idle resources.
[0057] The decision update unit is used to update the scaling decisions of each microservice by comparing the target number of replicas and the updated number of replicas of each microservice.
[0058] The parameter update unit is used to update the maximum number of replicas and the target number of replicas of the microservice using the resource limit and the updated number of replicas of the microservice.
[0059] The second scaling unit is used to execute the updated scaling decision for each of the nodes according to the updated target number of replicas of the microservice to which it belongs.
[0060] Optionally, in the above-described horizontal scaling system, the target computing unit includes:
[0061] The collection unit is used to collect the current number of replicas, current CPU utilization, preset threshold, and maximum number of replicas of the microservice belonging to each node.
[0062] The target replica count calculation unit is used to multiply the current replica count of the microservice by the ratio of the current CPU utilization to a preset threshold, and round the calculation result up to obtain the target replica count of the microservice.
[0063] Optionally, in the above-described horizontal scaling system, the decision-making unit includes:
[0064] The first generation unit is used to generate scaling up / down decisions when the target number of replicas of the microservice is greater than its current number of replicas.
[0065] The second generation unit is used to generate scaling up / down decisions when the target number of replicas of the microservice is less than its current number of replicas.
[0066] The third generation unit is used to generate scaling decisions without scaling when the target number of replicas of the microservice is equal to its current number of replicas.
[0067] Optionally, in the above-described horizontal scaling system, the resource analysis unit includes:
[0068] The first judgment unit is used to determine, through the central node, whether the target number of replicas of each microservice is greater than its maximum number of replicas;
[0069] The replica gap calculation unit is used to subtract the maximum number of replicas of the microservice from the target number of replicas of the microservice when the target number of replicas of the microservice is greater than its maximum number of replicas, so as to obtain the replica gap of the microservice.
[0070] The resource gap calculation unit is used to multiply the replica gap of the microservice by the resource requirement of a single replica to obtain the resource gap of the microservice.
[0071] The replica redundancy calculation unit is used to subtract the target number of replicas of the microservice from its maximum number of replicas to obtain the replica redundancy of the microservice when the target number of replicas of the microservice is not greater than its maximum number of replicas.
[0072] The resource redundancy calculation unit is used to multiply the replica gap of the microservice by the resource requirement of a single replica to obtain the resource redundancy of the microservice.
[0073] Optionally, in the above-described horizontal scaling system, the resource allocation unit includes:
[0074] An initialization unit is used to initialize the current total amount of idle resources to the sum of resource redundancy of each of the microservices with excess resources;
[0075] The first traversal unit is used to traverse each of the microservices with insufficient resources in descending order of resource gaps.
[0076] The replica allocation calculation unit is used to divide the current total amount of free resources by the resource requirement of a single replica, and use the result as the current number of allocable replicas.
[0077] The first setting unit is used to set the updated number of replicas and the resource limit of the microservice to the target number of replicas of the microservice when the current allocable number of replicas is not less than the replica gap of the microservice.
[0078] The second setting unit is used to, when the current allocable replica count is less than the replica gap of the microservice and not less than 1, set the updated replica count of the microservice to the sum of the integer part of the current allocable replica count and the maximum replica count of the microservice, and set the resource limit of the microservice to the updated replica count of the microservice.
[0079] The third setting unit is used to set the updated number of replicas and the resource limit of the microservice to the maximum number of replicas of the microservice when the current number of allocable replicas is less than 1.
[0080] The used resource calculation unit is used to multiply the difference between the updated number of replicas of the microservice and its maximum number of replicas by the single replica resource requirement to obtain the used resources of the microservice.
[0081] The first resource update unit is used to subtract the used resources of the microservice from the current total idle resources.
[0082] Optionally, in the above-described horizontal scaling system, the resource recovery unit includes:
[0083] The second traversal unit is used to traverse each of the microservices with excess resources in ascending order of redundancy gaps;
[0084] The replica recycling calculation unit is used to divide the current total amount of idle resources by the resource requirement of a single replica, and use the result as the current number of recyclable replicas.
[0085] The fourth setting unit is used to set the resource limit of the microservice to the maximum number of replicas of the microservice when the current recyclable number of replicas is not less than the replica redundancy of the microservice, and to set the updated number of replicas of the microservice to the target number of replicas of the microservice.
[0086] The fifth setting unit is used to set the resource limit of the microservice to the sum of the integer part of the current reclaimable replica number and the target replica number of the microservice when the current reclaimable replica number is less than the replica redundancy of the microservice and not less than 1, and to set the updated replica number of the microservice to the target replica number of the microservice.
[0087] The sixth setting unit is used to set the updated number of replicas and the resource limit of the microservice to the target number of replicas of the microservice when the current number of recyclable replicas is less than 1.
[0088] The resource recovery calculation unit is used to multiply the difference between the maximum number of replicas of the microservice and its resource limit by the resource requirement of a single replica to obtain the recovered resources of the microservice.
[0089] The second resource update unit is used to add the current total idle resources to the reclaimed resources of the microservice.
[0090] Optionally, in the above-described horizontal scaling system, the decision update unit includes:
[0091] The first decision update unit is used to maintain the scaling up / down decision of each microservice if the updated replica count of the microservice is consistent with the target replica count.
[0092] The second decision update unit is used to update the scaling decision of the microservice to scaling up when the number of replicas of the microservice after the update is greater than the maximum number of replicas and less than the target number of replicas.
[0093] The third decision update unit is used to update the scaling decision of the microservice to no scaling when the number of replicas of the microservice after the update is not greater than the maximum number of replicas.
[0094] A third aspect of this application provides an electronic device, comprising:
[0095] Memory and processor;
[0096] The memory is used to store programs;
[0097] The processor is used to execute the program, which, when executed, is specifically used to implement the horizontal scaling method as described in any of the above.
[0098] A fourth aspect of this application provides a computer storage medium for storing a computer program, which, when executed by a processor, is used to implement the horizontal scaling method as described in any of the preceding claims.
[0099] This application provides a method for horizontal scaling, which involves collecting operational metrics of the microservices belonging to each node and calculating the target number of replicas for each microservice using these metrics and preset thresholds. Then, by comparing the target number of replicas with the current number of replicas, a scaling decision is determined. If the target number of replicas for each microservice is not greater than its maximum number of replicas, the scaling decision is executed according to the target number of replicas for each microservice, thus enabling efficient scaling through distributed nodes when resources are sufficient. If the target number of replicas for any microservice is greater than its maximum number of replicas, the central node calculates the replica gap and resource gap, or replica redundancy and resource redundancy, for each microservice based on the difference between the target number and the maximum number of replicas. Then, the method iterates through the microservices with insufficient resources in descending order of resource gap. Based on the current total available resources and the replica gap of each microservice, it analyzes the updated replica number and resource limit of the microservice after resource allocation and updates the current total available resources, thereby analyzing the resource coordination capabilities of the current total available resources for each microservice. Then, based on the excess resource quantity of each microservice in ascending order of redundancy gap, and considering the current total idle resources and the replica redundancy of the microservices, the updated replica count and resource limit of the microservices after resource reclamation are analyzed, and the current total idle resources are updated to determine the resources that need to be reclaimed. Finally, by comparing the target replica count and the updated replica count of each microservice, the scaling decisions of each microservice are updated. Using the resource limit and the updated replica count of the microservices, the maximum replica count and target replica count of the microservices are updated, and each node executes its updated scaling decisions according to the updated target replica count of its respective microservice. This combines distributed decision-making with centralized coordination, achieving efficient scaling when resources are not limited. When resources are limited, the central node coordinates and adjusts the maximum replica count of microservices, thereby reclaiming excess resources and allocating them to microservices with insufficient resources. This is no longer limited by fixed resource limits, achieving efficient resource utilization and ensuring normal business execution. Attached Figure Description
[0100] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of this application. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.
[0101] Figure 1 A flowchart illustrating a method for lateral scaling provided in this application embodiment;
[0102] Figure 2A flowchart illustrating a method for calculating gaps and redundancies in microservices, provided as an embodiment of this application;
[0103] Figure 3 A flowchart illustrating a resource allocation method for microservices provided in this application embodiment;
[0104] Figure 4 A flowchart illustrating a microservice resource reclamation method provided in this application embodiment;
[0105] Figure 5 A schematic diagram of the architecture of a horizontally scalable system provided in an embodiment of this application;
[0106] Figure 6 This is a schematic diagram of the architecture of an electronic device provided in an embodiment of this application. Detailed Implementation
[0107] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0108] In this application, relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0109] This application provides a method for lateral expansion and contraction, such as... Figure 1 As shown, it includes the following steps:
[0110] S101. Collect the operation metrics of the microservices belonging to each node, and calculate the target number of replicas for each microservice using the operation metrics of the microservices and preset thresholds.
[0111] It should be noted that, in order to enable rapid scaling up and down, when resources are sufficient to meet current needs, the scaling up or down of each microservice is performed using distributed nodes. Therefore, by collecting operational metrics from each node for its respective microservice, and using these metrics along with preset thresholds, the target number of replicas for each microservice is calculated, i.e., the number of replicas required for each microservice to scale up or down.
[0112] Optionally, in another embodiment of this application, one specific implementation of step S101 includes:
[0113] Collect the current number of replicas, current CPU utilization, preset threshold, and maximum number of replicas for each microservice on each node. Then, multiply the current number of replicas of the microservice by the ratio of the current CPU utilization to the preset threshold, and round the result up to obtain the target number of replicas for the microservice.
[0114] Specifically, collect the current number of replicas. Current CPU utilization Preset threshold , minimum number of copies , the maximum number of copies , (M is the total number of microservices).
[0115] Therefore, the target number of replicas for a microservice is:
[0116]
[0117] S102. By comparing the target number of replicas and the current number of replicas of the microservice, determine its scaling decision.
[0118] The target number of replicas for a microservice is the number of replicas that need to be scaled up or down. Therefore, by comparing the target number of replicas with the current number of replicas, the scaling decision is determined, i.e., scaling up, scaling down, or no scaling.
[0119] Optionally, in another embodiment of this application, one specific implementation of step S102 includes:
[0120] If the target number of replicas for a microservice is greater than its current number of replicas, then a scaling decision is generated. At that time, the scaling up / down decision is If the target number of replicas for a microservice is less than its current number of replicas, a scaling-down decision is generated. At that time, the scaling up / down decision is If the target number of replicas for a microservice equals its current number of replicas, then a scaling decision without scaling is generated; otherwise, the scaling decision is... .
[0121] S103. Determine whether the target number of replicas for each microservice is not greater than its maximum number of replicas.
[0122] It should be noted that the maximum number of replicas is the maximum number of replicas that its current resources can support.
[0123] If the target number of replicas for each microservice is not greater than its maximum number of replicas, it means that there are sufficient resources and the microservice will not be limited in scaling up or down to the target number of replicas. Therefore, step S104 is executed directly.
[0124] When the target number of replicas of any microservice exceeds its maximum number of replicas, it means that its resources are no longer sufficient to meet the resource requirements for scaling up to the target number of replicas. Therefore, resources need to be coordinated from other nodes, and step S105 is executed at this time.
[0125] S104. Execute scaling decisions based on the target number of replicas of the microservice.
[0126] Specifically, for scaling decisions, the number of microservice replicas is increased to the target number. For scaling decisions, the number of microservice replicas is decreased to the target number. For decisions without scaling, the number of replicas needs to be adjusted.
[0127] S105. Calculate the replica gap and resource gap, or replica redundancy and resource redundancy of the microservice, respectively, based on the difference between the target replica number and the maximum replica number of each microservice through the central node.
[0128] It's important to note that, since we need to analyze the situation of each node at this point, we need to allocate resources from microservices with excess resources to those with insufficient resources. This satisfies the needs of microservices with insufficient resources without affecting the resources of microservices with excess resources. Therefore, a centralized structure is used. The central node obtains relevant data from each microservice, and then calculates the difference between the current number of replicas and the maximum number of replicas for each microservice. This allows us to calculate the replica gap and resource gap, or the replica redundancy and resource redundancy of the microservices.
[0129] For microservices with a target number of replicas greater than the maximum number of replicas (i.e., microservices with insufficient resources), the replica gap and resource gap are calculated based on the difference between the current number of replicas and the maximum number of replicas. For microservices with a target number of replicas no greater than the maximum number of replicas (i.e., microservices with excess resources), the replica gap and resource gap are calculated based on the difference between the current number of replicas and the maximum number of replicas.
[0130] Optionally, in another embodiment of this application, one specific implementation of step S105 is as follows: Figure 2 As shown, it includes:
[0131] S201. Determine whether the target number of replicas for each microservice is greater than its maximum number of replicas through the central node.
[0132] If the target number of replicas of a microservice is greater than its maximum number of replicas, then proceed to step S202. If the target number of replicas of a microservice is not greater than its maximum number of replicas, then proceed to step S203.
[0133] S202. Subtract the maximum number of replicas from the target number of replicas of the microservice to obtain the replica gap of the microservice. Multiply the replica gap of the microservice by the resource requirement of a single replica to obtain the resource gap of the microservice.
[0134] In other words, the replica gap for microservices is: The resource gap for microservices is: .in, This represents the resource requirements for a single replica. Furthermore, to prioritize high-load microservices and thus meet more business requests, the resource gaps of microservices can be placed in the resource gap list Underprov in descending order.
[0135] S203. Subtract the target number of replicas from the maximum number of replicas of the microservice to obtain the replica redundancy of the microservice, and multiply the replica gap of the microservice by the resource requirement of a single replica to obtain the resource redundancy of the microservice.
[0136] The replica redundancy of microservices is as follows: The resource redundancy of microservices is as follows: .in, This refers to the resource requirements of a single replica, i.e., the amount of resources needed for one replica. Furthermore, to facilitate the priority reclamation of resources from microservices with low redundancy, thus satisfying more business requests, the resource redundancy of microservices can be placed in the resource gap list Overprov in descending order.
[0137] S106. Traverse each microservice with insufficient resources in descending order of resource gap. Based on the current total idle resources and the replica gap of the microservice, analyze the updated replica count and resource limit of the microservice after resource allocation, and update the current total idle resources.
[0138] Specifically, the current total idle resources represent the resources that can be reallocated. Therefore, based on the current total idle resources and the replica gap of a microservice, we can analyze the amount of resources that can be reallocated to that microservice. This allows us to analyze the number of replicas after resource reallocation and the maximum number of replicas that can be supported—that is, the updated replica count and resource limit of the microservice after resource reallocation. However, after a microservice reallocates resources, the current total idle resources obviously decrease, so they need to be updated to utilize the updated total idle resources for subsequent resource allocation and reclamation.
[0139] Optionally, in another embodiment of this application, one specific implementation of step S106 is as follows: Figure 3 As shown, it includes:
[0140] S301. Initialize the current total amount of idle resources to the sum of the resource redundancy of each microservice with excess resources.
[0141] Specifically, the current total amount of free resources is initialized as follows: Furthermore, it can simultaneously initialize the updated replica count for each replica. and resource limits .
[0142] S302. Traverse each microservice with insufficient resources in descending order of resource gap.
[0143] S303. Divide the current total amount of idle resources by the resource requirement of a single replica, and use the result as the current number of replicas that can be allocated.
[0144] Specifically, dividing the current total available resources by the resource requirement per replica yields the number of replicas that can be allocated. Therefore, the current number of allocable replicas is: .
[0145] S304. Determine whether the current number of allocable replicas is not less than the replica gap of the microservice.
[0146] If the number of currently allocable replicas is not less than the replica gap of the microservice, it indicates that there are enough free resources to fill all the replica gaps of the microservice, so step S305 is executed. If the number of currently allocable replicas is less than the replica gap of the microservice, it indicates that the free resources cannot meet all the replica gaps of the microservice, so step S306 is executed to determine the replica gap situation that can be met.
[0147] S305. Set the updated replica count and resource limit of the microservice to the target replica count of the microservice.
[0148] Since the current resource gap for the microservice can be filled, sufficient resources are allocated to allow it to scale up to the target number of replicas. Therefore, the updated replica count of the microservice is the target replica count. Correspondingly, the microservice's resource limit can then reach its target replica count, i.e., when... At that time, .
[0149] S306. Determine whether the current number of allocable replicas is not less than 1.
[0150] If the number of currently allocable replicas is not less than 1, it means that at least one replica of the microservice can be coordinated, so step S307 is executed. If the number of currently allocable replicas is less than 1, it means that the current resources are insufficient to increase the number of replicas for the microservice, so step S308 is executed.
[0151] S307. Set the updated replica count of the microservice to the sum of the integer part of the currently allocable replica count and the maximum replica count of the microservice, and set the resource limit of the microservice to the updated replica count of the microservice.
[0152] Since not all replica gaps can be met at this time, the maximum possible replica gap for this microservice is satisfied. Therefore, the updated replica count and resource limit of this microservice are set to the sum of the integer part of the currently allocable replica count and the maximum replica count of this microservice. In other words, when... hour, .
[0153] S308. Set the updated replica count and resource limit of the microservice to the maximum replica count of the microservice.
[0154] Since resources cannot be coordinated for it at this time, the best expansion is to its current maximum number of replicas. Therefore, the updated number of replicas and resource limit of this microservice are set to the maximum number of replicas of the microservice. hour, .
[0155] S309. Multiply the difference between the updated number of replicas of the microservice and its maximum number of replicas by the single replica resource requirement to obtain the used resources of the microservice.
[0156] In other words, the resources used by a microservice are: .
[0157] S310. Subtract the used resources of this microservice from the current total idle resources.
[0158] That is, .
[0159] S107. According to the redundancy gap from smallest to largest, for each microservice with excess resources, based on the current total idle resources and the microservice's replica redundancy, analyze the updated replica count and resource limit of the microservice after resource reclamation, and update the current total idle resources.
[0160] It should be noted that, in this embodiment, considering the current surplus of microservices, which may require future expansion, to avoid frequent resource coordination through the central node and thus affecting the efficiency of scaling up and down, not all surplus resources are directly reclaimed. Instead, resources are reclaimed based on demand, only those resources needed to fill resource gaps. Therefore, based on the current total amount of idle resources and the replica redundancy of a microservice, it can be determined whether the number of replicas to be reclaimed to supplement the microservice can be determined. This allows for the analysis of the updated replica count and resource limit of the microservice after the corresponding resources are reclaimed, and the current total idle resources are updated.
[0161] Optionally, in another embodiment of this application, one specific implementation of step S107 is as follows: Figure 4 As shown, it includes:
[0162] S401. Traverse each microservice with excess resources in ascending order of redundancy gaps.
[0163] S402. Divide the current total amount of idle resources by the resource requirement of a single replica, and use the result as the current number of reclaimable replicas.
[0164] That is, the current number of recyclable copies is: .
[0165] S403. Determine whether the current number of recyclable replicas is not less than the replica redundancy of the microservice.
[0166] If the number of currently reclaimable replicas is not less than the replica redundancy of the microservice, it means that resource reclamation for the microservice is not required, so step S404 is executed. If the number of currently reclaimable replicas is less than the replica redundancy of the microservice, the resources of the microservice still need to be reclaimed, so step S405 is executed.
[0167] S404. Set the resource limit of the microservice to the maximum number of replicas of the microservice, and set the updated number of replicas of the microservice to the target number of replicas of the microservice.
[0168] In other words, there is no need to reclaim resources at this time, so its current resource limit is retained. hour, .
[0169] S405. Determine whether the current number of recyclable copies is not less than 1.
[0170] If the current number of reclaimable replicas is not less than 1, then proceed to step S406. If the current number of reclaimable replicas is less than 1, then proceed to step 407.
[0171] S406, Set the resource limit of the microservice to the sum of the integer part of the current reclaimable replica number and the target replica number of the microservice, and set the updated replica number of the microservice to the target replica number of the microservice.
[0172] Since the current number of reclaimable replicas is less than the replica redundancy of the microservice, but not less than 1, some of them are reclaimed. hour, .
[0173] S407. Set the updated replica count and resource limit of the microservice to the target replica count of the microservice.
[0174] Since the current number of recyclable copies is too small, all idle resources need to be reclaimed. In other words, when... hour, , .
[0175] S408. Multiply the difference between the maximum number of replicas of the microservice and its resource limit by the single replica resource requirement to obtain the reclaimed resources of the microservice.
[0176] In other words, the reclaimed resources of a microservice are: .
[0177] S409. Add the current total idle resources to the reclaimed resources of this microservice.
[0178] That is, .
[0179] S108. By comparing the target number of replicas and the updated number of replicas for each microservice, update the scaling decisions for each microservice, and use the resource limit and the updated number of replicas for each microservice to update the maximum number of replicas and the target number of replicas for each microservice.
[0180] It's important to note that the updated replica count represents the actual number of replicas that can be updated after resource coordination. Therefore, by comparing the target replica count and the updated replica count for each microservice, a new scaling decision is determined, updating the original scaling decisions for each node. Furthermore, the resource cap for a microservice represents the maximum replica count it can achieve after resource adjustments; therefore, the resource cap is used as the new maximum replica count for that microservice. The updated replica count, on the other hand, represents the actual number of replicas to be adjusted; therefore, the updated replica count is used as the target replica count for that microservice.
[0181] Optionally, in another embodiment of this application, a specific implementation of updating the scaling decisions of each microservice includes:
[0182] For each microservice, if the number of replicas after the update matches the target number of replicas, the scaling decision for the microservice is maintained. That is... When that happens, the updated scaling decision is: .
[0183] If the number of replicas of a microservice after an update is greater than the maximum number of replicas but less than the target number of replicas, then the scaling decision for the updated microservice is to scale it up. That is, when... At that time, the updated scaling decision is: .
[0184] If the number of replicas of a microservice after an update is no greater than the maximum number of replicas, then the scaling decision for updating the microservice is no scaling. In other cases, the scaling decision for updating is: .
[0185] S109. Each node executes its updated scaling decision according to the updated target number of replicas of its microservice.
[0186] Since the scaling decisions, target number of replicas, and maximum number of replicas have already been updated, each node executes its updated scaling decisions according to the updated target number of replicas for its respective microservice.
[0187] This application provides a horizontal scaling method that collects operational metrics of the microservices belonging to each node and calculates the target number of replicas for each microservice using these metrics and preset thresholds. Then, by comparing the target number of replicas with the current number of replicas, a scaling decision is determined. If the target number of replicas for each microservice is not greater than its maximum number of replicas, the scaling decision is executed according to the target number of replicas for each microservice, thus enabling efficient scaling through distributed nodes when resources are sufficient. If the target number of replicas for any microservice is greater than its maximum number of replicas, the central node calculates the replica gap and resource gap, or replica redundancy and resource redundancy, for each microservice based on the difference between the target number and the maximum number of replicas. Then, the method iterates through the microservices with insufficient resources in descending order of resource gap. Based on the current total available resources and the replica gap of each microservice, it analyzes the updated replica number and resource limit of the microservice after resource allocation and updates the current total available resources, thereby analyzing the resource coordination capabilities of the current total available resources for each microservice. Then, based on the excess resource quantity of each microservice in ascending order of redundancy gap, and considering the current total idle resources and the replica redundancy of the microservices, the updated replica count and resource limit of the microservices after resource reclamation are analyzed, and the current total idle resources are updated to determine the resources that need to be reclaimed. Finally, by comparing the target replica count and the updated replica count of each microservice, the scaling decisions of each microservice are updated. Using the resource limit and the updated replica count of the microservices, the maximum replica count and target replica count of the microservices are updated, and each node executes its updated scaling decisions according to the updated target replica count of its respective microservice. This combines distributed decision-making with centralized coordination, achieving efficient scaling when resources are not limited. When resources are limited, the central node coordinates and adjusts the maximum replica count of microservices, thereby reclaiming excess resources and allocating them to microservices with insufficient resources. This is no longer limited by fixed resource limits, achieving efficient resource utilization and ensuring normal business execution.
[0188] Another embodiment of this application provides a system for horizontal scaling, such as... Figure 5 As shown, it includes:
[0189] The target calculation unit 501 is used to collect the operation metrics of the microservices belonging to each node, and calculate the target number of replicas of each microservice using the operation metrics of the microservices and preset thresholds.
[0190] The decision-making unit 502 is used to determine the scaling up or down decision of a microservice by comparing the target number of replicas with the current number of replicas.
[0191] The first scaling unit 503 is used to execute scaling decisions according to the target replica count of each microservice when the target replica count of each microservice is not greater than its maximum replica count.
[0192] Resource analysis unit 504 is used to calculate the replica gap and resource gap of a microservice, or the replica redundancy and resource redundancy of a microservice, respectively, based on the difference between the target replica number and the maximum replica number of each microservice, when the target replica number of any microservice is greater than its maximum replica number.
[0193] Resource allocation unit 505 is used to traverse each microservice with insufficient resources in descending order of resource gap. Based on the current total amount of idle resources and the replica gap of the microservice, it analyzes the updated replica number and resource limit of the microservice after resource allocation, and updates the current total amount of idle resources.
[0194] Resource reclamation unit 506 is used to analyze the updated replica count and resource limit of each microservice with excess resources in ascending order of redundancy gap, based on the current total idle resources and the replica redundancy of the microservice, and update the current total idle resources.
[0195] The decision update unit 507 is used to update the scaling decisions of each microservice by comparing the target number of replicas and the updated number of replicas for each microservice.
[0196] The parameter update unit 508 is used to update the maximum number of replicas and the target number of replicas of the microservice by utilizing the resource limit and the updated number of replicas of the microservice.
[0197] The second scaling unit 509 is used to execute the updated scaling decisions of each node according to the updated target number of replicas of the microservice to which it belongs.
[0198] Optionally, in another embodiment of the horizontal scaling system provided in this application, the target computing unit includes:
[0199] The collection unit is used to collect the current number of replicas, current CPU utilization, preset threshold, and maximum number of replicas of the microservice belonging to each node.
[0200] The target replica count calculation unit is used to multiply the current replica count of the microservice by the ratio of the current CPU utilization to a preset threshold, and round the result up to obtain the target replica count of the microservice.
[0201] Optionally, in another embodiment of the horizontal scaling system provided in this application, the decision-making unit includes:
[0202] The first generation unit is used to generate scaling decisions when the target number of replicas of a microservice is greater than its current number of replicas.
[0203] The second generation unit is used to generate scaling up / down decisions when the target number of replicas of a microservice is less than its current number of replicas.
[0204] The third generation unit is used to generate scaling decisions without scaling when the target number of microservice replicas is equal to its current number of replicas.
[0205] Optionally, in another embodiment of the horizontal scaling system provided in this application, the resource analysis unit includes:
[0206] The first judgment unit is used to determine, through the central node, whether the target number of replicas for each microservice is greater than its maximum number of replicas.
[0207] The replica gap calculation unit is used to subtract the maximum number of replicas of a microservice from its target number of replicas when the target number of replicas of the microservice is greater than its maximum number of replicas, thus obtaining the replica gap of the microservice.
[0208] The resource gap calculation unit is used to multiply the microservice's replica gap by the single replica resource requirement to obtain the microservice's resource gap.
[0209] The replica redundancy calculation unit is used to subtract the target number of replicas from the maximum number of replicas of a microservice to obtain the replica redundancy of the microservice when the target number of replicas is not greater than the maximum number of replicas.
[0210] The resource redundancy calculation unit is used to multiply the microservice's replica gap by the single replica resource requirement to obtain the microservice's resource redundancy.
[0211] Optionally, in another embodiment of the horizontal scaling system provided in this application, the resource allocation unit includes:
[0212] The initialization unit is used to initialize the current total amount of idle resources to the sum of resource redundancy of each microservice with excess resources.
[0213] The first traversal unit is used to traverse the microservices with insufficient resources in descending order of resource gap.
[0214] The replica allocation calculation unit is used to divide the current total amount of free resources by the resource requirement of a single replica, and use the result as the number of replicas that can be allocated at present.
[0215] The first setting unit is used to set the updated number of replicas and the resource limit of the microservice to the target number of replicas of the microservice when the current number of allocable replicas is not less than the replica gap of the microservice.
[0216] The second setting unit is used to set the updated replica number of the microservice to the sum of the integer part of the current allocable replica number and the maximum replica number of the microservice when the current allocable replica number is less than the microservice's replica gap and not less than 1, and to set the microservice's resource limit to the updated replica number of the microservice.
[0217] The third setting unit is used to set the updated number of replicas and the resource limit of the microservice to the maximum number of replicas of the microservice when the current number of allocable replicas is less than 1.
[0218] The used resource calculation unit is used to multiply the difference between the updated number of replicas of a microservice and its maximum number of replicas by the single replica resource requirement to obtain the used resources of the microservice.
[0219] The first resource update unit is used to subtract the used resources of the microservices from the current total idle resources.
[0220] Optionally, in another embodiment of the horizontal scaling system provided in this application, the resource recycling unit includes:
[0221] The second traversal unit is used to traverse the microservices with excess resources in ascending order of redundancy gaps.
[0222] The replica reclamation calculation unit is used to divide the current total amount of idle resources by the resource requirement of a single replica, and the result is used as the current number of reclaimable replicas.
[0223] The fourth setting unit is used to set the resource limit of the microservice to the maximum number of replicas of the microservice, and to set the updated number of replicas of the microservice to the target number of replicas of the microservice, when the current number of recyclable replicas is not less than the replica redundancy of the microservice.
[0224] The fifth setting unit is used to set the resource limit of the microservice to the sum of the integer part of the current reclaimable replica number and the target replica number of the microservice when the current reclaimable replica number is less than the replica redundancy of the microservice and not less than 1, and to set the updated replica number of the microservice to the target replica number of the microservice.
[0225] The sixth setting unit is used to set the updated number of microservice replicas and the resource limit to the target number of microservice replicas when the current number of recyclable replicas is less than 1.
[0226] The resource reclamation calculation unit is used to multiply the difference between the maximum number of replicas of a microservice and its resource limit by the resource requirement of a single replica to obtain the reclaimed resources of the microservice.
[0227] The second resource update unit is used to add the currently total idle resources to the reclaimed resources of the microservices.
[0228] Optionally, in a horizontal scaling system provided in another embodiment of this application, the decision update unit includes:
[0229] The first decision update unit is used to maintain the scaling decision of each microservice if the updated number of replicas of the microservice is consistent with the target number of replicas.
[0230] The second decision update unit is used to update the scaling decision of the microservice to scaling up when the number of replicas after the microservice update is greater than the maximum number of replicas but less than the target number of replicas.
[0231] The third decision update unit is used to update the scaling decision of the microservice to no scaling when the number of replicas after the microservice update is not greater than the maximum number of replicas.
[0232] It should be noted that the specific working process of each unit provided in the above embodiments of this application can be referred to the corresponding steps in the above method embodiments, and will not be repeated here.
[0233] Another embodiment of this application provides an electronic device, such as... Figure 6 As shown, it includes:
[0234] Memory 601 and processor 602.
[0235] The memory 601 is used to store the program.
[0236] The processor 602 is used to execute a program stored in the memory 601, which, when executed, is specifically used to implement the horizontal scaling method provided in any of the above embodiments.
[0237] Another embodiment of this application provides a computer storage medium for storing a computer program, which, when executed by a processor, is used to implement the horizontal scaling method provided in any of the above embodiments.
[0238] Computer storage media, including both permanent and non-permanent, removable and non-removable media, can store information using any method or technology. Information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.
[0239] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0240] The above description of the disclosed embodiments enables those skilled in the art to make or use this application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of this application. Therefore, this application is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A method for lateral expansion and contraction, characterized in that, include: The operation metrics of each microservice are collected from each node, and the target number of replicas for each microservice is calculated using the operation metrics of the microservice and a preset threshold. The scaling decision for the microservice is determined by comparing the target number of replicas with the current number of replicas. If the target number of replicas of each microservice is not greater than its maximum number of replicas, then the scaling decision is executed according to the target number of replicas of the microservice to which it belongs. If the target number of replicas of any microservice is greater than its maximum number of replicas, the central node calculates the replica gap and resource gap, or the replica redundancy and resource redundancy of the microservice based on the difference between the target number of replicas and the maximum number of replicas of each microservice. The system iterates through each microservice with insufficient resources in descending order of resource gap. Based on the current total available resources and the replica gap of the microservice, it analyzes the updated replica count and resource limit of the microservice after resource allocation, and updates the current total available resources. According to the order of redundancy gap from smallest to largest, for each microservice with excess resources, based on the current total idle resources and the replica redundancy of the microservice, analyze the updated replica number and resource limit of the microservice after resource reclamation, and update the current total idle resources. The scaling decisions for each microservice are updated by comparing the target number of replicas and the updated number of replicas. The maximum number of replicas and the target number of replicas for each microservice are also updated using the resource limit and the updated number of replicas for each microservice. Each node executes its updated scaling decision based on the updated target number of replicas of its respective microservice.
2. The method according to claim 1, characterized in that, The step of collecting operational metrics of each microservice from each node and calculating the target number of replicas for each microservice using these metrics and preset thresholds includes: The current number of replicas, current CPU utilization, preset threshold, and maximum number of replicas of the microservice to which each node belongs are collected respectively. Multiply the current number of replicas of the microservice by the ratio of the current CPU utilization to a preset threshold, and round the result up to obtain the target number of replicas of the microservice.
3. The method according to claim 1, characterized in that, The process of determining scaling decisions by comparing the target number of replicas and the current number of replicas of the microservice includes: If the target number of replicas of the microservice is greater than its current number of replicas, a scaling up or down decision is generated. If the target number of replicas of the microservice is less than its current number of replicas, a scaling-up / scaling decision is generated. If the target number of replicas of the microservice is equal to its current number of replicas, then a scaling decision without scaling is generated.
4. The method according to claim 1, characterized in that, The step of calculating the replica gap and resource gap, or the replica redundancy and resource redundancy of each microservice, by means of the difference between the target replica number and the maximum replica number of each microservice through the central node, includes: The central node determines whether the target number of replicas for each microservice is greater than its maximum number of replicas. If the target number of replicas of the microservice is greater than its maximum number of replicas, then the target number of replicas of the microservice is subtracted from its maximum number of replicas to obtain the replica gap of the microservice. Multiply the replica gap of the microservice by the resource requirement of a single replica to obtain the resource gap of the microservice. If the target number of replicas of the microservice is not greater than its maximum number of replicas, then the maximum number of replicas of the microservice is subtracted from its target number of replicas to obtain the replica redundancy of the microservice. Multiply the replica gap of the microservice by the resource requirement of a single replica to obtain the resource redundancy of the microservice.
5. The method according to claim 1, characterized in that, The process involves iterating through each microservice with insufficient resources in descending order of resource gap, analyzing the updated replica count and resource limit of the microservice after resource allocation based on the current total available resources and the replica gap of the microservice, and updating the current total available resources, including: The current total amount of idle resources is initialized to the sum of the resource redundancy of each of the microservices with excess resources; Iterate through each of the microservices with insufficient resources in descending order of resource gap; The current total amount of free resources is divided by the resource requirement of a single replica, and the result is taken as the current number of replicas that can be allocated. If the current number of allocable replicas is not less than the replica gap of the microservice, the updated number of replicas and the resource limit of the microservice are set to the target number of replicas of the microservice. If the current allocable replica count is less than the replica gap of the microservice, and not less than 1, the updated replica count of the microservice is set to the sum of the integer part of the current allocable replica count and the maximum replica count of the microservice, and the resource limit of the microservice is set to the updated replica count of the microservice. If the current number of allocable replicas is less than 1, then the updated number of replicas and the resource limit of the microservice are set to the maximum number of replicas of the microservice. Multiply the difference between the updated number of replicas of the microservice and its maximum number of replicas by the single replica resource requirement to obtain the used resources of the microservice; Subtract the used resources of the microservice from the current total idle resources.
6. The method according to claim 1, characterized in that, The process involves, according to the order of redundancy gaps from smallest to largest, identifying microservices with excess resources. Based on the current total idle resources and the replica redundancy of each microservice, the process analyzes the updated replica count and resource limit of the microservice after resource reclamation, and updates the current total idle resources. This includes: Iterate through the microservices with excess resources in ascending order of redundancy gaps; The current total amount of free resources is divided by the resource requirement of a single replica, and the result is taken as the current number of reclaimable replicas; If the current number of recyclable replicas is not less than the replica redundancy of the microservice, the resource limit of the microservice is set to the maximum number of replicas of the microservice, and the updated number of replicas of the microservice is set to the target number of replicas of the microservice. If the current number of reclaimable replicas is less than the replica redundancy of the microservice and not less than 1, the resource limit of the microservice is set to the sum of the integer part of the current number of reclaimable replicas and the target number of replicas of the microservice, and the updated number of replicas of the microservice is set to the target number of replicas of the microservice. If the current number of recyclable replicas is less than 1, then the updated number of replicas and the resource limit of the microservice are set to the target number of replicas of the microservice. Multiply the difference between the maximum number of replicas of the microservice and its resource limit by the resource requirement per replica to obtain the reclaimed resources of the microservice; Add the current total idle resources to the reclaimed resources of the microservice.
7. The method according to claim 1, characterized in that, The step of updating the scaling decisions for each microservice by comparing the target number of replicas with the updated number of replicas includes: For each of the microservices, if the updated number of replicas of the microservice is consistent with the target number of replicas, the scaling up / down decision of the microservice is maintained. If the number of replicas of the microservice after the update is greater than the maximum number of replicas and less than the target number of replicas, then the scaling decision for updating the microservice is to scale up. If the number of replicas of the microservice after the update is not greater than the maximum number of replicas, then the scaling decision for updating the microservice is no scaling.
8. A system for horizontal expansion and contraction, characterized in that, include: The target calculation unit is used to collect the operation metrics of the microservices belonging to each node, and use the operation metrics of the microservices and preset thresholds to calculate the target number of replicas of each microservice. The decision-making unit is used to determine the scaling-up / scaling decision of the microservice by comparing the target number of replicas with the current number of replicas. The first scaling unit is used to execute scaling decisions according to the target replica count of each microservice when the target replica count of each microservice is not greater than its maximum replica count. The resource analysis unit is used to calculate the replica gap and resource gap of each microservice, or the replica redundancy and resource redundancy of each microservice, by means of the central node, when the target number of replicas of any microservice is greater than its maximum number of replicas. The resource allocation unit is used to traverse each of the microservices with insufficient resources in descending order of resource gap, analyze the updated number of replicas and the resource limit of the microservice after resource allocation based on the current total idle resources and the replica gap of the microservice, and update the current total idle resources. The resource reclamation unit is used to analyze the updated number of replicas and the resource limit of each microservice with excess resources in ascending order of redundancy gap, based on the current total idle resources and the replica redundancy of the microservice, and update the current total idle resources. The decision update unit is used to update the scaling decisions of each microservice by comparing the target number of replicas and the updated number of replicas of each microservice. The parameter update unit is used to update the maximum number of replicas and the target number of replicas of the microservice using the resource limit and the updated number of replicas of the microservice. The second scaling unit is used to execute the updated scaling decision for each of the nodes according to the updated target number of replicas of the microservice to which it belongs.
9. An electronic device, characterized in that, include: Memory and processor; The memory is used to store programs; The processor is used to execute the program, which, when executed, is specifically used to implement the horizontal scaling method as described in any one of claims 1 to 7.
10. A computer storage medium, characterized in that, Used to store a computer program, which, when executed by a processor, is used to implement the horizontal scaling method as described in any one of claims 1 to 7.