Distributed database key value dynamic caching device
By using the dynamic statistics module of the FPGA hardware accelerated network card in a distributed database to detect the popularity of the cache key and update the high-hot key-value pairs, the performance degradation caused by changes in cache heat is solved, and higher cache hit rate and business stability are achieved. sex.
Patent Information
- Application Number
- CN202411068006.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-06
- Publication Date
- 2024-12-06
AI Technical Summary
In distributed databases, performance degradation and business impact caused by changes in cache heat, especially high access volumes that cannot be predicted in advance, lead to a decrease in cache hit rate, resulting in increased read latency, and may even lead to database paralysis.
A distributed database key-value dynamic cache device was designed, using FPGA hardware to accelerate network card to detect the popularity of cache keys through dynamic statistics modules, dynamically update high-hot key-value pairs, replace low-hot key-value pairs, improve cache hit rate, and avoid Performance degraded. The device includes a sending engine, a receiving engine, a filter module, a cache module and a dynamic statistics module. The access frequency of the approximate Count-Min sketch counter and one-dimensional vector counter statistics keys is used to determine whether the threshold is exceeded, and data is performed. renew.
It effectively avoids performance degradation caused by changes in cache heat, improves cache hit rate, ensures normal service response, and avoids database paralysis.
Smart Images

Figure CN119088542A_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the technical field of distributed databases, in particular to a distributed database key value dynamic cache device. Background Art
[0002] With the continuous development of the information age, a variety of Internet applications have been developed, and Internet applications cannot be separated from the support of data. Scenarios that require large traffic and low latency are everywhere in the network, requiring the network and equipment that carry the response service to provide higher performance. In order to adapt to different business scenarios and needs, it is necessary to divide data into multiple types. One way to divide data is to divide it according to the popularity of the data, which can be divided into hot data and cold data. Hot data refers to data that is frequently accessed. Some of these hot data are predictable, and their approximate popularity can be known in advance, and local caches can be prepared in advance to cope with high-frequency access. Other hot data is unexpected, and it is impossible to know in advance when and how much access this part of data will have. A large number of sudden accesses will make it difficult to hit the cache, and reading requires additional time overhead, which increases the reading latency, resulting in the inability to respond to normal queued access requests in time, and even causing the database to crash and affect the business.
[0003] In a distributed database architecture, cache requests from clients change over time and with cache heat. Different keys are accessed at different times with different frequencies. If the FPGA hardware acceleration network card uses a static cache method to store some key-value pairs, in certain circumstances, the cache hit rate may be reduced, resulting in no acceleration effect.
[0004] Therefore, how to avoid performance degradation and business impact caused by changes in cache heat is a technical problem that needs to be solved urgently. Summary of the invention
[0005] The technical task of the present invention is to provide a distributed database key-value dynamic caching device to solve the problem of how to avoid performance degradation and business impact caused by changes in cache heat.
[0006] The technical task of the present invention is achieved in the following manner: a distributed database key-value dynamic cache device, the device includes a client and a database server, the database server receives a cache request from the client and returns a response result to the client;
[0007] Among them, the database server includes CPU, memory system and FPGA hardware acceleration network card. The memory system is interconnected with the CPU. The FPGA hardware acceleration network card is mounted on the CPU through the PCIe bus and is used for the first-layer hardware cache and basic network task hardware offloading and communication protocol implementation; the FPGA hardware acceleration network card is interconnected with the client through optical fiber.
[0008] Preferably, the FPGA hardware acceleration network card includes a sending engine, a receiving engine, a filter module, a cache module and a dynamic statistics module; the working process of the FPGA hardware acceleration network card is as follows:
[0009] (i) When the receiving engine detects a network packet, it puts the network packet into the receiving queue, waits for the previous network packet to be parsed, and then starts to read a new network packet from the receiving queue, parses the protocol type, destination port number, cache request type, and data field information of the network packet, and passes the protocol type, destination port number, cache request type, and data field information of the network packet to the filter;
[0010] (II) The filter screens the protocol type and destination port number of the packet, as follows:
[0011] (1) If a network packet is detected that is not a cache request, it is directly bypassed to the CPU for processing;
[0012] (2) If a network packet is detected as a cache request, the request type is screened; the details are as follows:
[0013] ① If the request type satisfies the GET and SET types, the parsed request type and the key in the request are passed to the cache module;
[0014] ② If the request type does not meet the GET and SET types, it will be bypassed to the CPU for processing;
[0015] (3) When the sending engine detects the response data packet, it puts the response data packet into the sending queue, waits for the previous packet to be sent, and then starts to read the response data packet from the sending queue and packages it with the information of the destination port number, destination IP address and destination MAC address and sends it to the optical port;
[0016] (iv) The dynamic statistics module receives the key information and the cache hit / miss flag from the filter, starts the key statistics counting, and obtains the popularity of the cache request key.
[0017] Preferably, the cache module supports two request types: GET and SET, as follows:
[0018] If the cache module detects that the request type is GET, it uses the key in the request to index the memory and determines whether a hit occurs:
[0019] If a hit occurs, the queried value is directly written back to the filter; the filter module passes the received key information and hit flag to the dynamic statistics module for processing, and returns the key information and hit flag as a response data packet to the sending engine;
[0020] If no hit is sent, an empty flag is returned to the filter. After receiving the empty flag, the filter considers that the key query has failed. On the one hand, the key information and the empty flag are sent to the dynamic statistics module for processing. On the other hand, the request type and the key in the request are re-passed to the CPU for processing. The CPU writes the query result from the database back to the filter, and the filter returns the query result as a response data packet to the sending engine.
[0021] If the cache module detects that the request type is SET, it uses the key in the request to query the memory and determine whether a hit occurs:
[0022] If a hit occurs, the value corresponding to the key is updated;
[0023] If no hit occurs, a null flag is returned to the filter. After the filter detects that the SET fails, the request type and the key in the request are sent to the CPU for further processing.
[0024] Preferably, when the frequency value of any key exceeds the threshold, the frequency value of the key is recorded and saved and reported to the CPU. The CPU obtains the key statistics results obtained by the dynamic statistics module, obtains the high-heat key-value pairs that should be updated to the cache module and the low-heat key-value pairs that are currently cached, and updates the data.
[0025] In addition, the CPU sends control information for resetting, clearing counters, and setting thresholds to the dynamic statistics module.
[0026] Preferably, the dynamic statistics module includes a cache key selector, which is used to receive a cache key request signal and output it to different heat detection counters according to a cache hit or fail flag;
[0027] More preferably, the heat detection counter includes an approximate Count-Min sketch counter for detecting high-frequency keys and a one-dimensional vector counter for detecting low-frequency keys;
[0028] The approximate Count-Min sketch counter is used to receive the data stream with cache key missing;
[0029] The one-dimensional vector counter is used to increase the count value of the corresponding key by one after receiving the hit data stream.
[0030] Preferably, the dynamic statistics module further includes a threshold comparator, which is used to determine whether the estimated number of requests for the corresponding key exceeds a set threshold, and to report the statistical result to the CPU.
[0031] More preferably, the approximate Count-Min sketch counter is a hardware-implemented approximate Count-Min sketch algorithm counter that efficiently completes the element counting task;
[0032] Among them, the approximate Count-Min sketch counter uses four rolling hash functions. After calculating the hash values for the keys respectively, the count is increased by one at the corresponding position of each row of the two-dimensional vector of hash values according to the approximate Count-Min sketch algorithm, and then the minimum value of the corresponding count values of the four hash functions is taken as the estimated number of requests; after the calculation is completed, the estimated number of requests for the corresponding key is sent to the threshold comparator. If the threshold comparator determines that the estimated number of requests for the corresponding key exceeds the set threshold value, the record is saved and reported to the CPU.
[0033] The distributed database key value dynamic cache device of the present invention has the following advantages:
[0034] The present invention can dynamically detect the frequency of received request keys, count cache key heat, update the statistically obtained high-frequency cache key-value pairs to the FPGA hardware acceleration network card, and replace the low-frequency key-value pairs cached in the FPGA hardware acceleration network card, so as to avoid performance degradation and business impact caused by changes in cache heat. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] The present invention is further described below in conjunction with the accompanying drawings.
[0036] Attached Figure 1 It is a structural block diagram of a distributed database key-value dynamic cache device;
[0037] Attached Figure 2 This is the structural block diagram of the FPGA hardware acceleration network card;
[0038] Attached Figure 3 This is the structural block diagram of the dynamic statistics module. DETAILED DESCRIPTION
[0039] A distributed database key-value dynamic cache device of the present invention is described in detail below with reference to the accompanying drawings and specific embodiments of the specification.
[0040] Example:
[0041] This embodiment provides a distributed database key-value dynamic cache device, which includes a client and a database server. The database server receives cache requests from the client and returns the response results to the client. The database server consists of three parts, namely, the CPU, the memory system and the FPGA hardware acceleration network card. The FPGA hardware acceleration network card is mounted on the CPU through the PCIe bus and is mainly responsible for the first-layer hardware cache and basic network task hardware offloading and communication protocol implementation. Figure 1 shown.
[0042] As attached Figure 2 As shown, the FPGA hardware acceleration network card specifically includes a sending engine and a receiving engine related to protocol processing, a filter for filtering cache requests, a cache module for storing key value information, and a hot key dynamic statistics module.
[0043] Specifically, the workflow of the FPGA hardware accelerated network card is: when the receiving engine detects a network packet, it puts the network packet into the receiving queue. After waiting for the previous network packet to be parsed, the receiving engine starts to read new network packets from the receiving queue, first parsing the packet's protocol type, destination port number, cache request type, and data field, and then passes this information to the filter (steps ① and ③).
[0044] The filter first screens the protocol type and destination port number of the packet. If it detects that it is not a network packet for cache request, it will be directly bypassed to the CPU for processing (step ⑦). If it is, the request type will be screened; if the request type satisfies the GET and SET types, the parsed request type and the key in the request will be passed to the cache module (step ⑤), otherwise it will be bypassed to the CPU for processing (step ⑦). The cache module supports two request types, GET and SET. If the request type is detected to be GET, the key in the request is used to index the memory. If a hit occurs, the queried value is directly written back to the filter (step ⑥). On the one hand, the filter module passes the received key information and hit flag to the hot key dynamic statistics module for processing (step ⑨), and on the other hand, returns them as a response data packet to the sending engine (step ④). If no hit is sent, an empty flag is returned to the filter (step ⑥). After receiving the empty flag, the filter module considers that the key query has failed. On the one hand, the key information and the empty flag are sent to the hot key dynamic statistics module for processing (step ⑨), and on the other hand, the request type and the key in the request are re-passed to the CPU for processing (step ⑦). The CPU writes the results queried from the database back to the filter (step ⑧), and the filter returns the queried results as a response data packet to the sending engine (step ④). If the cache module detects that the request type is SET, it uses the key in the request to query the memory. If a hit occurs, the value corresponding to the key is updated. If no hit occurs, the empty flag is returned to the filter (step ⑥). After the filter detects that SET fails, it sends the request type and the key in the request to the CPU for further processing (step ⑦).
[0045] When the sending engine detects the response data packet, it puts the data packet into the sending queue and waits for the previous packet to be sent. Then, the sending engine starts to read the response data packet from the sending queue and packages it with the destination port number, destination IP address, destination MAC address and other information and sends it to the optical port (step ②);
[0046] The dynamic statistics module receives the key information and cache hit / miss flag from the filter, starts the key statistics count, and obtains the cache request key popularity. When the frequency value of a key exceeds the threshold, it is recorded and saved and reported to the CPU (step ), the CPU will obtain the key statistics results obtained by the dynamic statistics module, obtain the high-heat key-value pairs that should be updated to the cache module, and the low-heat key-value pairs that are currently cached, and update the data (step ⑩). In addition, the CPU can send control information such as reset, counter clearing and threshold setting to the dynamic statistics module (step ).
[0047] As attached Figure 3As shown, the dynamic statistics module of the cache key includes a cache key selector, an approximate Count-Min sketch counter for detecting high-frequency keys, a one-dimensional vector counter for detecting low-frequency keys, and a threshold comparator.
[0048] Specifically, the workflow of the dynamic statistics module of the cache key is as follows: the cache key selector receives the cache key request signal and outputs it to different heat detection counters in two ways according to the cache hit or miss flag. (1) The data stream with missing cache keys will enter the approximate Count-Min sketch counter, which is a hardware-implemented approximate Count-Min sketch algorithm counter that can efficiently complete the element counting task. The counter uses four rolling hash functions to calculate the hash value of the key respectively. According to the approximate Count-Min sketch algorithm, the count can be increased by one at the corresponding position of each row of its two-dimensional vector, and then the minimum value of the corresponding count values of the four hash functions is taken as the estimated number of requests. After the calculation is completed, the estimated number of requests for the key will be sent to the threshold comparator. If it exceeds the set threshold size, it will be recorded and reported to the CPU; (2) Since the approximate Count-Min sketch algorithm may have large errors when calculating data with low frequency, the cached low-frequency keys are directly counted using arrays. After receiving the input data stream in the one-dimensional vector calculator, the count value of the corresponding key is increased by one.
[0049] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.
Claims
1. A distributed database key-value dynamic cache device, characterized in that: The device includes a client and a database server, wherein the database server receives a cache request from the client and returns a response result to the client; The database server includes a CPU, a memory system, and an FPGA hardware acceleration network card. The memory system is interconnected with the CPU. The FPGA hardware acceleration network card is mounted on the CPU through the PCIe bus and is used for the first-layer hardware cache and basic network task hardware offload and communication protocol implementation. The FPGA hardware acceleration network card is interconnected with the client through optical fiber.
2. The distributed database key-value dynamic cache device according to claim 1, characterized in that: The FPGA hardware acceleration network card includes a sending engine, a receiving engine, a filter module, a cache module, and a dynamic statistics module. The working process of the FPGA hardware acceleration network card is as follows: (1) When the receiving engine detects a network packet, it places the network packet into the receiving queue and waits for the previous network packet to be parsed. Then, the receiving engine begins to read the new network packet from the receiving queue, parses the network packet's protocol type, destination port number, cache request type, and data field information, and passes the information to the filter. (2) The filter screens the protocol type and destination port number of the packet, as follows: (1) If a network packet is detected that is not a cache request, it is directly bypassed to the CPU for processing; (2) If a cache request is detected, the request type is filtered as follows: ① If the request type satisfies the GET and SET types, the parsed request type and the key in the request are passed to the cache module; ② If the request type does not meet the GET and SET types, it will be bypassed to the CPU for processing; (3) When the sending engine detects a response data packet, it places the response data packet into the sending queue and waits for the previous packet to be sent. Then, the sending engine starts to read the response data packet from the sending queue and packages it with the destination port number, destination IP address, and destination MAC address information and sends it to the optical port; (4) The dynamic statistics module receives the key information and the cache hit / fail flag from the filter, starts the key statistics counting, and obtains the popularity of the cache request key.
3. The distributed database key-value dynamic cache device according to claim 2, characterized in that: The cache module supports two request types: GET and SET, as follows: If the cache module detects that the request type is GET, it uses the key in the request to index the memory and determines whether a hit occurs: If a hit occurs, the queried value is directly written back to the filter; The filter module, on the one hand, passes the received key information and hit flag to the dynamic statistics module for processing, and on the other hand, returns the key information and hit flag as a response data packet to the sending engine; If no hit is sent, an empty flag is returned to the filter. After receiving the empty flag, the filter considers the key query failed. On the one hand, it sends the key information and the empty flag to the dynamic statistics module for processing. On the other hand, it re-passes the request type and the key in the request to the CPU for processing. The CPU writes the query result from the database back to the filter, and the filter returns the query result as a response data packet to the sending engine. If the cache module detects that the request type is SET, it uses the key in the request to query the memory and determine whether a hit occurs: If a hit occurs, the value corresponding to the key is updated; If no hit occurs, an empty flag is returned to the filter. After the filter detects that the SET fails, the request type and the key in the request are sent to the CPU for further processing.
4. The distributed database key-value dynamic cache device according to claim 2, characterized in that: When the frequency value of any key exceeds the threshold, the key frequency value is recorded and saved and reported to the CPU. The CPU obtains the key statistics results obtained by the dynamic statistics module, obtains the high-heat key-value pairs that should be updated to the cache module and the low-heat key-value pairs currently cached, and updates the data; In addition, the CPU sends control information for resetting, clearing counters, and setting thresholds to the dynamic statistics module.
5. The distributed database key-value dynamic cache device according to claim 1, characterized in that: The dynamic statistics module includes a cache key selector, which is used to receive a cache key request signal and output it to different heat detection counters according to a cache hit or fail flag.
6. The distributed database key-value dynamic cache device according to claim 5, characterized in that: The heat detection counters include an approximate Count-Min sketch counter for detecting high-frequency keys and a one-dimensional vector counter for detecting low-frequency keys; The approximate Count-Min sketch counter is used to receive the data stream of cache key misses; The one-dimensional vector counter is used to increase the count value of the corresponding key by one after receiving the hit data stream.
7. The distributed database key-value dynamic cache device according to claim 6, characterized in that: The dynamic statistics module further includes a threshold comparator, which is used to determine whether the estimated number of requests for the corresponding key exceeds a set threshold, and report the statistical result to the CPU.
8. The distributed database key-value dynamic cache device according to claim 6, characterized in that: The approximateCount-Min sketch counter is a hardware-implemented approximate Count-Min sketch algorithm counter that efficiently completes element counting tasks. Among them, the approximate Count-Min sketch counter uses four rolling hash functions. After calculating the hash value for each key, it increments the count by one at the corresponding position of each row of the two-dimensional vector of hash values according to the approximate Count-Min sketch algorithm. The minimum value of the corresponding count values of the four hash functions is then taken as the estimated number of requests. After the calculation is completed, the estimated number of requests for the corresponding key is sent to the threshold comparator. If the threshold comparator determines that the estimated number of requests for the corresponding key exceeds the set threshold, the record is saved and reported to the CPU.
