Data processing method and device, equipment and storage medium
By using a two-level cache structure and a hash function counter statistical method in the database to identify and store hotspot data, the problem of hotspot data identification and storage under limited memory is solved, and the cache query hit rate and system throughput rate are improved.
Patent Information
- Application Number
- CN202311403445.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-10-26
- Publication Date
- 2024-10-18
AI Technical Summary
Existing technologies are difficult to accurately identify and store hotspot data, resulting in a waste of memory resources and low query hit rates, especially when memory is limited.
A two-level cache structure is adopted, sorted by query time and query frequency growth rate, real-time hot data and recent hot data are stored in the first-level cache and second-level cache respectively, and high-level data are identified and stored through hash functions and counter statistical methods. Frequently accessed data.
It improves cache query hit rate, accurately identifies and stores hotspot data, effectively utilizes memory resources, and improves system throughput and query efficiency.
Smart Images

Figure CN118796883A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of memory cache management of a database, and in particular to a data processing method, apparatus, device and storage medium. Background Art
[0002] With the explosion of the data age, service providers generate massive amounts of data every day and store this data in databases for users to query and access. Operators usually store frequently accessed hot data in memory, using the high performance of reading and writing in memory to improve the system throughput, but memory is usually expensive, and memory in any system cannot be expanded unlimitedly like a hard disk. Memory usage is limited. Therefore, how to accurately identify hot data and store hot data in limited memory to improve query hit rate is an urgent problem to be solved. Summary of the invention
[0003] The embodiments of the present application provide a data processing method, apparatus, device and storage medium, which can accurately identify hotspot data and store the hotspot data in a cache to improve the cache query hit rate.
[0004] In a first aspect, an embodiment of the present application provides a data processing method, the data processing method comprising:
[0005] Get query records of multiple data in the database;
[0006] According to the query time in the query records of the multiple data, the multiple data are sorted in order from the nearest to the current time to obtain a first sorting sequence;
[0007] Determine first N first data in a first sorting sequence from a plurality of data, where N is a positive integer;
[0008] storing the first data in a first level cache;
[0009] Filter the data in the first sorting sequence to select the data whose query time is within the current cycle;
[0010] According to the query frequency growth rate of the data in the current cycle, the data in the current cycle are sorted in descending order of the query frequency growth rate to obtain a second sorting sequence;
[0011] Determine, at the query time, the first M second data in the second sorting sequence from the data in the current cycle, where M is a positive integer;
[0012] The second data is stored in a secondary cache, wherein the cache space corresponding to the database includes at least a primary cache and a secondary cache.
[0013] In some embodiments of the present application, the cache space corresponding to the database further includes a three-level cache, and the data processing method further includes:
[0014] According to the query records of the multiple data, a counter is used to count the query times of the multiple data to obtain the query times statistics result;
[0015] According to the query count statistics, multiple data are sorted in descending order of counts to obtain a third sorting sequence;
[0016] Determine, from among the plurality of data, third data that are located in the first Q of the third sorting sequence, where Q is a positive integer;
[0017] The third data is stored in the third level cache.
[0018] In some embodiments of the present application, according to the query frequency growth rate of the data in the current period, the data in the current period are sorted in descending order of the query frequency growth rate to obtain a second sorting sequence, including:
[0019] For each data, determine the query frequency of each data in the current cycle according to the weight of each query user corresponding to each data and the query times of each query user;
[0020] For each data, determine the query frequency growth rate of each data based on the query frequency in the current cycle and the query frequency in the previous cycle;
[0021] The data with query time in the current period are sorted in descending order of query frequency growth rate to obtain a second sorting sequence.
[0022] In some embodiments of the present application, for each data, before determining the query frequency of each data in the current cycle according to the weight of each query user corresponding to each data and the query times of each query user, the data processing method further includes:
[0023] For each query user and each data, the weight of each query user is determined according to the number of times each query user queries each data and the number of times all query users query each data.
[0024] In some embodiments of the present application, the weight of each query user is obtained by the following formula:
[0025]
[0026] Among them, w j is the weight of the j-th query user, MF jis the query count of the jth query user, MF l is the number of queries by the lth query user;
[0027] The query frequency in the current cycle is obtained by the following formula:
[0028]
[0029] in, is the query frequency of the i-th data in the k-th cycle;
[0030] The query frequency growth rate in the current cycle is obtained by the following formula:
[0031]
[0032] in, is the query frequency growth rate of the i-th data in the k-th cycle, is the query frequency of the i-th data in the k-1-th cycle.
[0033] In some embodiments of the present application, a counter is used to count the number of queries of the plurality of data according to the query records of the plurality of data to obtain a query number statistical result, including:
[0034] Preset p hash functions and q counting columns;
[0035] Determine an initial counter data table according to the p hash functions and the q count columns;
[0036] For each data, each data is queried once, and the counting result of each data is calculated according to the data identifier of each data, p hash functions and q counting columns;
[0037] According to the counting result, the initial counter data table is updated to obtain the query number statistics result;
[0038] Wherein, p and q are positive integers.
[0039] In some embodiments of the present application, for each data, each data is queried once, and the counting result of each data is calculated according to the data identifier of each data, p hash functions and q counting columns, including:
[0040] The counting result of each data is calculated according to the following formula:
[0041]
[0042] Among them, x k is the data identifier of the kth data, h1, h2...h p is the counting result.
[0043] In a second aspect, an embodiment of the present application provides a data processing device, the data processing device comprising:
[0044] The acquisition module is used to obtain query records of multiple data in the database;
[0045] A first sorting module is used to sort the multiple data in order from near to far from the current time according to the query time in the query records of the multiple data, so as to obtain a first sorting sequence;
[0046] A first determining module, used to determine the first N first data in a first sorting sequence from a plurality of data, where N is a positive integer;
[0047] A first storage module, used for storing the first data in a first-level cache;
[0048] A screening module, used to screen the data in the first sorting sequence, and screen out the data whose query time is within the current cycle;
[0049] A second sorting module is used to sort the data in the current cycle in descending order of query frequency growth rate according to the query frequency growth rate of the data in the current cycle, to obtain a second sorting sequence;
[0050] A second determination module is used to determine the first M second data in the second sorting sequence from the data in the current cycle at the query time, where M is a positive integer;
[0051] The second storage module is used to store the second data in the secondary cache, wherein the cache space corresponding to the database includes at least the primary cache and the secondary cache.
[0052] In a third aspect, an embodiment of the present application provides a data processing device, the data processing device comprising: a processor and a memory storing computer program instructions;
[0053] When the processor executes the computer program instructions, the data processing method of any of the above embodiments is implemented.
[0054] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, on which computer program instructions are stored. When the computer program instructions are executed by a processor, the data processing method of any of the above embodiments is implemented.
[0055] According to the data processing method, device, equipment and storage medium of the embodiments of the present application, the cache space corresponding to the database includes at least a first-level cache and a second-level cache. The first-level cache is used to store the first data whose query time ranks in the top N, that is, to store the hot data that appears in real time, so as to improve the cache query hit rate of the real-time hot data. The second-level cache is used to store the second data whose query frequency growth rate ranks in the top M in the current cycle, that is, to store the hot data in a recent period of time, so as to improve the cache query hit rate of the hot data in a recent period of time. By setting a two-level cache, the hot data can be accurately identified and stored, thereby improving the cache query hit rate. BRIEF DESCRIPTION OF THE DRAWINGS
[0056] In order to more clearly illustrate the technical solution of the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0057] Figure 1 A flowchart of a data processing method provided in an embodiment of the present application;
[0058] Figure 2 This is a flowchart of the memory elimination principle of the LRU algorithm;
[0059] Figure 3 Another flowchart of the data processing method provided in the embodiment of the present application;
[0060] Figure 4 A schematic diagram of the structure of a data processing device provided in an embodiment of the present application;
[0061] Figure 5 Another structural schematic diagram of a data processing device provided in an embodiment of the present application;
[0062] Figure 6 A schematic diagram of the structure of a data processing device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0063] The features and exemplary embodiments of various aspects of the present application will be described in detail below. In order to make the purpose, technical solutions and advantages of the present application clearer, the present application will be further described in detail below in conjunction with the accompanying drawings and specific embodiments. It should be understood that the specific embodiments described herein are only intended to explain the present application, rather than to limit the present application. For those skilled in the art, the present application can be implemented without the need for some of these specific details. The following description of the embodiments is only to provide a better understanding of the present application by illustrating the examples of the present application.
[0064] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the statement "include..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0065] With the explosion of the data age, service providers generate massive amounts of data every day and store this data in databases for users to query and access. Operators usually store frequently accessed hot data in memory, using the high performance of reading and writing in memory to improve the system throughput, but memory is usually expensive, and memory in any system cannot be expanded unlimitedly like a hard disk. Memory usage is limited. Therefore, how to accurately identify hot data and store hot data in limited memory to improve query hit rate is an urgent problem to be solved.
[0066] The main methods of memory elimination in the related art are LRU (Least Recently Used) algorithm and LFU (Least Frequently Used) algorithm.
[0067] The LRU method is simple and efficient when frequently accessing hot data, but its disadvantage is that the hit rate will be very low if cold data is accessed in batches occasionally. For example, if A is frequently accessed, and then a batch of cold data is accessed in batches until A is eliminated, then A has to be added to the cache again when it is accessed again. Obviously, this method is inappropriate because A has been accessed many times and it should not be eliminated and a bunch of data that has only been accessed once should be added to the cache.
[0068] The LFU algorithm counts the frequency of hot data in the recent period and deletes the low-frequency data. This method can effectively solve the problem of LRU algorithm deleting hot data due to batch cold data access. However, the method of simply increasing the counter is not perfect. The data access pattern changes frequently. For example, the latest added data is often kicked out because its initial method has a small number of times, and some data that was frequently accessed in the past cannot be eliminated due to the large number of accesses, resulting in inaccurate hot data. For example, in a flash sale scenario, the instantaneous high-frequency access volume is particularly large, and this part of the data is basically not used after the flash sale scenario. If the LFU algorithm is used, this part of the data will be cached in the memory, occupying storage space, and the real hot data will be easily deleted.
[0069] In order to solve the above technical problems, the embodiments of the present application provide a data processing method, apparatus, device and storage medium, which can accurately identify hotspot data and store the hotspot data in a cache to improve the cache query hit rate.
[0070] In a first aspect, an embodiment of the present application provides a data processing method.
[0071] Figure 1 A flowchart of a data processing method provided in an embodiment of the present application.
[0072] Combine the following Figure 1 The data processing method of the embodiment of the present application is introduced, and the data processing method includes:
[0073] S110, obtaining query records of multiple data in the database;
[0074] Specifically, each time a data is queried, a query record corresponding to the data will be stored in the database. The query record may include the query time, the query user, the query times, etc.
[0075] S120 , sorting the multiple data in order from near to the current time according to the query time in the query records of the multiple data, to obtain a first sorting sequence.
[0076] S130, determining first N first data in a first sorting sequence from a plurality of data, where N is a positive integer.
[0077] S140, storing the first data in a first-level cache.
[0078] Specifically, the first-level cache uses the LRU algorithm for caching. The design principle of the LRU algorithm is: if a piece of data has not been accessed in the recent period, then it is unlikely to be accessed in the future. In other words, when the limited space is full of data, the data that has not been accessed for the longest time should be eliminated. Figure 2 This is a schematic diagram of the LRU algorithm memory elimination principle process; combined Figure 2 As shown, the principle of the LRU algorithm is:
[0079] (1) When adding a key or value, first add a Node node to the head of the linked list. If it exceeds the threshold set by LRU, the node at the end of the queue is eliminated;
[0080] (2) When modifying the value corresponding to a key, first modify the value in the corresponding Node, and then move the Node to the head of the queue.
[0081] (3) When accessing the value corresponding to the key, just move the accessed Node to the head of the queue.
[0082] The first-level cache stores the most recently used hot data in the quasi-real-time data. The function of the first-level cache is to deal with quasi-real-time hot data, and this part of the data is also the hot data in the recent period of time.
[0083] When storing data, for example, assuming that points are used to redeem goods, hot goods need to be cached in memory to improve query efficiency. The specific product data is shown in Table 1.
[0084] Table 1 Query information of some commodities
[0085]
[0086]
[0087] (1) When a user queries a product, a node is added to the head of the linked list.<key,value> The key is "product id" and the value is "product name + redemption points".
[0088] (2) When a new product query comes in, follow step (1) until the first-level cache is fully stored.
[0089] (3) When the first-level cache is full, when there is another product query, the product is saved to the head of the linked list, and the data cached at the bottom of the linked list is automatically deleted.
[0090] In this way, the first-level cache adopts the LRU memory management method to cache high-frequency hot words that appear in real time. The role of this part of memory is to improve the cache hit rate of real-time hot words.
[0091] S150, filtering the data in the first sorting sequence to filter out the data whose query time is within the current cycle.
[0092] S160, according to the query frequency growth rate of the data in the current cycle, sort the data in the current cycle in descending order of the query frequency growth rate to obtain a second sorting sequence.
[0093] S170, determining the first M second data in the second sorting sequence from the data in the current cycle at the query time, where M is a positive integer.
[0094] S180, storing the second data in a secondary cache, wherein the cache space corresponding to the database includes at least a primary cache and a secondary cache.
[0095] Specifically, the current cycle refers to a recent period of time, which can be a month, a week, a quarter, etc. The query frequency growth rate refers to the growth rate of the frequency of data being queried in the current cycle compared to the frequency of data being queried in the previous cycle. The secondary cache stores recent hot data. Recent hot data is defined as a certain type of data that is used in large quantities in a recent period of time (usually a month) and is rarely used in the previous time window. Such words are cached in the secondary cache to cope with the use of recent hot words in query scenarios.
[0096] The above S160 specifically includes: for each data, according to the weight of each query user corresponding to each data and the query times of each query user, determining the query frequency of each data in the current cycle; for each data, according to the query frequency in the current cycle and the query frequency in the previous cycle, determining the query frequency growth rate of each data; sorting the data with query time in the current cycle in descending order of query frequency growth rate to obtain a second sorting sequence.
[0097] Among them, before determining the query frequency of each data in the current cycle according to the weight of each query user corresponding to each data and the query times of each query user, the data processing method also includes: for each query user and each data, determining the weight of each query user according to the number of times each query user queries each data and the number of times all query users query each data.
[0098] Specifically, the weight of each query user is obtained by the following formula:
[0099]
[0100] Among them, w j is the weight of the j-th query user, MF j is the query count of the jth query user, MF l is the number of queries by the lth query user;
[0101] The query frequency in the current cycle is obtained by the following formula:
[0102]
[0103] in, is the query frequency of the i-th data in the k-th cycle;
[0104] The query frequency growth rate in the current cycle is obtained by the following formula:
[0105]
[0106] in, is the query frequency growth rate of the i-th data in the k-th cycle, is the query frequency of the i-th data in the k-1-th cycle.
[0107] In this way, the secondary cache stores the hot words in the recent period (usually in months), and comprehensively calculates from the perspectives of data frequency, frequency growth rate, queryer weight, etc. to identify data that has been used a lot in the recent period and was rarely queried before, so as to cope with the scenario of querying hot words in the recent period. And the larger the amount of data a queryer has recently queried, the higher the influence. The data access frequency is calculated based on the queryer's weighted influence, and the access frequency of each data is sorted from high to low. The hot data with high data access frequency is cached in the secondary cache first, which can effectively improve the hit rate of recent hot words.
[0108] In some embodiments of the present application, the ratio of the first-level cache to the second-level cache in the cache space corresponding to the database can be 1:1, or 2:1, or can be set according to actual needs.
[0109] According to the data processing method of the embodiment of the present application, the cache space corresponding to the database includes at least a first-level cache and a second-level cache. The first-level cache is used to store the first data whose query time ranks in the top N, that is, to store the hot data that appears in real time, so as to improve the cache query hit rate of the real-time hot data. The second-level cache is used to store the second data whose query frequency growth rate ranks in the top M in the current cycle, that is, to store the hot data in a recent period of time, so as to improve the cache query hit rate of the hot data in a recent period of time. By setting a two-level cache, the hot data can be accurately identified and stored, thereby improving the cache query hit rate.
[0110] Figure 3 Another flowchart of the data processing method provided in the embodiment of the present application;
[0111] Combination Figure 3In some embodiments of the present application, the cache space corresponding to the database further includes a three-level cache, and the data processing method further includes:
[0112] S310, performing counter statistics on the query times of the multiple data according to the query records of the multiple data to obtain query times statistics results.
[0113] S320, sorting the plurality of data in descending order of counts according to the query count statistics result to obtain a third sorting sequence.
[0114] S330, determining the first Q third data in a third sorting sequence from the plurality of data, where Q is a positive integer.
[0115] S340, store the third data in the third-level cache.
[0116] Specifically, the above S310 includes: presetting p hash functions and q count columns; determining an initial counter data table based on the p hash functions and the q count columns; for each data, each data is queried once, and the counting result of each data is calculated based on the data identifier of each data, p hash functions and q count columns; based on the counting result, updating the initial counter data table to obtain the query number statistics result; wherein p and q are positive integers.
[0117] The three-level cache identifies hot data that is frequently accessed in any period based on all historical query data. Since the server has limited memory space, when the amount of data is very large, this application proposes an efficient hot data counter method, which maps the ID of each query data to different intervals through p hash functions, and uses q columns. When the data is accessed once, the p counter values are increased by 1 accordingly, and the number of accesses of each data is converted into the sum of p counters. Data with high access times are cached preferentially in the three-level cache. In this way, the access situation of any N (very large) set of data can be mapped into a storage method of p*q memory spaces, which greatly improves storage efficiency while greatly reducing the memory storage space and maintaining the accuracy of hot data.
[0118] Specifically, assuming that the data access situation is as shown in Table 1, the efficient hot data counter statistical method is as follows:
[0119] 1. The parameters are defined as follows:
[0120] Assume there are p hash functions in the system
[0121] Assume there are q count columns in the system
[0122] Space used in memory = p*q*memory per calculation space
[0123] p and q parameters are set manually
[0124] 2. There are p hash functions in the system, namely hash1, hash2, hash3...hash p , assuming that the id of a certain data is, calculate in sequence:
[0125]
[0126] Among them, x k is the data identifier of the kth data, h1, h2...h p is the counting result.
[0127] 3. The memory space initialization state is:
[0128] Table 2 Hotspot data counter statistics initialization
[0129] 0 1 2 4 5 ...... m-1 Hash1 0 0 0 0 0 0 0 Hash2 0 0 0 0 0 0 0 ...... 0 0 0 0 0 0 0 Hashp 0 0 0 0 0 0 0
[0130] For example, the calculation result of the data with data ID x1 after the above modulo operation is:
[0131]
[0132] That is, the storage space for the count of data with data ID x1 is mapped to (hash1, 4), (hash1, 3), ... (hash1, 4) in the table. p ,2),Every time the data with data ID x1 is accessed, 1 is added to the counter space, and the hot data counter becomes Table 3.
[0133] Table 3 Hotspot data counter statistics transformation 1
[0134] 0 1 2 3 4 ...... m-1 Hash1 0 0 0 0 1 0 0 Hash2 0 0 0 1 0 0 0 ...... 0 0 0 0 0 0 0 Hashp 0 0 1 0 0 0 0
[0135] The data corresponding to the remaining data IDs also have corresponding storage spaces, and each time the data is accessed, the count in the corresponding storage space is increased by 1.
[0136] Each query updates the data in the hot data counter in turn (Table 3). The query status of each data can be represented by the sum of the query times in p cells. The sum of the query times of p cells of each query data is calculated in turn, and the data with the largest sum of query times in p cells is cached preferentially in the three-level cache.
[0137] From the above algorithm, we can see that for the number of queries for each hotspot data, if we want to reduce the error range and make the query more accurate, we need larger p and q values. However, in an actual production environment, the memory cannot be infinite, and p and q cannot be infinite. Through the above algorithm, we can more accurately evaluate the access volume of hotspot data within the limited memory space, and achieve a good balance between storage space and query performance.
[0138] In some embodiments of the present application, the cache space occupancy ratio of the first-level cache, the second-level cache, and the third-level cache can be 3:3:4 or 4:3:3. The specific ratio can be set according to actual needs and is not limited by the present application.
[0139] In this way, the first-level cache uses the LRU memory management method to cache high-frequency hot words that appear in real time. The role of this part of memory is to improve the cache hit rate of real-time hot words; the second-level cache stores hot words in the recent period (usually in months), effectively improving the hit rate of recent hot words; the third-level cache is based on all historical data, effectively using memory space to cache the algorithm of historical query hot words, and improving the hit rate of historical hot words through effective space. Through this three-level cache mechanism, real-time, recent, and all historical hot words can be effectively covered, improving the efficiency of hot word management and hit rate.
[0140] In a second aspect, an embodiment of the present application provides a data processing device.
[0141] Figure 4 A schematic diagram of the structure of a data processing device provided in an embodiment of the present application.
[0142] Combine the following Figure 4 The data processing device of the embodiment of the present application is introduced, and the data processing device includes:
[0143] The acquisition module 401 is used to acquire query records of multiple data in the database;
[0144] A first sorting module 402 is used to sort the multiple data in order from near to far from the current time according to the query time in the query records of the multiple data, to obtain a first sorting sequence;
[0145] A first determining module 403 is used to determine the first N first data in a first sorting sequence from a plurality of data, where N is a positive integer;
[0146] A first storage module 404, configured to store the first data in a first-level cache;
[0147] A screening module, used to screen the data in the first sorting sequence, and screen out the data whose query time is within the current cycle 405;
[0148] The second sorting module 406 is used to sort the data in the current cycle in descending order of query frequency growth rate according to the query frequency growth rate of the data in the current cycle, to obtain a second sorting sequence;
[0149] A second determination module 407 is used to determine the first M second data in the second sorting sequence from the data in the current cycle at the query time, where M is a positive integer;
[0150] The second storage module 408 is used to store the second data in the secondary cache, wherein the cache space corresponding to the database includes at least the primary cache and the secondary cache.
[0151] Figure 5 Another structural schematic diagram of a data processing device provided in an embodiment of the present application;
[0152] In some embodiments of the present application, the cache space corresponding to the database further includes a three-level cache, and the data processing device further includes:
[0153] A statistics module 501 is used to count the query times of the multiple data according to the query records of the multiple data to obtain the query times statistics result;
[0154] The third sorting module 502 is used to sort the multiple data in descending order of counts according to the query count statistics result to obtain a third sorting sequence;
[0155] A third determining module 503 is used to determine the first Q third data in a third sorting sequence from the plurality of data, where Q is a positive integer;
[0156] The third storage module 504 is used to store the third data in the third-level cache.
[0157] In some embodiments of the present application, the second sorting module 406 is specifically configured to:
[0158] For each data, determine the query frequency of each data in the current cycle according to the weight of each query user corresponding to each data and the query times of each query user;
[0159] For each data, determine the query frequency growth rate of each data based on the query frequency in the current cycle and the query frequency in the previous cycle;
[0160] The data with query time in the current period are sorted in descending order of query frequency growth rate to obtain a second sorting sequence.
[0161] In some embodiments of the present application, the second ranking module 406 is further used to determine the weight of each query user and each data according to the number of times each query user queries each data and the number of times all query users query each data.
[0162] In some embodiments of the present application, the weight of each query user is obtained by the following formula:
[0163]
[0164] Among them, w j is the weight of the j-th query user, MF j is the query count of the jth query user, MF l is the number of queries by the lth query user;
[0165] The query frequency in the current cycle is obtained by the following formula:
[0166]
[0167] in, is the query frequency of the i-th data in the k-th cycle;
[0168] The query frequency growth rate in the current cycle is obtained by the following formula:
[0169]
[0170] in, is the query frequency growth rate of the i-th data in the k-th cycle, is the query frequency of the i-th data in the k-1-th cycle.
[0171] In some embodiments of the present application, the statistical module 501 is specifically used to preset p hash functions and q count columns; determine the initial counter data table based on the p hash functions and the q count columns; for each data, each data is queried once, and the counting result of each data is calculated based on the data identifier of each data, p hash functions and q count columns; based on the counting result, the initial counter data table is updated to obtain the query number statistics result; wherein p and q are positive integers.
[0172] In some embodiments of the present application, the counting result of each data is calculated according to the following formula:
[0173]
[0174] Among them, x k is the data identifier of the kth data, h1, h2...h p is the counting result.
[0175] According to the data processing device of the embodiment of the present application, the cache space corresponding to the database includes at least a first-level cache and a second-level cache. The first-level cache is used to store the first data whose query time ranks in the top N, that is, to store the hot data that appears in real time, thereby improving the cache query hit rate of the real-time hot data. The second-level cache is used to store the second data whose query frequency growth rate ranks in the top M in the current cycle, that is, to store the hot data in the current cycle, thereby improving the cache query hit rate of the hot data in the current cycle. By setting up a two-level cache, the hot data can be accurately identified and stored, thereby improving the cache query hit rate.
[0176] Figure 6 A schematic diagram of the structure of a data processing device provided in an embodiment of the present application.
[0177] The data processing device may include a processor 601 and a memory 602 storing computer program instructions.
[0178] Specifically, the processor 601 may include a central processing unit (CPU), or an application specific integrated circuit (ASIC), or may be configured to implement one or more integrated circuits of the embodiments of the present application.
[0179] The memory 602 may include a large capacity memory for data or instructions. By way of example and not limitation, the memory 602 may include a hard disk drive (HDD), a floppy disk drive, a flash memory, an optical disk, a magneto-optical disk, a magnetic tape, or a universal serial bus (USB) drive or a combination of two or more of these. In appropriate cases, the memory 602 may include a removable or non-removable (or fixed) medium. In appropriate cases, the memory 602 may be inside or outside the integrated gateway disaster recovery device. In a specific embodiment, the memory 602 is a non-volatile solid-state memory.
[0180] The memory may include read-only memory (ROM), random access memory (RAM), magnetic disk storage media devices, optical storage media devices, flash memory devices, electrical, optical or other physical / tangible memory storage devices. Thus, typically, the memory includes one or more tangible (non-transitory) computer-readable storage media (e.g., memory devices) encoded with software including computer-executable instructions, and when the software is executed (e.g., by one or more processors), it is operable to perform the operations described with reference to the method according to an aspect of the present disclosure.
[0181] The processor 601 implements the data processing method in the above embodiment by reading and executing the computer program instructions stored in the memory 602 .
[0182] In one example, the data processing device may further include a communication interface 603 and a bus 610. Figure 6 As shown, the processor 601, the memory 602, and the communication interface 603 are connected via a bus 610 and communicate with each other.
[0183] The communication interface 603 is mainly used to implement communication between various modules, devices, units and / or equipment in the embodiments of the present application.
[0184] Bus 610 includes hardware, software or both, and the components of the payment device are coupled to each other. For example, but not limitation, the bus may include an accelerated graphics port (AGP) or other graphics bus, an enhanced industrial standard architecture (EISA) bus, a front-side bus (FSB), a hypertransport (HT) interconnect, an industrial standard architecture (ISA) bus, an infinite bandwidth interconnect, a low pin count (LPC) bus, a memory bus, a microchannel architecture (MCA) bus, a peripheral component interconnect (PCI) bus, a PCI-Express (PCI-X) bus, a serial advanced technology attachment (SATA) bus, a video electronics standard association local (VLB) bus or other suitable bus or a combination of two or more of these. Where appropriate, bus 610 may include one or more buses. Although the present application embodiment describes and illustrates a specific bus, the present application considers any suitable bus or interconnect.
[0185] The data processing device executes the data processing method in the embodiment of the present application, thereby realizing Figure 1 and Figure 3 The data processing method shown.
[0186] In addition, in combination with the data processing method in the above embodiments, the present application embodiment can provide a computer storage medium for implementation. The computer storage medium stores computer program instructions; when the computer program instructions are executed by a processor, any one of the data processing methods in the above embodiments is implemented.
[0187] It should be clear that the present application is not limited to the specific configuration and processing described above and shown in the figures. For the sake of simplicity, a detailed description of the known method is omitted here. In the above embodiments, several specific steps are described and shown as examples. However, the method process of the present application is not limited to the specific steps described and shown, and those skilled in the art can make various changes, modifications and additions, or change the order between the steps after understanding the spirit of the present application.
[0188] The functional blocks shown in the above-described block diagram can be implemented as hardware, software, firmware or a combination thereof. When implemented in hardware, it can be, for example, an electronic circuit, an application specific integrated circuit (ASIC), appropriate firmware, a plug-in, a function card, etc. When implemented in software, the elements of the present application are programs or code segments that are used to perform the required tasks. The program or code segment can be stored in a machine-readable medium, or transmitted on a transmission medium or a communication link by a data signal carried in a carrier wave. "Machine-readable medium" can include any medium capable of storing or transmitting information. Examples of machine-readable media include electronic circuits, semiconductor memory devices, ROM, flash memory, erasable ROM (EROM), floppy disks, CD-ROMs, optical disks, hard disks, optical fiber media, radio frequency (RF) links, etc. The code segment can be downloaded via a computer network such as the Internet, an intranet, etc.
[0189] It should also be noted that the exemplary embodiments mentioned in this application describe some methods or systems based on a series of steps or devices. However, this application is not limited to the order of the above steps, that is, the steps can be performed in the order mentioned in the embodiment, or in a different order from the embodiment, or several steps can be performed simultaneously.
[0190] Aspects of the present disclosure are described above with reference to the flowchart and / or block diagram of the method, device (system) and computer program product according to the embodiment of the present disclosure. It should be understood that each box in the flowchart and / or block diagram and the combination of each box in the flowchart and / or block diagram can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device to produce a machine so that these instructions executed by the processor of the computer or other programmable data processing device enable the implementation of the function / action specified in one or more boxes of the flowchart and / or block diagram. Such a processor can be, but is not limited to, a general-purpose processor, a special-purpose processor, a special application processor, or a field programmable logic circuit. It can also be understood that each box in the block diagram and / or flowchart and the combination of boxes in the block diagram and / or flowchart can also be implemented by dedicated hardware that performs a specified function or action, or can be implemented by a combination of dedicated hardware and computer instructions.
[0191] The above is only a specific implementation of the present application. Those skilled in the art can clearly understand that for the convenience and simplicity of description, the specific working processes of the systems, modules and units described above can refer to the corresponding processes in the aforementioned method embodiments, and will not be repeated here. It should be understood that the protection scope of the present application is not limited to this. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed in this application, and these modifications or replacements should be included in the protection scope of this application.
Claims
1. A data processing method, characterized in that: The method comprises: Get query records of multiple data in the database; According to the query time in the query records of the multiple data, the multiple data are sorted in order from near to far from the current time to obtain a first sorting sequence; Determine first N first data in the first sorting sequence from the plurality of data, where N is a positive integer; storing the first data in a first-level cache; Filtering the data in the first sorting sequence to filter out data whose query time is within the current period; According to the query frequency growth rate of the data in the current cycle at the query time, the data in the current cycle are sorted in descending order of the query frequency growth rate to obtain a second sorting sequence; Determine the first M second data in the second sorting sequence from the data in the current cycle at the query time, where M is a positive integer; The second data is stored in a secondary cache, wherein the cache space corresponding to the database includes at least the primary cache and the secondary cache.
2. The method according to claim 2, characterized in that: The cache space corresponding to the database also includes a three-level cache, and the method further includes: According to the query records of the multiple data, a counter is used to count the query times of the multiple data to obtain a query times statistical result; According to the query count statistics result, the plurality of data are sorted in descending order of counts to obtain a third sorting sequence; Determine, from the plurality of data, third data located in the first Q of the third sorted sequence, where Q is a positive integer; The third data is stored in the L3 cache.
3. The method according to claim 1, characterized in that According to the query frequency growth rate of the data in the current cycle at the query time, the data in the current cycle at the query time is sorted in descending order of the query frequency growth rate to obtain a second sorting sequence, including: For each data, according to the weight of each query user corresponding to each data and the query times of each query user, determine the query frequency of each data in the current cycle; For each data, determine the query frequency growth rate of each data according to the query frequency in the current cycle and the query frequency in the previous cycle; The data with query time in the current period is sorted in descending order of query frequency growth rate to obtain the second sorting sequence.
4. The method according to claim 3, characterized in that Before determining, for each data, the query frequency of each data in the current cycle according to the weight of each query user corresponding to each data and the query times of each query user, the method further includes: For each query user and each data, the weight of each query user is determined according to the number of times each query user queries the each data and the number of times all query users query the each data.
5. The method according to claim 4, characterized in that The weight of each query user is obtained by the following formula: Among them, w j is the weight of the j-th query user, MF j is the query count of the jth query user, MF l is the number of queries by the lth query user; The query frequency in the current cycle is obtained by the following formula: in, is the query frequency of the i-th data in the k-th cycle; The query frequency growth rate in the current cycle is obtained by the following formula: in, is the query frequency growth rate of the i-th data in the k-th cycle, is the query frequency of the i-th data in the k-1-th cycle.
6. The method according to claim 2, characterized in that The performing counter statistics on the query times of the multiple data according to the query records of the multiple data to obtain the query times statistics result includes: Preset p hash functions and q counting columns; Determine an initial counter data table according to the p hash functions and the q count columns; For each data, each data is queried once, and a counting result of each data is calculated according to a data identifier of each data, the p hash functions and the q counting columns; According to the counting result, the initial counter data table is updated to obtain the query number statistics result; Wherein, p and q are positive integers.
7. The method according to claim 6, characterized in that For each data, each data is queried once, and a counting result of each data is calculated according to the data identifier of each data, the p hash functions and the q counting columns, including: The counting result of each data is calculated according to the following formula: Among them, x k is the data identifier of the kth data, h1, h2...h p is the counting result.
8. A data processing device, characterized in that: The device comprises: The acquisition module is used to obtain query records of multiple data in the database; A first sorting module, configured to sort the plurality of data in order from near to far from the current time according to the query time in the query records of the plurality of data, to obtain a first sorting sequence; A first determining module, configured to determine first N first data located in the first sorting sequence from the plurality of data, where N is a positive integer; A first storage module, used for storing the first data in a first-level cache; A screening module, used to screen the data in the first sorting sequence to screen out the data whose query time is within the current cycle; A second sorting module is used to sort the data in the current cycle according to the query frequency growth rate of the data in the current cycle, in descending order of the query frequency growth rate, to obtain a second sorting sequence; A second determining module, configured to determine the first M second data in the second sorting sequence from the data in the current cycle at the query time, where M is a positive integer; The second storage module is used to store the second data in a secondary cache, wherein the cache space corresponding to the database includes at least the primary cache and the secondary cache.
9. A data processing device, characterized in that: The device comprises: a processor and a memory storing computer program instructions; When the processor executes the computer program instructions, the data processing method according to claims 1-7 is implemented.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer program instructions, and when the computer program instructions are executed by a processor, the data processing method according to claims 1-7 is implemented.
Citation Information
Cited By
Data query method and device, electronic equipment and storage medium
CN115221200A
