Distributed cache optimization method, device, electronic device and storage medium
By introducing hot data prediction and reinforcement learning models into the distributed cache system and dynamically adjusting the cache strategy, the problems of low cache hit rate and uneven resource allocation are solved, and efficient cache management and resource utilization are achieved.
Patent Information
- Application Number
- CN202510408706.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-02
- Publication Date
- 2025-09-19
- Estimated Expiration
- 2045-04-02
AI Technical Summary
The low cache hit rate, lack of dynamic adjustment capabilities and unbalanced resource allocation in traditional distributed cache systems lead to system performance degradation and resource waste.
By introducing hot data prediction models and reinforcement learning models, future hot data can be predicted in advance and loaded into the cache. Combined with the real-time load information and performance indicators of the cache nodes, the cache strategy can be dynamically adjusted to achieve balanced allocation and optimal management of resources.
Improves cache hit rate and reduces miss rate, ensuring optimal cache management under different load and request modes and avoiding resource waste between nodes.
Smart Images

Figure CN120336007B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of distributed cache technology, and in particular to a distributed cache optimization method, device, electronic device and storage medium. Background Art
[0002] In a distributed cache system, the effective utilization of cache resources and the improvement of cache hit rate are key factors in improving system performance. Traditional distributed cache systems use static cache replacement strategies (such as LRU, FIFO), which usually encounter the following problems: Low cache hit rate: Due to the static nature of the cache strategy, it cannot effectively respond to changes in different loads and request patterns, resulting in a low cache hit rate, which affects system performance. Lack of dynamic adjustment capabilities: Existing cache systems are unable to dynamically adjust cache strategies in real time based on factors such as changes in user requests and changes in node resources, resulting in a waste of cache resources. Unbalanced resource allocation: In a distributed environment, the load differences between multiple cache nodes are large, and traditional methods cannot coordinate the cache content between nodes, resulting in an uneven distribution of cache resources. Therefore, how to optimize distributed cache has become a technical issue that cannot be underestimated. Summary of the Invention
[0003] In view of this, the purpose of this application is to provide a distributed cache optimization method, device, electronic device and storage medium to predict future hot data in advance and load the hot data into the cache in advance, reduce the cache miss rate, introduce a reinforcement learning model to continuously adjust the cache strategy based on real-time feedback, ensure optimal cache management under different loads and request modes, achieve balanced allocation of resources, and avoid resource waste between nodes.
[0004] The present invention provides a method for optimizing distributed cache, which includes:
[0005] Inputting historical request data of multiple hot data into a hot data prediction model, performing data preprocessing, feature extraction, and future access frequency prediction on the historical request data, and predicting the access frequency of each hot data in a future time period; wherein the hot data prediction model is obtained by iteratively training a long short-term memory network model;
[0006] Determine data information of target hotspot data whose access frequency is greater than a preset access frequency, and perform node caching on the data information of the target hotspot data based on real-time load resource usage information of each cache node;
[0007] The cache strategy of each cache node is dynamically adjusted based on the reinforcement learning model and multiple performance indicator data of each cache node.
[0008] In one possible implementation, for each of the hot data, the historical request data of the plurality of hot data are input into the hot data prediction model, and the historical request data are subjected to data preprocessing, feature extraction, and future access frequency prediction processing to predict the access frequency of each of the hot data in the future time period, including:
[0009] Extracting time features, access frequency features, and data ID embedding vectors from historical request data of the hot data based on the hot data prediction model, and constructing time series of the time features, access frequency features, and data ID embedding vectors according to multiple preset time windows to determine the time series features under each time window;
[0010] Performing data cleaning on the time series features in each time window to determine the target time series features in each time window;
[0011] Based on the first long short-term memory network layer of the hot data prediction model, short-term feature capture is performed on the target time series features under each time window, and a short-term feature capture sequence of each time window is output;
[0012] Inputting the short-term feature capture sequence of each time window into the second long short-term memory network layer to capture long-term trend features, and determining the long-term feature capture sequence of each time window;
[0013] The long-term feature capture sequence of each time window is input into the fully connected network layer of the hot data prediction model for processing, and the access frequency of the hot data in the future time period is output.
[0014] In a possible implementation, the hotspot data prediction model is determined by the following steps:
[0015] Inputting historical request data of a plurality of sample hotspot data into the long short-term memory network model, processing the historical request data of each sample hotspot data, and determining the predicted access frequency of each sample hotspot data in a future time period;
[0016] Determine a root mean square error (RMSE) and a mean absolute error (MAE) based on the actual access frequency and the predicted access frequency of each sample hotspot data in a future time period;
[0017] If either the root mean square error value or the mean absolute error is greater than a preset threshold, the network parameters of the long short-term memory network model are optimized, and the optimized long short-term memory network model is continuously trained until the root mean square error value and the mean absolute error are both less than or equal to the preset threshold, and the training is stopped to determine the hotspot data prediction model.
[0018] In a possible implementation manner, the node caching of data information of target hotspot data based on real-time load resource usage information of each cache node includes:
[0019] Detecting whether the cache node with the lowest real-time load resource usage has sufficient cache space to accommodate the data information of the target hotspot data;
[0020] If so, the data information of the target hotspot data in the future time period is loaded and cached into the cache node with the lowest real-time load resource usage;
[0021] If not, the low-frequency data in the cache node with the lowest real-time load resource usage is deleted to complete the expansion of the cache node, and the data information of the target hot data in the future time period is cached in the expanded cache node.
[0022] In a possible implementation manner, dynamically adjusting the caching strategy of each cache node based on the reinforcement learning model and multiple performance indicator data of each cache node includes:
[0023] Extracting features from a plurality of performance indicator data of each cache node to determine a state feature vector of each cache node; wherein the performance indicator data includes cache hit rate, average request latency, node load, and cache space utilization;
[0024] Inputting the state feature vector of each cache node into a reinforcement learning model, and performing reinforcement optimization on the cache strategy adjustment action of the state feature vector of each cache node based on a greedy algorithm and a preset reward mechanism;
[0025] Based on the cache policy adjustment action of each cache node, the corresponding cache node is dynamically adjusted; wherein the cache policy adjustment action includes cache content adjustment action and load balancing.
[0026] In one possible implementation, for the load balancing adjustment action, the cache policy adjustment action based on each cache node dynamically adjusts the corresponding cache node; wherein the cache policy adjustment action includes a cache content adjustment action or a load balancing adjustment action, including:
[0027] Based on the distributed cache cluster and consistent hashing algorithm, the cache data of hot data in the high-load cache node is migrated to the low-load cache node.
[0028] In a possible implementation manner, after determining the data information of the target hotspot data having an access frequency greater than a preset access frequency, and performing node caching on the data information of the target hotspot data based on the real-time load resource usage information of each cache node, the optimization method further includes:
[0029] After receiving a request from the client to update cache data, the cache node forwards the update request to a leading cache node in the distributed cache cluster;
[0030] The updated information of the cache data is synchronously written into the log of the leader cache node. After the log synchronization is completed, the leader cache node broadcasts the cache update operation to all cache nodes through the Kafka message queue.
[0031] The present application also provides a distributed cache optimization device, the optimization device comprising:
[0032] An access frequency prediction module is used to input historical request data of multiple hot data into a hot data prediction model, perform data preprocessing, feature extraction, and future access frequency prediction on the historical request data, and predict the access frequency of each hot data in a future time period; wherein the hot data prediction model is obtained by iteratively training a long short-term memory network model;
[0033] A cache allocation module is used to determine the data information of target hotspot data whose access frequency is greater than a preset access frequency, and perform node caching on the data information of the target hotspot data based on the real-time load resource usage information of each cache node;
[0034] A dynamic optimization module is used to dynamically adjust the cache strategy of each cache node based on a reinforcement learning model and multiple performance indicator data of each cache node.
[0035] An embodiment of the present application also provides an electronic device, comprising: a processor, a memory and a bus, wherein the memory stores machine-readable instructions executable by the processor. When the electronic device is running, the processor and the memory communicate through the bus, and when the machine-readable instructions are executed by the processor, the steps of the distributed cache optimization method as described above are performed.
[0036] An embodiment of the present application further provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the steps of the distributed cache optimization method as described above are executed.
[0037] The embodiments of the present application provide a distributed cache optimization method, device, electronic device and storage medium, which inputs historical request data of multiple hotspot data into a hotspot data prediction model, performs data preprocessing, feature extraction and future access frequency prediction processing on the historical request data, and predicts the access frequency of each of the hotspot data in the future time period; wherein, the hotspot data prediction model is obtained by iteratively training a long short-term memory network model; determines the data information of the target hotspot data whose access frequency is greater than the preset access frequency, and performs node caching on the data information of the target hotspot data based on the real-time load resource usage information of each cache node; dynamically adjusts the cache strategy of each cache node based on the reinforcement learning model and multiple performance indicator data of each cache node. Predict future hotspot data in advance, and load the hotspot data into the cache in advance to reduce the cache miss rate, introduce a reinforcement learning model to continuously adjust the cache strategy according to real-time feedback, ensure optimal cache management under different loads and request modes, achieve balanced resource allocation, and avoid resource waste between nodes.
[0038] In order to make the above-mentioned objects, features and advantages of the present application more obvious and easy to understand, preferred embodiments are given below and described in detail with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other relevant drawings can be obtained based on these drawings without creative work.
[0040] Figure 1 A flowchart of a distributed cache optimization method provided in an embodiment of the present application;
[0041] Figure 2 This is one of the structural diagrams of a distributed cache optimization device provided in an embodiment of the present application;
[0042] Figure 3 This is a second structural diagram of a distributed cache optimization device provided in an embodiment of the present application;
[0043] Figure 4 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0044] In order to make the purpose, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all of the embodiments. The components of the embodiments of the present application generally described and shown in the drawings here can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the application for which protection is claimed, but merely represents the selected embodiments of the present application. Based on the embodiments of the present application, each other embodiment obtained by those skilled in the art without making creative work falls within the scope of protection of the present application.
[0045] First, the application scenarios to which this application is applicable are introduced. This application can be applied in the field of distributed cache technology.
[0046] Based on this, an embodiment of the present application provides a distributed cache optimization method, which predicts future hot data in advance and loads the hot data into the cache in advance, reduces the cache miss rate, introduces a reinforcement learning model to continuously adjust the cache strategy based on real-time feedback, ensures optimal cache management under different loads and request modes, achieves balanced distribution of resources, and avoids resource waste between nodes.
[0047] See also Figure 1 , Figure 1 This is a flow chart of a distributed cache optimization method provided by an embodiment of the present application. Figure 1 As shown in , the optimization method provided in the embodiment of the present application includes:
[0048] S101: Inputting historical request data of multiple hot data into a hot data prediction model, performing data preprocessing, feature extraction and future access frequency prediction processing on the historical request data, and predicting the access frequency of each hot data in a future time period; wherein, the hot data prediction model is obtained by iteratively training a long short-term memory network model.
[0049] In this step, the historical request data of multiple hot data are input into the hot data prediction model, and the historical request data are subjected to data preprocessing, feature extraction and future access frequency prediction processing to predict the access frequency of each hot data in the future time period.
[0050] Historical request data includes: Timestamp: Records the time of each cache request. Data ID (data_id): Identifies the data being accessed. Request type (request_type): For example, read or write. Access frequency (frequency): The number of accesses within a specified time window.
[0051] In one possible implementation, for each of the hot data, the historical request data of the plurality of hot data are input into the hot data prediction model, and the historical request data are subjected to data preprocessing, feature extraction, and future access frequency prediction processing to predict the access frequency of each of the hot data in the future time period, including:
[0052] A: Based on the hot data prediction model, the time features, access frequency features and data ID embedding vectors of the historical request data of the hot data are extracted, and the time features, access frequency features and data ID embedding vectors are constructed into a time series according to multiple preset time windows to determine the time series features under each time window.
[0053] Here, timestamps are converted into easily understandable features, such as hours, minutes, peak hours (weekdays from 9:00 AM to 6:00 PM), and holidays. For example, the timestamp 2025-01-14 14:30:00 is converted to [14, 30, 1, 0], where 14 represents the hour, 30 represents the minute, and 1 represents peak hours on weekdays. 0 represents non-holidays. The number of visits to each data ID within a specific time period (e.g., an hour or a day) is calculated, and the frequency is then normalized to [0, 1] to keep all feature values within a uniform range and prevent differences in feature magnitude from affecting the analysis results. For example, suppose a product has been visited 100 times in the past hour. If the maximum visit frequency is set to 200, then the normalized frequency = 100 / 200 = 0.5. The visit frequency is split into time series features based on fixed time windows.
[0054] For example, construct a time series feature input using a fixed time window (e.g., the past hour, divided into 12 5-minute windows). Example: [window 1: 50 times, window 2: 60 times, ..., window 12: 100 times].
[0055] Here, the data ID embedding vector provides a vector representation for each data ID through embedding technology, and the data ID embedding vector is input into the model together with the time feature and access frequency feature to improve the prediction accuracy.
[0056] B: Perform data cleaning on the time series features in each time window to determine the target time series features in each time window.
[0057] Here, for the time series features in each time window, requests with obviously abnormal frequencies (such as sudden surges or abnormally low frequencies, or those caused by crawlers or erroneous operations) are removed, and interpolation is used to fill in data for missing time periods (if there is no data in some time periods, interpolation is used to fill in the missing values to ensure data continuity), and the target time series features in each time window are determined.
[0058] C: Based on the first long short-term memory network layer of the hot data prediction model, short-term feature capture is performed on the target time series features under each time window, and a short-term feature capture sequence of each time window is output.
[0059] Here, the first long short-term memory network layer of the hot data prediction model performs short-term feature capture on the target time series features under each time window, and outputs the short-term feature capture sequence of each time window.
[0060] D: Inputting the short-term feature capture sequence of each time window into the second long short-term memory network layer to capture long-term trend features, and determining the long-term feature capture sequence of each time window.
[0061] Here, the short-term feature capture sequence of each time window is input into the second long short-term memory network layer to capture the long-term trend features, and the long-term feature capture sequence of each time window is determined.
[0062] Among them, the two-layer long short-term memory network extracts short-term and long-term dependencies in time series.
[0063] E: Input the long-term feature capture sequence of each time window into the fully connected network layer of the hot data prediction model for processing, and output the access frequency of the hot data in the future time period.
[0064] Here, after the fully connected layer processes the long-term feature capture sequence of each time window, the access frequency of each hot data ID in the future time period is generated.
[0065] In a specific embodiment, based on LSTM (Long Short-Term Memory Network), it is used to predict the future access frequency of each data ID. The core goal is to capture the pattern of access frequency through historical access data (time series) to predict future access volume. Input features: including historical access frequency, time features (such as hours, weeks, holidays), and embedding vectors of data IDs. LSTM layer: Two layers of LSTM are used, the first layer captures short-term patterns, and the second layer captures long-term trends. Fully connected layer: Converts the features output by LSTM into predicted values of future access frequency. Output features: After processing by the fully connected layer, a prediction of the future access frequency of each data ID is generated.
[0066] In a possible implementation, the hotspot data prediction model is determined by the following steps:
[0067] (1): Input the historical request data of multiple sample hotspot data into the long short-term memory network model, process the historical request data of each sample hotspot data, and determine the predicted access frequency of each sample hotspot data in the future time period.
[0068] Here, the historical request data of multiple sample hotspot data are input into the long short-term memory network model, the historical request data of each sample hotspot data are processed, and the predicted access frequency of each sample hotspot data in the future time period is determined.
[0069] The process of determining the predicted access frequency of the sample hotspot data is consistent with the process of determining the access frequency of the hotspot data in the future time period, and will not be described in detail in this section.
[0070] When the amount of historical access data is small, the model may underfit (i.e., fail to capture effective patterns). Data augmentation expands the sample space by adding reasonable perturbations (noise) or simulating data. Adding random noise: Adding small random variations to the original data to generate "augmented samples." For example, if the original access frequencies are [100, 120, 150], adding 5% random noise to [105, 126, 157] enhances the model's robustness to data fluctuations. Simulating access trends of data IDs: Create virtual samples based on existing data with characteristics similar to those of hotspot data. For example, if the access frequencies of hotspot data exhibit a "peak-then-fall" trend of [200, 250, 300, 270, 240], simulate data IDs that follow a similar trend but are slightly scaled to [150, 190, 220, 210, 180], allowing the model to adapt to more potential access patterns.
[0071] (2): Based on the actual access frequency and predicted access frequency of each sample hotspot data in the future time period, the root mean square error value and the mean absolute error are determined.
[0072] Among them, the root mean square error RMSE and the mean absolute error MAE are determined by the following formula:
[0073]
[0074] in, is the predicted access frequency of the i-th sample hotspot data in the future time period, y i is the actual access frequency of the i-th sample hotspot data in the future time period, and N is the total number of samples.
[0075] (3): If either the root mean square error value or the mean absolute error is greater than a preset threshold, the network parameters of the long short-term memory network model are optimized, and the optimized long short-term memory network model is continuously trained until the root mean square error value and the mean absolute error are both less than or equal to the preset threshold, and the training is stopped to determine the hot data prediction model.
[0076] Here, if either the root mean square error value or the mean absolute error is greater than the preset threshold, the network parameters of the long short-term memory network model are optimized, and the optimized long short-term memory network model is continued to be trained until the root mean square error value and the mean absolute error are both less than or equal to the preset threshold. The training is stopped to determine the hot data prediction model.
[0077] S102: Determine data information of target hotspot data whose access frequency is greater than a preset access frequency, and perform node caching on the data information of the target hotspot data based on real-time load resource usage information of each cache node.
[0078] In this step, data information of target hotspot data having an access frequency greater than a preset access frequency is determined, and node caching is performed on the data information of the target hotspot data according to real-time load resource usage information of each cache node.
[0079] In a possible implementation manner, the node caching of data information of target hotspot data based on real-time load resource usage information of each cache node includes:
[0080] a: Detect whether the cache node with the lowest real-time load resource usage has enough cache space to accommodate the data information of the target hotspot data.
[0081] Here, it is detected whether the cache node with the lowest real-time load resource usage has enough cache space to accommodate the data information of the target hotspot data.
[0082] b: If yes, then the data information of the target hotspot data in the future time period is loaded and cached into the cache node with the lowest real-time load resource usage.
[0083] Here, if yes, the data information of the target hotspot data in the future time period is loaded and cached into the cache node with the lowest real-time load resource usage.
[0084] c: If not, the low-frequency data in the cache node with the lowest real-time load resource usage is deleted to complete the expansion of the cache node, and the data information of the target hot data in the future time period is cached in the expanded cache node.
[0085] If not, the low-frequency data in the cache node with the lowest real-time load resource usage is deleted to complete the expansion of the cache node, and the data information of the target hot data in the future time period is cached in the expanded cache node.
[0086] In a specific embodiment, the system loads this data from the hard disk or distributed storage into the cache in advance based on the prediction results of the LSTM model (such as [A101: 300 times, B202: 200 times]). Example: Data ID A101 is predicted to be accessed 300 times and is loaded into the cache node in advance. Data ID B202 is predicted to be accessed 200 times and is also loaded into the cache. When the cache space is insufficient, the LRU (least recently used) strategy is used to eliminate low-frequency data to make room for hot data. For example, the system checks whether there is enough space in the current cache to accommodate the predicted hot data. Example: The remaining cache space can only store 2MB of data, while the hot data A101 and B202 require a total of 3MB. According to the LRU strategy, the data with the least recent access is deleted from the cache. Example: Assuming that the access frequencies of C303 and D404 are low, with C303 accessed 10 times and D404 accessed 8 times, the data with the least recent access in the cache is eliminated first. After deleting low-frequency data, A101 and B202 are loaded into the cache to complete the preloading of hot data. The cache capacity and data distribution of each node are dynamically adjusted to optimize cache hit rate and resource utilization.
[0087] S103: Dynamically adjust the cache strategy of each cache node based on the reinforcement learning model and multiple performance indicator data of each cache node.
[0088] In this step, the cache strategy of each cache node is dynamically adjusted based on the reinforcement learning model and multiple performance indicator data of each cache node.
[0089] Each cache node has an embedded monitoring module that uses Redis statistical commands to collect data on cache hit rate, average request latency, node load, and cache space utilization. Node load includes CPU utilization, memory utilization, and disk I / O. The monitoring module encapsulates the collected data in JSON format and transmits it to the central control system via Kafka. The data is then written to the time series database (InfluxDB) for subsequent query and analysis.
[0090] In this application, you can also configure performance thresholds: cache hit rate below 80%, average latency above 100ms, and node CPU utilization exceeding 90%. Once the set thresholds are exceeded, the central control system will trigger an alarm mechanism and notify the developer via email or instant messaging tools (such as Slack). You can also use Grafana to build the following dashboards: Cache hit rate trend chart: shows how the cache hit rate of each node changes over time; Request latency distribution chart: shows the changes in average latency and 95% response time; System load heat map: shows the distribution of node load in the cluster; Cache space utilization analysis: helps determine whether cache capacity needs to be expanded.
[0091] In a possible implementation manner, dynamically adjusting the caching strategy of each cache node based on the reinforcement learning model and multiple performance indicator data of each cache node includes:
[0092] I: Extracting features from a plurality of performance indicator data of each cache node to determine a state feature vector of each cache node; wherein the performance indicator data includes cache hit rate, average request delay, node load, and cache space utilization.
[0093] Here, feature extraction is performed on multiple performance indicator data of each cache node to determine the state feature vector of each cache node. For example, the state feature vector S t [H t , L t 、U t , O t ], where H t is the cache hit rate, L t is the average request delay, U t is the node load, O t Cache space utilization.
[0094] The performance indicator data includes cache hit rate, average request delay, node load and cache space utilization.
[0095] Here, you set thresholds and alarm mechanisms, defining load warning thresholds, such as CPU usage > 80%, memory utilization > 70%, and network bandwidth usage > 85%. When the load exceeds the threshold, the system triggers an alarm and marks the node as a high-load node.
[0096] II: Inputting the state feature vector of each cache node into the reinforcement learning model, and strengthening and optimizing the cache strategy adjustment action of the state feature vector of each cache node based on the greedy algorithm and the preset reward mechanism.
[0097] Here, the state feature vector of each cache node is input into the reinforcement learning model, and the cache strategy adjustment action of the state feature vector of each cache node is reinforced and optimized according to the greedy algorithm and the preset reward mechanism.
[0098] Specific cache policy operations include cache content adjustment and load balancing. Cache content adjustment includes: 1) Replacement strategy: selecting which cached data should be eliminated (e.g., based on a LRU strategy or prioritizing hot data over non-hot data); 2) Cache preloading: dynamically loading high-priority data based on predicted hot data. Load balancing operations include data migration, migrating hot data from high-load nodes to low-load nodes. This is accomplished by calling the gRPC communication interface.
[0099] Here, the greedy algorithm primarily aims to strike a balance between exploration and exploitation. In reinforcement learning, actions to adjust the cache policy are selected based on the current state characteristics. The core of the greedy algorithm is to select the action most likely to produce the optimal outcome based on the current state. For example, the action with the highest current Q-value is selected with probability 1-∈ (i.e., adopting the known optimal policy), while a random action is selected with probability ∈ (i.e., exploring new possible policies). This approach helps the system optimize based on existing policies while also exploring new possible policies. The reward mechanism provides feedback for reinforcement learning, used to evaluate the effectiveness of cache policy adjustments. By setting appropriate reward and penalty rules, the model can be guided toward optimization goals (such as improving cache hit rate and reducing request latency). For example: Cache hit rate reward: If the cache hit rate improves, a positive reward is given; if the cache hit rate decreases, no reward or a negative penalty is applied. Latency penalty: If latency increases, a negative penalty is applied based on the increased latency. Load balancing reward: If the load is balanced, a positive reward is given; if a node is overloaded, a penalty is imposed.
[0100] Here, the reward mechanism design includes: cache hit rate reward R h for:
[0101] R h =ΔH t ×10
[0102] Example: If the hit rate increases from 80% to 85%, the reward is (85-80)×10=50.
[0103] Among them, the average request delay penalty R l for
[0104] R l =-ΔL t ×5
[0105] Example: If the latency increases by 10ms, the penalty is -10×5=-50.
[0106] Here, the negative node load balancing reward r u Rewards are given when the node load is close to balanced:
[0107] R u =-|U max -U min |×2
[0108] Among them, the formula for the total reward R is:
[0109] R=R h +R l +R u
[0110] III: Dynamically adjusting the corresponding cache node based on the cache policy adjustment action of each cache node; wherein the cache policy adjustment action includes a cache content adjustment action or a load balancing adjustment action.
[0111] Here, the corresponding cache node is dynamically adjusted according to the cache policy adjustment action of each cache node.
[0112] Among them, cache content adjustment includes replacement strategy: selecting which cached data should be eliminated (such as eliminating non-hotspot data based on LRU strategy or hotspot data first). Cache preloading: dynamically loading high-priority data based on predicted hotspot data. Load balancing adjustment includes load relief: migrating hotspot data from high-load nodes to low-load nodes, which is achieved by calling the interface through gRPC communication to complete data migration. Action example: replacing low-priority data to free up cache space, or migrating hotspot data from node A to node B with lower load.
[0113] For example, the current situation is: Node A: Hit rate = 55%, load = 85%. Node B: Hit rate = 85%, load = 40%. The adjustment plan is to increase the cache capacity of Node B to store more hot data. Hot data ID = 456 is migrated from Node A to Node B to improve the hit rate of Node A. After the adjustment, the hit rate of Node A increases to 70%, significantly improving overall performance.
[0114] In a specific embodiment, the reinforcement learning model employs the following steps: Initialize the Q network: A two-layer fully connected neural network is used, which inputs the state vector St and outputs the Q value of each action. The network parameters are defined and trained using PyTorch. Strategy selection: An ∈-greedy algorithm is used to balance exploration and exploitation: An action is randomly selected with probability ∈, and the action with the maximum Q value is selected with probability 1-∈. After each action is executed, the strategy is adjusted based on the reward. Experience replay: Historical states, actions, and rewards are stored in a replay pool, and samples are drawn in batches to train the network, improving training efficiency.
[0115] In one possible implementation, for the load balancing adjustment action, the cache policy adjustment action based on each cache node dynamically adjusts the corresponding cache node; wherein the cache policy adjustment action includes a cache content adjustment action or a load balancing adjustment action, including:
[0116] Based on the distributed cache cluster and consistent hashing algorithm, the cache data of hot data in the high-load cache node is migrated to the low-load cache node.
[0117] Here, RedisCluste and consistent hashing are used to locate the target node through consistent hashing, and hot data is copied from high-load nodes to low-load nodes, ensuring that the minimum amount of data needs to be redistributed during the migration process, reducing performance impact.
[0118] In a possible implementation manner, after determining the data information of the target hotspot data having an access frequency greater than a preset access frequency, and performing node caching on the data information of the target hotspot data based on the real-time load resource usage information of each cache node, the optimization method further includes:
[0119] (1): After receiving a request from a client to update cache data, the cache node forwards the update request to a leading cache node in the distributed cache cluster.
[0120] Here, each cache node registers its information (IP, port, resource status, etc.) with the cluster management module upon startup. After completing registration, the node joins the distributed cache cluster. Using the Raft consensus protocol, the cluster elects a leader node, which is responsible for log management, cache updates, and global coordination. Other cache (follower) nodes monitor the leader's status changes and perform synchronization operations. The client initiates an update request for cached data (such as write or delete). The update request reaches the follower node, which forwards the request to the leader node.
[0121] (2) The updated information of the cache data is synchronously written into the log of the leader cache node. After the log synchronization is completed, the leader cache node broadcasts the cache update operation to all cache nodes through the Kafka message queue.
[0122] Here, the leader node writes the update operation to the log (including key, value, timestamp, etc.) and broadcasts it to all follower nodes. When a majority of nodes (more than half) confirm receipt of the log entry, the leader applies the operation to the cache and notifies the client of the success of the operation.
[0123] After Raft log synchronization is complete, the leader node broadcasts the cache update to all nodes via the Kafka message queue. Each node subscribes to a topic (such as Cache_Update) to listen for update events. Kafka persists the message log, ensuring that data lost due to network delays or node offline can be re-consumed after the node is restored.
[0124] Conflict detection and version control can also be implemented in this application: Timestamp-based conflict resolution: The update operation is accompanied by a timestamp, and the node selects the data with a newer timestamp when synchronizing. Version number-based conflict detection: Each update operation increments the version number, and the node compares the version number to determine the latest data version. Conflict handling strategy: If the timestamp and version number are consistent, the system defaults to the Leader's data as the final version. Example: Nodes A and B update the cache key = 789 at the same time, and the timestamp of node A is 2025-01-14T15:05:00Z. The timestamp of node B is 2025-01-14T15:04:59Z. The system selects the update of node A and broadcasts it to all nodes for synchronization.
[0125] In a specific embodiment, the present application can also implement periodic consistency checks and snapshot synchronization, periodic status verification: the system regularly calculates the cache hash values of all nodes and compares whether there are data differences. When a difference is detected, log replay or snapshot synchronization is triggered. Snapshot synchronization optimization: Raft regularly generates snapshot files to replace long log chains and reduce recovery time. The snapshot contains complete status information of the cache, and each node can directly load the snapshot for recovery. Example: The cache hash value of node A is hash_A=abc123, and that of node B is hash_B=xyz789. The system detects that node B is missing a log, node A sends a snapshot file to node B, node B loads the snapshot, and completes the consistency repair. Fault tolerance and abnormal recovery: When the network is partitioned, only the leader in the partition is allowed to perform write operations, and other partitions suspend writing and wait for the network to recover before repairing the data through log synchronization. Node failure recovery: After the failed node recovers, the Kafka message queue is used to re-consume the update operation. If the node is offline for a long time, the data is directly restored through the Raft snapshot. Example: Node B recovers 10 minutes after failure: Consume the 50 lost update messages from Kafka. If too many logs are missing, request the latest snapshot file from Leader node A.
[0126] In this application, the monitoring module is used to collect performance data such as cache hit rate, request latency, and node load, and the data is transmitted to the central control system in real time through Kafka, and the time series database (InfluxDB) is used to store historical data. A deep learning model (such as LSTM or Transformer) is used to predict the access pattern of hot data, dynamically allocate cache resources, and prioritize hot data to improve system performance. By dynamically expanding and reducing the node cache capacity, combined with the consistent hashing algorithm and RedisCluster, balanced data migration is achieved to ensure that the cache pressure of high-load nodes is effectively dispersed. Configure performance thresholds such as cache hit rate and latency. When the indicators are abnormal, an alarm is triggered and the relevant personnel are informed through the notification mechanism to intervene in time. Use Grafana to build a performance indicator visualization dashboard, which supports multi-dimensional data display such as cache hit rate trends, latency distribution, and node load, and generates system optimization reports.
[0127] An embodiment of the present application provides an optimization method for a distributed cache, the optimization method comprising: inputting historical request data of multiple hotspot data into a hotspot data prediction model, performing data preprocessing, feature extraction, and future access frequency prediction processing on the historical request data, and predicting the access frequency of each of the hotspot data in a future time period; wherein the hotspot data prediction model is obtained by iteratively training a long short-term memory network model; determining the data information of target hotspot data whose access frequency is greater than a preset access frequency, and performing node caching on the data information of the target hotspot data based on the real-time load resource usage information of each cache node; and dynamically adjusting the cache strategy of each cache node based on a reinforcement learning model and multiple performance indicator data of each cache node. Predict future hotspot data in advance, and load the hotspot data into the cache in advance to reduce the cache miss rate, introduce a reinforcement learning model to continuously adjust the cache strategy based on real-time feedback, ensure optimal cache management under different loads and request modes, achieve balanced resource allocation, and avoid resource waste between nodes.
[0128] See also Figure 2 、 Figure 3 , Figure 2 This is one of the structural diagrams of a distributed cache optimization device provided in an embodiment of the present application; Figure 3 This is a second structural diagram of a distributed cache optimization device provided in an embodiment of the present application. Figure 2 As shown in FIG, the distributed cache optimization device 200 includes:
[0129] The access frequency prediction module 210 is used to input the historical request data of multiple hot data into the hot data prediction model, perform data preprocessing, feature extraction and future access frequency prediction on the historical request data, and predict the access frequency of each hot data in the future time period; wherein the hot data prediction model is obtained by iteratively training the long short-term memory network model;
[0130] The cache allocation module 220 is used to determine the data information of the target hotspot data whose access frequency is greater than the preset access frequency, and perform node caching on the data information of the target hotspot data based on the real-time load resource usage information of each cache node;
[0131] The dynamic optimization module 230 is configured to dynamically adjust the cache strategy of each cache node based on a reinforcement learning model and a plurality of performance indicator data of each cache node.
[0132] Furthermore, the access frequency prediction module 210 is used to input the historical request data of the plurality of hotspot data into the hotspot data prediction model for each of the hotspot data, perform data preprocessing, feature extraction, and future access frequency prediction processing on the historical request data, and predict the access frequency of each of the hotspot data in the future time period. Specifically, the access frequency prediction module 210 is used to:
[0133] Extracting time features, access frequency features, and data ID embedding vectors from historical request data of the hot data based on the hot data prediction model, and constructing time series of the time features, access frequency features, and data ID embedding vectors according to multiple preset time windows to determine the time series features under each time window;
[0134] Performing data cleaning on the time series features in each time window to determine the target time series features in each time window;
[0135] Based on the first long short-term memory network layer of the hot data prediction model, short-term feature capture is performed on the target time series features under each time window, and a short-term feature capture sequence of each time window is output;
[0136] Inputting the short-term feature capture sequence of each time window into the second long short-term memory network layer to capture long-term trend features, and determining the long-term feature capture sequence of each time window;
[0137] The long-term feature capture sequence of each time window is input into the fully connected network layer of the hot data prediction model for processing, and the access frequency of the hot data in the future time period is output.
[0138] Further, such as Figure 3 As shown, the distributed cache optimization device further includes a model training module 240, which determines the hot data prediction model through the following steps:
[0139] Inputting historical request data of a plurality of sample hotspot data into the long short-term memory network model, processing the historical request data of each sample hotspot data, and determining the predicted access frequency of each sample hotspot data in a future time period;
[0140] Determine a root mean square error (RMSE) and a mean absolute error (MAE) based on the actual access frequency and the predicted access frequency of each sample hotspot data in a future time period;
[0141] If either the root mean square error value or the mean absolute error is greater than a preset threshold, the network parameters of the long short-term memory network model are optimized, and the optimized long short-term memory network model is continuously trained until the root mean square error value and the mean absolute error are both less than or equal to the preset threshold, and the training is stopped to determine the hotspot data prediction model.
[0142] Furthermore, when the cache allocation module 220 is used to perform node caching on the data information of the target hotspot data based on the real-time load resource usage information of each cache node, the cache allocation module 220 is specifically used to:
[0143] Detecting whether the cache node with the lowest real-time load resource usage has sufficient cache space to accommodate the data information of the target hotspot data;
[0144] If so, the data information of the target hotspot data in the future time period is loaded and cached into the cache node with the lowest real-time load resource usage;
[0145] If not, the low-frequency data in the cache node with the lowest real-time load resource usage is deleted to complete the expansion of the cache node, and the data information of the target hot data in the future time period is cached in the expanded cache node.
[0146] Furthermore, when the dynamic optimization module 230 is used to dynamically adjust the cache strategy of each cache node based on the reinforcement learning model and the multiple performance indicator data of each cache node, the dynamic optimization module 230 is specifically used to:
[0147] Extracting features from a plurality of performance indicator data of each cache node to determine a state feature vector of each cache node; wherein the performance indicator data includes cache hit rate, average request latency, node load, and cache space utilization;
[0148] Inputting the state feature vector of each cache node into a reinforcement learning model, and performing reinforcement optimization on the cache strategy adjustment action of the state feature vector of each cache node based on a greedy algorithm and a preset reward mechanism;
[0149] Based on the cache policy adjustment action of each cache node, the corresponding cache node is dynamically adjusted; wherein the cache policy adjustment action includes cache content adjustment action and load balancing.
[0150] Furthermore, the dynamic optimization module 230 is configured to dynamically adjust the corresponding cache node based on the cache policy adjustment action of each cache node for the load balancing adjustment action; wherein, when the cache policy adjustment action includes a cache content adjustment action or a load balancing adjustment action, the dynamic optimization module 230 is specifically configured to:
[0151] Based on the distributed cache cluster and consistent hashing algorithm, the cache data of hot data in the high-load cache node is migrated to the low-load cache node.
[0152] Further, such as Figure 3 As shown, the distributed cache optimization device further includes a node synchronization module 250, which is used to:
[0153] After receiving a request from the client to update cache data, the cache node forwards the update request to a leading cache node in the distributed cache cluster;
[0154] The updated information of the cache data is synchronously written into the log of the leader cache node. After the log synchronization is completed, the leader cache node broadcasts the cache update operation to all cache nodes through the Kafka message queue.
[0155] The embodiment of the present application provides an optimization device for a distributed cache, the optimization device comprising: an access frequency prediction module for inputting historical request data of multiple hotspot data into a hotspot data prediction model, performing data preprocessing, feature extraction, and future access frequency prediction processing on the historical request data, and predicting the access frequency of each of the hotspot data in a future time period; wherein the hotspot data prediction model is obtained by iteratively training a long short-term memory network model; a cache allocation module for determining data information of target hotspot data whose access frequency is greater than a preset access frequency, and performing node caching on the data information of the target hotspot data based on the real-time load resource usage information of each cache node; a dynamic optimization module for dynamically adjusting the cache strategy of each cache node based on a reinforcement learning model and multiple performance indicator data of each cache node. Predict future hotspot data in advance and load the hotspot data into the cache in advance to reduce the cache miss rate, introduce a reinforcement learning model to continuously adjust the cache strategy based on real-time feedback, ensure optimal cache management under different loads and request modes, achieve balanced resource allocation, and avoid resource waste between nodes.
[0156] See also Figure 4 , Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Figure 4 As shown in FIG, the electronic device 400 includes a processor 410 , a memory 420 and a bus 430 .
[0157] The memory 420 stores machine-readable instructions executable by the processor 410. When the electronic device 400 is running, the processor 410 communicates with the memory 420 via the bus 430. When the machine-readable instructions are executed by the processor 410, the above-mentioned Figure 1 The steps of the distributed cache optimization method in the illustrated method embodiment and the specific implementation thereof can be found in the method embodiment, which will not be described in detail here.
[0158] The embodiment of the present application also provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the computer program can execute the above-mentioned Figure 1 as well as Figure 2 The steps of the distributed cache optimization method in the illustrated method embodiment and the specific implementation thereof can be found in the method embodiment, which will not be described in detail here.
[0159] Those skilled in the art will clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0160] In the several embodiments provided in this application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the units is merely a logical function division. There may be other division methods in actual implementation. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed may be through some communication interface, indirect coupling or communication connection of devices or units, which may be electrical, mechanical or other forms.
[0161] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.
[0162] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0163] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a non-volatile computer-readable storage medium that is executable by a processor. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0164] Finally, it should be noted that the above-described embodiments are only specific implementation methods of the present application, which are used to illustrate the technical solutions of the present application, rather than to limit them. The scope of protection of the present application is not limited thereto. Although the present application has been described in detail with reference to the above-mentioned embodiments, those skilled in the art should understand that any person skilled in the art can modify or easily conceive of changes to the technical solutions described in the above-mentioned embodiments within the technical scope disclosed in the present application, or perform equivalent replacements for some of the technical features thereof. These modifications, changes, or replacements do not deviate from the spirit and scope of the technical solutions of the embodiments of the present application, and should be included in the scope of protection of the present application. Therefore, the scope of protection of the present application should be based on the scope of protection of the claims.
Claims
1. A distributed cache optimization method, characterized in that: The optimization method comprises: Inputting historical request data of multiple hot data into a hot data prediction model, performing data preprocessing, feature extraction, and future access frequency prediction on the historical request data, and predicting the access frequency of each hot data in a future time period; wherein the hot data prediction model is obtained by iteratively training a long short-term memory network model; Determine data information of target hotspot data whose access frequency is greater than a preset access frequency, and perform node caching on the data information of the target hotspot data based on real-time load resource usage information of each cache node; Dynamically adjusting the cache strategy of each cache node based on a reinforcement learning model and multiple performance indicator data of each cache node; For each of the hot data, the historical request data of the multiple hot data are input into the hot data prediction model, and the historical request data are subjected to data preprocessing, feature extraction, and future access frequency prediction processing to predict the access frequency of each of the hot data in the future time period, including: Extracting time features, access frequency features, and data ID embedding vectors from historical request data of the hot data based on the hot data prediction model, and constructing time series of the time features, access frequency features, and data ID embedding vectors according to multiple preset time windows to determine the time series features under each time window; Performing data cleaning on the time series features in each time window to determine the target time series features in each time window; Based on the first long short-term memory network layer of the hot data prediction model, short-term feature capture is performed on the target time series features under each time window, and a short-term feature capture sequence of each time window is output; Inputting the short-term feature capture sequence of each time window into the second long short-term memory network layer to capture long-term trend features, and determining the long-term feature capture sequence of each time window; The long-term feature capture sequence of each time window is input into the fully connected network layer of the hot data prediction model for processing, and the access frequency of the hot data in the future time period is output.
2. The optimization method according to claim 1, characterized in that The hotspot data prediction model is determined by the following steps: Inputting historical request data of a plurality of sample hotspot data into the long short-term memory network model, processing the historical request data of each sample hotspot data, and determining the predicted access frequency of each sample hotspot data in a future time period; Determine a root mean square error (RMSE) and a mean absolute error (MAE) based on the actual access frequency and the predicted access frequency of each sample hotspot data in a future time period; If either the root mean square error value or the mean absolute error is greater than a preset threshold, the network parameters of the long short-term memory network model are optimized, and the optimized long short-term memory network model is continuously trained until the root mean square error value and the mean absolute error are both less than or equal to the preset threshold, and the training is stopped to determine the hotspot data prediction model.
3. The optimization method according to claim 1, characterized in that The node caching of data information of target hotspot data based on the real-time load resource usage information of each cache node includes: Detecting whether the cache node with the lowest real-time load resource usage has sufficient cache space to accommodate the data information of the target hotspot data; If so, the data information of the target hotspot data in the future time period is loaded and cached into the cache node with the lowest real-time load resource usage; If not, the low-frequency data in the cache node with the lowest real-time load resource usage is deleted to complete the expansion of the cache node, and the data information of the target hot data in the future time period is cached in the expanded cache node.
4. The optimization method according to claim 1, characterized in that The dynamically adjusting the cache strategy of each cache node based on the reinforcement learning model and the multiple performance indicator data of each cache node includes: Extracting features from a plurality of performance indicator data of each cache node to determine a state feature vector of each cache node; wherein the performance indicator data includes cache hit rate, average request latency, node load, and cache space utilization; Inputting the state feature vector of each cache node into a reinforcement learning model, and performing reinforcement optimization on the cache strategy adjustment action of the state feature vector of each cache node based on a greedy algorithm and a preset reward mechanism; Based on the cache policy adjustment action of each cache node, the corresponding cache node is dynamically adjusted; wherein the cache policy adjustment action includes cache content adjustment and load balancing.
5. The optimization method according to claim 4, characterized in that: With respect to the load balancing adjustment action, the cache policy adjustment action based on each cache node dynamically adjusts the corresponding cache node; wherein the cache policy adjustment action includes a cache content adjustment action or a load balancing adjustment action, including: Based on the distributed cache cluster and consistent hashing algorithm, the cache data of hot data in the high-load cache node is migrated to the low-load cache node.
6. The optimization method according to claim 1, characterized in that: After determining the data information of the target hotspot data whose access frequency is greater than the preset access frequency, and performing node caching on the data information of the target hotspot data based on the real-time load resource usage information of each cache node, the optimization method further includes: After receiving a request from the client to update cache data, the cache node forwards the update request to a leading cache node in the distributed cache cluster; The updated information of the cache data is synchronously written into the log of the leader cache node. After the log synchronization is completed, the leader cache node broadcasts the cache update operation to all cache nodes through the Kafka message queue.
7. A distributed cache optimization device, characterized in that: The optimization device comprises: An access frequency prediction module is used to input historical request data of multiple hot data into a hot data prediction model, perform data preprocessing, feature extraction, and future access frequency prediction on the historical request data, and predict the access frequency of each hot data in a future time period; wherein the hot data prediction model is obtained by iteratively training a long short-term memory network model; A cache allocation module is used to determine the data information of target hotspot data whose access frequency is greater than a preset access frequency, and perform node caching on the data information of the target hotspot data based on the real-time load resource usage information of each cache node; A dynamic optimization module, configured to dynamically adjust the cache strategy of each cache node based on a reinforcement learning model and a plurality of performance indicator data of each cache node; The access frequency prediction module is used to input the historical request data of multiple hot data into the hot data prediction model for each hot data, perform data preprocessing, feature extraction and future access frequency prediction on the historical request data, and predict the access frequency of each hot data in the future time period. The access frequency prediction module is specifically used to: Extracting time features, access frequency features, and data ID embedding vectors from historical request data of the hot data based on the hot data prediction model, and constructing time series of the time features, access frequency features, and data ID embedding vectors according to multiple preset time windows to determine the time series features under each time window; Performing data cleaning on the time series features in each time window to determine the target time series features in each time window; Based on the first long short-term memory network layer of the hot data prediction model, short-term feature capture is performed on the target time series features under each time window, and a short-term feature capture sequence of each time window is output; Inputting the short-term feature capture sequence of each time window into the second long short-term memory network layer to capture long-term trend features, and determining the long-term feature capture sequence of each time window; The long-term feature capture sequence of each time window is input into the fully connected network layer of the hot data prediction model for processing, and the access frequency of the hot data in the future time period is output.
8. An electronic device, characterized in that: include: A processor, a memory and a bus, wherein the memory stores machine-readable instructions executable by the processor. When the electronic device is running, the processor and the memory communicate through the bus, and the machine-readable instructions are executed by the processor to execute the steps of the distributed cache optimization method as described in any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the distributed cache optimization method according to any one of claims 1 to 6 are executed.
Citation Information
Patent Citations
Intelligent hotspot data prediction and caching method
CN112637273A
Edge cache deployment strategy based on wireless edge network
CN118555615A