A method and system for dynamically scaling a stateful service

By coordinating programs to monitor the health status of server nodes, dynamically migrate data and process requests, the downtime problem of stateful services during scaling is solved, and a seamless scaling experience is achieved.

CN116048806BActive Publication Date: 2025-08-01FUJIAN TQ DIGITAL
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310078723.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-01-18
Publication Date
2025-08-01
Estimated Expiration
2043-01-18

AI Technical Summary

Technical Problem

In the prior art, stateful services need to be shut down when dynamic expansion and capacity expansion, resulting in loss of player experience and unable to achieve dynamic expansion and capacity expansion without shutting down.

Method used

By coordinating the program to collect the health status of the server nodes, count the CPU usage and memory usage, select the node with the lowest CPU usage for migration, and migrate the node with the second highest CPU usage for migration, and migrate data and process requests without shutting down to achieve dynamic expansion and scaling.

Benefits of technology

It realizes dynamic expansion and expansion without shutting down stateful services, improving user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116048806B_ABST
    Figure CN116048806B_ABST
Patent Text Reader

Abstract

The present invention provides a method for dynamically scaling the capacity of stateful services, including: 1. The coordination program collects the operating conditions of all server nodes, selects the server node with the lowest CPU usage rate for migration out, and selects the server node with the second lowest CPU usage rate for migration in; 2. The coordination program notifies the server node to be migrated out that it needs to scale down, and after the server node to be migrated out completes the scaling down, it sends a command indicating the completion of relocation to the coordination program; 3. After receiving the command indicating the completion of relocation of the server node to be migrated out, the coordination program sends a replacement instruction to the server node to be migrated in. After receiving the instruction, the server node to be migrated in loads the database data and starts processing the user requests forwarded by the server node to be migrated out; 4. Count the number of server nodes with a CPU usage rate and a memory usage rate higher than 80%. When the number of server nodes exceeds more than half of the total number of server nodes, select a server node from the standby pool to join the cluster. The present invention can dynamically scale the capacity without downtime for stateful services.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer communication technologies, and particularly to a method and system for dynamically scaling a stateful service. Background Art

[0002] Services are divided into stateless services and stateful services. Stateless services do not cache data locally and read and write data from the database in real time for each request processing. The advantage is that the server is stateless and can be scaled more easily. The disadvantage is that frequent database reads and writes increase the pressure on the database, resulting in high service response and low performance.

[0003] A stateless service can have one or more instances; a stateful service has only one instance. There is no strong association relationship between requests, so it is more convenient to expand a stateless service. Requests can be sent to any service without considering request switching issues. A stateful service can implement transactions. Simply put, a transaction is a set composed of multiple things. For the set to be completed, each thing in the set must be completed correctly. If one of the things in the set is not completed, even if other things are completed, the relevant data of the completed things has to be restored to the original state, that is, rolled back. For some services with high requirements for latency sensitivity, a stateful service needs to be selected. Since a stateful service caches data locally and preferentially obtains and processes data from the cache, the response is fast and the performance is high. Then, how to solve the problem of dynamically scaling a stateful service? The most straightforward way is to stop the service for update, but the problem brought is the loss of the player experience. This patent proposes a method and system for dynamically scaling a stateful service to solve the above pain points.

[0004] A network node server is a server device, and a server node is for a server cluster. It is mainly applied to services such as WEB, FTP, and VPN. Summary of the Invention

[0005] To overcome the above problems, the object of the present invention is to provide a method for dynamically scaling a stateful service, which can dynamically scale under the condition that the stateful service does not stop.

[0006] The present invention is implemented as follows: A method for dynamically scaling a stateful service, the method comprising the following steps:

[0007] Step S1, the coordination program collects the operating conditions of all server nodes, counts the number of server nodes whose CPU usage rate and memory usage rate are continuously lower than 30% within a set time. When the number of server nodes exceeds more than half of the total number of server nodes, the coordination program selects the server node with the lowest CPU usage rate for migration out, and selects the server node with the second lowest CPU usage rate for migration in;

[0008] Step S2: The coordination program notifies the server node to be migrated out that it needs to scale down. After the server node to be migrated out completes the scaling down, it sends a command indicating the completion of relocation to the coordination program.

[0009] Step S3: After receiving the command indicating the completion of relocation of the server node to be migrated out, it sends a replacement instruction to the server node to be migrated in. After receiving the instruction, the server node to be migrated in loads the database data and starts processing the user requests forwarded by the server node to be migrated out.

[0010] Step S4: Count the number of server nodes with CPU usage rate and memory usage rate higher than 80%. When the number of server nodes exceeds more than half of the total number of server nodes, select a server node from the standby pool to join the cluster.

[0011] Further, Step S2 is further specifically as follows: The coordination program notifies the server node to be migrated out that it needs to scale down. This server node to be migrated out enters the relocation state, no longer processes new user requests, and forwards the requests received later to the server node to be migrated in; the server node to be migrated out writes the in-memory service data back to the database and sends the in-memory temporary data to the server node to be migrated in. The server node to be migrated in receives the in-memory temporary data of the server node to be migrated out and merges and loads it into the original in-memory temporary data structure of the server node to be migrated in. After the server node to be migrated out completes the scaling down, it sends a command indicating the completion of relocation to the coordination program.

[0012] Further, after the server node to be migrated out sends a command indicating the completion of relocation to the coordination program, the server node to be migrated out and the server node to be migrated in complete the relocation work. At this time, the server node to be migrated out can be taken offline and no longer used. It sends a command indicating the completion of relocation to the coordination program, and the coordination program removes the server node to be migrated out from the cluster list and transfers it to the standby pool for standby.

[0013] The present invention also provides a system for dynamic scaling of stateful services, and the system includes a migration determination module, a scaling-down processing module, a migration-in service processing module, and a standby pool processing module;

[0014] The migration determination module collects the operating conditions of all server nodes through the coordination program, counts the number of server nodes with CPU usage rate and memory usage rate continuously lower than 30% within the set time. When the number of server nodes exceeds more than half of the total number of server nodes, the coordination program selects the server node with the lowest CPU usage rate for migration out and selects the server node with the second lowest CPU usage rate for migration in;

[0015] The scaling-down processing module notifies the server node to be migrated out that it needs to scale down through the coordination program. After the server node to be migrated out completes the scaling down, it sends a command indicating the completion of relocation to the coordination program;

[0016] The migration service processing module, after receiving the command that the migration of the outgoing server node is completed, sends a replacement instruction to the migration server node. After receiving the instruction, the migration server node loads the database data and starts to process the user request forwarded by the migration server node;

[0017] The backup pool processing module counts the number of server nodes whose CPU usage and memory usage are higher than 80%. When the number of server nodes exceeds more than half of the total number of server nodes, a server node in the backup pool is selected to join the cluster.

[0018] Furthermore, the shrinking processing module is further specified as follows: the coordination program notifies the outgoing server node that it needs to shrink, the outgoing server node changes to the relocation state, no longer processes new user requests, and forwards the requests received later to the incoming server node; the outgoing server node writes the memory business data back to the database, and sends the memory temporary data to the incoming server node, the incoming server node receives the memory temporary data of the outgoing server node, merges and loads it into the original incoming server node memory temporary data structure, and sends the relocation completion command to the coordination program after the shrinking of the outgoing server node is completed.

[0019] Furthermore, after the outgoing server node is scaled down, a relocation completion command is sent to the coordination program, and the outgoing server node and the incoming server node complete the relocation work. At this time, the outgoing server node can be offline and no longer used. A relocation completion command is sent to the coordination program, and the coordination program removes the outgoing server node from the cluster list and transfers it to the backup pool for backup.

[0020] The beneficial effects of the present invention are: the coordination program of the present invention collects the operating status of all server nodes, and counts the number of server nodes whose CPU utilization and memory utilization are continuously lower than 30% within the set time. When the number of server nodes exceeds more than half of the total number of server nodes, the coordination program selects the server node with the lowest CPU utilization to migrate out, and selects the server node with the second highest CPU utilization to migrate in; the coordination program notifies the migrated server node that it needs to be scaled down, and the migrated server node is scaled down, that is, the data of the node with the lowest CPU utilization is migrated to the node with the second highest CPU utilization. It can dynamically expand and shrink without stopping the stateful service, thereby improving the user experience. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] Figure 1 It is a schematic flow chart of the method of the present invention.

[0022] Figure 2 It is a system principle block diagram of the present invention. DETAILED DESCRIPTION

[0023] The present invention will be further described below with reference to the accompanying drawings.

[0024] Please refer to Figure 1 As shown, a method for dynamically scaling a stateful service includes the following steps:

[0025] Step S1: The coordination program collects the operating conditions of all server nodes, counts the number of server nodes whose CPU usage rate and memory usage rate have been lower than 30% continuously within a set time. When the number of server nodes exceeds half of the total number of server nodes, the coordination program selects the server node with the lowest CPU usage rate for migration out, and selects the server node with the second lowest CPU usage rate for migration in.

[0026] Step S2: The coordination program notifies the server node to be migrated out that it needs to scale down. After the server node to be migrated out completes the scaling down, it sends a command indicating the completion of relocation to the coordination program.

[0027] Step S3: After receiving the command indicating the completion of relocation of the server node to be migrated out, the coordination program sends a replacement instruction to the server node to be migrated in. After receiving the instruction, the server node to be migrated in loads the database data and starts processing the user requests forwarded by the server node to be migrated out.

[0028] Step S4: Count the number of server nodes whose CPU usage rate and memory usage rate are higher than 80%. When the number of server nodes exceeds half of the total number of server nodes, select a server node from the standby pool to join the cluster.

[0029] The present invention will be further described below with reference to a specific embodiment:

[0030] A method for dynamically scaling a stateful service is as follows:

[0031] Step 1: The coordination program collects the health conditions of all server nodes. When the number of server nodes whose CPU usage rate and memory usage rate have been lower than 30% continuously for 1 - 24 hours exceeds half of the total number of server nodes, the coordination program selects the server node with the lowest CPU usage rate for migration out, and selects the server node with the second lowest CPU usage rate for migration in.

[0032] That is, each server node reports its current CPU usage rate and memory usage rate to the coordinator every minute. If the coordinator detects that the number of server nodes with CPU usage rate and memory usage rate continuously lower than 30% for 1 to 24 hours exceeds more than half of the total number of server nodes, it means that there are too many idle resources on the servers and capacity reduction is needed. The coordinator selects the server node with the lowest CPU usage rate as the node to be reduced in capacity, that is, the migrated-out node. The server node with the second lowest CPU usage rate is selected as the migrated-in node for the migrated-out node, that is, the data of the node with the lowest CPU usage rate is migrated to the node with the second lowest CPU usage rate.

[0033] Step 2: The coordinator notifies the migrated-out server node that capacity reduction is needed. This server node becomes in the migration state, no longer processes new user requests, and forwards the requests received later to the migrated-in server node. The migrated-out server node writes back the memory service data to the database and sends the memory temporary data to the migrated-in node. The migrated-in node receives the memory temporary data of the migrated-out node and merges and loads it into the original memory temporary data structure. After the migrated-out server node finishes, it sends a command indicating that the migration is complete to the coordinator.

[0034] That is, the coordinator notifies the migrated-out server node that capacity reduction is needed. This server node temporarily becomes in the migration state, no longer processes new user requests, and forwards the user requests received later to the migrated-in server node. Before the migrated-out server node goes offline, it needs to handle the status data in the current service and immediately write back the service data in the memory to the database for preservation. Since the temporary data in the memory has no corresponding service database for preservation but stores data such as statistics and calculations and cannot be discarded, the memory temporary data is sent to the migrated-in server node. After receiving the memory temporary data, the migrated-in server node merges and loads it into the memory temporary data structure of this service. At this point, the migrated-out server node and the migrated-in server node have completed the migration work. At this time, the migrated-out server node can go offline and no longer be used, and sends a command indicating that the migration is complete to the coordinator. The coordinator removes the migrated-out server node from the cluster list and transfers it to the standby pool for standby.

[0035] Step 3: After receiving the command indicating that the migration of the migrated-out server node is complete, the coordinator sends a replacement instruction to the migrated-in node. After receiving the instruction, the migrated-in node loads the database data and starts processing the user requests forwarded by the migrated-out node.

[0036] That is, after receiving the command indicating that the migration of the migrated-out server node is complete, the coordinator sends a replacement command to the migrated-in node. At this time, the migrated-in node can completely replace the migrated-out node to work. After receiving the replacement instruction, the migrated-out node loads the service data saved in the database by the migrated-out node into the memory, and then can officially start processing the user requests forwarded by the migrated-out node.

[0037] Step 4: When the coordination program discovers that the number of server nodes with CPU usage and memory usage higher than 80% exceeds more than half of the total number of nodes, i.e., more than 50%, select a server node from the standby pool to join the cluster.

[0038] That is: If the coordination program discovers that the number of server nodes with CPU usage and memory usage higher than 80% exceeds 50% - 100% of the total number of server nodes, then select a server node from the standby pool to join the cluster. Since there is no historical data to process for the newly added server nodes, it is relatively simple. Just add them to the cluster and wait for user requests to enter.

[0039] Please refer to Figure 2 As shown, the present invention also provides a system for dynamic scaling of stateful services, which includes a migration determination module, a scaling-down processing module, a migration service processing module, and a standby pool processing module;

[0040] The migration determination module collects the operating conditions of all server nodes through the coordination program, and counts the number of server nodes whose CPU usage and memory usage are continuously lower than 30% within a set time. When the number of server nodes exceeds more than half of the total number of server nodes, the coordination program selects the server node with the lowest CPU usage for migration, and selects the server node with the second lowest CPU usage for migration;

[0041] The scaling-down processing module notifies the migrated server node through the coordination program that it needs to scale down. After the migrated server node completes the scaling down, it sends a relocation completion command to the coordination program;

[0042] The scaling-down processing module is further specifically: The coordination program notifies the migrated server node that it needs to scale down. This migrated server node becomes in a relocation state, no longer processes new user requests, and forwards the requests received later to the migrated-in server node; The migrated server node writes back the memory service data to the database and sends the memory temporary data to the migrated-in server node. The migrated-in server node receives the memory temporary data of the migrated server node and merges and loads it into the original memory temporary data structure of the migrated-in server node. After the migrated server node completes the scaling down, it sends a relocation completion command to the coordination program.

[0043] After the migrated server node completes the scaling down and sends a relocation completion command to the coordination program, the migrated server node and the migrated-in server node complete the relocation work. At this time, the migrated server node can be taken offline and no longer used, and send a relocation completion command to the coordination program. The coordination program removes the migrated server node from the cluster list and transfers it to the standby pool for standby.

[0044] The migration service processing module, after receiving the command that the migration of the outgoing server node is completed, sends a replacement instruction to the migration server node. After receiving the instruction, the migration server node loads the database data and starts to process the user request forwarded by the migration server node;

[0045] The backup pool processing module counts the number of server nodes whose CPU usage and memory usage are higher than 80%. When the number of server nodes exceeds more than half of the total number of server nodes, a server node in the backup pool is selected to join the cluster.

[0046] In summary, the coordination program of the present invention collects the operating status of all server nodes, and counts the number of server nodes whose CPU utilization and memory utilization are continuously lower than 30% within the set time. When the number of server nodes exceeds more than half of the total number of server nodes, the coordination program selects the server node with the lowest CPU utilization to migrate out, and selects the server node with the second highest CPU utilization to migrate in; the coordination program notifies the migrated server node that it needs to be scaled down, and the migrated server node is scaled down, that is, the data of the node with the lowest CPU utilization is migrated to the node with the second highest CPU utilization. It can dynamically expand and shrink without shutting down the stateful service, thereby improving the user experience.

[0047] The above description is only a preferred embodiment of the present invention. All equivalent changes and modifications made according to the scope of the patent application of the present invention should fall within the scope of the present invention.

Claims

1. A method for dynamically scaling a stateful service, characterized in that: The method includes the following steps: Step S1: The coordination program collects the operating conditions of all server nodes, counts the number of server nodes whose CPU usage rate and memory usage rate have been continuously lower than 30% within a set time. When the number of server nodes exceeds more than half of the total number of server nodes, the coordination program selects the server node with the lowest CPU usage rate for migration out, and selects the server node with the second lowest CPU usage rate for migration in; Step S2: The coordination program notifies the server node to be migrated out that it needs to scale down. After the server node to be migrated out completes the scaling down, it sends a relocation completion command to the coordination program; Step S3: After receiving the relocation completion command of the server node to be migrated out, it sends a replacement instruction to the server node to be migrated in. After receiving the instruction, the server node to be migrated in loads the database data and starts to process the user requests forwarded by the server node to be migrated out; Step S4: Counts the number of server nodes with a CPU usage rate and a memory usage rate higher than 80%. When the number of server nodes exceeds more than half of the total number of server nodes, a server node in the spare pool is selected to join the cluster; The specific content of step S2 is further as follows: The coordination program notifies the server node to be migrated out that it needs to scale down, and this server node to be migrated out becomes in a relocation state and no longer processes new user requests, and forwards the requests received later to the server node to be migrated in; The server node to be migrated out writes the memory service data back to the database, and sends the memory temporary data to the server node to be migrated in. The server node to be migrated in receives the memory temporary data of the server node to be migrated out, and merges and loads it into the original memory temporary data structure of the server node to be migrated in. After the server node to be migrated out completes the scaling down, it sends a relocation completion command to the coordination program.

2. The method for dynamically scaling a stateful service according to claim 1, wherein: After the server node to be migrated out completes the scaling down and sends a relocation completion command to the coordination program, the server node to be migrated out and the server node to be migrated in complete the relocation work. At this time, the server node to be migrated out can be taken offline and no longer used. After sending the relocation completion command to the coordination program, the coordination program removes the server node to be migrated out from the cluster list and transfers it to the spare pool for standby.

3. A system for dynamically scaling a stateful service, characterized in that: The system includes a migration-out determination module, a scaling-down processing module, a migration-in service processing module, and a spare pool processing module; The migration-out determination module collects the operating conditions of all server nodes through the coordination program, counts the number of server nodes whose CPU usage rate and memory usage rate have been continuously lower than 30% within a set time. When the number of server nodes exceeds more than half of the total number of server nodes, the coordination program selects the server node with the lowest CPU usage rate for migration out, and selects the server node with the second lowest CPU usage rate for migration in; The scaling-down processing module notifies the server node to be migrated out that it needs to scale down through the coordination program. After the server node to be migrated out completes the scaling down, it sends a relocation completion command to the coordination program; The migration-in service processing module sends a replacement instruction to the server node to be migrated in after receiving the relocation completion command of the server node to be migrated out. After receiving the instruction, the server node to be migrated in loads the database data and starts to process the user requests forwarded by the server node to be migrated out; The spare pool processing module counts the number of server nodes with CPU usage and memory usage higher than 80%. When the number of server nodes exceeds more than half of the total number of server nodes, a server node in the spare pool is selected to join the cluster; The scale-down processing module is further specifically as follows: The coordination program notifies the server node to be migrated that it needs to be scaled down. This server node to be migrated becomes in a migration state, no longer processes new user requests, and forwards the requests received later to the server node to be migrated in. The server node to be migrated writes back the memory service data to the database and sends the memory temporary data to the server node to be migrated in. The server node to be migrated in receives the memory temporary data of the server node to be migrated out and merges and loads it into the original memory temporary data structure of the server node to be migrated in. After the server node to be migrated out completes the scale-down, it sends a migration completed command to the coordination program.

4. A system for dynamically scaling a stateful service according to claim 3, characterized in that: After the server node to be migrated out completes the scale-down and sends a migration completed command to the coordination program, the server node to be migrated out and the server node to be migrated in complete the migration work. At this time, the server node to be migrated out can be taken offline and no longer used. It sends a migration completed command to the coordination program, and the coordination program removes the server node to be migrated out from the cluster list and transfers it to the spare pool for standby.

Citation Information

Patent Citations

  • Distributed type dynamic cache expanding method and system supporting load balancing

    CN102244685A

  • Database cluster capacity expansion and shrinkage method, service system and storage medium

    CN114328440A