Stateful service dynamic expansion method, apparatus and device, and storage medium
Through a consistent hashing algorithm, the associated IM information of stateful services is calculated and data migrated, which solves the problem that stateful services cannot dynamic lossless expansion, and effectively respond to business sudden increase scenarios and improves service stability.
Patent Information
- Application Number
- CN202510059720.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-14
- Publication Date
- 2025-05-13
AI Technical Summary
Stateful services cannot dynamic lossless expansion in real-time communication systems, and cannot cope with sudden business growth scenarios. When problems occur in grassroots components, the service is prone to collapse, resulting in serious business losses.
The consistent hashing algorithm calculates the associated IM information of a stateful service, and obtains migration data from the connection layer to migrate to a stateful service to realize dynamic lossless expansion of a stateful service.
Effectively respond to the service needs of business sudden increase scenarios, alleviate service crashes caused by abnormalities in grassroots components, and reduce business losses caused by abnormal situations.
Smart Images

Figure CN119996366A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of instant messaging technology, and in particular to a method, device, equipment and storage medium for dynamic expansion of stateful services. Background Art
[0002] Message Service Framework (MSF) is an application architecture that allows different systems or services to communicate and interact through messaging by providing a message service mechanism. For example, the pomelo framework is a high-performance, highly scalable message service framework written in the nodejs programming language. The pomelo framework can be used to implement instant messaging (IM) functions between users.
[0003] Based on the message service framework, services applied to instant messaging functions can be provided. For example, instant messaging services based on the pomelo framework. The pomelo framework can provide support for instant messaging services through high-performance distributed architecture, communication capabilities based on socket.io, rich chat functions, and multi-platform client software development kit (SDK) support. During the operation of the instant messaging service provided by the pomelo framework, it is necessary to ensure the real-time nature of the messages, the arrival rate of the messages, and the stability of the service.
[0004] Instant messaging services provided by the message service framework may include stateful services. For example, when using the pomelo framework to provide instant messaging services, due to the architectural design of the pomelo framework, stateful service sessions (chat) will inevitably appear. Chat can be used to save the relationship between users and rooms and determine the message forwarding target. However, as the number of users grows, the number of chat services will continue to increase. The data stored in different chats is different, making them stateful, which will lead to problems such as inability to dynamically and losslessly expand and inability to cope with sudden business increases. When problems occur in the basic components of the service and cause the service to crash, business losses are severe, affecting message forwarding. Summary of the invention
[0005] In view of this, the embodiments of the present application provide a method, apparatus, device and storage medium for dynamic elastic expansion of a stateful service to solve the problem that a stateful service cannot be dynamically and losslessly elastically expanded.
[0006] According to one aspect of the present application, a stateful service dynamic elastic expansion method is provided, which is applied to an instant messaging system, wherein the instant messaging system includes a connection layer and a service layer, wherein the connection layer includes a connection node that establishes a long connection with a user client, and the service layer includes a plurality of service nodes, at least one service node being configured as a stateful service; the method includes:
[0007] In response to a joining event of a stateful service, calculating associated IM information of the stateful service based on a consistent hashing algorithm, the associated IM information including a room ID and a user ID;
[0008] Acquire first migration data from the connection layer according to the associated IM information, wherein the first migration data is data backed up to the memory of the connection node when the user client establishes a long connection with the connection node of the connection layer; the first migration data includes an association relationship between the user ID and the room ID;
[0009] Migrate the first migration data to the stateful service.
[0010] Optionally, the method further includes:
[0011] Obtaining a registration request for the stateful service;
[0012] Acquire service information of the stateful service according to the registration request, the service information including service node information and migration data information;
[0013] The service information is sent to all services in the service layer.
[0014] Optionally, the method further includes:
[0015] Reading an associated service node from the associated IM information;
[0016] Monitoring the traffic status of the associated service node, wherein the traffic status is associated with the instant messaging behavior of the user client;
[0017] querying the associated service node for second migration data according to the traffic state, where the second migration data is data backed up to the connection layer when the traffic state changes;
[0018] Migrate the second migration data to the stateful service.
[0019] Optionally, the method further includes:
[0020] Obtaining a room joining request from the user client, wherein the room joining request includes a user ID and a room ID;
[0021] Allocating a connection node of a connection layer to the user client according to the room joining request;
[0022] Establishing a persistent connection between the connecting node and the user client;
[0023] Perform consistent hash calculation according to the room ID to determine a service node that provides an instant messaging function for the user client;
[0024] The association relationship between the user ID and the room ID is stored in the memory of the connection node.
[0025] Optionally, the method further includes:
[0026] In response to a leaving event of a stateful service, extracting associated IM information of the stateful service from a room service relationship table, wherein the room service relationship table is used to store an association relationship between a room ID and a service ID;
[0027] Searching for a receiving migration node according to the associated IM information, the receiving migration node being at least one service node in the service layer;
[0028] extracting third migration data of the stateful service from the connection layer according to the associated IM information;
[0029] The third migration data is migrated to the receiving migration node.
[0030] Optionally, the method further includes:
[0031] In response to a leaving event of the stateful service, generating a leaving message, the leaving message including node information and migration data information of the stateful service;
[0032] Sending the leave message to all service nodes of the service layer;
[0033] After searching for a receiving migration node according to the associated IM information, generating a migration reception notification, wherein the migration reception notification is used to enable the receiving migration node to receive the third migration data;
[0034] The migration reception notification is sent to the receiving migration node.
[0035] Optionally, searching for a receiving migration node according to the associated IM information includes:
[0036] Acquire a room list associated with the associated IM information, wherein the room list includes at least one room ID for executing instant communication through the stateful service;
[0037] Perform consistent hash calculation on the room IDs one by one to obtain an array of service IDs corresponding to the room IDs;
[0038] The receiving migration node is determined according to the array of service IDs.
[0039] According to another aspect of the present application, a stateful service dynamic elastic expansion device is provided, which is applied to an instant messaging system, wherein the instant messaging system includes a connection layer and a service layer, wherein the connection layer includes a connection node that establishes a long connection with a user client, and the service layer includes a plurality of service nodes, at least one of which is configured as a stateful service; the device includes:
[0040] A routing module, configured to respond to a joining event of a stateful service and calculate associated IM information of the stateful service based on a consistent hashing algorithm, wherein the associated IM information includes a room ID and a user ID;
[0041] A migration data acquisition module is configured to acquire first migration data from the connection layer according to the associated IM information, wherein the first migration data is data backed up to the memory of the connection node when the user client establishes a long connection with the connection node of the connection layer; the first migration data includes an association relationship between the user ID and the room ID;
[0042] The data migration module is configured to migrate the first migration data to the stateful service.
[0043] According to another aspect of the present application, a computer device is provided, including a storage medium, a processor, and a computer program stored on the storage medium and executable on the processor, wherein the processor implements the above-mentioned stateful service dynamic expansion method when executing the program.
[0044] According to another aspect of the present application, a storage medium is provided, on which a computer program is stored, and when the program is executed by a processor, the above-mentioned stateful service dynamic expansion method is implemented.
[0045] By means of the above technical solution, the embodiment of the present application provides a method, device, equipment and storage medium for dynamic elastic expansion of a stateful service. The method can calculate the associated IM information of the stateful service based on the consistent hashing algorithm in response to the joining event of the stateful service. And obtain the first migration data from the connection layer according to the associated IM information, and migrate the first migration data to the stateful service. Among them, the first migration data is the data backed up to the memory of the connection node when the user client establishes a long connection with the connection node of the connection layer. The first migration data includes the association relationship between the user ID and the room ID. The method can determine the associated service node based on the routing calculation strategy of the consistent hashing algorithm. And back up the migration data through the connection layer, so that when the stateful service changes, the migration data is migrated to the associated service node, so as to realize the lossless dynamic elastic expansion of the stateful service. The method can effectively cope with the service demand of the business sudden increase scenario, and can alleviate the service crash problem caused by the abnormality of the basic component, and reduce the business loss caused by the abnormal situation.
[0046] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0047] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0048] Figure 1 A schematic diagram of the instant messaging system structure provided in an embodiment of the present application;
[0049] Figure 2 A flowchart of a method for dynamically expanding a stateful service provided in an embodiment of the present application;
[0050] Figure 3 A schematic diagram of a routing calculation process provided in an embodiment of the present application;
[0051] Figure 4 A schematic diagram of a consistent hashing algorithm provided for an embodiment of the present application;
[0052] Figure 5 A schematic diagram of the backup and migration data process provided in an embodiment of the present application;
[0053] Figure 6 A schematic diagram of the data migration process when a stateful service is added provided in an embodiment of the present application;
[0054] Figure 7 A schematic diagram of the registration process when joining a stateful service provided in an embodiment of the present application;
[0055] Figure 8 A schematic diagram of the registration and data migration process provided for an embodiment of the present application;
[0056] Fig. 9 A schematic diagram of the secondary data migration process provided in an embodiment of the present application;
[0057] Fig.10 A flowchart of another method for dynamically scaling stateful services provided in an embodiment of the present application;
[0058] Fig.11 A schematic diagram of a notification flow when a stateful service leaves provided in an embodiment of the present application;
[0059] Fig.12 A schematic diagram of the data migration process when a stateful service leaves an embodiment of the present application;
[0060] Fig.13 A schematic diagram of the structure of a stateful service dynamic elastic expansion device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0061] The present application will be described in detail below with reference to the accompanying drawings and in combination with embodiments. It should be noted that the embodiments and features in the embodiments of the present application can be combined with each other without conflict.
[0062] In the embodiment of the present application, instant messaging (IM) is an online real-time communication method that allows users to communicate in real time via text, voice, and video over the Internet. The combination of hardware devices and software applications arranged to implement instant messaging is called an instant messaging system.
[0063] The instant messaging system may include multiple nodes, which are devices that participate in the instant messaging message transmission, including but not limited to computers, servers, mobile terminals, smart wearable devices, industrial control machines, etc. Multiple nodes can establish communication connection relationships between multiple user clients according to specific functional combinations, thereby providing instant messaging services for different user clients. Multiple nodes can establish communication connection relationships through communication protocols such as Remote Procedure Call (RPC).
[0064] The nodes in the instant messaging system can be divided into different types according to their specific functions. For example, some nodes in the instant messaging system are configured to have a connection function, which is called a connection node (connector). Some nodes in the instant messaging system are also configured to provide instant messaging services, which are called service nodes (chat). Some nodes in the instant messaging system can also be configured to manage the entire instant messaging system, which are called management nodes (master). Based on the above node functions, the instant messaging system can also be divided into multiple levels. For example, a connection layer including multiple connection nodes and a service layer including multiple service nodes.
[0065] like Figure 1 As shown, when performing instant messaging, the user client can maintain a long connection with the connection node of the connection layer. The instant messaging message can be sent to the connection node through the user client, and is passed to the service node through routing calculation, and then passed to another connection node connected to the user client through the service node, and finally passed to another user client.
[0066] When providing instant messaging functions, the service node can simultaneously process multiple instant messaging messages between multiple clients. To this end, in some embodiments, the service node can establish multiple instant messaging rooms according to the instant messaging objects. A room can be used for message delivery for two or more users. For example, after user A, user B, and user C join room-1, an instant messaging message sent by user A can be delivered to the clients of user B and user C respectively through the service node chat-0, realizing multi-person instant messaging.
[0067] When performing instant messaging, in order to facilitate message delivery, the instant messaging system can set identification information for the service node, user client and room respectively. This includes setting a user ID for the user client, a room ID for the room, and a service ID for the service node. In order to facilitate message delivery, the user ID, room ID and service ID can be encoded according to a specific coding specification. In some embodiments, the user ID, room ID and service ID may include a type code for characterizing a specific type and a number for distinguishing multiple individuals of the same type, forming an identification ID structure of type coding and numbering. For example, the type code of the user ID is USER, and the number is a number greater than or equal to 0, so the user ID can be in the form of USER001, USER-001, etc. Similarly, the room ID can be in the form of room-0, channel-1, etc. The service ID can be in the form of chat-0, chat-1, etc.
[0068] Instant messaging systems can implement instant messaging functions based on specific server architectures. For example, an instant messaging system can use the pomelo framework as a messaging service. The pomelo framework is a high-performance, distributed server framework based on Node.js, which is suitable for developing instant messaging services and high-real-time web applications.
[0069] As the number of users grows, the number of chat services is also increasing. Different chats store different data, making some services stateful. Therefore, in some server architectures, stateful services appear to store the relationship between users and rooms and determine the message forwarding target.
[0070] For example, if there are two rooms, room-0 and room-1, then after routing calculation, room-0 can be mapped to the chat-0 process, and room-1 can be mapped to the chat-1 process. At this time, if the user client sends a message to room-0, it can only be forwarded to the chat-0 process. Forwarding to chat-1 or other processes will result in failure. The same is true for room-1. Each chat process stores different room data. Instant messaging messages need to be accurately sent to the specified chat to be successful, making the chat service a stateful service. On the contrary, if a request can achieve the same effect when sent to any process, then this type of service is a stateless service.
[0071] During the operation of instant messaging system services, it is necessary not only to ensure the real-time nature of messages, but also to ensure the message arrival rate and service stability. However, due to the stateful nature of chat services, clusters cannot dynamically and losslessly expand and cannot cope with sudden business surges. In addition, when problems occur in the basic components of the service and cause the service to crash, it will cause serious business losses. Specifically, when business traffic suddenly increases, service capacity cannot be expanded in real time, and when stateful service failures affect message forwarding.
[0072] In order to alleviate the problem that stateful services cannot be dynamically and losslessly expanded, a stateful service dynamic expansion method is provided in this embodiment, which is applied to an instant messaging system. The instant messaging system includes a connection layer and a service layer, the connection layer includes a connection node that establishes a long connection with a user client, and the service layer includes multiple service nodes, at least one of which is configured as a stateful service.
[0073] In some embodiments, the instant messaging system may further include a management (master) node. The management node may be an independent control device in the instant messaging system that has data processing and communication functions. For example, the management node may be a combination of one or more devices such as a server, a computer, a mobile terminal, an intelligent wearable device, an industrial control machine, etc. The management node may also be a service node or a connection node in the instant messaging system, that is, at least one service node is configured as a management node. Alternatively, at least one connection node is configured as a management node.
[0074] The management node can control the operation of the entire instant messaging system, including but not limited to controlling the joining and exiting of service nodes, monitoring the load information of service nodes, distributing service nodes to clients, maintaining user login status, providing a relay for communication between service nodes, optimizing architecture design, containerized management, etc. For example, if the instant messaging system is a system based on the pomelo framework, the management node can serve as the registration center of the pomelo framework and be responsible for managing the node cluster of the entire pomelo framework.
[0075] The management node is a key component in the instant messaging system. Through the above control function, the high availability, high concurrent processing capability and good scalability of the instant messaging system can be ensured. Therefore, the management node can be configured to execute the method steps corresponding to the stateful service dynamic expansion method, such as Figure 2 As shown, the method includes:
[0076] S101. In response to a joining event of a stateful service, calculate associated IM information of the stateful service based on a consistent hashing algorithm.
[0077] During the operation of the instant messaging system, the service node joins and leaves. During the process of joining and leaving the service node, a service node change event will be generated. That is, when a service node joins the instant messaging system, a join event will be generated. When a service node leaves the instant messaging system, a leave event will be generated. The management node can call the event monitoring process to monitor the change events of the entire instant messaging system. When a stateful service join event is monitored, a routing calculation can be performed in response to the stateful service join event.
[0078] Among them, routing calculation refers to the process of determining the best path for a message from the sender to the receiver. The instant messaging system can preset a routing calculation strategy, and determine the service (chat) of the user client during instant messaging through the preset routing calculation strategy. For example, when using the pomelo framework to forward instant messaging messages, based on a message link, a routing calculation can be performed on the room ID to determine which chat the user is in. The routing calculation can use a hash modulo method, by obtaining the room ID and traversing the current number of stateful services, and then taking the modulo of the number of stateful services with the room ID to obtain the service ID corresponding to the instant messaging room. Exemplary, such as Figure 3 As shown, assuming that the room ID is 13, and the number of stateful services obtained by traversal is 4, then 13mod 4=1 can be calculated, that is, the service ID is determined to be chat-1. Similarly, when a new stateful service node is added, the number of stateful services increases from 4 to 5, and by calculating 13mod 5=3, the service ID can be determined to be chat-5.
[0079] It can be seen that when a service node changes when using the hash modulo algorithm for routing calculation, the calculation results of the entire service cluster will be affected, making it impossible for the services under the pomelo framework to dynamically expand. For this reason, in an embodiment of the present application, the routing calculation strategy can be replaced. In order to achieve dynamic expansion, the routing calculation strategy can be replaced with a consistent hashing algorithm. The consistent hashing algorithm is a hashing algorithm used in a distributed system to solve the problem of data distribution and routing selection in a dynamically changing network environment.
[0080] In order to implement the consistent hashing algorithm, a hash ring can be constructed according to the system requirements of the instant messaging system. The hash ring can map the entire hash value space into a virtual ring, and the value range of the entire hash space is 0 to 2. 32 -1. The hash ring is continuous, that is, the maximum value and the minimum value are connected to form a closed loop structure. Then, by calculating the hash value of each service node, the service nodes in the instant messaging system are mapped to the hash ring. The position of the service node on the ring is determined by the hash value corresponding to the service node. The hash value can be calculated using the unique identifier of the service node (such as IP address or name) through a hash function.
[0081] When calculating the route of an instant messaging message, the message data can be mapped to a hash ring and the corresponding hash value can be calculated using a hash algorithm. The calculated hash value is mapped to the hash ring and searched clockwise or counterclockwise along the ring. The first service node encountered is the corresponding service node for processing the request.
[0082] When adding or deleting a service node, the only data affected is the data between the newly added or deleted service node and the previous service node in its ring space. Other data will not be affected. This minimizes the cost of data migration when adding or removing service nodes, making the entire instant messaging system more fault-tolerant and scalable. For example, Figure 4 As shown in the figure, adding or reducing a stateful service (chat-4) will only affect a nearby service node (chat-2) but will not affect the entire service cluster.
[0083] Based on the above consistent hashing algorithm, the management node can calculate the associated IM information of the stateful service. The associated IM information may include the user ID and the room ID. That is, when a stateful service is newly added, the newly added stateful service is located on the hash ring. At this time, the management node can calculate the hash value corresponding to each room ID based on the consistent hashing algorithm, and thus determine the room ID to be routed to the newly added stateful service according to the hash value, so that the data that needs to be migrated at the connection layer can be determined based on the association between the room ID and the user ID.
[0084] In some embodiments, in order to calculate and obtain the associated IM information of a stateful service, the management node may obtain the node information of the stateful service corresponding to the joining event after monitoring the joining event of the stateful service. Among them, the node information may include the identification information of the service node corresponding to the newly joined stateful service, such as the IP address, the node server name, the node server identification ID, etc. Then, according to the node information, the stateful service is added to the hash ring. Among them, the newly joined stateful service is located at a specific position associated with the node information on the hash ring. Call the consistent hash function, and use the consistent hash function to perform a consistent hash calculation on the room ID to obtain the hash value corresponding to each room ID. Then, according to the hash value, along the preset search direction on the hash ring, determine the hash value adjacent to the newly joined stateful service in the preset search direction, so as to determine the room ID that can be routed to the newly joined stateful service. Then, according to the association relationship between the room ID and the user ID, determine the associated user ID, thereby generating associated IM information.
[0085] S102: Acquire first migration data from the connection layer according to the associated IM information.
[0086] After obtaining the associated IM information through consistent hashing, the first migration data can be obtained from the connection layer according to the associated IM information, wherein the first migration data is data backed up to the memory of the connection node when the user client establishes a long connection with the connection node of the connection layer.
[0087] Data migration requires backing up the data of stateful services first. Since the connection layer, as the part that communicates directly with the user client, can guarantee data accuracy to the highest degree, the migrated data can be backed up to the connection layer to ensure the real-time and consistency of the data.
[0088] In some embodiments, in order to perform migration data backup, when a user client sends a request to join a room, the request to join a room of the user client can be obtained. The request to join a room includes a user ID and a room ID. Then, according to the request to join a room, a connection node of a connection layer is allocated to the user client, and a long connection is established between the connection node and the user client. Then, a consistent hash calculation is performed according to the room ID to determine a service node that provides an instant messaging function for the user client. Then, the association between the user ID and the room ID is stored in the memory of the connection node.
[0089] For example, Figure 5 As shown, when a user uses the instant messaging function, he can send a room-joining request to the instant messaging system through the client. The room-joining request can include the current user ID and the room ID to be joined, that is, USER001 and room-1. Then, a connection node is allocated to the user client according to the room-joining request. The allocated connection node can be one of the multiple connection nodes connector-0, connector-1, ..., connector-n in the connection layer. The network port device when the user sends the room-joining request can also be directly used as the connection node. For example, when the client sends the room-joining request through connector-0, connector-0 is used as the connection node to establish a long connection with the user client.
[0090] After the user client establishes a long connection with the connection node, the instant messaging system can extract the room ID to be joined, that is, room-1. Then, according to the consistent hashing algorithm, the hash value corresponding to the room ID is calculated, and the hash value mapping is performed on the hash ring to determine the service node that provides instant messaging functions for the current user client. That is, in the preset search direction of the hash ring, the service node corresponding to the first stateful service adjacent to the mapped hash value. Then extract the node information of the service node, such as chat-2. The association between the user ID (USER001) and the room ID (room-1) can be stored in the memory of the connection node (connector-0).
[0091] It can be seen that after the user establishes a long connection with the connection layer, he will send a request to join the room. After receiving the request to join the room, the connection layer can synchronously save the association between the user and the room to the memory of the connection layer for use in stateful service data migration.
[0092] After the migration data is backed up through the above embodiment, when a stateful service changes, the migration data corresponding to the changed stateful service can be quickly migrated to other stateful services that are running normally through the connection layer. That is, when a stateful service changes, the associated IM information can be calculated through the consistent hashing algorithm, and the first migration data can be obtained from the connection layer based on the associated IM information. The first migration data includes the association between the user ID and the room ID.
[0093] S103: Migrate the first migration data to the stateful service.
[0094] After obtaining the first migration data through the connection layer, the first migration data can be sent to the stateful service, thereby migrating the first migration data to the stateful service. After the first migration data is migrated to the stateful service, the newly added stateful service can replace the original service node for instant messaging service according to the first migration data, thereby realizing dynamic elastic expansion of the stateful service.
[0095] For example, Figure 6 As shown, when the service layer includes stateful services such as chat-0, chat-1, chat-2, and chat-3, a new stateful service chat-4 is added. Then, according to the consistent hashing algorithm, it is determined that the stateful service associated with the stateful service chat-4 is chat-2. Therefore, the first migration data of the chat-2 backup can be extracted from the connection layer, including room IDs, such as room-0, room-1, room-2, etc. Each room ID can also be associated with at least two user IDs, such as room-0 is associated with USER001 and USER002, which is used to realize instant communication between USER001 and USER002; room-1 is associated with USER003 and USER004, which is used to realize instant communication between USER003 and USER004; room-2 is associated with USER005, USER006, and USER007, which is used to realize instant communication between USER005, USER006, and USER007.
[0096] Then migrate the first migration data to the newly added stateful service chat-4, so that the stateful service chat-4 can replace chat-2 to provide instant messaging services between users associated with rooms such as room-0, room-1, and room-2. Therefore, through data migration, the newly added stateful service chat-4 can share some of the instant messaging service functions of the original service node chat-2, and alleviate the data forwarding volume of the original service node chat-2, so that the instant messaging system can better cope with scenarios such as user growth and business surges, and realize dynamic and lossless elastic expansion of stateful services.
[0097] In some embodiments, when the first migration data is migrated to a stateful service, the first migration data can be sent to a service node of the newly added stateful service, so that the service node of the newly added stateful service can set the service parameters of the instant communication according to the first migration data to meet the instant communication function requirements of the user ID and room ID corresponding to the first migration data.
[0098] Furthermore, in order to further perform dynamic elastic expansion and meet subsequent data migration requirements, in some embodiments, after migrating the first migration data to the stateful service, the backup data of the connection layer can also be synchronously updated. For example, the index of the first migration data is changed from the node information of the original service node to the node information of the newly added stateful service, that is, in the process of migrating the first migration data from chat-2 to chat-4, the index of the first migration data in the connection layer can be changed from chat-2 to chat-4.
[0099] It should be noted that after the migration data is migrated to other stateful services, the original service node will no longer provide instant messaging services for the user ID and room ID related to the migration data. Therefore, in some embodiments, after the migration data is migrated to the newly added stateful service, the relevant content of the migration data needs to be deleted in the original service node. That is, the management node can monitor the data migration process, and when it monitors the migration receipt signal of the first migration data being migrated to the stateful service, it sends a deletion instruction to the original service node. The original service node can then delete the first migration data in response to the deletion instruction.
[0100] For example, the first migration data includes room-0 (USER001, USER002); room-1 (USER003, USER004); room-2 (USER005, USER006, USER007). After migrating the first migration data from chat-2 to chat-4, chat-4 can send a migration receipt signal to the management node to indicate that the data migration has been completed. At this time, the management node can send a deletion instruction to chat-2, and chat-2 responds to the deletion instruction and deletes the content related to the first migration data in the service node, so that chat-2 no longer provides instant messaging services for USER001~USER007 and room-0, room-1, and room-2.
[0101] When a stateful service changes, the migration data on the service needs to be quickly migrated to other stateful services that are running normally, and other stateful services need to know the migration process to start the task of migrating data. Therefore, in some embodiments, the node cluster in the entire instant messaging system can also be managed through a registration center mechanism. For example, Figure 6 As shown, you can use the registration center mechanism of the pomelo framework and use the master node as the registration center of the pomelo framework to manage the entire cluster.
[0102] When a new stateful service is added, the stateful service will register with the master node. After receiving the registration request, the master will notify all registered services of the service information. If new data traffic is generated by the instant communication process during the migration process, that is, when the information of the service is notified to all registered services, the traffic generated by the instant communication process has been sent, and the data of the stateful service may not have been migrated yet, which will lead to data inconsistency.
[0103] In order to alleviate the data inconsistency problem caused by instant messaging traffic, in some embodiments, after migrating the first migration data to the stateful service, the management node can obtain a registration request for the stateful service. Then obtain the service information of the stateful service according to the registration request. Among them, the service information includes service node information and migration data information. Node information is identification information used to characterize the service node, that is, the node information may include the IP address, node server name, node server identification ID, etc. shown in the above embodiment. The migration data information is used to characterize the specific instant messaging service provided by the stateful service node after performing data migration. Then send the service information to all services in the service layer to notify other service nodes in the service layer of the relevant information of the newly added stateful service.
[0104] It can be seen that in the above embodiment, the method of migrating data first and then registering the master can reduce the scope of data loss and alleviate the problem of data inconsistency caused by the flow of the instant messaging process. However, due to the real-time nature of the instant messaging process, the method of migrating data first and then registering the master still has a certain probability of causing data inconsistency. Therefore, a secondary migration mechanism can be added to improve data consistency.
[0105] In some embodiments, after obtaining the associated IM information through consistent hashing algorithm, the associated service node can be read from the associated IM information, and then the traffic state of the associated service node is monitored, wherein the traffic state is associated with the instant messaging behavior of the user client.
[0106] For example, after calculating and obtaining the associated IM information, the associated service node chat-2 can be read from the associated IM information. Then, during the data migration process, the instant messaging system can call the traffic status monitoring process to monitor the traffic status of chat-2 using the traffic status monitoring process. The traffic status monitoring process can obtain different monitoring results according to whether chat-2 generates new instant messaging traffic during the data migration process.
[0107] If during the data migration period, the instant communication process corresponding to chat-2 has instant communication behaviors such as user requests, joining rooms, and chat data, the traffic status monitoring process can monitor that chat-2 has generated new instant communication traffic, and the corresponding traffic status monitoring result of Monitoring result = 1 is generated. Similarly, if during the data migration period, the instant communication process corresponding to chat-2 does not have instant communication behaviors such as user requests, joining rooms, and chat data, the traffic status monitoring process can monitor that chat-2 has not generated new instant communication traffic, and the corresponding traffic status monitoring result of Monitoringresult = 0 is generated.
[0108] After monitoring and obtaining the traffic state of the associated service node, the second migration data of the associated service node can also be queried according to the traffic state, and the second migration data can be migrated to the stateful service. The second migration data is the data backed up to the connection layer when the traffic state changes.
[0109] For example, Figure 8 , Fig. 9 As shown, the newly added stateful service is chat-1, and the corresponding associated service node is chat-0, that is, the data migration process is to migrate data from chat-0 to chat-1. According to the data migration method in the above embodiment, room-0, room-1, and room-2 in chat-0 can be migrated to chat-1 during the first migration. At this time, chat-0 is still receiving instant messaging traffic. For example, because the user requests to create a new room-3, the first migration process did not migrate room-3 from chat-0 to chat-1. Therefore, when the registration master corresponding to chat-1 is completed, the instant messaging related traffic is forwarded to chat-1, but the data of room-3 does not exist in chat-1, which will cause data forwarding failure. Therefore, after there is traffic corresponding to instant messaging, it is necessary to perform a secondary migration to migrate the newly added room-3 to chat-1 so that the data in chat-1 is consistent with the original data in the associated service node.
[0110] It can be seen that the integrity of the migrated data can be guaranteed through the second migration. Since most of the data has been migrated before the newly added service is registered with the master, the second migration can be triggered after the service is registered with the master. The missing data can be supplemented by checking for omissions and filling in the gaps, thereby ensuring data integrity through two data migrations.
[0111] By applying the technical solution of this embodiment, the method can determine the associated IM information based on the routing calculation strategy of the consistent hashing algorithm. And by backing up the migration data through the connection layer, when a stateful service is newly added, the migration data corresponding to the associated IM information is migrated to the newly added stateful service node, so as to achieve lossless dynamic expansion when the stateful service is newly added. In addition, the method of migration first and then registration is adopted, which not only meets the registration center mechanism of the instant messaging service architecture, but also reduces the scope of data missing. In addition, the consistency of data is improved through the secondary migration mechanism.
[0112] Further, as a refinement and extension of the specific implementation of the above embodiment, in order to fully illustrate the specific implementation process of this embodiment, some embodiments of this application also provide a stateful service dynamic elastic expansion method, such as Fig.10 As shown, the method includes:
[0113] S201. In response to a leaving event of a stateful service, extract associated IM information of the stateful service from a room service relationship table.
[0114] Similar to the joining event generated when the stateful service newly joins, a leaving event may also be generated when the stateful service leaves the instant messaging system. The management node may call the event monitoring process to monitor the leaving event of the entire instant messaging system. When the leaving event of the stateful service is monitored, the service information of the stateful service may be obtained in response to the leaving event of the stateful service.
[0115] It should be noted that in the embodiments of the present application, the stateful service that generates the departure event can be any stateful service in the service layer, that is, the stateful service corresponding to the departure event can be the newly added stateful service described in the above embodiments, or it can be other stateful services other than the newly added stateful service in the service layer.
[0116] In some embodiments, a stateful service can generate a departure event under various circumstances. For example, a stateful service can actively disconnect the network connection with the instant messaging system, and a departure event can be generated when the network connection is disconnected. For another example, the management node can monitor the online status of each service node through a heartbeat signal. When an abnormality occurs in a stateful service exception and the online status fails to be fed back in response to the heartbeat signal, a departure event is generated. For another example, the instant messaging system can dynamically manage the working status of each node in the system and the current system instant messaging traffic. When the management node detects that the current system instant messaging traffic is low and each node is in a relatively idle state, it can actively shut down some service nodes. Therefore, when the management node shuts down a stateful service node, a departure event is generated.
[0117] After monitoring the departure event of the stateful service, the management node can extract the associated IM information of the stateful service from the room service relationship table. Similar to the associated IM information in the above embodiment, the associated IM information can include instant messaging information. The instant messaging information is used to characterize the specific instant messaging service provided by the stateful service node, such as user ID, room ID, consistent hash algorithm result, hash ring information, etc.
[0118] In some embodiments, the management node may store a room service relationship table for recording the service information of each service node, so that the master node can store the association between the room and the stateful service, that is, the room service relationship table can store the association between the room ID and the service ID. For example, the master node can maintain a map locally, in which the service IDs of all service nodes in the current instant messaging system, that is, chat-id, can be recorded. The room IDs of the instant messaging services provided by each service node, that is, room-id or channel-id, are also recorded.
[0119] The service ID and the room ID may form a specific data table in the room service relationship table. In some embodiments, in the room service relationship table, the service ID and the room ID may form a local map in the form of "chat-id: [channel-id]". For example, the room service relationship table may be in the form of a channel map, i.e., chat-1: [room-0, room-1, room-2]; chat-2: [room-4, room-5], chat-3: [room-6].
[0120] In some embodiments, when a stateful service leaves the instant messaging system, the management node may also notify all service nodes in the service layer so that the service nodes can be aware of the departure status of the stateful service to prevent other service nodes from performing data migration to the departing stateful service node. Fig.11 As shown. To this end, the management node can generate a leave message in response to the leave event of the stateful service. The leave message includes the node information and migration data information of the stateful service. Then the leave message is sent to all service nodes of the service layer.
[0121] It can be seen that when a stateful service has an exception and is disconnected from the master node, the master node can perceive the departure event of the stateful service and notify all registered service nodes in the service layer of the departure message.
[0122] The associated IM information can also be calculated based on the consistent hashing algorithm. That is, when any stateful service leaves, the management node can remap the hash ring to obtain a hash ring that does not include the stateful service that has left. Then, based on the consistent hashing algorithm, the hash value corresponding to each room ID is calculated. Therefore, based on the hash value, the stateful service adjacent to the hash value in the preset search direction is determined in order to determine the associated IM information. Since the stateful service that has left has been removed from the hash ring, the hash value that was originally adjacent to the stateful service that has left will be routed to other service nodes. Therefore, the room ID corresponding to the hash value that needs to be routed to other service nodes can be recorded, and the user ID can be determined based on the association between the room ID and the user ID, thereby obtaining the associated IM information.
[0123] For example, Fig.12 As shown in the figure, the instant messaging system includes five stateful services: chat-0, chat-1, chat-2, chat-3, and chat-4. When chat-3 can no longer provide instant messaging services due to abnormal circumstances, a leave event will be generated. Therefore, when the master node senses that chat-3 is disconnected, it will extract chat-3's service information chat-3: [room-6] from the local map, that is, obtain all room IDs under chat-3, room-6. Then, based on the association between the room ID and the user ID, the user ID corresponding to each room ID is determined, that is, the associated IM information is obtained.
[0124] S202: Search for a receiving migration node according to the associated IM information.
[0125] After obtaining the associated IM information, the receiving migration node can be searched according to the associated IM information. The receiving migration node is at least one service node in the service layer, which is used to receive the migration data corresponding to the departing stateful service. For example, according to the consistent hashing algorithm, after calculating the hash value corresponding to the room ID in the associated IM information, the adjacent service nodes are determined according to the preset search direction on the hash ring after removing the departing stateful service according to the hash value, so as to determine the service node adjacent to the hash value corresponding to the room ID as the receiving migration node.
[0126] In some embodiments, in order to determine the receiving migration node, when searching for the receiving migration node according to the associated IM information, a room list associated with the associated IM information can be obtained, wherein the room list includes at least one room ID for performing instant communication through the stateful service. Then, consistent hash calculation is performed one by one for the room IDs to obtain an array of service IDs corresponding to the room IDs. Thus, the receiving migration node is determined according to the array of service IDs.
[0127] For example, when chat-3 leaves the instant messaging system, the room list associated with the associated IM information, namely [room-6], can be obtained. The room ID is then subjected to consistent hashing, that is, a hash value is calculated based on the room ID, and the hash value of the room ID [room-6] is mapped to the hash ring after chat-3 is removed, and the adjacent service nodes are determined according to the preset search direction, that is, other stateful services that can provide instant messaging services for the room ID are determined.
[0128] By using the method for determining the receiving migration node provided in the above embodiment, when the departing stateful service node provides instant messaging services for multiple rooms, the service tasks of multiple rooms can be dispersed to multiple other service nodes, so as to alleviate the problem of instantaneous increase in data processing volume caused by data migration of a single node, and ensure the normal execution of the instant messaging service.
[0129] In some embodiments, after searching for a receiving migration node according to the associated IM information, a migration reception notification may be generated and then sent to the receiving migration node so that the receiving migration node receives the migration data of the departing stateful service according to the migration reception notification.
[0130] For example, after the node chat-3 is removed from the instant messaging system, all existing instant messaging related data on chat-3 needs to be migrated to the adjacent node chat-1. The master only needs to notify chat-1 to migrate the data, without notifying chat-0, chat-2, and chat-4, thereby reducing the amount of redundant data transmission in the instant messaging system.
[0131] S203: Extract third migration data of the stateful service from the connection layer according to the associated IM information.
[0132] After determining the receiving migration node, the third migration data of the stateful service that has left can be extracted from the connection layer according to the associated IM information. Similar to the first migration data and the second migration data in the above embodiment, the third migration data is also data backed up to the memory of the connection node when the user client establishes a long connection with the connection node of the connection layer. Therefore, the third migration data also includes the association relationship between the user ID and the room ID.
[0133] For example, the stateful service that generates the leave event is chat-3. After determining that the receiving migration node is chat-1, the third migration data can be searched at the connection layer according to the room ID (room-6) of the stateful service that left, including the room ID (room-6) and user IDs (USER008 and USER009).
[0134] S204: Migrate the third migration data to the receiving migration node.
[0135] After extracting the third migration data of the departing stateful service from the connection layer, the third migration data can be migrated according to the determined receiving migration node, thereby migrating the third migration data to the receiving migration node, thereby realizing dynamic lossless elastic expansion when the stateful service leaves.
[0136] Similar to the data migration method provided in the above embodiment, in this embodiment, when migrating the third migration data to the receiving migration node, data migration can also be achieved by transferring the third migration data in the departing stateful service node to the receiving migration node.
[0137] However, when an exception occurs or the stateful service node actively leaves, the stateful service node has disconnected from the instant messaging system, that is, the third migration data cannot be extracted from the departing stateful service node. Therefore, the management node can extract the third migration data from the connection layer and send the third migration data to the receiving migration node.
[0138] By applying the technical solution of this embodiment, the method can determine the receiving migration node based on the routing calculation strategy of the consistent hashing algorithm. And the migration data is backed up through the connection layer, so that when the stateful service leaves, the migration data is migrated to the receiving migration node, realizing lossless dynamic elastic expansion of the stateful service. In addition, the method can also alleviate the service crash problem caused by abnormalities in the basic components and reduce business losses in abnormal situations.
[0139] Further, as a specific implementation of the stateful service dynamic elastic expansion method described in the above embodiment, the embodiment of the present application provides a stateful service dynamic elastic expansion device, which is applied to an instant messaging system, wherein the instant messaging system includes a connection layer and a service layer, wherein the connection layer includes a connection node that establishes a long connection with a user client, and the service layer includes multiple service nodes, at least one of which is configured as a stateful service. Fig.13 As shown, the device comprises:
[0140] A routing module, configured to respond to a joining event of a stateful service and calculate associated IM information of the stateful service based on a consistent hashing algorithm, wherein the associated IM information includes a room ID and a user ID;
[0141] A migration data acquisition module is configured to acquire first migration data from the connection layer according to the associated IM information, wherein the first migration data is data backed up to the memory of the connection node when the user client establishes a long connection with the connection node of the connection layer; the first migration data includes an association relationship between the user ID and the room ID;
[0142] The data migration module is configured to migrate the first migration data to the stateful service.
[0143] By applying the technical solution of this embodiment, the stateful service dynamic expansion device can respond to the stateful service joining event, and calculate the associated IM information of the stateful service based on the consistent hashing algorithm. And obtain the first migration data from the connection layer according to the associated IM information, and migrate the first migration data to the stateful service. Among them, the first migration data is the data backed up to the memory of the connection node when the user client establishes a long connection with the connection node of the connection layer. The first migration data includes the association relationship between the user ID and the room ID. The device can determine the associated service node based on the routing calculation strategy of the consistent hashing algorithm. And back up the migration data through the connection layer, so that when the stateful service changes, the migration data is migrated to the associated service node, realizing lossless dynamic expansion of the stateful service. The device can effectively cope with the service needs of the business surge scenario, and can alleviate the service crash problem caused by abnormalities in the base layer components, and reduce business losses in abnormal situations.
[0144] It should be noted that for other corresponding descriptions of the functional units involved in a stateful service dynamic elastic expansion device provided in an embodiment of the present application, reference can be made to the corresponding descriptions in the stateful service dynamic elastic expansion method provided in the above embodiment, and will not be repeated here.
[0145] The embodiment of the present application also provides a computer device, which can be a personal computer, a server, a network device, etc. The computer device includes a bus, a processor, a memory and a communication interface, and can also include an input and output interface and a display device. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store location information. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, the steps in each method embodiment are implemented.
[0146] Those skilled in the art will appreciate that the structure of the above-mentioned computer device is only a partial structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components, or combine certain components, or have a different arrangement of components.
[0147] In one embodiment, a computer-readable storage medium is also provided. The computer-readable storage medium may be non-volatile or volatile, and stores a computer program thereon. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.
[0148] In one embodiment, a computer program product is also provided, including a computer program, which implements the steps in the above method embodiments when executed by a processor.
[0149] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties.
[0150] A person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be implemented by instructing related hardware through a computer program. The computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods.
[0151] Among them, any reference to memory, database or other media used in the embodiments provided in this application may include at least one of non-volatile and volatile memory. Non-volatile memory may include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc.
[0152] Volatile memory may include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM may be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM).
[0153] The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. The non-relational database may include a distributed database based on blockchain, etc., but is not limited thereto. The processor involved in each embodiment provided in this application may be a general-purpose processor, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but is not limited thereto.
[0154] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0155] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A method for dynamic elastic expansion of stateful services, characterized in that: Applied to an instant messaging system, the instant messaging system includes a connection layer and a service layer, the connection layer includes a connection node that establishes a persistent connection with a user client, the service layer includes a plurality of service nodes, at least one service node is configured as a stateful service; the method includes: In response to a joining event of a stateful service, calculating associated IM information of the stateful service based on a consistent hashing algorithm, the associated IM information including a room ID and a user ID; Acquire first migration data from the connection layer according to the associated IM information, wherein the first migration data is data backed up to the memory of the connection node when the user client establishes a long connection with the connection node of the connection layer; the first migration data includes an association relationship between the user ID and the room ID; Migrate the first migration data to the stateful service.
2. The method according to claim 1, characterized in that The method further comprises: Obtaining a registration request for the stateful service; Acquire service information of the stateful service according to the registration request, the service information including service node information and migration data information; The service information is sent to all services in the service layer.
3. The method according to claim 1, characterized in that The method further comprises: Determine an associated service node according to the associated IM information; Monitoring the traffic status of the associated service node, wherein the traffic status is associated with the instant messaging behavior of the user client; querying the associated service node for second migration data according to the traffic state, where the second migration data is data backed up to the connection layer when the traffic state changes; Migrate the second migration data to the stateful service.
4. The method according to claim 1, characterized in that: The method further comprises: Obtaining a room joining request from the user client, wherein the room joining request includes a user ID and a room ID; Allocating a connection node of a connection layer to the user client according to the room joining request; Establishing a persistent connection between the connecting node and the user client; Perform consistent hash calculation according to the room ID to determine a service node that provides an instant messaging function for the user client; The association relationship between the user ID and the room ID is stored in the memory of the connection node.
5. The method according to claim 1, characterized in that The method further comprises: In response to a leaving event of a stateful service, extracting associated IM information of the stateful service from a room service relationship table, wherein the room service relationship table is used to store an association relationship between a room ID and a service ID; Searching for a receiving migration node according to the associated IM information, the receiving migration node being at least one service node in the service layer; extracting third migration data of the stateful service from the connection layer according to the associated IM information; The third migration data is migrated to the receiving migration node.
6. The method according to claim 5, characterized in that The method further comprises: In response to a leaving event of the stateful service, generating a leaving message, the leaving message including node information and migration data information of the stateful service; Sending the leave message to all service nodes of the service layer; After searching for a receiving migration node according to the associated IM information, generating a migration reception notification, wherein the migration reception notification is used to enable the receiving migration node to receive the third migration data; The migration reception notification is sent to the receiving migration node.
7. The method according to claim 5, characterized in that Searching for a receiving migration node according to the associated IM information includes: Acquire a room list associated with the associated IM information, wherein the room list includes at least one room ID for executing instant communication through the stateful service; Perform consistent hash calculation on the room IDs one by one to obtain an array of service IDs corresponding to the room IDs; The receiving migration node is determined according to the array of service IDs.
8. A stateful service dynamic elastic expansion device, characterized in that: Applied to an instant messaging system, the instant messaging system includes a connection layer and a service layer, the connection layer includes a connection node that establishes a long connection with a user client, the service layer includes a plurality of service nodes, at least one service node is configured as a stateful service; the device includes: A routing module, configured to respond to a joining event of a stateful service and calculate associated IM information of the stateful service based on a consistent hashing algorithm, wherein the associated IM information includes a room ID and a user ID; A migration data acquisition module is configured to acquire first migration data from the connection layer according to the associated IM information, wherein the first migration data is data backed up to the memory of the connection node when the user client establishes a long connection with the connection node of the connection layer; the first migration data includes an association relationship between the user ID and the room ID; The data migration module is configured to migrate the first migration data to the stateful service.
9. A computer device comprising a storage medium, a processor, and a computer program stored in the storage medium and executable on the processor, characterized in that: When the processor executes the computer program, the method according to any one of claims 1 to 7 is implemented.
10. A storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
Citation Information
Cited By
Request forwarding device and method based on traffic hijacking and dynamic routing, and related equipment
CN120881153A
A request forwarding apparatus and method based on traffic hijacking and dynamic routing, and related devices
CN120881153B