Data caching method and device, equipment and storage medium

By building a hash ring and a consistent hash algorithm, batch cache of cached data is realized, solving the problem of limited memory resources of microservices, improving performance and reducing resource consumption.

CN119903081APending Publication Date: 2025-04-29BEIJING WODONG TIANJUN INFORMATION TECH CO LTD +1
View PDF 0 Cites 4 Cited by

Patent Information

Application Number
CN202311416075.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-10-27
Publication Date
2025-04-29

AI Technical Summary

Technical Problem

The local memory resources of microservices are very valuable and cannot cache data in batches, resulting in poor microservice query performance in high concurrency and low latency scenarios.

Method used

By building a hash ring, the hash value of the data to be cached is determined based on a consistent hash algorithm, and divided it into multiple groups and cached it to multiple machine nodes respectively to realize batch cache of the data to be cached.

Benefits of technology

It realizes batch cache of cached data, improves the performance of microservices, reduces dependence on Redis clusters, and reduces the consumption of machine resources.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119903081A_ABST
    Figure CN119903081A_ABST
Patent Text Reader

Abstract

The embodiment of the invention discloses a data caching method and device, equipment and a storage medium, and relates to the technical field of data processing. The method comprises the following steps: constructing a hash ring according to the number of machine nodes in the current micro-service and the number of virtual nodes in a consistent hash algorithm, wherein each position in the hash ring corresponds to each virtual node of each machine node in the current micro-service; receiving to-be-cached data, determining a hash value corresponding to each to-be-cached data based on a consistent hash algorithm, and performing data segmentation on the to-be-cached data based on the hash value corresponding to each to-be-cached data; and determining a target machine node for storing each group of to-be-cached data in the current micro-service in the hash ring based on the hash value corresponding to each group of segmented to-be-cached data, and caching each group of to-be-cached data to the target machine node. According to the technical scheme, batch caching of the to-be-cached data is realized based on the local memory of the current micro-service, so that the current micro-service can obtain the data from the local memory, and the performance of the current micro-service is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] Embodiments of the present invention relate to the field of data processing technology, and in particular to a data caching method, apparatus, device and storage medium. Background Art

[0002] In a microservice system, in order to improve the performance of reading data from the database, data is usually cached in a distributed cache Redis cluster and then provided to microservices for query. The Redis cluster can easily store billions of data and provide high-performance query services. Since the Redis cluster is isolated from the microservice, in the scenario of ultra-high concurrency (tens of millions of QPS) and low latency (within 5 milliseconds), the microservice first obtains data from the Redis cluster and then performs related business logic processing, which often leads to timeouts and brings exponential machine resource overhead.

[0003] In the prior art, batch data in the database can be cached in the local memory of the microservice to improve the data query performance of the microservice.

[0004] In the process of implementing the present invention, the inventors found that there are at least the following technical problems in the prior art:

[0005] The local memory resources of microservices are very precious, the data that can be stored is very limited, and it is impossible to cache data in batches. Summary of the invention

[0006] The present invention provides a data caching method, apparatus, device and storage medium to achieve batch caching of cached data and improve the performance of microservices.

[0007] In a first aspect, an embodiment of the present invention provides a data caching method, comprising:

[0008] Constructing a hash ring according to the number of machine nodes in the current microservice and the number of virtual nodes in the consistent hashing algorithm, wherein each position in the hash ring corresponds to each virtual node of each machine node in the current microservice;

[0009] Receive data to be cached, determine hash values ​​corresponding to each of the data to be cached based on the consistent hashing algorithm, and perform data segmentation on the data to be cached based on the hash values ​​corresponding to each of the data to be cached;

[0010] Based on the hash values ​​corresponding to the divided groups of data to be cached, the target machine nodes storing the groups of data to be cached in the current microservice are determined in the hash ring, and the groups of data to be cached are cached to the target machine nodes.

[0011] In a second aspect, an embodiment of the present invention further provides a data cache device, including:

[0012] A construction module, used to construct a hash ring according to the number of machine nodes in the current microservice and the number of virtual nodes in the consistent hashing algorithm, wherein each position in the hash ring corresponds to each virtual node of each machine node in the current microservice;

[0013] A segmentation module, used for receiving data to be cached, determining a hash value corresponding to each data to be cached based on the consistent hashing algorithm, and performing data segmentation on the data to be cached based on the hash value corresponding to each data to be cached;

[0014] The cache module is used to determine the target machine node storing each group of data to be cached in the current microservice in the hash ring based on the hash values ​​corresponding to each group of data to be cached after the segmentation, and cache each group of data to be cached to the target machine node.

[0015] In a third aspect, an embodiment of the present invention further provides an electronic device, the electronic device comprising:

[0016] one or more processors;

[0017] a storage device for storing one or more programs,

[0018] When the one or more programs are executed by the one or more processors, the one or more processors implement the data caching method as described in any one of the first aspects.

[0019] In a fourth aspect, an embodiment of the present invention further provides a storage medium comprising computer executable instructions, wherein the computer executable instructions, when executed by a computer processor, are used to execute the data caching method as described in any one of the first aspects.

[0020] The embodiments of the above invention have the following advantages or beneficial effects:

[0021] An embodiment of the present invention provides a data caching method, which includes: constructing a hash ring according to the number of machine nodes in a current microservice and the number of virtual nodes in a consistent hashing algorithm, wherein each position in the hash ring corresponds to each virtual node of each machine node in the current microservice; receiving data to be cached, determining a hash value corresponding to each data to be cached based on the consistent hashing algorithm, and performing data segmentation on the data to be cached based on the hash value corresponding to each data to be cached; determining a target machine node in the current microservice for storing each group of data to be cached based on the hash value corresponding to each group of data to be cached after segmentation, and caching each group of data to be cached to the target machine node. The above technical solution, first, can determine the number of positions of the hash ring according to the number of machine nodes in the current microservice and the number of virtual nodes in the consistent hash algorithm, and secondly, determine the position corresponding to each virtual node of each machine node in the current microservice on the hash ring to realize the construction of the hash ring. After receiving the data to be cached, the hash value corresponding to each data to be cached can be determined, and the data to be cached can be divided into at least one group of data to be cached according to the hash value corresponding to each data to be cached, so as to realize the segmentation of the data to be cached. For each group of data to be cached after segmentation, the corresponding position is determined in the hash ring according to the hash value corresponding to the current group of data to be cached, and the machine node to which the virtual node corresponding to the position belongs is determined as the target machine node for caching the current group of data to be cached, so as to realize the determination of the target machine node corresponding to each group of data to be cached, and then each group of data to be cached can be cached to the corresponding target machine node, so as to realize the batch caching of the data to be cached. Of course, the data to be cached cached to the machine node of the current microservice enables the current microservice to directly obtain data from the local memory, thereby improving the performance of the current microservice. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] Figure 1 This is an interaction diagram of the upstream microservice, current microservice, and Redis cluster when data is cached in the Redis cluster;

[0023] Figure 2 A flow chart of a data caching method provided by an embodiment of the present invention;

[0024] Figure 3 A flowchart of another data caching method provided by an embodiment of the present invention;

[0025] Figure 4 A schematic diagram of a hash ring constructed in another data caching method provided in an embodiment of the present invention;

[0026] Figure 5 Interaction diagram of upstream microservices, current microservice, data synchronization service, and database when data is cached in the local memory of the current microservice;

[0027] Figure 6 A schematic diagram of caching data to be cached in another data caching method provided by an embodiment of the present invention;

[0028] Figure 7 A schematic diagram of a data structure of data to be cached stored in a Data node in another data caching method provided by an embodiment of the present invention;

[0029] Figure 8 A schematic diagram of data push in another data caching method provided by an embodiment of the present invention;

[0030] Fig. 9 A schematic diagram of the structure of a data cache device provided by an embodiment of the present invention;

[0031] Fig.10 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0032] The present invention will be further described in detail below in conjunction with the accompanying drawings and embodiments. It is to be understood that the specific embodiments described herein are only used to explain the present invention, rather than to limit the present invention. It should also be noted that, for ease of description, only parts related to the present invention, rather than all structures, are shown in the accompanying drawings.

[0033] It should be mentioned before discussing exemplary embodiments in more detail that some exemplary embodiments are described as processes or methods depicted as flow charts. Although the flow charts describe various operations (or steps) as sequential processes, many operations therein can be implemented in parallel, concurrently or simultaneously. In addition, the order of various operations can be rearranged. The process can be terminated when its operation is completed, but can also have additional steps not included in the accompanying drawings. The process can correspond to methods, functions, procedures, subroutines, subprograms, etc. In addition, the embodiments in the present invention and the features in the embodiments can be combined with each other without conflict.

[0034] In the prior art, data in a database can be cached in a Redis cluster. Figure 1 The interaction diagram of the upstream microservice, current microservice, and Redis cluster when data is cached in the Redis cluster is as follows: Figure 1 As shown in the figure, when the data is cached in the Redis cluster, the upstream microservice calls the current microservice through the Remote Procedure Call (RPC) protocol. The current microservice reads the data in the Redis cluster, performs relevant business logic processing, and returns the processing results to the upstream microservice.

[0035] When microservices currently read data from the Redis cluster through network communication, there is a performance bottleneck (millisecond level), which leads to a throughput bottleneck, and a large amount of resources (machine resources of the microservice and the machine resources of the Redis cluster). Since the throughput of each machine node of the current microservice has a bottleneck, the throughput that each shard in the Redis cluster can withstand also has a bottleneck. Under the premise of exponentially increasing traffic and meeting the requirements of high performance and low latency, the only solution is to expand capacity.

[0036] The existing technology can also cache batch data in the database in the local memory of the microservice to improve the data query performance of the microservice. However, the local memory resources of the microservice are very precious, and the data that can be stored is very limited, so it is impossible to cache data in batches.

[0037] Therefore, the present application proposes a data caching method to implement distributed localized caching of cached data, implement batch caching of cached data, and improve the performance of microservices at the same time.

[0038] The data caching method proposed in this application will be described in detail below with reference to diagrams and embodiments.

[0039] Figure 2 The flowchart of a data caching method provided by an embodiment of the present invention is applicable to the situation where it is necessary to batch cache the cached data while improving the performance of microservices. The method can be executed by a data caching device, which can be implemented by software and / or hardware. Figure 2 The method specifically comprises the following steps:

[0040] Step 210: construct a hash ring according to the number of machine nodes in the current microservice and the number of virtual nodes in the consistent hashing algorithm.

[0041] Among them, each position in the hash ring corresponds to each virtual node of each machine node in the current microservice.

[0042] The current microservice contains multiple machine nodes, each of which can be used to cache data. In order to batch cache the data to be cached and improve the performance of the current microservice, the data to be cached can be cached to each machine node of the current microservice. In order to facilitate the correspondence between the cache location of the data to be cached and the machine node of the current microservice, a hash ring can be constructed based on the machine node of the current microservice.

[0043] Specifically, first, the number of machine nodes in the current microservice and the number of virtual nodes in the consistent hashing algorithm can be determined. Secondly, the number of positions in the hash ring can be determined according to the number of machine nodes in the current microservice and the number of virtual nodes corresponding to each machine node determined by the number of virtual nodes in the consistent hashing algorithm. Furthermore, the hash value of each virtual node is determined according to the instance IP of each machine node in the current microservice and the index number of each virtual node. For each virtual node, the unique position corresponding to the virtual node is determined on the hash ring based on the hash value of the virtual node to achieve the construction of the hash ring.

[0044] In an embodiment of the present invention, the number of positions in the hash ring can be determined according to the number of machine nodes in the current microservice and the number of virtual nodes in the consistent hashing algorithm, and the position corresponding to each virtual node of each machine node in the current microservice is determined on the hash ring to realize the construction of the hash ring.

[0045] Step 220: Receive the data to be cached, determine the hash value corresponding to each of the data to be cached based on the consistent hashing algorithm, and perform data segmentation on the data to be cached based on the hash value corresponding to each of the data to be cached.

[0046] The data to be cached are all key-value data, and the cache location of the data to be cached can be determined according to the keyword key of the data to be cached.

[0047] Specifically, after receiving the data to be cached, the data synchronization service can determine the hash value corresponding to each data to be cached based on the consistent hashing algorithm. Specifically, the hash operation can be performed on the keyword of each data to be cached based on the consistent hashing algorithm to obtain the hash value corresponding to each data to be cached. While determining the hash value corresponding to each data to be cached, the data to be cached can be segmented based on the hash value corresponding to each data to be cached, so as to segment the data to be cached into at least one group of data to be cached, thereby achieving the segmentation of the data to be cached.

[0048] In an embodiment of the present invention, after receiving the data to be cached, the data synchronization service can determine the hash value corresponding to each data to be cached, and divide the data to be cached into at least one group of data to be cached according to the hash value corresponding to each data to be cached, thereby realizing the division of the data to be cached.

[0049] Step 230: determine the target machine node storing each group of data to be cached in the current microservice in the hash ring based on the hash values ​​corresponding to each group of data to be cached after the segmentation, and cache each group of data to be cached to the target machine node.

[0050] Specifically, each position in the hash ring corresponds to each virtual node of each machine node in the current microservice. For each group of data to be cached after segmentation, after determining the position corresponding to the hash value corresponding to the current group of data to be cached in the hash ring, determine the virtual node corresponding to the position, and determine the machine node to which the virtual node belongs as the target machine node for caching the current group of data to be cached. After determining the target machine nodes for caching each group of data to be cached, each group of data to be cached can be cached to each target machine node, and batch caching of the data to be cached can be achieved with the limited local memory of the current microservice. At the same time, the data to be cached cached to the machine node of the current microservice allows the current microservice to obtain data directly from the local memory without obtaining data from the Redis cluster, thereby improving the performance of the current microservice.

[0051] In an embodiment of the present invention, for each group of data to be cached after segmentation, the corresponding position in the hash ring is determined according to the hash value corresponding to the current group of data to be cached, and the machine node to which the virtual node corresponding to the position belongs is determined as the target machine node for caching the current group of data to be cached, thereby determining the target machine node corresponding to each group of data to be cached, and then each group of data to be cached can be cached to the corresponding target machine node, thereby realizing batch caching of the data to be cached.

[0052] The data caching method provided by an embodiment of the present invention includes: constructing a hash ring according to the number of machine nodes in the current microservice and the number of virtual nodes in a consistent hashing algorithm, wherein each position in the hash ring corresponds to each virtual node of each machine node in the current microservice; receiving data to be cached, determining a hash value corresponding to each data to be cached based on the consistent hashing algorithm, and performing data segmentation on the data to be cached based on the hash value corresponding to each data to be cached; determining in the hash ring a target machine node for storing each group of data to be cached in the current microservice based on the hash value corresponding to each group of data to be cached after segmentation, and caching each group of data to be cached to the target machine node. The above technical solution, first, can determine the number of positions of the hash ring according to the number of machine nodes in the current microservice and the number of virtual nodes in the consistent hash algorithm, and secondly, determine the position corresponding to each virtual node of each machine node in the current microservice on the hash ring to realize the construction of the hash ring. After receiving the data to be cached, the hash value corresponding to each data to be cached can be determined, and the data to be cached can be divided into at least one group of data to be cached according to the hash value corresponding to each data to be cached, so as to realize the segmentation of the data to be cached. For each group of data to be cached after segmentation, the corresponding position is determined in the hash ring according to the hash value corresponding to the current group of data to be cached, and the machine node to which the virtual node corresponding to the position belongs is determined as the target machine node for caching the current group of data to be cached, so as to realize the determination of the target machine node corresponding to each group of data to be cached, and then each group of data to be cached can be cached to the corresponding target machine node, so as to realize the batch caching of the data to be cached. Of course, the data to be cached cached to the machine node of the current microservice enables the current microservice to directly obtain data from the local memory, thereby improving the performance of the current microservice.

[0053] Figure 3 A flowchart of another data caching method provided by an embodiment of the present invention. The embodiment of the present invention can be applied to situations where it is necessary to batch cache the data to be cached while improving the performance of microservices. Based on the above embodiment, after the data to be cached is segmented based on the hash values ​​corresponding to each of the data to be cached, the embodiment of the present invention adds "storing each group of data to be cached after segmentation into the data buffer pool." The explanations of the terms that are the same or corresponding to the above embodiments are not repeated here. Figure 3 , the data caching method provided by the embodiment of the present invention includes:

[0054] Step 310: construct a hash ring according to the number of machine nodes in the current microservice and the number of virtual nodes in the consistent hashing algorithm.

[0055] Among them, each position in the hash ring corresponds to each virtual node of each machine node in the current microservice.

[0056] In one implementation, step 310 may specifically include:

[0057] Determine the number of positions of the hash ring according to the number of machine nodes in the current microservice and the number of virtual nodes in the consistent hashing algorithm; determine the hash value of each virtual node of each machine node in the current microservice, and determine the position of each virtual node in the hash ring according to the hash value of each virtual node to obtain the hash ring.

[0058] Specifically, first, the number of machine nodes in the current microservice and the number of virtual nodes in the consistent hashing algorithm can be determined, and the number of virtual nodes of each machine node in the current microservice can be determined according to the number of virtual nodes in the consistent hashing algorithm. Then, the number of positions in the hash ring can be determined according to the number of machine nodes in the current microservice and the number of virtual nodes of each machine node in the current microservice. Secondly, the hash value of each virtual node of each machine node in the current microservice can be determined, and the position of each virtual node in the hash ring can be determined according to the hash value of each virtual node, so as to determine the virtual nodes corresponding to each position of the hash ring and obtain the hash ring.

[0059] Further, determining the hash value of each virtual node of each machine node in the current microservice includes:

[0060] Determine the location identifier of each virtual node of each machine node in the current microservice, and determine the hash value of each virtual node according to the location identifier of each virtual node.

[0061] Specifically, first, the location identifier of each virtual node of each machine node in the current microservice can be determined according to the instance IP of each machine node in the current microservice and the index number of each virtual node. The instance IP of each machine node in the current microservice can be understood as the unique identifier of each machine node, and the index number of each virtual node can be understood as the unique identifier of each virtual node in all virtual nodes corresponding to the machine node to which it belongs. According to the unique identifier of each machine node in the current microservice and the unique identifier of each virtual node in all virtual nodes corresponding to the machine node to which it belongs, the location identifier of each virtual node is determined. Furthermore, the hash value of each virtual node is determined according to the location identifier of each virtual node.

[0062] In actual applications, the number of machine nodes in the current microservice is 8, the number of virtual nodes in the consistent hashing algorithm is 8, and the instance IPs of the 8 machine nodes are represented by A, B, C, D, E, F, G, and H respectively. Figure 4 A schematic diagram of a hash ring constructed in another data caching method provided in an embodiment of the present invention, such as Figure 4As shown in the figure, 8 machine nodes are virtualized into 8 virtual nodes, and it can be determined that there are 64 positions in the hash ring. The instance IP of the machine node is A, and it can be determined that the virtual node virtualized by the machine node with instance IP A is A. i , i = 1, 2, 3…8, and so on. It can be determined that the virtual node virtualized by the machine node with instance IP B is B. i , i = 1, 2, 3…8, the virtual node virtualized by the machine node with instance IP C is C i , i = 1, 2, 3…8, the virtual node virtualized by the machine node with instance IP D is D i , i = 1, 2, 3…8, the virtual node virtualized by the machine node with instance IP E is E i , i = 1, 2, 3 ... 8, the virtual node virtualized by the machine node with instance IP F is F i , i = 1, 2, 3…8, the virtual node virtualized by the machine node with instance IP G is G i , i = 1, 2, 3…8, the virtual node virtualized by the machine node with instance IP H is H i ,i=1,2,3…8.

[0063] Then, the location identifier of each virtual node is determined by splicing the instance IP of each machine node in the current microservice with the index number of each virtual node. After determining the location identifier of each virtual node, the hash value of each virtual node is determined based on Formula 1, that is, the instance IP of the machine node is spliced ​​with the index number of the virtual node, the hash value is calculated, and then the modulus is taken by 64, so that each virtual node can find a unique corresponding position on the hash ring, and the hash ring is constructed.

[0064] idHashValue=hash(IP+i)%64,i=1,2,3…8 Formula 1

[0065] Among them, ip represents the location identifier of the virtual node, IP represents the unique identifier of the machine node to which the virtual node belongs, and i represents the unique identifier of the virtual node among all virtual nodes corresponding to the machine node to which it belongs.

[0066] In an embodiment of the present invention, the number of positions in the hash ring can be determined according to the number of machine nodes in the current microservice and the number of virtual nodes in the consistent hashing algorithm, and the position corresponding to each virtual node of each machine node in the current microservice is determined on the hash ring to realize the construction of the hash ring.

[0067] Step 320: Receive data to be cached.

[0068] In one implementation, step 320 may specifically include:

[0069] The data to be cached is received and sent by the database based on a message queue.

[0070] Figure 5 The interaction diagram of the upstream microservice, current microservice, data synchronization service, and database when data is cached in the local memory of the current microservice, such as Figure 5 As shown, in order to solve the data delay problem, the database can send the data to be cached to the data synchronization service through a message queue (MQ). Therefore, the data synchronization service can receive the data to be cached sent by the database based on the message queue.

[0071] It should be noted that the data to be cached received by the data synchronization service is key-value data.

[0072] In the embodiment of the present invention, the data synchronization service receives the data to be cached sent by the database based on the message queue method, thereby solving the problem of data delay.

[0073] Step 330: Determine the hash value corresponding to each of the to-be-cached data based on the consistent hashing algorithm, and segment the to-be-cached data based on the hash value corresponding to each of the to-be-cached data.

[0074] In one implementation, step 330 may specifically include:

[0075] Determine the hash value corresponding to each of the data to be cached based on the consistent hashing algorithm; perform data segmentation on the data to be cached based on each of the hash values ​​to obtain at least one group of data to be cached, wherein the hash values ​​corresponding to the same group of data to be cached are consistent.

[0076] Specifically, based on the consistent hashing algorithm, the keywords of the cached data are subjected to consistent hashing calculation to obtain the hash value corresponding to the cached data. When the cached data is a user ID and a user risk value in the form of key-value, the keyword of the cached data is the user ID, and the user ID is subjected to consistent hashing calculation based on Formula 2, that is, the hash value of the user ID is calculated, and then modulo 64 is taken to obtain the hash value corresponding to the cached data.

[0077] idHashValue=hash(id)%64 Formula 2

[0078] Here, id represents the user ID.

[0079] While determining the hash value corresponding to each data to be cached, the data to be cached can be segmented based on the hash value corresponding to each data to be cached, so as to segment the data to be cached into at least one group of data to be cached, thereby achieving segmentation of the data to be cached. Of course, the hash values ​​corresponding to each group of data to be cached are different, and the hash values ​​corresponding to the same group of data to be cached are consistent.

[0080] The amount of data to be cached is 1 billion. The number of machine nodes in the current microservice is 100. After the data to be cached is divided by the consistent hashing algorithm, each machine node needs to cache 10 million data. When 10 million data are cached in off-heap memory, 500M is required, that is, each machine node only needs to extract 500M memory to cache the data to be cached.

[0081] In an embodiment of the present invention, after receiving the data to be cached, the data synchronization service can determine the hash value corresponding to each data to be cached, and divide the data to be cached into at least one group of data to be cached according to the hash value corresponding to each data to be cached, thereby realizing the division of the data to be cached.

[0082] Step 340: Determine, in the hash ring, a target machine node storing each group of data to be cached in the current microservice based on the hash values ​​corresponding to each group of data to be cached after segmentation.

[0083] As mentioned above, each position in the hash ring corresponds to each virtual node of each machine node in the current microservice. For each group of data to be cached after segmentation, after determining the position corresponding to the hash value corresponding to the current group of data to be cached in the hash ring, determine the virtual node corresponding to the position, and determine the machine node to which the virtual node belongs as the target machine node for caching the current group of data to be cached.

[0084] In one implementation, step 340 may specifically include:

[0085] The target position is determined in the hash ring based on the hash values ​​corresponding to the divided groups of data to be cached; and the target machine node storing the groups of data to be cached in the current microservice is determined according to the virtual node corresponding to the target position.

[0086] Further, determining the target machine node storing each group of data to be cached in the current microservice according to the virtual node corresponding to the target location includes:

[0087] When it is determined that the running status of the machine node to which the virtual node corresponding to the target position belongs is normal, the machine node to which the virtual node corresponding to the target position belongs is determined as the target machine node; when it is determined that the running status of the machine node to which the virtual node corresponding to the target position belongs is abnormal, the target virtual node is determined on the hash ring according to the virtual node corresponding to the target position, and the machine node to which the target virtual node belongs is determined as the target machine node.

[0088] Optionally, determining the target virtual node on the hash ring according to the virtual node corresponding to the target position includes:

[0089] The virtual node corresponding to the next position corresponding to the target position on the hash ring is determined as the target virtual node.

[0090] Specifically, for each group of data to be cached after segmentation, a unique target position can be determined in the hash ring according to the hash value corresponding to the current group of data to be cached. The target position also uniquely corresponds to a virtual node. Furthermore, the target machine node used to cache the current group of data to be cached in the current microservice can be determined according to the virtual node corresponding to the target position. When the operating status of the machine node to which the virtual node corresponding to the target position belongs is normal, the machine node to which the virtual node corresponding to the target position belongs is determined as the target solar term node; otherwise, the virtual node corresponding to the next position corresponding to the target position on the hash ring is determined as the target virtual node, and the machine node to which the target virtual node belongs is determined as the target machine node, and the target machine node can cache the current group of data to be cached. Finally, it is possible to determine the target machine node corresponding to each group of data to be cached.

[0091] For example, when the running status of machine node A is abnormal, the hash value corresponding to the current group of cached data can determine the unique target location in the hash ring, and the corresponding virtual node is A. i ,i=1,2,3…8, the virtual node B1 C2 D3 E4 F5 G6 H7 B8 corresponding to the next position corresponding to the target position on the hash ring can be determined as the target virtual node in a clockwise direction. It can be obtained that the current microservice has a total of n machine nodes, and the operating status of k machine nodes is abnormal. The number of virtual nodes in the consistent hashing algorithm is i. When n,i is large enough, the proportion of the offset traffic at this time λ=k / n, that is, the traffic of the machine node with abnormal operating status will be almost evenly distributed to other machine nodes.

[0092] In an embodiment of the present invention, for each group of data to be cached after segmentation, the corresponding position is determined in the hash ring according to the hash value corresponding to the current group of data to be cached, and the machine node to which the virtual node corresponding to the position belongs is determined as the target machine node for caching the current group of data to be cached, thereby determining the target machine node corresponding to each group of data to be cached.

[0093] Step 350: Cache each group of data to be cached to the target machine node.

[0094] In one implementation, step 350 may specifically include:

[0095] Each group of data to be cached is sent to the target machine node based on the TCP long link, so that the target machine node caches the keywords of each group of data to be cached into the in-heap cache and caches each group of data to be cached into the out-heap cache.

[0096] Specifically, in order to further solve the problem of data delay, the data synchronization service establishes a TCP long link with each machine node of the current microservice. The data synchronization service receives the data to be cached sent by the database through the message queue, and after splitting the data to be cached, each group of data to be cached obtained by the split can be pushed to the corresponding machine node through each TCP long link to control the data delay within 5ms.

[0097] In current microservices, if data is cached in the heap memory, it will not only occupy a large amount of local memory, but also cause too much unnecessary burden on the garbage collection (GC) mechanism of the current microservice. Under normal circumstances, the GC mechanism will scan all local memory and recycle objects without any references at irregular intervals when the memory is idle or the memory usage is too high. The more data cached in the local memory, the more CPU resources are occupied by scanning the data and the longer the service is suspended. Therefore, in order to cache as much data as possible in the limited local memory, after the target machine node receives the data to be cached sent by the data synchronization service, it can serialize the keywords of the data to be cached and save them in the heap memory. Caching the data to be cached in the off-heap cache will not only reduce the usage of local memory, but also reduce the impact on the GC mechanism.

[0098] Figure 6 A schematic diagram of caching data to be cached in another data caching method provided by an embodiment of the present invention, such as Figure 6 As shown in the figure, the structure of the in-heap cache includes a Map object that provides basic interface operations and a segment structure. The segment structure can implement segment locks and improve microservice performance. Each segment structure corresponds to a group of buckets with consecutive memory addresses, called hashTable. Buckets are used to maintain data linked lists. The data that really needs to be cached is stored in the Data node. The hashTable and Data structure are both stored in the off-heap memory.

[0099] Figure 7 A schematic diagram of a data structure of data to be cached stored in a Data node in another data caching method provided by an embodiment of the present invention, such as Figure 7 As shown, the data to be cached stored in the Data node includes 6 data headers and data. Table 1 shows the meaning of each data header. The data includes key and value. The key and value are serialized into byte arrays and then concatenated together to form hashEntry data.

[0100] Table 1

[0101] Serial number name Occupied Bytes meaning 0 NEXT 8 The next node of the normal linked list 1 REFCOUNT 8 The number of references to hashEntry 2 EXPIRE_AT 8 Specific data expiration time 3 HASH 8 hashEntry hash value 4 KEY-LENGTH 4 The key length of hashEntry 5 VALUE-LENGTH 4 The length of hashEntry value

[0102] In addition, when searching for data, calculate the hash value of the key, find the corresponding segment and bucket based on the hash value, and then traverse the Data nodes of the bucket until the Data node storing the data corresponding to the key is found. When adding new data, calculate the hash value of the key, find the corresponding segment and bucket based on the hash value, add a Data node to the bucket, store the newly added data in the newly added Data node, and place the newly added Data node at the end of the bucket. In order to appropriately reduce the number of buckets traversed, the number of buckets can be appropriately increased, but the increase in the number of buckets will also cause more memory to be occupied. Therefore, the number of buckets can be determined based on actual conditions.

[0103] It should be noted that the data synchronization service also subscribes to the incremental update data of the database. The data synchronization service also splits the incremental update data through the consistent hashing algorithm, and caches each group of incremental update data obtained by the split to the machine node of the current microservice, thereby realizing full data update and real-time data update.

[0104] The above solution improves the performance of the current microservices and reduces the consumption of machine resources. However, there are still the following problems: availability problem, hot key problem, and data consistency problem.

[0105] For the availability issue, in order to ensure that the upstream microservice can correctly find the corresponding data cache each time it calls the current microservice through RPC, a set of consistent hashing algorithm load balancing needs to be defined for RPC. The routing strategy of the consistent hashing algorithm load balancing is consistent with the consistent hashing algorithm data segmentation strategy used by the data synchronization service to segment the data to be cached. If any machine node of the current microservice is down (downtime or restart), it will affect the load balancing routing of the RPC call, that is, routing deviation will occur, and the request that should be routed to machine node A will be routed to machine node B. Of course, after these requests are identified, data can be obtained by querying the data source. The number of machine nodes in the current microservice is n, and the number of machine nodes that have been down is k, then the ratio of deviation requests is k / n. Deviation requests can be identified and directed to the data source to determine the data corresponding to the deviation request using the traditional Redis+DB solution, thereby ensuring that the availability of the current microservice will not be affected. In addition, in order to finally eliminate deviation requests, the data synchronization service can re-trigger the data redistribution logic, that is, the number of machine nodes in the current microservice can be determined as nk, and the data to be cached can be re-segmented based on the consistent hashing algorithm.

[0106] For the hot key problem, when a hot key occurs in the current microservice, a machine node will have too high traffic, resulting in too high CPU and too slow response, which is much different from the expected TP999 0ms (about 10us), even reaching the second level, thus causing a chain reaction of upstream microservices. To solve the hot key problem, hot key detection is introduced. After the current microservice finds the hot key based on hot key detection, it adds the hot key in the response and returns it to the upstream microservice. The upstream microservice can locally cache the data cached by the machine node where the hot key occurs, thereby avoiding the hot traffic from hitting the current microservice.

[0107] Figure 8 A schematic diagram of data push in another data caching method provided by an embodiment of the present invention, such as Figure 8 As shown, the data synchronization service includes a real-time data processing module and a data push module. The real-time data processing module is used to segment the received real-time data and write each group of segmented real-time data into a data buffer pool. The data push module communicates in real time through a TCP long link between the machine nodes of the current microservice. The communication content includes data push, status reporting, command issuance, etc.

[0108] Regarding the data consistency issue, the local memory of the current microservice caches data and keeps updating it all the time. As time goes by, there is a problem of data consistency between the data in the local memory and the data in the data source. To reduce the impact of data consistency, on the one hand, the data is cached in the local memory and kept updated in full. The local memory is cleared every day and a new copy of data is reloaded. Specifically, an offline task can be set to run a copy of T+1 stock data at a fixed time every day, with a deadline of 0:00 on the same day. The data file is saved in the object storage service. When a machine node is restarted, in order to quickly load historical data (including T+1 stock data and real-time data of the day), the machine node will first load the latest T+1 stock data into the memory, and then load the real-time data from the buffer pool. To ensure that the data in the memory is as consistent as possible with the database, in addition to reloading when the machine node is restarted, when the offline task of T+1 is completed every day, it will also notify all machine nodes to reload the data. Of course, in order to keep the data service uninterrupted, data can be loaded by switching between AB tables; on the other hand, a scheduled task can be set to sample and verify the data.

[0109] In an embodiment of the present invention, batches of data to be cached are cached in the machine nodes of the current microservice. Each machine node only needs to cache a part of the data, and all data cached by all machine nodes is the full data, so that the current microservice can directly obtain data from the local memory, reducing the network IO delay consumption caused by the current microservice accessing the Redis cluster.

[0110] After executing step 330 , step 360 may also be executed.

[0111] Step 360: Store each group of data to be cached in the data buffer pool.

[0112] Specifically, for each group of data to be cached after segmentation, the data synchronization service may also write each group of data to be cached into a data buffer pool.

[0113] When it is determined that any machine node in the current microservice has been restarted, the full data can be loaded according to the above steps, and then the historical data can be appended from the data buffer pool to avoid multiple requests to the database.

[0114] In the embodiment of the present invention, after segmenting the data to be cached, the data synchronization service may also write the segmented groups of data to be cached into the data buffer pool to implement backup of the data to be cached and avoid multiple requests to the database.

[0115] When the upstream microservice is the order service and the current microservice is the user risk identification service, after the user risk identification service receives the user risk identification request sent by the order service, it needs to determine the user risk value based on the user ID contained in the user risk identification request. At this time, the data to be cached received by the data synchronization service is the user ID and user risk value in the form of key-value.

[0116] The data synchronization service can determine the hash value corresponding to the user identifier in the data to be cached based on the consistent hashing algorithm, and perform data segmentation on the data to be cached based on the hash value to obtain at least one group of data to be cached. Specifically, the data to be cached corresponding to the user identifier corresponding to the same hash value can be divided into the same group of data to be cached. According to the hash value corresponding to the user identifier in the data to be cached, the target position is determined in the hash ring, and the machine node to which the virtual node corresponding to the target position belongs is determined as the target machine node for storing each group of data to be cached. Each group of data to be cached is cached to the corresponding target machine node to achieve caching of the data to be cached.

[0117] After the order service receives the order request triggered by the current user, it needs to determine whether the current user is a risky user. Specifically, the order service calls the user risk identification service through RPC. After the user risk identification service receives the user risk identification request sent by the order service, it determines the corresponding user risk value based on the user identifier contained in the user risk identification request, and determines whether the user risk value is greater than the preset threshold. If the user risk value is greater than the preset threshold, it returns that the current user is a risky user, otherwise it returns that the current user is a risk-free user. After the order service receives the return result of the user risk identification service, it decides whether to allow the current user to continue to submit orders based on whether the return result is a risky user. The consistent hashing algorithm load balancing strategy used by the order service when remotely calling the user risk identification service through RPC is completely consistent with the consistent hashing algorithm used for data segmentation. In this way, the order service only needs to use the user identifier as a routing parameter to select the corresponding machine node for remote calling. The order service receives the order request from user q, and requests the user risk identification service based on RPC. The user risk identification service calculates hash(q)%64=22 based on the consistent hashing algorithm load balancing, and then determines that the machine node H to which the virtual node H3 corresponding to position 22 belongs on the hash ring is determined. The order service can perform a remote RPC call based on machine node H.

[0118] The data caching method provided by an embodiment of the present invention includes: constructing a hash ring according to the number of machine nodes in the current microservice and the number of virtual nodes in the consistent hashing algorithm; receiving data to be cached; determining the hash value corresponding to each data to be cached based on the consistent hashing algorithm, and performing data segmentation on the data to be cached based on the hash value corresponding to each data to be cached; determining the target machine node for storing each group of data to be cached in the current microservice based on the hash value corresponding to each group of data to be cached after segmentation; caching each group of data to be cached to the target machine node; and storing each group of data to be cached in a data buffer pool. In the above technical solution, first, the data synchronization service can determine the number of positions of the hash ring according to the number of machine nodes in the current microservice and the number of virtual nodes in the consistent hashing algorithm. Secondly, the position corresponding to each virtual node of each machine node in the current microservice is determined on the hash ring to realize the construction of the hash ring. The data synchronization service can receive the data to be cached sent by the database based on the message queue method to solve the data delay problem. After receiving the data to be cached, the hash value corresponding to each data to be cached can be determined, and the data to be cached can be divided into at least one group of data to be cached according to the hash value corresponding to each data to be cached, so as to realize the segmentation of the data to be cached. The data to be cached in the group is determined according to the hash value corresponding to the current group of data to be cached. The machine node to which the virtual node corresponding to the position belongs is determined as the target machine node for caching the data to be cached in the current group, so as to determine the target machine node corresponding to each group of data to be cached. Then, the batch of data to be cached can be cached in the machine node of the current microservice. Each machine node only needs to cache a part of the data, and all the data cached by all machine nodes is the full data, so that the current microservice can directly obtain data from the local memory, reducing the network IO delay consumption caused by the current microservice accessing the Redis cluster, and improving the performance of the current microservice. After the data synchronization service divides the data to be cached, it can also write the divided groups of data to be cached into the data buffer pool to realize the backup of the cached data and avoid multiple requests to the database.

[0119] In addition, based on the consistent hashing algorithm, the data to be cached is batch-cached to the local memory of the current microservice, which can significantly reduce machine costs and significantly improve the performance of the current microservice, thereby improving the throughput of the current microservice. In terms of machine resources, compared with traditional solutions, the current microservice itself can save 73% of machine resources, and the Redis cluster can save 75% of machine resources. In terms of performance, compared with traditional solutions, the performance of the current microservice providing services to the outside world has been improved from milliseconds to microseconds, which is hundreds of times better.

[0120] Fig. 9The structure diagram of a data cache device provided by an embodiment of the present invention is shown in FIG. The device and the data cache methods of the above embodiments belong to the same inventive concept. For details not described in detail in the embodiment of the data cache device, reference can be made to the embodiment of the above data cache method.

[0121] The specific structure of the data cache device is as follows: Fig. 9 As shown, including:

[0122] A construction module 910 is used to construct a hash ring according to the number of machine nodes in the current microservice and the number of virtual nodes in the consistent hashing algorithm, wherein each position in the hash ring corresponds to each virtual node of each machine node in the current microservice;

[0123] The segmentation module 920 is used to receive the data to be cached, determine the hash value corresponding to each of the data to be cached based on the consistent hashing algorithm, and perform data segmentation on the data to be cached based on the hash value corresponding to each of the data to be cached;

[0124] The cache module 930 is used to determine the target machine node storing each group of data to be cached in the current microservice in the hash ring based on the hash values ​​corresponding to each group of data to be cached after the segmentation, and cache each group of data to be cached to the target machine node.

[0125] Based on the above embodiment, a module 910 is constructed, which is specifically used for:

[0126] Determine the number of positions of the hash ring according to the number of machine nodes in the current microservice and the number of virtual nodes in the consistent hashing algorithm;

[0127] Determine the hash value of each virtual node of each machine node in the current microservice, determine the position of each virtual node in the hash ring according to the hash value of each virtual node, and obtain the hash ring.

[0128] In one implementation, determining the hash value of each virtual node of each machine node in the current microservice includes:

[0129] Determine the location identifier of each virtual node of each machine node in the current microservice, and determine the hash value of each virtual node according to the location identifier of each virtual node.

[0130] Based on the above embodiment, the segmentation module 920 is specifically used for:

[0131] Receive the data to be cached sent by the database based on a message queue; determine the hash value corresponding to each data to be cached based on the consistent hashing algorithm; perform data segmentation on the data to be cached based on each hash value to obtain at least one group of data to be cached, wherein the hash values ​​corresponding to the same group of data to be cached are consistent.

[0132] Based on the above embodiment, the cache module 930 is specifically used for:

[0133] Based on the hash values ​​corresponding to the divided groups of data to be cached, a target position is determined in the hash ring; according to the virtual nodes corresponding to the target positions, a target machine node storing each group of data to be cached in the current microservice is determined; based on a TCP long link, each group of data to be cached is sent to the target machine node, so that the target machine node caches the keywords of each group of data to be cached into an in-heap cache, and caches each group of data to be cached into an off-heap cache.

[0134] In one implementation, determining the target machine node storing each group of data to be cached in the current microservice according to the virtual node corresponding to the target location includes:

[0135] When it is determined that the running status of the machine node to which the virtual node corresponding to the target position belongs is normal, the machine node to which the virtual node corresponding to the target position belongs is determined as the target machine node; when it is determined that the running status of the machine node to which the virtual node corresponding to the target position belongs is abnormal, the target virtual node is determined on the hash ring according to the virtual node corresponding to the target position, and the machine node to which the target virtual node belongs is determined as the target machine node.

[0136] Optionally, determining the target virtual node on the hash ring according to the virtual node corresponding to the target position includes:

[0137] The virtual node corresponding to the next position corresponding to the target position on the hash ring is determined as the target virtual node.

[0138] Based on the above embodiment, the device further includes:

[0139] The storage module is used to store the divided groups of cached data into a data buffer pool.

[0140] The data caching device provided in the embodiment of the present invention can execute the data caching method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of executing the data caching method.

[0141] It is worth noting that in the embodiment of the above-mentioned data caching device, the various units and modules included are only divided according to functional logic, but are not limited to the above-mentioned division, as long as the corresponding functions can be achieved; in addition, the specific names of the functional units are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of the present invention.

[0142] Fig.10 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. Fig.10 A block diagram of an exemplary electronic device 10 suitable for use in implementing embodiments of the present invention is shown. Fig.10 The electronic device 10 shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.

[0143] like Fig.10 As shown, electronic device 10 is in the form of a general purpose computing electronic device. Components of electronic device 10 may include, but are not limited to: one or more processors or processing units 16, system memory 28, and bus 18 connecting various system components (including system memory 28 and processing unit 16).

[0144] Bus 18 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processor or a local bus using any of a variety of bus architectures. By way of example, these architectures include, but are not limited to, an Industry Standard Architecture (ISA) bus, a Micro Channel Architecture (MAC) bus, an Enhanced ISA bus, a Video Electronics Standards Association (VESA) local bus, and a Peripheral Component Interconnect (PCI) bus.

[0145] The electronic device 10 typically includes a variety of computer system readable media. These media can be any available media that can be accessed by the electronic device 10, including volatile and non-volatile media, removable and non-removable media.

[0146] The system memory 28 may include computer system readable media in the form of volatile memory, such as random access memory (RAM) 30 and / or cache memory 32. The electronic device 10 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, the storage system 34 may be used to read and write non-removable, non-volatile magnetic media ( Fig.10 not shown, usually called a "hard drive"). Although Fig.10Not shown in the figure, a disk drive for reading and writing to a removable non-volatile disk (e.g., a "floppy disk"), and an optical disk drive for reading and writing to a removable non-volatile optical disk (e.g., a CD-ROM, a DVD-ROM, or other optical media) may be provided. In these cases, each drive may be connected to the bus 18 via one or more data medium interfaces. The system memory 28 may include at least one program product having a set (e.g., at least one) of program modules that are configured to perform the functions of the various embodiments of the present invention.

[0147] A program / utility 40 having a set (at least one) of program modules 42 may be stored, for example, in system memory 28, such program modules 42 including, but not limited to, an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment. Program modules 42 generally perform the functions and / or methods of the embodiments described herein.

[0148] The electronic device 10 may also communicate with one or more external devices 14 (e.g., keyboards, pointing devices, displays 24, etc.), one or more devices that enable a user to interact with the electronic device 10, and / or any device that enables the electronic device 10 to communicate with one or more other computing devices (e.g., network cards, modems, etc.). Such communication may be performed through an input / output (I / O) interface 22. Furthermore, the electronic device 10 may also communicate with one or more networks (e.g., a local area network (LAN), a wide area network (WAN), and / or a public network, such as the Internet) through a network adapter 20. Fig.10 As shown, the network adapter 20 communicates with other modules of the electronic device 10 via the bus 18. It should be understood that although Fig.10 Not shown, other hardware and / or software modules may be used in conjunction with the electronic device 10, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.

[0149] The processing unit 16 executes various functional applications and page displays by running the programs stored in the system memory 28, for example, implementing the data caching method provided in the embodiment of the present invention, which includes:

[0150] Constructing a hash ring according to the number of machine nodes in the current microservice and the number of virtual nodes in the consistent hashing algorithm, wherein each position in the hash ring corresponds to each virtual node of each machine node in the current microservice;

[0151] Receive data to be cached, determine hash values ​​corresponding to each of the data to be cached based on the consistent hashing algorithm, and perform data segmentation on the data to be cached based on the hash values ​​corresponding to each of the data to be cached;

[0152] Based on the hash values ​​corresponding to the divided groups of data to be cached, the target machine nodes storing the groups of data to be cached in the current microservice are determined in the hash ring, and the groups of data to be cached are cached to the target machine nodes.

[0153] Of course, those skilled in the art can understand that the processor can also implement the technical solution of the data caching method provided by any embodiment of the present invention.

[0154] An embodiment of the present invention provides a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, for example, a data caching method provided in an embodiment of the present invention is implemented. The method includes:

[0155] Constructing a hash ring according to the number of machine nodes in the current microservice and the number of virtual nodes in the consistent hashing algorithm, wherein each position in the hash ring corresponds to each virtual node of each machine node in the current microservice;

[0156] Receive data to be cached, determine hash values ​​corresponding to each of the data to be cached based on the consistent hashing algorithm, and perform data segmentation on the data to be cached based on the hash values ​​corresponding to each of the data to be cached;

[0157] Based on the hash values ​​corresponding to the divided groups of data to be cached, the target machine nodes storing the groups of data to be cached in the current microservice are determined in the hash ring, and the groups of data to be cached are cached to the target machine nodes.

[0158] The computer storage medium of the embodiment of the present invention can adopt any combination of one or more computer-readable media. The computer-readable medium can be a computer-readable signal medium or a computer-readable storage medium. The computer-readable storage medium can be, for example, but not limited to: an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples (non-exhaustive list) of computer-readable storage media include: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this document, a computer-readable storage medium can be any tangible medium containing or storing a program, which can be used by an instruction execution system, device or device or used in combination with it.

[0159] Computer-readable signal media may include data signals propagated in baseband or as part of a carrier wave, which carry computer-readable program code. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than a computer-readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.

[0160] The program code embodied on the computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.

[0161] Computer program code for performing the operations of the present invention may be written in one or more programming languages ​​or a combination thereof, including object-oriented programming languages ​​such as Java, Smalltalk, C++, and conventional procedural programming languages ​​such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0162] It should be understood by those skilled in the art that the modules or steps of the present invention described above can be implemented by a general-purpose computing device, they can be concentrated on a single computing device, or distributed on a network composed of multiple computing devices, optionally, they can be implemented by a program code executable by a computer device, so that they can be stored in a storage device and executed by the computing device, or they can be made into individual integrated circuit modules, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. Thus, the present invention is not limited to any specific combination of hardware and software.

[0163] It should be noted that the collection, collection, updating, analysis, processing, use, transmission, storage and other aspects of user personal information involved in the technical solution of this disclosure are in compliance with the provisions of relevant laws and regulations, are used for legitimate purposes, and do not violate public order and good morals. Necessary measures are taken for user personal information to prevent illegal access to user personal information data and maintain the security of user personal information, network security and national security.

[0164] After collecting the data to be cached, we will de-identify the data through technical means.

[0165] Note that the above are only preferred embodiments of the present invention and the technical principles used. Those skilled in the art will understand that the present invention is not limited to the specific embodiments herein, and that various obvious changes, readjustments and substitutions can be made by those skilled in the art without departing from the scope of protection of the present invention. Therefore, although the present invention has been described in more detail through the above embodiments, the present invention is not limited to the above embodiments, and may include more other equivalent embodiments without departing from the concept of the present invention, and the scope of the present invention is determined by the scope of the appended claims.

Claims

1. A data caching method, characterized in that: include: Constructing a hash ring according to the number of machine nodes in the current microservice and the number of virtual nodes in the consistent hashing algorithm, wherein each position in the hash ring corresponds to each virtual node of each machine node in the current microservice; Receive data to be cached, determine hash values ​​corresponding to each of the data to be cached based on the consistent hashing algorithm, and perform data segmentation on the data to be cached based on the hash values ​​corresponding to each of the data to be cached; Based on the hash values ​​corresponding to the divided groups of data to be cached, the target machine nodes storing the groups of data to be cached in the current microservice are determined in the hash ring, and the groups of data to be cached are cached to the target machine nodes.

2. The data caching method according to claim 1, characterized in that: A hash ring is constructed based on the number of machine nodes in the current microservice and the number of virtual nodes in the consistent hashing algorithm, including: Determine the number of positions of the hash ring according to the number of machine nodes in the current microservice and the number of virtual nodes in the consistent hashing algorithm; Determine the hash value of each virtual node of each machine node in the current microservice, determine the position of each virtual node in the hash ring according to the hash value of each virtual node, and obtain the hash ring.

3. The data caching method according to claim 2, characterized in that: Determining the hash value of each virtual node of each machine node in the current microservice includes: Determine the location identifier of each virtual node of each machine node in the current microservice, and determine the hash value of each virtual node according to the location identifier of each virtual node.

4. The data caching method according to claim 1, characterized in that: Receive data to be cached, including: The data to be cached is received and sent by the database based on a message queue.

5. The data caching method according to claim 1, characterized in that: Determining a hash value corresponding to each of the to-be-cached data based on the consistent hashing algorithm, and performing data segmentation on the to-be-cached data based on the hash value corresponding to each of the to-be-cached data, including: Determine the hash value corresponding to each of the data to be cached based on the consistent hashing algorithm; The data to be cached is segmented based on each of the hash values ​​to obtain at least one group of data to be cached, wherein the hash values ​​corresponding to the same group of data to be cached are consistent.

6. The data caching method according to claim 1, characterized in that: Determining the target machine node storing each group of data to be cached in the current microservice in the hash ring based on the hash values ​​corresponding to each group of data to be cached after the division, including: Determine the target position in the hash ring based on the hash values ​​corresponding to each group of data to be cached after segmentation; The target machine node storing each group of data to be cached in the current microservice is determined according to the virtual node corresponding to the target location.

7. The data caching method according to claim 6, characterized in that: Determining the target machine node storing each group of data to be cached in the current microservice according to the virtual node corresponding to the target location includes: When it is determined that the running state of the machine node to which the virtual node corresponding to the target position belongs is normal, determining the machine node to which the virtual node corresponding to the target position belongs as the target machine node; When it is determined that the operating status of the machine node to which the virtual node corresponding to the target position belongs is abnormal, the target virtual node is determined on the hash ring according to the virtual node corresponding to the target position, and the machine node to which the target virtual node belongs is determined as the target machine node.

8. The data caching method according to claim 7, characterized in that: Determining a target virtual node on the hash ring according to the virtual node corresponding to the target position includes: The virtual node corresponding to the next position corresponding to the target position on the hash ring is determined as the target virtual node.

9. The data caching method according to claim 1, characterized in that: After the data to be cached is segmented based on the hash value corresponding to each of the data to be cached, the method further includes: The divided groups of data to be cached are stored in the data buffer pool.

10. The data caching method according to claim 1, characterized in that: Caching each group of to-be-cached data to the target machine node, including: Each group of data to be cached is sent to the target machine node based on the TCP long link, so that the target machine node caches the keywords of each group of data to be cached into the in-heap cache and caches each group of data to be cached into the out-heap cache.

11. A data cache device, characterized in that: include: A construction module, used to construct a hash ring according to the number of machine nodes in the current microservice and the number of virtual nodes in the consistent hashing algorithm, wherein each position in the hash ring corresponds to each virtual node of each machine node in the current microservice; A segmentation module, used for receiving data to be cached, determining a hash value corresponding to each data to be cached based on the consistent hashing algorithm, and performing data segmentation on the data to be cached based on the hash value corresponding to each data to be cached; The cache module is used to determine the target machine node storing each group of data to be cached in the current microservice in the hash ring based on the hash values ​​corresponding to each group of data to be cached after the segmentation, and cache each group of data to be cached to the target machine node.

12. An electronic device, characterized in that: The electronic device comprises: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the data caching method as described in any one of claims 1 to 10.

13. A storage medium containing computer executable instructions, characterized in that: The computer executable instructions are used to execute the data caching method according to any one of claims 1 to 10 when executed by a computer processor.

Citation Information

Cited By

  • Electronic medical record distributed storage method based on Hash algorithm

    CN120199400A

  • System message queue processing method and system, computer equipment and medium

    CN120729812A

  • A system message queue processing method, system, computer device and medium

    CN120729812B

  • User data protection method and system for online promotion platform

    CN120850336A