WO2021139431A1 - Data synchronization method and apparatus for microservice, electronic device and storage medium - Google Patents
Data synchronization method and apparatus for microservice, electronic device and storage medium Download PDFInfo
- Publication number
- WO2021139431A1 WO2021139431A1 PCT/CN2020/131898 CN2020131898W WO2021139431A1 WO 2021139431 A1 WO2021139431 A1 WO 2021139431A1 CN 2020131898 W CN2020131898 W CN 2020131898W WO 2021139431 A1 WO2021139431 A1 WO 2021139431A1
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- microservice
- instance
- unit
- load balancing
- data
- Prior art date
Links
- 238000000034 method Methods 0.000 title claims abstract description 37
- 230000008859 change Effects 0.000 claims abstract description 30
- 238000001514 detection method Methods 0.000 claims abstract description 20
- 238000012544 monitoring process Methods 0.000 claims abstract description 20
- 230000006870 function Effects 0.000 claims description 27
- 238000012217 deletion Methods 0.000 claims description 14
- 230000037430 deletion Effects 0.000 claims description 14
- 230000008569 process Effects 0.000 claims description 11
- 230000002688 persistence Effects 0.000 claims description 10
- 230000010076 replication Effects 0.000 claims description 8
- 238000013500 data storage Methods 0.000 claims description 7
- 238000010276 construction Methods 0.000 description 5
- 238000012545 processing Methods 0.000 description 5
- 238000011144 upstream manufacturing Methods 0.000 description 5
- 238000004891 communication Methods 0.000 description 4
- 238000010586 diagram Methods 0.000 description 4
- 230000007246 mechanism Effects 0.000 description 4
- 230000004044 response Effects 0.000 description 4
- 230000008878 coupling Effects 0.000 description 3
- 238000010168 coupling process Methods 0.000 description 3
- 238000005859 coupling reaction Methods 0.000 description 3
- 238000005516 engineering process Methods 0.000 description 3
- 238000005457 optimization Methods 0.000 description 3
- 239000004973 liquid crystal related substance Substances 0.000 description 2
- 230000003287 optical effect Effects 0.000 description 2
- 230000001360 synchronised effect Effects 0.000 description 2
- 230000009466 transformation Effects 0.000 description 1
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/52—Program synchronisation; Mutual exclusion, e.g. by means of semaphores
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/50—Allocation of resources, e.g. of the central processing unit [CPU]
- G06F9/5005—Allocation of resources, e.g. of the central processing unit [CPU] to service a request
- G06F9/5027—Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals
- G06F9/505—Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals considering the load
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/54—Interprogram communication
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F2209/00—Indexing scheme relating to G06F9/00
- G06F2209/50—Indexing scheme relating to G06F9/50
- G06F2209/5017—Task decomposition
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F2209/00—Indexing scheme relating to G06F9/00
- G06F2209/54—Indexing scheme relating to G06F9/54
- G06F2209/547—Messaging middleware
Definitions
- This application relates to the field of big data technology, and in particular to a data synchronization method, device, electronic device, and storage medium for microservices.
- Microservice architecture is a new technology for deploying applications and services in the cloud. With the gradual application of microservice architecture, an upstream system will dock with N downstream systems.
- the inventor realizes that the optimization of upstream systems is limited due to the different standards of each downstream system's response to the interface, the inability of business specificity to cooperate with optimization, and the real-time data synchronization between each system, which leads to the limitation of the optimization of the upstream system, which leads to the degree of coupling between the systems. Too high, the upstream system server pressure is too high, and the upstream system interface response is too slow.
- a data synchronization method for microservices provided in this application includes:
- the load balancing scene of the original microservice is dynamically added and deleted to obtain the standard load balancing scene, where the standard load balancing scene includes the instance load monitoring of the microservice and the instance state change detection of the microservice ;
- the real-time data set is input into the unit nodes of the pre-created unit server group, and real-time data synchronization between the unit nodes is realized through message middleware.
- This application provides a data synchronization device for microservices, and the device includes:
- Load balancing scene creation module used to dynamically add and delete load balancing scenes of the original microservices based on a pre-built consistent hash algorithm to obtain a standard load balancing scene, where the standard load balancing scene includes microservice instance load monitoring And microservice instance state change detection;
- Real-time data reading module used to read real-time data from the standard load balancing scene through a pre-created unit server group to obtain a real-time data set;
- Real-time data synchronization module used to input the real-time data set into the unit nodes of the pre-created unit server group, and realize real-time data synchronization between the unit nodes through message middleware.
- the present application provides an electronic device that includes a memory and a processor.
- the memory stores a data synchronization program of a microservice that can run on the processor.
- the data synchronization program of the microservice is controlled by the processor.
- the processor executes to implement the following steps:
- the load balancing scene of the original microservice is dynamically added and deleted to obtain the standard load balancing scene, where the standard load balancing scene includes the instance load monitoring of the microservice and the instance state change detection of the microservice ;
- the real-time data set is input into the unit nodes of the pre-created unit server group, and real-time data synchronization between the unit nodes is realized through message middleware.
- This application also provides a computer-readable storage medium on which a data synchronization program of a microservice is stored, and the data synchronization program of the microservice can be executed by one or more processors to achieve the following step:
- the load balancing scene of the original microservice is dynamically added and deleted to obtain the standard load balancing scene, where the standard load balancing scene includes the instance load monitoring of the microservice and the instance state change detection of the microservice ;
- the real-time data set is input into the unit nodes of the pre-created unit server group, and real-time data synchronization between the unit nodes is realized through message middleware.
- FIG. 1 is a schematic flowchart of a data synchronization method for microservices provided by an embodiment of this application;
- FIG. 2 is a schematic diagram of the internal structure of an electronic device provided by an embodiment of the application.
- FIG. 3 is a schematic diagram of modules of a microservice data synchronization device provided by an embodiment of the application.
- This application provides a data synchronization method for microservices.
- FIG. 1 it is a schematic flowchart of a data synchronization method for microservices provided by an embodiment of this application.
- the method can be executed by a device, and the device can be implemented by software and/or hardware.
- the data synchronization method for microservices includes:
- the core idea of the consistent hashing algorithm is to convert the node selection criteria in the common hashing algorithm from a specific value to a range, and the range can be expressed as a closed loop A small continuous range.
- the pre-built consistent hash algorithm in this application includes: preset number of virtual nodes, constructing the data storage structure of the virtual node, and selecting the hash function of the virtual node.
- a. Realize the balance of storage space allocation by pre-setting the number of virtual nodes. For example, there are only two physical nodes in a system. If there are no virtual nodes, it is difficult to evenly distribute user requests to these two nodes due to the randomness of the hash algorithm to a certain extent. If the two physical nodes in the system are divided into 200 virtual nodes and mapped to the storage space, and hashing is performed according to the 200 virtual nodes, the balance of storage space allocation can be greatly improved. Therefore, when the system has fewer physical nodes, the number of virtual nodes needs to be increased, and when there are more physical nodes, the number of virtual nodes should be reduced. In this application, a suitable number of virtual nodes can be set according to the number of specific physical nodes.
- TreeMap data structure Use the TreeMap data structure in Java to implement the construction of the data storage structure of the virtual node, and the TreeMap data structure implements the storage of the node through a red-black tree.
- MurMurHash function As the hash function of the virtual node.
- the MurMurHash algorithm refers to a non-cryptographic hash function, and the hash retrieval operation of the virtual node is realized through the MurMurHash function.
- the load balancing scenario of the original microservice mentioned in this application refers to amortizing tasks to multiple unit servers for joint completion, where the operation unit may include a Web server, an FTP server, an enterprise key application server, and Other mission-critical servers, etc.
- the preferred embodiment of the present application implements the dynamic addition and deletion of instances in the load balancing scenario of microservices through the virtual nodes provided by the consistent hash algorithm, and obtains the standard load balancing scenario. For example, each caller sends its request to the same microservice instance as the load balancing scenario of the microservice, where, when the instance crashes and becomes unavailable, the virtual algorithm in the consistent hashing algorithm is changed. The number of nodes can evenly distribute the requests to be received by the instance to other available microservice instances.
- the standard load balancing scenario described in this application includes instance load monitoring of microservices, and instance state change detection of microservices.
- the instance load monitoring of the microservice includes: instance invocation of the microservice, concurrency of the instance of the microservice, and instance data update of the microservice. This application regularly detects whether the instance state change of the microservice is an instance addition and/or deletion through load balancing.
- the consistent hash algorithm is used to reallocate the instance request, and the allocation result is returned to the corresponding caller; when the instance of the microservice
- the status change is not an instance addition and/or deletion, report the running load status of the instance, and periodically determine whether the load status of the instance reaches the preset load threshold, and when the preset load threshold is not reached, No request adjustment is made.
- the preset load threshold is reached, the partial requests of the microservice instances are evenly distributed to other microservice instances that do not exceed the load threshold, and the load threshold is determined according to the load. Balancing the results of timing detection, the caller can modify the local cached microservice address information, thereby reducing the coupling between systems.
- the unit server group is constructed through Redis in the load balancing scenario of the microservice.
- the Redis is an open source, memory-based key-value pair storage system that provides rich data structures such as strings, lists, sets, and hash objects.
- the construction of the unit server through Redis in this application includes: constructing the storage data structure of the unit server, selecting the unit server persistence mode, and using the replication function of Redis to realize the data backup of the unit server And storing the fixed data of the unit server.
- the constructing the storage data structure of the unit server includes: using the data type provided by Redis to select the data structure to facilitate classified storage and rapid retrieval. Since the key value provided by Redis supports the function of binary security, any form of binary sequence can be used in the selection of the form of the key in this application.
- the form of the key for the state attribute of the microservice instance can be set to the string "microservice:instance:state:instanceId”
- the real-time location information of the microservice instance can be set to the string "service_id:instance_id:url”.
- the key pattern formed by the multiple fields and symbol intervals has good structure, and can quickly classify and search data in Redis.
- the selecting the unit server persistence mode includes: performing data persistence through the AOF (Append Only File) persistence mode in Redis.
- the AOF saves the write commands executed by the Redis to persist the state of the database, and also provides an AOF rewrite mechanism to reduce Redundancy in AOF files, thereby improving storage efficiency.
- the use of the replication function of Redis to implement the data backup of the unit server includes: selecting a certain unit server among the unit servers as the master unit server, and setting the remaining unit servers through the Redis command and slaveof configuration attributes Set as the slave unit server of the master unit server; after the slave unit server is started, a synchronization command is sent to the master unit server, and a background process is started by the master unit server to generate a snapshot of memory data, and at the same time it is recorded in the generation The newly executed write command during the snapshot completes the data backup of the main unit server. If there are multiple slave unit servers requesting synchronization at the same time, the master unit server only needs to execute the bgsave command once to process the synchronization requests of the multiple slave unit servers.
- storing the fixed data of the unit server in combination with MySQL includes: storing fixed data in microservice attributes in combination with MySQL.
- the fixed data may be the name attribute, version attribute, capacity attribute, and provider information of the microservice. Wait.
- the unit server constructed according to the preferred embodiment of the present application can read real-time data to the load balancing scene of the microservice to obtain a real-time data set, wherein the unit server can support high-concurrency data Reading operation improves the response speed of the system.
- the unit node is constructed in the unit server group according to the attributes of real-time data and the needs of users.
- the attributes of the real-time data can be field names, parameter types, etc., and the user
- the demand can be to obtain data in real time, not to obtain data in real time, etc.
- the message middleware in this application is MQ message middleware, and the MQ message middleware refers to those that can effectively guarantee and support the sending and receiving of messages through a synchronous or asynchronous mechanism in a distributed application system.
- Middleware system The real-time data synchronization between the pre-built unit nodes can be realized through the MQ message middleware, thereby ensuring data consistency in a microservice-based scenario.
- the invention also provides an electronic device.
- FIG. 2 it is a schematic diagram of the internal structure of an electronic device provided by an embodiment of this application.
- the electronic device 1 may be a PC (Personal Computer, personal computer), or a data processing device such as a smart phone, a tablet computer, or a portable computer, or a server or the like.
- the electronic device 1 at least includes a memory 11, a processor 12, a communication bus 13, and a network interface 14.
- the memory 11 includes at least one type of readable storage medium.
- the readable storage medium may be non-volatile or volatile.
- the readable storage medium includes flash memory, hard disk, multimedia card, and card type. Storage (for example, SD or DX storage, etc.), magnetic storage, magnetic disk, optical disk, etc.
- the memory 11 may be an internal storage unit of the electronic device 1 in some embodiments, such as a hard disk of the electronic device 1. In other embodiments, the memory 11 may also be an external storage device of the electronic device 1, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), and a secure digital (Secure Digital, SD) equipped on the electronic device 1. Flash memory card Card) and so on.
- the memory 11 may also include both an internal storage unit of the electronic device 1 and an external storage device.
- the memory 11 can be used not only to store application software and various types of data installed in the electronic device 1, such as the code of a data synchronization program for microservices, etc., but also to temporarily store data that has been output or will be output.
- the processor 12 may be a central processing unit (Central Processing Unit) in some embodiments.
- Central Processing Unit CPU
- controller a controller
- microcontroller a microprocessor
- other data processing chips are used to run program codes or process data stored in the memory 11, such as executing data synchronization programs for microservices.
- the communication bus 13 is used to realize the connection and communication between these components.
- the network interface 14 may optionally include a standard wired interface and a wireless interface (such as a WI-FI interface), and is usually used to establish a communication connection between the apparatus 1 and other electronic devices.
- the electronic device 1 may further include a user interface.
- the user interface may include a display (Display) and an input unit such as a keyboard (Keyboard).
- the optional user interface may also include a standard wired interface and a wireless interface.
- the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, and an OLED (Organic Light-Emitting Diode, organic light-emitting diode) touch device and so on.
- the display can also be appropriately called a display screen or a display unit, which is used to display the information processed in the electronic device 1 and to display a visualized user interface.
- Figure 2 only shows the electronic device 1 with components 11-14 and a data synchronization program for microservices. Those skilled in the art can understand that the structure shown in Figure 2 does not constitute a limitation on the electronic device 1, and may include Fewer or more parts than shown, or some parts in combination, or different parts arrangement.
- the data synchronization program of the microservice is stored in the memory 11; when the processor 12 executes the data synchronization program of the microservice stored in the memory 11, the following steps are implemented:
- Step 1 Based on the pre-built consistent hash algorithm, dynamically add and delete the load balancing scene of the original microservice to obtain a standard load balancing scene, where the standard load balancing scene includes instance load monitoring of microservices and instances of microservices State change detection.
- the core idea of the consistent hashing algorithm is to convert the node selection criteria in the common hashing algorithm from a specific value to a range, and the range can be expressed as a closed loop A small continuous range.
- the pre-built consistent hash algorithm in this application includes: preset number of virtual nodes, constructing the data storage structure of the virtual node, and selecting the hash function of the virtual node.
- a. Realize the balance of storage space allocation by pre-setting the number of virtual nodes. For example, there are only two physical nodes in a system. If there are no virtual nodes, it is difficult to evenly distribute user requests to these two nodes due to the randomness of the hash algorithm to a certain extent. If the two physical nodes in the system are divided into 200 virtual nodes and mapped to the storage space, and hashing is performed according to the 200 virtual nodes, the balance of storage space allocation can be greatly improved. Therefore, when the system has fewer physical nodes, the number of virtual nodes needs to be increased, and when there are more physical nodes, the number of virtual nodes should be reduced. In this application, a suitable number of virtual nodes can be set according to the number of specific physical nodes.
- TreeMap data structure in Java implements the construction of the data storage structure of the virtual node, and the TreeMap data structure implements the storage of the node through a red-black tree.
- MurMurHash function As the hash function of the virtual node.
- the MurMurHash algorithm refers to a non-cryptographic hash function, and the hash retrieval operation of the virtual node is realized through the MurMurHash function.
- the load balancing scenario of the original microservice mentioned in this application refers to amortizing tasks to multiple unit servers for joint completion, where the operation unit may include a Web server, an FTP server, an enterprise key application server, and Other mission-critical servers, etc.
- the preferred embodiment of the present application implements the dynamic addition and deletion of instances in the load balancing scenario of microservices through the virtual nodes provided by the consistent hash algorithm, and obtains the standard load balancing scenario. For example, each caller sends its request to the same microservice instance as the load balancing scenario of the microservice, where, when the instance crashes and becomes unavailable, the virtual algorithm in the consistent hashing algorithm is changed. The number of nodes can evenly distribute the requests to be received by the instance to other available microservice instances.
- the standard load balancing scenario described in this application includes instance load monitoring of microservices, and instance state change detection of microservices.
- the instance load monitoring of the microservice includes: instance invocation of the microservice, concurrency of the instance of the microservice, and instance data update of the microservice. This application regularly detects whether the instance state change of the microservice is an instance addition and/or deletion through load balancing.
- the consistent hash algorithm is used to reallocate the instance request, and the allocation result is returned to the corresponding caller; when the instance of the microservice
- the status change is not an instance addition and/or deletion, report the running load status of the instance, and periodically determine whether the load status of the instance reaches the preset load threshold, and when the preset load threshold is not reached, No request adjustment is made.
- the preset load threshold is reached, the partial requests of the microservice instances are evenly distributed to other microservice instances that do not exceed the load threshold, and the load threshold is determined according to the load. Balancing the results of timing detection, the caller can modify the local cached microservice address information, thereby reducing the coupling between systems.
- Step 2 Read real-time data from the standard load balancing scene through the pre-created unit server group to obtain a real-time data set.
- the preferred embodiment of the present application is based on the construction of the unit server group through Redis in the load balancing scenario of the microservice.
- the Redis is an open source, memory-based key-value pair storage system that provides rich data structures such as strings, lists, sets, and hash objects.
- the construction of the unit server through Redis in this application includes: constructing the storage data structure of the unit server, selecting the unit server persistence mode, and using the replication function of Redis to realize the data backup of the unit server And storing the fixed data of the unit server.
- the constructing the storage data structure of the unit server includes: using the data type provided by Redis to select the data structure to facilitate classified storage and rapid retrieval. Since the key value provided by Redis supports the function of binary security, any form of binary sequence can be used in the selection of the form of the key in this application.
- the form of the key for the state attribute of the microservice instance can be set to the string "microservice:instance:state:instanceId”
- the real-time location information of the microservice instance can be set to the string "service_id:instance_id:url”.
- the key pattern formed by the multiple fields and symbol intervals has good structure, and can quickly classify and search data in Redis.
- the selecting the unit server persistence mode includes: performing data persistence through the AOF (Append Only File) persistence mode in Redis.
- the AOF saves the write commands executed by the Redis to persist the state of the database, and also provides an AOF rewrite mechanism to reduce Redundancy in AOF files, thereby improving storage efficiency.
- the use of the replication function of Redis to implement the data backup of the unit server includes: selecting a certain unit server among the unit servers as the master unit server, and setting the remaining unit servers through the Redis command and slaveof configuration attributes Set as the slave unit server of the master unit server; after the slave unit server is started, a synchronization command is sent to the master unit server, and a background process is started by the master unit server to generate a snapshot of memory data, and at the same time it is recorded in the generation The newly executed write command during the snapshot completes the data backup of the main unit server. If there are multiple slave unit servers requesting synchronization at the same time, the master unit server only needs to execute the bgsave command once to process the synchronization requests of the multiple slave unit servers.
- storing the fixed data of the unit server in combination with MySQL includes: storing fixed data in microservice attributes in combination with MySQL.
- the fixed data may be the name attribute, version attribute, capacity attribute, and provider information of the microservice. Wait.
- the unit server constructed according to the preferred embodiment of the present application can read real-time data to the load balancing scene of the microservice to obtain a real-time data set, wherein the unit server can support high-concurrency data Reading operation improves the response speed of the system.
- Step 3 Input the real-time data set into the unit nodes of the pre-created unit server group, and realize real-time data synchronization between the unit nodes through message middleware.
- the unit node is constructed in the unit server group according to the attributes of real-time data and the needs of users.
- the attributes of the real-time data can be field names, parameter types, etc., and the user
- the demand can be to obtain data in real time, not to obtain data in real time, etc.
- the message middleware in this application is MQ message middleware, and the MQ message middleware refers to those that can effectively guarantee and support the sending and receiving of messages through a synchronous or asynchronous mechanism in a distributed application system.
- Middleware system The real-time data synchronization between the pre-built unit nodes can be realized through the MQ message middleware, thereby ensuring data consistency in a microservice-based scenario.
- FIG. 3 this is a schematic diagram of modules in an embodiment of the data synchronization device 2 for microservices of this application.
- the data synchronization device for microservices can be divided into a load balancing scene creation module 10 and real-time data.
- the reading module 20 and the real-time data synchronization module 30 are exemplary:
- the load balancing scene creation module 10 is used to dynamically add and delete load balancing scenes of the original microservices based on a pre-built consistent hash algorithm to obtain a standard load balancing scene, where the standard load balancing scene includes microservices Instance load monitoring and microservice instance status change detection.
- the real-time data reading module 20 is configured to read real-time data from the standard load balancing scene through a pre-created unit server group to obtain a real-time data set.
- the real-time data synchronization module 30 is configured to input the real-time data set into the unit nodes of the pre-created unit server group, and realize real-time data synchronization between the unit nodes through message middleware.
- the load balancing scenario creation module 10 can form a micro-service data synchronization system, such as an APP that can be installed on a user's mobile phone or computer.
- a micro-service data synchronization system such as an APP that can be installed on a user's mobile phone or computer.
- the embodiment of the present application also proposes a computer-readable storage medium.
- the computer-readable storage medium may be non-volatile or volatile, and the computer-readable storage medium stores microservice data.
- the data synchronization program of the microservice can be executed by one or more processors to achieve the following operations:
- the load balancing scene of the original microservice is dynamically added and deleted to obtain the standard load balancing scene, where the standard load balancing scene includes the instance load monitoring of the microservice and the instance state change detection of the microservice ;
- the real-time data set is input into the unit nodes of the pre-created unit server group, and real-time data synchronization between the unit nodes is realized through message middleware.
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
A data synchronization method for a microservice, comprising: on the basis of a pre-constructed consistent hash algorithm, dynamically adding and deleting load balancing scenarios of an original microservice to obtain a standard load balancing scenario, which comprises instance load monitoring of the microservice and instance state change detection of the microservice (S1); reading real-time data from the standard load balancing scenario by means of a pre-created cell server group to obtain a real-time data set (S2); and inputting the real-time data set to cell nodes of the pre-created cell server group to achieve real-time data synchronization among the cell nodes by means of message-oriented middleware (S3). Further provided are a data synchronization apparatus for the microservice, an electronic device and a computer-readable storage medium.
Description
本申请要求于2020年1月9日提交中国专利局、申请号为2020025271.8,发明名称为“微服务的数据同步方法、装置及计算机可读存储介质”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application claims the priority of a Chinese patent application filed with the Chinese Patent Office on January 9, 2020, the application number is 2020025271.8, and the invention title is "microservice data synchronization method, device and computer-readable storage medium", and its entire content Incorporated in this application by reference.
本申请涉及大数据技术领域,尤其涉及一种微服务的数据同步方法、装置、电子设备及存储介质。This application relates to the field of big data technology, and in particular to a data synchronization method, device, electronic device, and storage medium for microservices.
微服务架构是一项在云中部署应用和服务的新技术,随着微服务架构的逐渐应用,一个上游系统会对接N个下游系统。Microservice architecture is a new technology for deploying applications and services in the cloud. With the gradual application of microservice architecture, an upstream system will dock with N downstream systems.
发明人意识到由于每一个下游系统对接口响应的标准不一样、业务特殊性不能配合优化以及各个系统之间的实时数据同步等问题导致上游系统的优化受限制,从而导致系统之间的耦合度过高,上游系统服务器压力过大,上游系统接口响应过慢。The inventor realizes that the optimization of upstream systems is limited due to the different standards of each downstream system's response to the interface, the inability of business specificity to cooperate with optimization, and the real-time data synchronization between each system, which leads to the limitation of the optimization of the upstream system, which leads to the degree of coupling between the systems. Too high, the upstream system server pressure is too high, and the upstream system interface response is too slow.
本申请提供的一种微服务的数据同步方法,包括:A data synchronization method for microservices provided in this application includes:
基于预先构建的一致性哈希算法对原始微服务的负载均衡场景进行动态增删,得到标准负载均衡场景,其中,所述标准负载均衡场景包括微服务的实例负载监控和微服务的实例状态变化检测;Based on the pre-built consistent hash algorithm, the load balancing scene of the original microservice is dynamically added and deleted to obtain the standard load balancing scene, where the standard load balancing scene includes the instance load monitoring of the microservice and the instance state change detection of the microservice ;
通过预先创建的单元服务器组向所述标准负载均衡场景进行实时数据读取,得到实时数据集;Read real-time data from the standard load balancing scene through a pre-created unit server group to obtain a real-time data set;
将所述实时数据集输入至所述预先创建的单元服务器组的单元节点中,通过消息中间件实现所述单元节点之间的实时数据同步。The real-time data set is input into the unit nodes of the pre-created unit server group, and real-time data synchronization between the unit nodes is realized through message middleware.
本申请提供一种微服务的数据同步装置,所述装置包括:This application provides a data synchronization device for microservices, and the device includes:
负载均衡场景创建模块:用于基于预先构建的一致性哈希算法对原始微服务的负载均衡场景进行动态增删,得到标准负载均衡场景,其中,所述标准负载均衡场景包括微服务的实例负载监控和微服务的实例状态变化检测;Load balancing scene creation module: used to dynamically add and delete load balancing scenes of the original microservices based on a pre-built consistent hash algorithm to obtain a standard load balancing scene, where the standard load balancing scene includes microservice instance load monitoring And microservice instance state change detection;
实时数据读取模块:用于通过预先创建的单元服务器组向所述标准负载均衡场景进行实时数据读取,得到实时数据集;Real-time data reading module: used to read real-time data from the standard load balancing scene through a pre-created unit server group to obtain a real-time data set;
实时数据同步模块:用于将所述实时数据集输入至所述预先创建的单元服务器组的单元节点中,通过消息中间件实现所述单元节点之间的实时数据同步。Real-time data synchronization module: used to input the real-time data set into the unit nodes of the pre-created unit server group, and realize real-time data synchronization between the unit nodes through message middleware.
本申请提供一种电子设备,所述电子设备包括存储器和处理器,所述存储器上存储有可在所述处理器上运行的微服务的数据同步程序,所述微服务的数据同步程序被所述处理器执行,以实现如下步骤:The present application provides an electronic device that includes a memory and a processor. The memory stores a data synchronization program of a microservice that can run on the processor. The data synchronization program of the microservice is controlled by the processor. The processor executes to implement the following steps:
基于预先构建的一致性哈希算法对原始微服务的负载均衡场景进行动态增删,得到标准负载均衡场景,其中,所述标准负载均衡场景包括微服务的实例负载监控和微服务的实例状态变化检测;Based on the pre-built consistent hash algorithm, the load balancing scene of the original microservice is dynamically added and deleted to obtain the standard load balancing scene, where the standard load balancing scene includes the instance load monitoring of the microservice and the instance state change detection of the microservice ;
通过预先创建的单元服务器组向所述标准负载均衡场景进行实时数据读取,得到实时数据集;Read real-time data from the standard load balancing scene through a pre-created unit server group to obtain a real-time data set;
将所述实时数据集输入至所述预先创建的单元服务器组的单元节点中,通过消息中间件实现所述单元节点之间的实时数据同步。The real-time data set is input into the unit nodes of the pre-created unit server group, and real-time data synchronization between the unit nodes is realized through message middleware.
本申请还提供一种计算机可读存储介质,所述计算机可读存储介质上存储有微服务的数据同步程序,所述微服务的数据同步程序可被一个或者多个处理器执行,以实现如下步骤:This application also provides a computer-readable storage medium on which a data synchronization program of a microservice is stored, and the data synchronization program of the microservice can be executed by one or more processors to achieve the following step:
基于预先构建的一致性哈希算法对原始微服务的负载均衡场景进行动态增删,得到标准负载均衡场景,其中,所述标准负载均衡场景包括微服务的实例负载监控和微服务的实例状态变化检测;Based on the pre-built consistent hash algorithm, the load balancing scene of the original microservice is dynamically added and deleted to obtain the standard load balancing scene, where the standard load balancing scene includes the instance load monitoring of the microservice and the instance state change detection of the microservice ;
通过预先创建的单元服务器组向所述标准负载均衡场景进行实时数据读取,得到实时数据集;Read real-time data from the standard load balancing scene through a pre-created unit server group to obtain a real-time data set;
将所述实时数据集输入至所述预先创建的单元服务器组的单元节点中,通过消息中间件实现所述单元节点之间的实时数据同步。The real-time data set is input into the unit nodes of the pre-created unit server group, and real-time data synchronization between the unit nodes is realized through message middleware.
图1为本申请一实施例提供的微服务的数据同步方法的流程示意图;FIG. 1 is a schematic flowchart of a data synchronization method for microservices provided by an embodiment of this application;
图2为本申请一实施例提供的电子设备的内部结构示意图;2 is a schematic diagram of the internal structure of an electronic device provided by an embodiment of the application;
图3为本申请一实施例提供的微服务的数据同步装置的模块示意图。FIG. 3 is a schematic diagram of modules of a microservice data synchronization device provided by an embodiment of the application.
本申请目的的实现、功能特点及优点将结合实施例,参照附图做进一步说明。The realization, functional characteristics, and advantages of the purpose of this application will be further described in conjunction with the embodiments and with reference to the accompanying drawings.
应当理解,此处所描述的具体实施例仅仅用以解释本申请,并不用于限定本申请。It should be understood that the specific embodiments described here are only used to explain the present application, and are not used to limit the present application.
本申请提供一种微服务的数据同步方法。参照图1所示,为本申请一实施例提供的微服务的数据同步方法的流程示意图。该方法可以由一个装置执行,该装置可以由软件和/或硬件实现。This application provides a data synchronization method for microservices. Referring to FIG. 1, it is a schematic flowchart of a data synchronization method for microservices provided by an embodiment of this application. The method can be executed by a device, and the device can be implemented by software and/or hardware.
在本实施例中,微服务的数据同步方法包括:In this embodiment, the data synchronization method for microservices includes:
S1、基于预先构建的一致性哈希算法对原始微服务的负载均衡场景进行动态增删,得到标准负载均衡场景,其中,所述标准负载均衡场景包括微服务的实例负载监控、微服务的实例状态变化检测。S1. Based on the pre-built consistent hash algorithm, dynamically add and delete the load balancing scene of the original microservice to obtain the standard load balancing scene, where the standard load balancing scene includes the instance load monitoring of the microservice and the instance status of the microservice Change detection.
本申请较佳实施例中,所述一致性哈希算法的核心思想为将普通哈希算法中的节点选择标准从一个具体的值转换为一段范围,所述一段范围可以表示为闭合环上的某一小段连续的范围。进一步地,本申请中所述预先构建的一致性哈希算法包括:预设虚拟节点的数目、构建所述虚拟节点的数据存储结构以及选择所述虚拟节点的散列函数。In the preferred embodiment of this application, the core idea of the consistent hashing algorithm is to convert the node selection criteria in the common hashing algorithm from a specific value to a range, and the range can be expressed as a closed loop A small continuous range. Further, the pre-built consistent hash algorithm in this application includes: preset number of virtual nodes, constructing the data storage structure of the virtual node, and selecting the hash function of the virtual node.
详细地,本申请较佳实施例中所述预先构建的一致性哈希算法如下所示:In detail, the pre-built consistent hash algorithm described in the preferred embodiment of the present application is as follows:
a、通过预设虚拟节点数目实现存储空间分配的均衡性。例如,某系统中只有两个物理节点,如果没有虚拟节点存在,由于哈希算法一定程度上的随机性,很难将用户请求均匀地分配到这两个节点中。如果将所述系统中的两个物理节点分成200个虚拟节点并映射到存储空间中,根据所述200个虚拟节点来进行哈希,可以大大提高了存储空间分配的均衡性。于是,当系统物理节点较少时,需要增加虚拟节点数目的设置,而当物理节点较多时则应该减少虚拟节点的设置。本申请可以根据具体物理节点的数量来设置合适的虚拟节点的数目。a. Realize the balance of storage space allocation by pre-setting the number of virtual nodes. For example, there are only two physical nodes in a system. If there are no virtual nodes, it is difficult to evenly distribute user requests to these two nodes due to the randomness of the hash algorithm to a certain extent. If the two physical nodes in the system are divided into 200 virtual nodes and mapped to the storage space, and hashing is performed according to the 200 virtual nodes, the balance of storage space allocation can be greatly improved. Therefore, when the system has fewer physical nodes, the number of virtual nodes needs to be increased, and when there are more physical nodes, the number of virtual nodes should be reduced. In this application, a suitable number of virtual nodes can be set according to the number of specific physical nodes.
b、采用Java中的 TreeMap 数据结构来实现所述虚拟节点的数据存储结构的构建,所述TreeMap 数据结构通过红黑树实现所述节点的存储。b. Use the TreeMap data structure in Java to implement the construction of the data storage structure of the virtual node, and the TreeMap data structure implements the storage of the node through a red-black tree.
c、将MurMurHash函数作为所述虚拟节点的散列函数。其中,所述MurMurHash 算法指的是非加密性哈希函数,通过所述MurMurHash 函数实现所述虚拟节点的哈希检索操作。c. Use the MurMurHash function as the hash function of the virtual node. Wherein, the MurMurHash algorithm refers to a non-cryptographic hash function, and the hash retrieval operation of the virtual node is realized through the MurMurHash function.
进一步地,本申请中所述原始微服务的负载均衡场景指的是将任务分摊到多个单元服务器上进行共同完成,其中,所述操作单元可以包括Web服务器、FTP服务器、企业关键应用服务器和其它关键任务服务器等。本申请较佳实施例通过所述一致性哈希算法提供的虚拟节点实现微服务的负载均衡场景中实例的动态增删,得到标准负载均衡场景。例如以每个调用者都将其请求发往同一个微服务实例作为所述微服务的负载均衡场景,其中,当所述实例崩溃而不可用的时,改变所述一致性哈希算法中虚拟节点的数目,可以将所述实例要接收的请求均匀分布到其他可用微服务实例上。Further, the load balancing scenario of the original microservice mentioned in this application refers to amortizing tasks to multiple unit servers for joint completion, where the operation unit may include a Web server, an FTP server, an enterprise key application server, and Other mission-critical servers, etc. The preferred embodiment of the present application implements the dynamic addition and deletion of instances in the load balancing scenario of microservices through the virtual nodes provided by the consistent hash algorithm, and obtains the standard load balancing scenario. For example, each caller sends its request to the same microservice instance as the load balancing scenario of the microservice, where, when the instance crashes and becomes unavailable, the virtual algorithm in the consistent hashing algorithm is changed. The number of nodes can evenly distribute the requests to be received by the instance to other available microservice instances.
较佳地,本申请中所述标准负载均衡场景包括微服务的实例负载监控、微服务的实例状态变化检测。详细地,所述微服务的实例负载监控包括:微服务的实例调用、微服务的实例并发以及微服务的实例数据更新。本申请通过负载均衡定时检测所述微服务的实例状态变化是否为实例增加和/或删除。当所述微服务的实例状态变化是实例增加和/或删除时,采用一致性哈希算法对所述实例请求进行重新分配,并将分配结果返回对应的调用者;当所述微服务的实例状态变化不是实例增加和/或删除时,报告所述实例运行的负载状态,并定时判断所述实例的负载状态是否达到预设的负载阀值,当没有达到所述预设的负载阈值时,则不做请求的调整,当达到所述预设的负载阈值时,则将所述微服务的实例部分请求均匀地分配到其他未超过负载阀值的微服务的实例中,并根据所述负载均衡定时检测的结果,调用者可以修改本地缓存的微服务地址信息,从而减少系统之间的耦合性。Preferably, the standard load balancing scenario described in this application includes instance load monitoring of microservices, and instance state change detection of microservices. In detail, the instance load monitoring of the microservice includes: instance invocation of the microservice, concurrency of the instance of the microservice, and instance data update of the microservice. This application regularly detects whether the instance state change of the microservice is an instance addition and/or deletion through load balancing. When the instance state change of the microservice is the addition and/or deletion of the instance, the consistent hash algorithm is used to reallocate the instance request, and the allocation result is returned to the corresponding caller; when the instance of the microservice When the status change is not an instance addition and/or deletion, report the running load status of the instance, and periodically determine whether the load status of the instance reaches the preset load threshold, and when the preset load threshold is not reached, No request adjustment is made. When the preset load threshold is reached, the partial requests of the microservice instances are evenly distributed to other microservice instances that do not exceed the load threshold, and the load threshold is determined according to the load. Balancing the results of timing detection, the caller can modify the local cached microservice address information, thereby reducing the coupling between systems.
S2、通过预先创建的单元服务器组向所述标准负载均衡场景进行实时数据读取,得到实时数据集。S2. Read real-time data from the standard load balancing scene through the pre-created unit server group to obtain a real-time data set.
本申请较佳实施例在所述微服务的负载均衡场景下,通过Redis构建所述单元服务器组。所述Redis 是开源的、基于内存的键值对存储系统,提供了字符串、列表、集合、哈希对象等丰富的数据结构。较佳地,本申请中所述通过Redis构建所述单元服务器包括:构建所述单元服务器的存储数据结构、选择所述单元服务器持久化方式、利用Redis的复制功能实现所述单元服务器的数据备份以及存储所述单元服务器固定的数据。In the preferred embodiment of the present application, the unit server group is constructed through Redis in the load balancing scenario of the microservice. The Redis is an open source, memory-based key-value pair storage system that provides rich data structures such as strings, lists, sets, and hash objects. Preferably, the construction of the unit server through Redis in this application includes: constructing the storage data structure of the unit server, selecting the unit server persistence mode, and using the replication function of Redis to realize the data backup of the unit server And storing the fixed data of the unit server.
进一步地,所述构建所述单元服务器存储数据结构包括:利用 Redis 提供的数据类型选择数据结构以便于分类存储和快速检索。由于所述Redis 提供的键值支持二进制安全的功能,所以本申请在键的形式的选择上可以采用任何形式的二进制序列。比如,对微服务实例的状态属性的键的形式可以设置为字符串“microservice:instance:state:instanceId”,微服务实例实时的位置信息则可以设置为字符串“service_id:instance_id:url”,通过所述多个字段和符号间隔而组成键的模式具备良好的结构性,可以对 Redis 中数据进行快速的分类和查找。Further, the constructing the storage data structure of the unit server includes: using the data type provided by Redis to select the data structure to facilitate classified storage and rapid retrieval. Since the key value provided by Redis supports the function of binary security, any form of binary sequence can be used in the selection of the form of the key in this application. For example, the form of the key for the state attribute of the microservice instance can be set to the string "microservice:instance:state:instanceId", and the real-time location information of the microservice instance can be set to the string "service_id:instance_id:url". The key pattern formed by the multiple fields and symbol intervals has good structure, and can quickly classify and search data in Redis.
进一步地,所述选择所述单元服务器持久化方式包括:通过所述Redis中AOF(Append Only File)持久化方式进行数据的持久化。所述AOF采用保存所述Redis执行的写命令的方式来持久化数据库的状态,并且还提供了 AOF 重写的机制来降低
AOF 文件中的冗余度,从而提高存储效率。Further, the selecting the unit server persistence mode includes: performing data persistence through the AOF (Append Only File) persistence mode in Redis. The AOF saves the write commands executed by the Redis to persist the state of the database, and also provides an AOF rewrite mechanism to reduce
Redundancy in AOF files, thereby improving storage efficiency.
进一步地,所述利用Redis的复制功能实现所述单元服务器的数据备份包括:选择所述单元服务器中某一个单元服务器作为主单元服务器,通过所述Redis的laveof命令和slaveof 配置属性将剩余单元服务器设置为所述主单元服务器的从单元服务器;启动所述从单元服务器后向所述主单元服务器发送同步的命令,通过所述主单元服务器启动后台进程来生成内存数据的快照,同时记录在生成快照期间新执行的写命令,完成所述主单元服务器的数据备份。如果有多个从单元服务器同时请求同步的时候,所述主单元服务器只需要执行一次bgsave命令就可以处理所述多个从单元服务器的同步请求。Further, the use of the replication function of Redis to implement the data backup of the unit server includes: selecting a certain unit server among the unit servers as the master unit server, and setting the remaining unit servers through the Redis command and slaveof configuration attributes Set as the slave unit server of the master unit server; after the slave unit server is started, a synchronization command is sent to the master unit server, and a background process is started by the master unit server to generate a snapshot of memory data, and at the same time it is recorded in the generation The newly executed write command during the snapshot completes the data backup of the main unit server. If there are multiple slave unit servers requesting synchronization at the same time, the master unit server only needs to execute the bgsave command once to process the synchronization requests of the multiple slave unit servers.
进一步地,所述结合mysql存储所述单元服务器固定的数据包括:结合MySQL存储微服务属性中固定的数据,所述固定的数据可以为微服务的名称属性,版本属性,容量属性,提供者信息等。Further, storing the fixed data of the unit server in combination with MySQL includes: storing fixed data in microservice attributes in combination with MySQL. The fixed data may be the name attribute, version attribute, capacity attribute, and provider information of the microservice. Wait.
进一步地,本申请较佳实施例根据所述搭建的单元服务器可以向所述微服务的负载均衡场景进行实时数据的读取,得到实时数据集,其中,所述单元服务器可以支持高并发的数据读取操作,提高系统的响应速度。Further, the unit server constructed according to the preferred embodiment of the present application can read real-time data to the load balancing scene of the microservice to obtain a real-time data set, wherein the unit server can support high-concurrency data Reading operation improves the response speed of the system.
S3、将所述实时数据集输入至所述预先创建的单元服务器组的单元节点中,通过消息中间件实现所述单元节点之间的实时数据同步。S3. Input the real-time data set into the unit nodes of the pre-created unit server group, and realize real-time data synchronization between the unit nodes through message middleware.
本申请较佳实施例中,所述单元节点根据实时数据的属性以及用户的需求在所述单元服务器组中进行构建得到,所述实时数据的属性可以为字段名,参数类型等,所述用户的需求可以为实时获取数据,不实时获取数据等。较佳地,本申请中所述消息中间件为MQ消息中间件,所述MQ消息中间件指的是能够有效的保证及支持在分布式应用系统中,通过同步或异步的机制进行消息收发的中间件系统。通过所述MQ消息中间件可以实现所述预先构建的单元节点之间的实时数据同步,从而保证了基于微服务场景下的数据一致性。In a preferred embodiment of the present application, the unit node is constructed in the unit server group according to the attributes of real-time data and the needs of users. The attributes of the real-time data can be field names, parameter types, etc., and the user The demand can be to obtain data in real time, not to obtain data in real time, etc. Preferably, the message middleware in this application is MQ message middleware, and the MQ message middleware refers to those that can effectively guarantee and support the sending and receiving of messages through a synchronous or asynchronous mechanism in a distributed application system. Middleware system. The real-time data synchronization between the pre-built unit nodes can be realized through the MQ message middleware, thereby ensuring data consistency in a microservice-based scenario.
发明还提供一种电子设备。参照图2所示,为本申请一实施例提供的电子设备的内部结构示意图。The invention also provides an electronic device. Referring to FIG. 2, it is a schematic diagram of the internal structure of an electronic device provided by an embodiment of this application.
在本实施例中,所述电子设备1可以是PC(Personal Computer,个人电脑),或者是智能手机、平板电脑、便携计算机等数据处理设备,也可以是一种服务器等。该电子设备1至少包括存储器11、处理器12,通信总线13,以及网络接口14。In this embodiment, the electronic device 1 may be a PC (Personal Computer, personal computer), or a data processing device such as a smart phone, a tablet computer, or a portable computer, or a server or the like. The electronic device 1 at least includes a memory 11, a processor 12, a communication bus 13, and a network interface 14.
其中,存储器11至少包括一种类型的可读存储介质,所述可读存储介质可以是非易失性,也可以是易失性,所述可读存储介质包括闪存、硬盘、多媒体卡、卡型存储器(例如,SD或DX存储器等)、磁性存储器、磁盘、光盘等。存储器11在一些实施例中可以是电子设备1的内部存储单元,例如该电子设备1的硬盘。存储器11在另一些实施例中也可以是电子设备1的外部存储设备,例如电子设备1上配备的插接式硬盘,智能存储卡(Smart Media Card, SMC),安全数字(Secure Digital, SD)卡,闪存卡(Flash
Card)等。进一步地,存储器11还可以既包括电子设备1的内部存储单元也包括外部存储设备。存储器11不仅可以用于存储安装于电子设备1的应用软件及各类数据,例如微服务的数据同步程序的代码等,还可以用于暂时地存储已经输出或者将要输出的数据。The memory 11 includes at least one type of readable storage medium. The readable storage medium may be non-volatile or volatile. The readable storage medium includes flash memory, hard disk, multimedia card, and card type. Storage (for example, SD or DX storage, etc.), magnetic storage, magnetic disk, optical disk, etc. The memory 11 may be an internal storage unit of the electronic device 1 in some embodiments, such as a hard disk of the electronic device 1. In other embodiments, the memory 11 may also be an external storage device of the electronic device 1, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), and a secure digital (Secure Digital, SD) equipped on the electronic device 1. Flash memory card
Card) and so on. Further, the memory 11 may also include both an internal storage unit of the electronic device 1 and an external storage device. The memory 11 can be used not only to store application software and various types of data installed in the electronic device 1, such as the code of a data synchronization program for microservices, etc., but also to temporarily store data that has been output or will be output.
处理器12在一些实施例中可以是一中央处理器(Central
Processing Unit, CPU)、控制器、微控制器、微处理器或其他数据处理芯片,用于运行存储器11中存储的程序代码或处理数据,例如执行微服务的数据同步程序等。The processor 12 may be a central processing unit (Central Processing Unit) in some embodiments.
Processing Unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chips are used to run program codes or process data stored in the memory 11, such as executing data synchronization programs for microservices.
通信总线13用于实现这些组件之间的连接通信。The communication bus 13 is used to realize the connection and communication between these components.
网络接口14可选的可以包括标准的有线接口、无线接口(如WI-FI接口),通常用于在该装置1与其他电子设备之间建立通信连接。The network interface 14 may optionally include a standard wired interface and a wireless interface (such as a WI-FI interface), and is usually used to establish a communication connection between the apparatus 1 and other electronic devices.
可选地,所述电子设备1还可以包括用户接口,用户接口可以包括显示器(Display)、输入单元比如键盘(Keyboard),可选的用户接口还可以包括标准的有线接口、无线接口。可选地,在一些实施例中,显示器可以是LED显示器、液晶显示器、触控式液晶显示器以及OLED(Organic Light-Emitting
Diode,有机发光二极管)触摸器等。其中,显示器也可以适当的称为显示屏或显示单元,用于显示在电子设备1中处理的信息以及用于显示可视化的用户界面。Optionally, the electronic device 1 may further include a user interface. The user interface may include a display (Display) and an input unit such as a keyboard (Keyboard). The optional user interface may also include a standard wired interface and a wireless interface. Optionally, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, and an OLED (Organic Light-Emitting
Diode, organic light-emitting diode) touch device and so on. Among them, the display can also be appropriately called a display screen or a display unit, which is used to display the information processed in the electronic device 1 and to display a visualized user interface.
图2仅示出了具有组件11-14以及微服务的数据同步程序的电子设备1,本领域技术人员可以理解的是,图2示出的结构并不构成对电子设备1的限定,可以包括比图示更少或者更多的部件,或者组合某些部件,或者不同的部件布置。Figure 2 only shows the electronic device 1 with components 11-14 and a data synchronization program for microservices. Those skilled in the art can understand that the structure shown in Figure 2 does not constitute a limitation on the electronic device 1, and may include Fewer or more parts than shown, or some parts in combination, or different parts arrangement.
在图2所示的电子设备1实施例中,存储器11中存储有微服务的数据同步程序;处理器12执行存储器11中存储的微服务的数据同步程序时实现如下步骤:In the embodiment of the electronic device 1 shown in FIG. 2, the data synchronization program of the microservice is stored in the memory 11; when the processor 12 executes the data synchronization program of the microservice stored in the memory 11, the following steps are implemented:
步骤一、基于预先构建的一致性哈希算法对原始微服务的负载均衡场景进行动态增删,得到标准负载均衡场景,其中,所述标准负载均衡场景包括微服务的实例负载监控、微服务的实例状态变化检测。Step 1. Based on the pre-built consistent hash algorithm, dynamically add and delete the load balancing scene of the original microservice to obtain a standard load balancing scene, where the standard load balancing scene includes instance load monitoring of microservices and instances of microservices State change detection.
本申请较佳实施例中,所述一致性哈希算法的核心思想为将普通哈希算法中的节点选择标准从一个具体的值转换为一段范围,所述一段范围可以表示为闭合环上的某一小段连续的范围。进一步地,本申请中所述预先构建的一致性哈希算法包括:预设虚拟节点的数目、构建所述虚拟节点的数据存储结构以及选择所述虚拟节点的散列函数。In the preferred embodiment of this application, the core idea of the consistent hashing algorithm is to convert the node selection criteria in the common hashing algorithm from a specific value to a range, and the range can be expressed as a closed loop A small continuous range. Further, the pre-built consistent hash algorithm in this application includes: preset number of virtual nodes, constructing the data storage structure of the virtual node, and selecting the hash function of the virtual node.
详细地,本申请较佳实施例中所述预先构建的一致性哈希算法如下所示:In detail, the pre-built consistent hash algorithm described in the preferred embodiment of the present application is as follows:
a、通过预设虚拟节点数目实现存储空间分配的均衡性。例如,某系统中只有两个物理节点,如果没有虚拟节点存在,由于哈希算法一定程度上的随机性,很难将用户请求均匀地分配到这两个节点中。如果将所述系统中的两个物理节点分成200个虚拟节点并映射到存储空间中,根据所述200个虚拟节点来进行哈希,可以大大提高了存储空间分配的均衡性。于是,当系统物理节点较少时,需要增加虚拟节点数目的设置,而当物理节点较多时则应该减少虚拟节点的设置。本申请可以根据具体物理节点的数量来设置合适的虚拟节点的数目。a. Realize the balance of storage space allocation by pre-setting the number of virtual nodes. For example, there are only two physical nodes in a system. If there are no virtual nodes, it is difficult to evenly distribute user requests to these two nodes due to the randomness of the hash algorithm to a certain extent. If the two physical nodes in the system are divided into 200 virtual nodes and mapped to the storage space, and hashing is performed according to the 200 virtual nodes, the balance of storage space allocation can be greatly improved. Therefore, when the system has fewer physical nodes, the number of virtual nodes needs to be increased, and when there are more physical nodes, the number of virtual nodes should be reduced. In this application, a suitable number of virtual nodes can be set according to the number of specific physical nodes.
b、采用
Java中的 TreeMap 数据结构来实现所述虚拟节点的数据存储结构的构建,所述TreeMap 数据结构通过红黑树实现所述节点的存储。b. Adopt
The TreeMap data structure in Java implements the construction of the data storage structure of the virtual node, and the TreeMap data structure implements the storage of the node through a red-black tree.
c、将MurMurHash函数作为所述虚拟节点的散列函数。其中,所述MurMurHash 算法指的是非加密性哈希函数,通过所述MurMurHash 函数实现所述虚拟节点的哈希检索操作。c. Use the MurMurHash function as the hash function of the virtual node. Wherein, the MurMurHash algorithm refers to a non-cryptographic hash function, and the hash retrieval operation of the virtual node is realized through the MurMurHash function.
进一步地,本申请中所述原始微服务的负载均衡场景指的是将任务分摊到多个单元服务器上进行共同完成,其中,所述操作单元可以包括Web服务器、FTP服务器、企业关键应用服务器和其它关键任务服务器等。本申请较佳实施例通过所述一致性哈希算法提供的虚拟节点实现微服务的负载均衡场景中实例的动态增删,得到标准负载均衡场景。例如以每个调用者都将其请求发往同一个微服务实例作为所述微服务的负载均衡场景,其中,当所述实例崩溃而不可用的时,改变所述一致性哈希算法中虚拟节点的数目,可以将所述实例要接收的请求均匀分布到其他可用微服务实例上。Further, the load balancing scenario of the original microservice mentioned in this application refers to amortizing tasks to multiple unit servers for joint completion, where the operation unit may include a Web server, an FTP server, an enterprise key application server, and Other mission-critical servers, etc. The preferred embodiment of the present application implements the dynamic addition and deletion of instances in the load balancing scenario of microservices through the virtual nodes provided by the consistent hash algorithm, and obtains the standard load balancing scenario. For example, each caller sends its request to the same microservice instance as the load balancing scenario of the microservice, where, when the instance crashes and becomes unavailable, the virtual algorithm in the consistent hashing algorithm is changed. The number of nodes can evenly distribute the requests to be received by the instance to other available microservice instances.
较佳地,本申请中所述标准负载均衡场景包括微服务的实例负载监控、微服务的实例状态变化检测。详细地,所述微服务的实例负载监控包括:微服务的实例调用、微服务的实例并发以及微服务的实例数据更新。本申请通过负载均衡定时检测所述微服务的实例状态变化是否为实例增加和/或删除。当所述微服务的实例状态变化是实例增加和/或删除时,采用一致性哈希算法对所述实例请求进行重新分配,并将分配结果返回对应的调用者;当所述微服务的实例状态变化不是实例增加和/或删除时,报告所述实例运行的负载状态,并定时判断所述实例的负载状态是否达到预设的负载阀值,当没有达到所述预设的负载阈值时,则不做请求的调整,当达到所述预设的负载阈值时,则将所述微服务的实例部分请求均匀地分配到其他未超过负载阀值的微服务的实例中,并根据所述负载均衡定时检测的结果,调用者可以修改本地缓存的微服务地址信息,从而减少系统之间的耦合性。Preferably, the standard load balancing scenario described in this application includes instance load monitoring of microservices, and instance state change detection of microservices. In detail, the instance load monitoring of the microservice includes: instance invocation of the microservice, concurrency of the instance of the microservice, and instance data update of the microservice. This application regularly detects whether the instance state change of the microservice is an instance addition and/or deletion through load balancing. When the instance state change of the microservice is the addition and/or deletion of the instance, the consistent hash algorithm is used to reallocate the instance request, and the allocation result is returned to the corresponding caller; when the instance of the microservice When the status change is not an instance addition and/or deletion, report the running load status of the instance, and periodically determine whether the load status of the instance reaches the preset load threshold, and when the preset load threshold is not reached, No request adjustment is made. When the preset load threshold is reached, the partial requests of the microservice instances are evenly distributed to other microservice instances that do not exceed the load threshold, and the load threshold is determined according to the load. Balancing the results of timing detection, the caller can modify the local cached microservice address information, thereby reducing the coupling between systems.
步骤二、通过预先创建的单元服务器组向所述标准负载均衡场景进行实时数据读取,得到实时数据集。Step 2: Read real-time data from the standard load balancing scene through the pre-created unit server group to obtain a real-time data set.
本申请较佳实施例基于在所述微服务的负载均衡场景下,通过Redis构建所述单元服务器组。所述Redis 是开源的、基于内存的键值对存储系统,提供了字符串、列表、集合、哈希对象等丰富的数据结构。较佳地,本申请中所述通过Redis构建所述单元服务器包括:构建所述单元服务器的存储数据结构、选择所述单元服务器持久化方式、利用Redis的复制功能实现所述单元服务器的数据备份以及存储所述单元服务器固定的数据。The preferred embodiment of the present application is based on the construction of the unit server group through Redis in the load balancing scenario of the microservice. The Redis is an open source, memory-based key-value pair storage system that provides rich data structures such as strings, lists, sets, and hash objects. Preferably, the construction of the unit server through Redis in this application includes: constructing the storage data structure of the unit server, selecting the unit server persistence mode, and using the replication function of Redis to realize the data backup of the unit server And storing the fixed data of the unit server.
进一步地,所述构建所述单元服务器存储数据结构包括:利用 Redis 提供的数据类型选择数据结构以便于分类存储和快速检索。由于所述Redis 提供的键值支持二进制安全的功能,所以本申请在键的形式的选择上可以采用任何形式的二进制序列。比如,对微服务实例的状态属性的键的形式可以设置为字符串“microservice:instance:state:instanceId”,微服务实例实时的位置信息则可以设置为字符串“service_id:instance_id:url”,通过所述多个字段和符号间隔而组成键的模式具备良好的结构性,可以对 Redis 中数据进行快速的分类和查找。Further, the constructing the storage data structure of the unit server includes: using the data type provided by Redis to select the data structure to facilitate classified storage and rapid retrieval. Since the key value provided by Redis supports the function of binary security, any form of binary sequence can be used in the selection of the form of the key in this application. For example, the form of the key for the state attribute of the microservice instance can be set to the string "microservice:instance:state:instanceId", and the real-time location information of the microservice instance can be set to the string "service_id:instance_id:url". The key pattern formed by the multiple fields and symbol intervals has good structure, and can quickly classify and search data in Redis.
进一步地,所述选择所述单元服务器持久化方式包括:通过所述Redis中AOF(Append Only File)持久化方式进行数据的持久化。所述AOF采用保存所述Redis执行的写命令的方式来持久化数据库的状态,并且还提供了 AOF 重写的机制来降低
AOF 文件中的冗余度,从而提高存储效率。Further, the selecting the unit server persistence mode includes: performing data persistence through the AOF (Append Only File) persistence mode in Redis. The AOF saves the write commands executed by the Redis to persist the state of the database, and also provides an AOF rewrite mechanism to reduce
Redundancy in AOF files, thereby improving storage efficiency.
进一步地,所述利用Redis的复制功能实现所述单元服务器的数据备份包括:选择所述单元服务器中某一个单元服务器作为主单元服务器,通过所述Redis的laveof命令和slaveof 配置属性将剩余单元服务器设置为所述主单元服务器的从单元服务器;启动所述从单元服务器后向所述主单元服务器发送同步的命令,通过所述主单元服务器启动后台进程来生成内存数据的快照,同时记录在生成快照期间新执行的写命令,完成所述主单元服务器的数据备份。如果有多个从单元服务器同时请求同步的时候,所述主单元服务器只需要执行一次bgsave命令就可以处理所述多个从单元服务器的同步请求。Further, the use of the replication function of Redis to implement the data backup of the unit server includes: selecting a certain unit server among the unit servers as the master unit server, and setting the remaining unit servers through the Redis command and slaveof configuration attributes Set as the slave unit server of the master unit server; after the slave unit server is started, a synchronization command is sent to the master unit server, and a background process is started by the master unit server to generate a snapshot of memory data, and at the same time it is recorded in the generation The newly executed write command during the snapshot completes the data backup of the main unit server. If there are multiple slave unit servers requesting synchronization at the same time, the master unit server only needs to execute the bgsave command once to process the synchronization requests of the multiple slave unit servers.
进一步地,所述结合mysql存储所述单元服务器固定的数据包括:结合MySQL存储微服务属性中固定的数据,所述固定的数据可以为微服务的名称属性,版本属性,容量属性,提供者信息等。Further, storing the fixed data of the unit server in combination with MySQL includes: storing fixed data in microservice attributes in combination with MySQL. The fixed data may be the name attribute, version attribute, capacity attribute, and provider information of the microservice. Wait.
进一步地,本申请较佳实施例根据所述搭建的单元服务器可以向所述微服务的负载均衡场景进行实时数据的读取,得到实时数据集,其中,所述单元服务器可以支持高并发的数据读取操作,提高系统的响应速度。Further, the unit server constructed according to the preferred embodiment of the present application can read real-time data to the load balancing scene of the microservice to obtain a real-time data set, wherein the unit server can support high-concurrency data Reading operation improves the response speed of the system.
步骤三、将所述实时数据集输入至所述预先创建的单元服务器组的单元节点中,通过消息中间件实现所述单元节点之间的实时数据同步。Step 3: Input the real-time data set into the unit nodes of the pre-created unit server group, and realize real-time data synchronization between the unit nodes through message middleware.
本申请较佳实施例中,所述单元节点根据实时数据的属性以及用户的需求在所述单元服务器组中进行构建得到,所述实时数据的属性可以为字段名,参数类型等,所述用户的需求可以为实时获取数据,不实时获取数据等。较佳地,本申请中所述消息中间件为MQ消息中间件,所述MQ消息中间件指的是能够有效的保证及支持在分布式应用系统中,通过同步或异步的机制进行消息收发的中间件系统。通过所述MQ消息中间件可以实现所述预先构建的单元节点之间的实时数据同步,从而保证了基于微服务场景下的数据一致性。In a preferred embodiment of the present application, the unit node is constructed in the unit server group according to the attributes of real-time data and the needs of users. The attributes of the real-time data can be field names, parameter types, etc., and the user The demand can be to obtain data in real time, not to obtain data in real time, etc. Preferably, the message middleware in this application is MQ message middleware, and the MQ message middleware refers to those that can effectively guarantee and support the sending and receiving of messages through a synchronous or asynchronous mechanism in a distributed application system. Middleware system. The real-time data synchronization between the pre-built unit nodes can be realized through the MQ message middleware, thereby ensuring data consistency in a microservice-based scenario.
参照图3所示,为本申请微服务的数据同步装置2一实施例中的模块示意图,该实施例中,所述微服务的数据同步装置可以被分割为负载均衡场景创建模块10、实时数据读取模块20以及实时数据同步模块30,示例性地:Referring to Figure 3, this is a schematic diagram of modules in an embodiment of the data synchronization device 2 for microservices of this application. In this embodiment, the data synchronization device for microservices can be divided into a load balancing scene creation module 10 and real-time data. The reading module 20 and the real-time data synchronization module 30 are exemplary:
所述负载均衡场景创建模块10用于:基于预先构建的一致性哈希算法对原始微服务的负载均衡场景进行动态增删,得到标准负载均衡场景,其中,所述标准负载均衡场景包括微服务的实例负载监控和微服务的实例状态变化检测。The load balancing scene creation module 10 is used to dynamically add and delete load balancing scenes of the original microservices based on a pre-built consistent hash algorithm to obtain a standard load balancing scene, where the standard load balancing scene includes microservices Instance load monitoring and microservice instance status change detection.
所述实时数据读取模块20用于:通过预先创建的单元服务器组向所述标准负载均衡场景进行实时数据读取,得到实时数据集。The real-time data reading module 20 is configured to read real-time data from the standard load balancing scene through a pre-created unit server group to obtain a real-time data set.
所述实时数据同步模块30用于:将所述实时数据集输入至所述预先创建的单元服务器组的单元节点中,通过消息中间件实现所述单元节点之间的实时数据同步。The real-time data synchronization module 30 is configured to input the real-time data set into the unit nodes of the pre-created unit server group, and realize real-time data synchronization between the unit nodes through message middleware.
上述负载均衡场景创建模块10、实时数据读取模块20以及实时数据同步模块30等程序模块被执行时所实现的功能或操作步骤与上述实施例大体相同,在此不再赘述。The functions or operation steps implemented by the program modules such as the load balancing scenario creation module 10, the real-time data reading module 20, and the real-time data synchronization module 30 when executed are substantially the same as those in the foregoing embodiment, and will not be repeated here.
优选地,本申请所述负载均衡场景创建模块10、实时数据读取模块20以及实时数据同步模块30可以组成一个微服务的数据同步系统,如可以安装在用户手机或者电脑上的一个APP。Preferably, the load balancing scenario creation module 10, the real-time data reading module 20, and the real-time data synchronization module 30 described in this application can form a micro-service data synchronization system, such as an APP that can be installed on a user's mobile phone or computer.
此外,本申请实施例还提出一种计算机可读存储介质,所述计算机可读存储介质可以是非易失性,也可以是易失性,所述计算机可读存储介质上存储有微服务的数据同步程序,所述微服务的数据同步程序可被一个或多个处理器执行,以实现如下操作:In addition, the embodiment of the present application also proposes a computer-readable storage medium. The computer-readable storage medium may be non-volatile or volatile, and the computer-readable storage medium stores microservice data. A synchronization program. The data synchronization program of the microservice can be executed by one or more processors to achieve the following operations:
基于预先构建的一致性哈希算法对原始微服务的负载均衡场景进行动态增删,得到标准负载均衡场景,其中,所述标准负载均衡场景包括微服务的实例负载监控和微服务的实例状态变化检测;Based on the pre-built consistent hash algorithm, the load balancing scene of the original microservice is dynamically added and deleted to obtain the standard load balancing scene, where the standard load balancing scene includes the instance load monitoring of the microservice and the instance state change detection of the microservice ;
通过预先创建的单元服务器组向所述标准负载均衡场景进行实时数据读取,得到实时数据集;Read real-time data from the standard load balancing scene through a pre-created unit server group to obtain a real-time data set;
将所述实时数据集输入至所述预先创建的单元服务器组的单元节点中,通过消息中间件实现所述单元节点之间的实时数据同步。The real-time data set is input into the unit nodes of the pre-created unit server group, and real-time data synchronization between the unit nodes is realized through message middleware.
本申请计算机可读存储介质具体实施方式与上述微服务的数据同步装置和方法各实施例基本相同,在此不作累述。The specific implementation of the computer-readable storage medium of this application is basically the same as the above-mentioned embodiments of the microservice data synchronization device and method, and will not be repeated here.
需要说明的是,上述本申请实施例序号仅仅为了描述,不代表实施例的优劣。并且本文中的术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、装置、物品或者方法不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、装置、物品或者方法所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括该要素的过程、装置、物品或者方法中还存在另外的相同要素。It should be noted that the serial numbers of the above-mentioned embodiments of the present application are only for description, and do not represent the superiority or inferiority of the embodiments. And the terms "include", "include" or any other variants thereof in this article are intended to cover non-exclusive inclusion, so that a process, device, article or method including a series of elements not only includes those elements, but also includes those elements that are not explicitly included. The other elements listed may also include elements inherent to the process, device, article, or method. If there are no more restrictions, the element defined by the sentence "including a..." does not exclude the existence of other identical elements in the process, device, article, or method that includes the element.
通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到上述实施例方法可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件,但很多情况下前者是更佳的实施方式。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品存储在如上所述的一个存储介质(如ROM/RAM、磁碟、光盘)中,包括若干指令用以使得一台终端设备(可以是手机,计算机,服务器,或者网络设备等)执行本申请各个实施例所述的方法。Through the description of the above implementation manners, those skilled in the art can clearly understand that the above-mentioned embodiment method can be implemented by means of software plus the necessary general hardware platform, of course, it can also be implemented by hardware, but in many cases the former is better.的实施方式。 Based on this understanding, the technical solution of this application essentially or the part that contributes to the existing technology can be embodied in the form of a software product, and the computer software product is stored in a storage medium (such as ROM/RAM) as described above. , Magnetic disks, optical disks), including several instructions to make a terminal device (which can be a mobile phone, a computer, a server, or a network device, etc.) execute the method described in each embodiment of the present application.
以上仅为本申请的优选实施例,并非因此限制本申请的专利范围,凡是利用本申请说明书及附图内容所作的等效结构或等效流程变换,或直接或间接运用在其他相关的技术领域,均同理包括在本申请的专利保护范围内。The above are only the preferred embodiments of the application, and do not limit the scope of the patent for this application. Any equivalent structure or equivalent process transformation made using the content of the description and drawings of the application, or directly or indirectly applied to other related technical fields , The same reason is included in the scope of patent protection of this application.
Claims (20)
- 一种微服务的数据同步方法,其中,所述方法包括:A data synchronization method for microservices, wherein the method includes:基于预先构建的一致性哈希算法对原始微服务的负载均衡场景进行动态增删,得到标准负载均衡场景,其中,所述标准负载均衡场景包括微服务的实例负载监控和微服务的实例状态变化检测;Based on the pre-built consistent hash algorithm, the load balancing scene of the original microservice is dynamically added and deleted to obtain the standard load balancing scene, where the standard load balancing scene includes the instance load monitoring of the microservice and the instance state change detection of the microservice ;通过预先创建的单元服务器组向所述标准负载均衡场景进行实时数据读取,得到实时数据集;Read real-time data from the standard load balancing scene through a pre-created unit server group to obtain a real-time data set;将所述实时数据集输入至所述预先创建的单元服务器组的单元节点中,通过消息中间件实现所述单元节点之间的实时数据同步。The real-time data set is input into the unit nodes of the pre-created unit server group, and real-time data synchronization between the unit nodes is realized through message middleware.
- 如权利要求1所述的微服务的数据同步方法,其中,所述预先构建的一致性哈希算法包括:The data synchronization method for microservices according to claim 1, wherein the pre-built consistent hashing algorithm comprises:预设虚拟节点的数目,以实现存储空间分配的均衡性;Preset the number of virtual nodes to achieve a balanced distribution of storage space;采用TreeMap 数据结构对所述虚拟节点的数据存储结构进行构建,所述TreeMap 数据结构通过红黑树实现所述节点的存储;Using the TreeMap data structure to construct the data storage structure of the virtual node, the TreeMap data structure implements the storage of the node through a red-black tree;选择所述虚拟节点的散列函数,通过所述散列函数实现所述虚拟节点的哈希检索操作。The hash function of the virtual node is selected, and the hash retrieval operation of the virtual node is realized through the hash function.
- 如权利要求1所述的微服务的数据同步方法,其中,所述原始微服务的负载均衡场景包括将任务分摊到多个单元服务器上共同完成,其中,所述操作单元包括Web服务器、FTP服务器、企业关键应用服务器。The method for data synchronization of microservices according to claim 1, wherein the load balancing scenario of the original microservice includes allocating tasks to multiple unit servers for joint completion, wherein the operation unit includes a Web server, an FTP server , Enterprise key application server.
- 如权利要求1至3中任意一项所述的微服务的数据同步方法,其中,所述微服务的实例负载监控包括:微服务的实例调用、微服务的实例并发以及微服务的实例数据更新。The microservice data synchronization method according to any one of claims 1 to 3, wherein the instance load monitoring of the microservice includes: instance invocation of the microservice, concurrency of the instance of the microservice, and update of the instance data of the microservice .
- 如权利要求1至3中任意一项所述的微服务的数据同步方法,其中,所述微服务的实例状态变化检测包括:The data synchronization method of a microservice according to any one of claims 1 to 3, wherein the detection of the instance state change of the microservice comprises:通过负载均衡定时检测所述微服务的实例状态变化是否为实例增加和/或删除;Periodically detecting whether the instance state change of the microservice is an instance addition and/or deletion through load balancing;当所述微服务的实例状态变化是实例增加和/或删除时,采用所述一致性哈希算法对所述实例请求进行重新分配,并将分配结果返回对应的调用者;When the instance state of the microservice changes as an instance is added and/or deleted, the consistent hash algorithm is used to reallocate the instance request, and the allocation result is returned to the corresponding caller;当所述微服务的实例状态变化不是实例增加和/或删除时,报告所述实例运行的负载状态,并定时判断所述实例的负载状态是否达到预设的负载阀值。When the instance status change of the microservice is not an instance addition and/or deletion, the load status of the instance operation is reported, and it is periodically determined whether the load status of the instance reaches a preset load threshold.
- 如权利要求1至3中任意一项所述的微服务的数据同步方法,其中,所述方法还包括:The data synchronization method for microservices according to any one of claims 1 to 3, wherein the method further comprises:构建所述单元服务器组存储数据结构、选择所述单元服务器组持久化方式、利用Redis的复制功能实现所述单元服务器组的数据备份以及存储所述单元服务器组固定的数据,以完成对所述单元服务器组的创建。Construct the storage data structure of the unit server group, select the persistence mode of the unit server group, use the replication function of Redis to realize the data backup of the unit server group and store the fixed data of the unit server group to complete the Creation of a cell server group.
- 如权利要求6所述的微服务的数据同步方法,其中,所述利用Redis的复制功能实现所述单元服务器组的数据备份,包括:7. The data synchronization method for microservices according to claim 6, wherein said using the replication function of Redis to implement data backup of said unit server group comprises:选择所述单元服务器组其中一个单元服务器作为主单元服务器,通过所述Redis的laveof命令和slaveof 配置属性将所述单元服务器组中剩余单元服务器设置为所述主单元服务器的从单元服务器;Select one of the unit servers in the unit server group as the master unit server, and set the remaining unit servers in the unit server group as the slave unit servers of the master unit server through the laveof command and slaveof configuration attribute of the Redis;启动所述从单元服务器,向所述主单元服务器发送同步的命令,通过所述主单元服务器启动后台进程来生成内存数据的快照,同时记录生成快照期间新执行的写命令,完成所述单元服务器组中主单元服务器的数据备份。Start the slave unit server, send a synchronization command to the master unit server, start a background process through the master unit server to generate a snapshot of the memory data, and record the newly executed write commands during the snapshot generation to complete the unit server Data backup of the main unit server in the group.
- 一种微服务的数据同步装置,其中,所述装置包括:A data synchronization device for microservices, wherein the device includes:负载均衡场景创建模块:用于基于预先构建的一致性哈希算法对原始微服务的负载均衡场景进行动态增删,得到标准负载均衡场景,其中,所述标准负载均衡场景包括微服务的实例负载监控和微服务的实例状态变化检测;Load balancing scene creation module: used to dynamically add and delete load balancing scenes of the original microservices based on a pre-built consistent hash algorithm to obtain a standard load balancing scene, where the standard load balancing scene includes microservice instance load monitoring And microservice instance state change detection;实时数据读取模块:用于通过预先创建的单元服务器组向所述标准负载均衡场景进行实时数据读取,得到实时数据集;Real-time data reading module: used to read real-time data from the standard load balancing scene through a pre-created unit server group to obtain a real-time data set;实时数据同步模块:用于将所述实时数据集输入至所述预先创建的单元服务器组的单元节点中,通过消息中间件实现所述单元节点之间的实时数据同步。Real-time data synchronization module: used to input the real-time data set into the unit nodes of the pre-created unit server group, and realize real-time data synchronization between the unit nodes through message middleware.
- 一种电子设备,其中,所述电子设备包括存储器和处理器,所述存储器上存储有可在所述处理器上运行的微服务的数据同步程序,所述微服务的数据同步程序被所述处理器执行,以实现如下步骤:An electronic device, wherein the electronic device includes a memory and a processor, the memory stores a data synchronization program of a microservice that can be run on the processor, and the data synchronization program of the microservice is The processor executes to achieve the following steps:基于预先构建的一致性哈希算法对原始微服务的负载均衡场景进行动态增删,得到标准负载均衡场景,其中,所述标准负载均衡场景包括微服务的实例负载监控和微服务的实例状态变化检测;Based on the pre-built consistent hash algorithm, the load balancing scene of the original microservice is dynamically added and deleted to obtain the standard load balancing scene, where the standard load balancing scene includes the instance load monitoring of the microservice and the instance state change detection of the microservice ;通过预先创建的单元服务器组向所述标准负载均衡场景进行实时数据读取,得到实时数据集;Read real-time data from the standard load balancing scene through a pre-created unit server group to obtain a real-time data set;将所述实时数据集输入至所述预先创建的单元服务器组的单元节点中,通过消息中间件实现所述单元节点之间的实时数据同步。The real-time data set is input into the unit nodes of the pre-created unit server group, and real-time data synchronization between the unit nodes is realized through message middleware.
- 如权利要求9所述的电子设备,其中,所述预先构建的一致性哈希算法包括:9. The electronic device of claim 9, wherein the pre-built consistent hashing algorithm comprises:预设虚拟节点的数目,以实现存储空间分配的均衡性;Preset the number of virtual nodes to achieve a balanced distribution of storage space;采用TreeMap 数据结构对所述虚拟节点的数据存储结构进行构建,所述TreeMap 数据结构通过红黑树实现所述节点的存储;Using the TreeMap data structure to construct the data storage structure of the virtual node, the TreeMap data structure implements the storage of the node through a red-black tree;选择所述虚拟节点的散列函数,通过所述散列函数实现所述虚拟节点的哈希检索操作。The hash function of the virtual node is selected, and the hash retrieval operation of the virtual node is realized through the hash function.
- 如权利要求9所述的电子设备,其中,所述原始微服务的负载均衡场景包括将任务分摊到多个单元服务器上共同完成,其中,所述操作单元包括Web服务器、FTP服务器、企业关键应用服务器。The electronic device according to claim 9, wherein the load balancing scenario of the original microservice includes allocating tasks to a plurality of unit servers for joint completion, wherein the operation unit includes a Web server, an FTP server, and a key enterprise application server.
- 如权利要求9至11中任意一项所述的电子设备,其中,所述微服务的实例负载监控包括:微服务的实例调用、微服务的实例并发以及微服务的实例数据更新。The electronic device according to any one of claims 9 to 11, wherein the instance load monitoring of the microservice includes: instance invocation of the microservice, concurrency of the instance of the microservice, and instance data update of the microservice.
- 如权利要求9至11中任意一项所述的电子设备,其中,所述微服务的实例状态变化检测包括:The electronic device according to any one of claims 9 to 11, wherein the detection of the instance state change of the microservice comprises:通过负载均衡定时检测所述微服务的实例状态变化是否为实例增加和/或删除;Periodically detecting whether the instance state change of the microservice is an instance addition and/or deletion through load balancing;当所述微服务的实例状态变化是实例增加和/或删除时,采用所述一致性哈希算法对所述实例请求进行重新分配,并将分配结果返回对应的调用者;When the instance state of the microservice changes as an instance is added and/or deleted, the consistent hash algorithm is used to reallocate the instance request, and the allocation result is returned to the corresponding caller;当所述微服务的实例状态变化不是实例增加和/或删除时,报告所述实例运行的负载状态,并定时判断所述实例的负载状态是否达到预设的负载阀值。When the instance status change of the microservice is not an instance addition and/or deletion, the load status of the instance operation is reported, and it is periodically determined whether the load status of the instance reaches a preset load threshold.
- 如权利要求9至11中任意一项所述的电子设备,其中,所述微服务的数据同步程序被所述处理器执行还实现如下步骤:The electronic device according to any one of claims 9 to 11, wherein the execution of the data synchronization program of the microservice by the processor further implements the following steps:构建所述单元服务器组存储数据结构、选择所述单元服务器组持久化方式、利用Redis的复制功能实现所述单元服务器组的数据备份以及存储所述单元服务器组固定的数据,以完成对所述单元服务器组的创建。Construct the storage data structure of the unit server group, select the persistence mode of the unit server group, use the replication function of Redis to realize the data backup of the unit server group and store the fixed data of the unit server group to complete the Creation of a cell server group.
- 如权利要求14所述的电子设备,其中,所述利用Redis的复制功能实现所述单元服务器组的数据备份,包括:The electronic device according to claim 14, wherein said using the replication function of Redis to realize the data backup of the unit server group comprises:选择所述单元服务器组其中一个单元服务器作为主单元服务器,通过所述Redis的laveof命令和slaveof 配置属性将所述单元服务器组中剩余单元服务器设置为所述主单元服务器的从单元服务器;Select one of the unit servers in the unit server group as the master unit server, and set the remaining unit servers in the unit server group as the slave unit servers of the master unit server through the laveof command and slaveof configuration attribute of the Redis;启动所述从单元服务器,向所述主单元服务器发送同步的命令,通过所述主单元服务器启动后台进程来生成内存数据的快照,同时记录生成快照期间新执行的写命令,完成所述单元服务器组中主单元服务器的数据备份。Start the slave unit server, send a synchronization command to the master unit server, start a background process through the master unit server to generate a snapshot of the memory data, and record the newly executed write commands during the snapshot generation to complete the unit server Data backup of the main unit server in the group.
- 一种计算机可读存储介质,其中,所述计算机可读存储介质上存储有微服务的数据同步程序,所述微服务的数据同步程序可被一个或者多个处理器执行,以实现如下步骤:A computer-readable storage medium, wherein a data synchronization program of a microservice is stored on the computer-readable storage medium, and the data synchronization program of the microservice can be executed by one or more processors to implement the following steps:基于预先构建的一致性哈希算法对原始微服务的负载均衡场景进行动态增删,得到标准负载均衡场景,其中,所述标准负载均衡场景包括微服务的实例负载监控和微服务的实例状态变化检测;Based on the pre-built consistent hash algorithm, the load balancing scene of the original microservice is dynamically added and deleted to obtain the standard load balancing scene, where the standard load balancing scene includes the instance load monitoring of the microservice and the instance state change detection of the microservice ;通过预先创建的单元服务器组向所述标准负载均衡场景进行实时数据读取,得到实时数据集;Read real-time data from the standard load balancing scene through a pre-created unit server group to obtain a real-time data set;将所述实时数据集输入至所述预先创建的单元服务器组的单元节点中,通过消息中间件实现所述单元节点之间的实时数据同步。The real-time data set is input into the unit nodes of the pre-created unit server group, and real-time data synchronization between the unit nodes is realized through message middleware.
- 如权利要求16所述的计算机可读存储介质,其中,所述预先构建的一致性哈希算法包括:15. The computer-readable storage medium of claim 16, wherein the pre-built consistent hashing algorithm comprises:预设虚拟节点的数目,以实现存储空间分配的均衡性;Preset the number of virtual nodes to achieve a balanced distribution of storage space;采用TreeMap 数据结构对所述虚拟节点的数据存储结构进行构建,所述TreeMap 数据结构通过红黑树实现所述节点的存储;Using the TreeMap data structure to construct the data storage structure of the virtual node, the TreeMap data structure implements the storage of the node through a red-black tree;选择所述虚拟节点的散列函数,通过所述散列函数实现所述虚拟节点的哈希检索操作。The hash function of the virtual node is selected, and the hash retrieval operation of the virtual node is realized through the hash function.
- 如权利要求16所述的计算机可读存储介质,其中,所述原始微服务的负载均衡场景包括将任务分摊到多个单元服务器上共同完成,其中,所述操作单元包括Web服务器、FTP服务器、企业关键应用服务器。16. The computer-readable storage medium according to claim 16, wherein the load balancing scenario of the original microservice includes allocating tasks to multiple unit servers for joint completion, wherein the operation unit includes a Web server, an FTP server, Enterprise critical application server.
- 如权利要求16至18中任意一项所述的计算机可读存储介质,其中,所述微服务的实例负载监控包括:微服务的实例调用、微服务的实例并发以及微服务的实例数据更新。The computer-readable storage medium according to any one of claims 16 to 18, wherein the instance load monitoring of the microservice includes: instance invocation of the microservice, concurrency of the instance of the microservice, and instance data update of the microservice.
- 如权利要求16至18中任意一项所述的计算机可读存储介质,其中,所述微服务的实例状态变化检测包括:The computer-readable storage medium according to any one of claims 16 to 18, wherein the detection of the instance state change of the microservice comprises:通过负载均衡定时检测所述微服务的实例状态变化是否为实例增加和/或删除;Periodically detecting whether the instance state change of the microservice is an instance addition and/or deletion through load balancing;当所述微服务的实例状态变化是实例增加和/或删除时,采用所述一致性哈希算法对所述实例请求进行重新分配,并将分配结果返回对应的调用者;When the instance state of the microservice changes as an instance is added and/or deleted, the consistent hash algorithm is used to reallocate the instance request, and the allocation result is returned to the corresponding caller;当所述微服务的实例状态变化不是实例增加和/或删除时,报告所述实例运行的负载状态,并定时判断所述实例的负载状态是否达到预设的负载阀值。When the instance status change of the microservice is not an instance addition and/or deletion, the load status of the instance operation is reported, and it is periodically determined whether the load status of the instance reaches a preset load threshold.
Applications Claiming Priority (2)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010025271.8 | 2020-01-09 | ||
CN202010025271.8A CN111209120A (en) | 2020-01-09 | 2020-01-09 | Data synchronization method and device for microservice and computer readable storage medium |
Publications (1)
Publication Number | Publication Date |
---|---|
WO2021139431A1 true WO2021139431A1 (en) | 2021-07-15 |
Family
ID=70786702
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
PCT/CN2020/131898 WO2021139431A1 (en) | 2020-01-09 | 2020-11-26 | Data synchronization method and apparatus for microservice, electronic device and storage medium |
Country Status (2)
Country | Link |
---|---|
CN (1) | CN111209120A (en) |
WO (1) | WO2021139431A1 (en) |
Families Citing this family (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111209120A (en) * | 2020-01-09 | 2020-05-29 | 平安科技(深圳)有限公司 | Data synchronization method and device for microservice and computer readable storage medium |
CN114077639B (en) * | 2020-08-20 | 2024-08-23 | 北京字节跳动网络技术有限公司 | Data writing method, device, electronic equipment and storage medium |
CN112929424B (en) * | 2021-01-26 | 2022-11-15 | 成都佳发安泰教育科技股份有限公司 | Gateway load balancing method, device, equipment and storage medium |
CN113689103B (en) * | 2021-08-18 | 2023-11-24 | 国电南瑞南京控制系统有限公司 | Adaptive load balancing using offload intelligent scheduling management method, device and system |
CN113760597B (en) * | 2021-09-15 | 2024-11-22 | 卫宁健康科技集团股份有限公司 | Intermediate data processing method, device, electronic device and storage medium |
CN115242812B (en) * | 2022-07-25 | 2024-10-15 | 济南浪潮数据技术有限公司 | Node data synchronization method and device and computer readable storage medium |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20020109715A1 (en) * | 2001-02-09 | 2002-08-15 | Autodesk, Inc. | Optimizing graphical data synchronization between a graphical client and a stateless server |
CN101355518A (en) * | 2008-09-08 | 2009-01-28 | 北京航空航天大学 | A Multi-Server Dynamic Region Adjustment Method Based on Path Combination |
CN106506605A (en) * | 2016-10-14 | 2017-03-15 | 华南理工大学 | A SaaS application construction method based on microservice architecture |
CN111209120A (en) * | 2020-01-09 | 2020-05-29 | 平安科技(深圳)有限公司 | Data synchronization method and device for microservice and computer readable storage medium |
-
2020
- 2020-01-09 CN CN202010025271.8A patent/CN111209120A/en active Pending
- 2020-11-26 WO PCT/CN2020/131898 patent/WO2021139431A1/en active Application Filing
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20020109715A1 (en) * | 2001-02-09 | 2002-08-15 | Autodesk, Inc. | Optimizing graphical data synchronization between a graphical client and a stateless server |
CN101355518A (en) * | 2008-09-08 | 2009-01-28 | 北京航空航天大学 | A Multi-Server Dynamic Region Adjustment Method Based on Path Combination |
CN106506605A (en) * | 2016-10-14 | 2017-03-15 | 华南理工大学 | A SaaS application construction method based on microservice architecture |
CN111209120A (en) * | 2020-01-09 | 2020-05-29 | 平安科技(深圳)有限公司 | Data synchronization method and device for microservice and computer readable storage medium |
Also Published As
Publication number | Publication date |
---|---|
CN111209120A (en) | 2020-05-29 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
WO2021139431A1 (en) | Data synchronization method and apparatus for microservice, electronic device and storage medium | |
US11711420B2 (en) | Automated management of resource attributes across network-based services | |
CN102779185B (en) | High-availability distribution type full-text index method | |
US10922303B1 (en) | Early detection of corrupt data partition exports | |
CN102349062B (en) | Method and system for synchronizing browser caches across devices and web services | |
CN102495857B (en) | Load balancing method for distributed database | |
JP2005276192A (en) | Method and apparatus for increasing data storage capacity | |
WO2020093501A1 (en) | File storage method and deletion method, server, and storage medium | |
JP5375972B2 (en) | Distributed file system, data selection method thereof, and program | |
US10262024B1 (en) | Providing consistent access to data objects transcending storage limitations in a non-relational data store | |
US20200409584A1 (en) | Load balancing for scalable storage system | |
CN102360314A (en) | System and method for managing resources of data center | |
CN111475515A (en) | Compensation management method, device, computer equipment and storage medium for failed tasks | |
US7996511B1 (en) | Enterprise-scalable scanning using grid-based architecture with remote agents | |
WO2014166446A1 (en) | File access processing method, system and computer storage medium | |
WO2023103341A1 (en) | Blockchain-based smart contract invocation method, apparatus and device | |
CN113806300A (en) | Data storage method, system, device, equipment and storage medium | |
JP6418419B2 (en) | Method and apparatus for hard disk to execute application code | |
WO2020151337A1 (en) | Distributed file processing method and apparatus, computer device and storage medium | |
US11017032B1 (en) | Document recovery utilizing serialized data | |
WO2012171363A1 (en) | Method and equipment for data operation in distributed cache system | |
JP2024545379A (en) | Blockchain-based data processing method, device, equipment, and computer program | |
CN113868184B (en) | Configuration method and system of configuration center based on cache of master-slave architecture | |
CN111708626B (en) | Data access method, device, computer equipment and storage medium | |
CN118519964A (en) | Data processing method, apparatus, computer program product, device and storage medium |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
121 | Ep: the epo has been informed by wipo that ep was designated in this application |
Ref document number: 20911340 Country of ref document: EP Kind code of ref document: A1 |
|
NENP | Non-entry into the national phase |
Ref country code: DE |
|
122 | Ep: pct application non-entry in european phase |
Ref document number: 20911340 Country of ref document: EP Kind code of ref document: A1 |