Method and system for data compression based on key-value storage
By generating a compression dictionary applicable to all data on the server side and monitoring the compression efficiency, the problem of low client-side dictionary compression efficiency in key-value storage systems is solved, achieving more efficient data compression and reducing storage costs.
Patent Information
- Application Number
- CN202010693451.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-07-17
- Publication Date
- 2024-10-18
- Estimated Expiration
- 2040-07-17
AI Technical Summary
When the existing key-value storage system performs dictionary compression on the client, high-frequency vocabulary analysis takes a long time, the compression efficiency is low, and the storage space is increased, and the compression dictionary generated by each data needs to be saved in the storage system, which increases Extra storage space.
Generate the current dictionary on the server side, extract high-frequency strings from a large amount of key-value data, generate a compression dictionary suitable for all data, and use this dictionary during data compression, monitor the compression efficiency, and automatically update the dictionary when the efficiency drops.
It improves the speed and efficiency of data compression, reduces storage costs, avoids the consumption of storage space for each data generation dictionary, and updates the dictionary in a timely manner to maintain high efficiency.
Smart Images

Figure CN111782660B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of storage technology, and in particular to a method and system for data compression based on key-value storage. Background Art
[0002] With the rapid development of computer technology and network technology, more and more data and information have appeared in people's daily lives, which need to be stored and retained, so database systems have emerged. Database systems can realize the sharing and centralized management of data in databases, and the centralized management includes operations such as writing, reading and modifying data. The data managed by the database system is stored in the storage system, so the space and access speed of the storage system have an impact on the data management operations of the database system. When the data stored in the storage system continues to increase, the available space will become smaller. At this time, it is necessary to compress the data in the storage system to release some space.
[0003] At present, the key-value storage system has been widely used. The key-value storage system is a system that stores data in key-value pairs. Among them, key is a value keyword, and value refers to the value corresponding to the keyword. The key-value storage system can extract the corresponding value according to the keyword. The key-value storage system has low time complexity when querying, so it can often obtain high query performance for precise query scenarios. In the prior art, the key-value storage system usually uses a method of compressing the stored data using dictionary compression on the client, and then transmitting the compressed stored data to the server for storage. However, since the client usually generates a compression dictionary for a single data when performing dictionary compression on the stored data, the compressed data of the single data is sent to the storage system for storage together with the dictionary used for compression. Therefore, when the client performs dictionary compression, it is necessary to perform high-frequency vocabulary analysis on each data of the client to generate a corresponding dictionary, which increases the time and delay consumed by compression, and the compression dictionary generated when each data is compressed will be stored in the storage system, which will increase additional storage space. In addition, since the data volume of a single data is small, there are fewer high-frequency words in the generated compression dictionary, and the compression efficiency is low.
[0004] Therefore, there is a need for a data compression method and system based on key-value storage that has higher compression efficiency and can compress data from a server side. Summary of the invention
[0005] The present specification provides a method, system and non-transitory storage medium for data compression based on key-value storage, which can effectively and automatically identify the operational risks of the operations (such as trading operations) currently performed by the user on the system and disclose the risk categories to the user.
[0006] In a first aspect, the present specification provides a method for data compression based on key-value storage, comprising: generating a current dictionary based on multiple key values in a storage system on a server side; receiving key-value pairs sent by a client; and using the current dictionary to compress the key values in the key-value pairs and store them in the storage system.
[0007] In some embodiments, the storage system comprises a cache storage system.
[0008] In some embodiments, generating a current dictionary based on multiple key values in the storage system of the server includes: selecting N key values from the multiple key values in the storage system as training data, where N is an integer greater than 1; setting dictionary training parameters, training a dictionary based on the dictionary training parameters and the training data to obtain multiple candidate dictionaries; and selecting a candidate dictionary with the highest compression efficiency from the multiple candidate dictionaries as the current dictionary.
[0009] In some embodiments, generating the current dictionary based on multiple key values in the storage system of the server also includes: selecting M key values from the multiple key values in the storage system as verification data, where M is an integer greater than 1; selecting the candidate dictionary with the highest compression efficiency from the multiple candidate dictionaries as the current dictionary, including: selecting the candidate dictionary with the highest compression efficiency from the multiple candidate dictionaries as the target dictionary; verifying the compression efficiency of the target dictionary based on the verification data; and using the target dictionary as the current dictionary.
[0010] In some embodiments, the M is equal to the N.
[0011] In some embodiments, the method further includes: determining that the compression efficiency of the storage system decreases, and updating the current dictionary.
[0012] In some embodiments, determining that the compression efficiency of the storage system has decreased and updating the current dictionary includes: calculating the overall compression efficiency of the current dictionary for the storage system at the current moment; determining that the overall compression efficiency of the current dictionary for the storage system at the current moment has decreased by more than a target threshold compared with the overall compression efficiency at the previous moment; and updating the current dictionary.
[0013] In some embodiments, updating the current dictionary includes: generating a candidate update dictionary based on multiple key values in the storage system of the server at the current moment; compressing the multiple key values in the storage system using the candidate update dictionary; determining that the overall compression efficiency of the candidate update dictionary for the storage system is higher than the overall compression efficiency of the current dictionary for the storage system at the current moment; and using the candidate update dictionary as the current dictionary.
[0014] In some embodiments, determining that the compression efficiency of the storage system has decreased and updating the current dictionary also includes: using the current dictionary before the update to decompress the compressed key values stored in the storage system; and using the updated current dictionary to compress the key values decompressed by the current dictionary before the update to obtain updated compressed key values.
[0015] In some embodiments, the method further includes: reading a target key value in the storage system.
[0016] In some embodiments, reading the target key value in the storage system includes: receiving a read request for the target key value sent by a target client, the client includes the target client, and the multiple key values include the target key value; using the current dictionary to decompress the compressed key value corresponding to the target key value to obtain the target key value; and sending the target key value to the target client.
[0017] In a second aspect, the present specification provides a system for data compression based on key-value storage, comprising at least one storage medium and at least one processor, the at least one storage medium comprising at least one instruction set for data compression based on key-value storage; the at least one processor is communicatively connected to the at least one storage medium, wherein, when the system is running, the at least one processor reads the at least one instruction set and executes the method for data compression based on key-value storage described in the first aspect of this specification according to the instructions of the at least one instruction set.
[0018] It can be seen from the above technical solutions that the method and system for data compression based on key-value storage provided in this specification can perform dictionary compression on the key-value data in the storage system from the server side. Since a large amount of key-value data is stored in the storage system on the server side, for example, there are hundreds of millions of key-value data in the existing storage system. The dictionary generated based on the data on the server side can find common high-frequency character strings from a large amount of data, so the data compression efficiency is higher. In addition, since the dictionary is generated based on a large amount of data on the server side, the dictionary can be applied to all data on the server side, and there is no need to generate a dictionary for each data. Therefore, the method and system can increase the speed of data compression, thereby reducing the cost of the storage system. At the same time, the method and system provided in this specification can monitor the overall efficiency of data compression on the server side, and when the overall efficiency of data compression decreases, the compression dictionary is automatically updated to ensure the overall efficiency of data compression.
[0019] Other features of the method and system for data compression based on key-value storage provided by this specification will be partially listed in the following description. Based on the description, the content introduced by the following figures and examples will be obvious to those of ordinary skill in the art. The creative aspects of the method, system and storage medium for data compression based on key-value storage provided by this specification can be fully explained by practicing or using the methods, devices and combinations described in the following detailed examples. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] In order to more clearly illustrate the technical solutions in the embodiments of this specification, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this specification. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0021] Figure 1 A schematic diagram of an application scenario of a data compression system based on key-value storage provided according to an embodiment of this specification is shown;
[0022] Figure 2 A schematic diagram of a device for data compression based on key-value storage provided according to an embodiment of this specification is shown;
[0023] Figure 3 A flow chart of a method for data compression based on key-value storage provided according to an embodiment of this specification is shown;
[0024] Figure 4 A flowchart of generating a current dictionary according to an embodiment of this specification is shown;
[0025] Figure 5A flow chart of compressing new data according to an embodiment of this specification is shown;
[0026] Figure 6 A flowchart of updating a current dictionary according to an embodiment of this specification is shown; and
[0027] Figure 7 A flowchart of data reading provided according to an embodiment of this specification is shown. DETAILED DESCRIPTION
[0028] The following description provides specific application scenarios and requirements of this specification, with the purpose of enabling those skilled in the art to make and use the contents of this specification. Various local modifications to the disclosed embodiments will be apparent to those skilled in the art, and the general principles defined herein may be applied to other embodiments and applications without departing from the spirit and scope of this specification. Therefore, this specification is not limited to the embodiments shown, but to the widest scope consistent with the claims.
[0029] The terms used herein are only used for the purpose of describing specific example embodiments and are not restrictive. For example, unless the context clearly indicates otherwise, as used herein, the singular forms "a", "an" and "the" may also include plural forms. When used in this specification, the terms "include", "comprise" and / or "contain" mean that the associated integers, steps, operations, elements and / or components exist, but do not exclude the existence of one or more other features, integers, steps, operations, elements, components and / or groups or that other features, integers, steps, operations, elements, components and / or groups may be added in the system / method.
[0030] In view of the following description, these and other features of the present specification, as well as the operation and function of the related elements of the structure, and the economy of the combination and manufacture of the parts can be significantly improved. Reference is made to the accompanying drawings, all of which form a part of this specification. However, it should be clearly understood that the drawings are for illustration and description purposes only and are not intended to limit the scope of this specification. It should also be understood that the drawings are not drawn to scale.
[0031] The flowcharts used in this specification illustrate the operations implemented by the system according to some embodiments in this specification. It should be clearly understood that the operations of the flowcharts may not be implemented in sequence. On the contrary, the operations may be implemented in reverse order or simultaneously. In addition, one or more other operations may be added to the flowchart. One or more operations may be removed from the flowchart.
[0032] In the prior art, most of the data stored in the key-value storage system is compressed on the client side. In particular, for the cache storage system, since the data in the cache storage system is read more and written less, and the data mobility in the cache storage system is large, most of the prior art adopts the client compression method for the cache storage system, that is, the client compresses each key-value data, and transmits the compressed data and the compression dictionary used for compression to the cache storage system for storage, which increases additional storage space. The overall compression efficiency of the data stored in the cache storage system is low, and the cost is high for the storage system with large data volume. The overall compression efficiency can be the ratio of the data size before compression of all data stored in the storage system to the data size after compression of all data. The larger the ratio, the higher the overall compression efficiency; the smaller the ratio, the lower the overall compression efficiency. The overall compression efficiency can also be the ratio of the data size after compression of all data stored in the storage system to the data size before compression of all data. The smaller the ratio, the higher the overall compression efficiency; the larger the ratio, the lower the overall compression efficiency. For the convenience of demonstration, we will take the overall compression efficiency as the ratio of the data size of all data stored in the storage system before compression to the data size of all data after compression as an example for description. Dictionary compression mainly maps repeated content in the data to corresponding characters. The size of the repeated content is usually larger than or even much larger than the corresponding characters, thereby achieving the purpose of compressing data packets. For example, a certain data "AAA, BBB, CCC, AAA, BBB, CCC"; assuming that "AAA" corresponds to "X", "BBB" corresponds to "Y", and "CCC" corresponds to "Z" in the compression dictionary; then, the content in this data can be mapped to "X, Y, Z" through the compression dictionary; the size of the data after compression is greatly reduced compared to before compression. Since the data in the key-value storage system is typeless data, the key-value storage system is suitable for dictionary compression but not for encoding compression.
[0033] The method and system for data compression based on key-value storage provided in this specification are applied to the server side, and can perform dictionary compression on the key-value data in the storage system from the server side. Since a large amount of key-value data is stored in the storage system on the server side, the dictionary generated based on the data on the server side can find common high-frequency character strings from a large amount of data, so the data compression efficiency is higher. In addition, since the dictionary is generated based on a large amount of data on the server side, the dictionary can be applied to all data on the server side, and there is no need to generate a dictionary for each data. Therefore, the method and system can improve the speed of data compression, thereby reducing the cost of the storage system.
[0034] Figure 1The schematic diagram of an application scenario of a system 100 for data compression based on key-value storage is shown. The system 100 may include a server 200 , a client 300 and a network 120 .
[0035] The client 300 may be an electronic device carrying a target application (target APP). The user 110 may be a user of the client 300. The client 300 may be connected to the server 200 in communication. In some embodiments, the client 300 may be installed with one or more applications (APPs). The APP can provide the target user 110 with the ability and interface to interact with the outside world through the network 120. The target APP refers to the client APP corresponding to the server 200. In some embodiments, the client 300 may include a mobile device 300-1, a tablet computer 300-2, a laptop computer 300-3, a built-in device of a motor vehicle 300-4, or the like, or any combination thereof. In some embodiments, the mobile device 300-1 may include a smart home device, a smart mobile device or the like, or any combination thereof. In some embodiments, the smart home device may include a smart TV, a desktop computer, etc., or any combination thereof. In some embodiments, the smart mobile device may include a smart phone, a personal digital assistant, etc., or any combination thereof. In some embodiments, the client 300 may be a device with positioning technology for locating the position of the client 300.
[0036] The server side 200 may store data or instructions for executing the method for data compression based on key-value storage described in this specification, and may execute the data and / or instructions. The client side 300 may have the authority to access the server side 200, and the client side 300 may access the data or instructions stored in the server side 200 through the network 120. The key-value storage system may be a memory storage system and a hard disk storage system, or a cache storage system. The server side 200 may include a key-value storage system, which may store key-value data obtained from the client side 300. The server side 200 may be responsible for all key-value data write, read and delete operation requests. All requests for data write, read and delete are completed by the server side 200. These requests may come from the client side 300. The server side 200 may be an independent server. The server side 200 may also be a distributed server cluster. The distributed server cluster may include a plurality of distributed connected sub-servers. The plurality of sub-servers may communicate with each other to exchange data and information. For example, the plurality of sub-servers may be connected together through the network 120. The multiple sub-servers may share a common work target, and each of the multiple sub-servers completes one or more sub-targets in the work target, and transmits the running results of the sub-targets to other sub-servers that need the sub-targets. In addition to one or more processors, each sub-server may also include one or more storage media (such as memory) to store key-value data and other data that need to be stored when processing the sub-targets. Of course, each sub-server may also share one or more storage media (such as memory). The storage medium may be connected to each sub-server via network 120. The data or instructions of the data compression method based on key-value storage described in this specification may be stored in the storage medium. The sub-server may be a general-purpose computer or a special-purpose computer. For example, the sub-server may be a server, a personal computer, a portable computer (such as a notebook computer, a tablet computer, etc.), or an electronic device with other computing capabilities.
[0037] Network 120 may facilitate the exchange of information and / or data. Figure 1As shown, the client 300 and the server 200 can be connected to the network 120, and transmit information and / or data to each other through the network 120. For example, the server 200 can obtain a key-value pair from the client 300 through the network 120. In some embodiments, the network 120 can be any type of wired or wireless network, or a combination thereof. For example, the network 120 can include a cable network, a wired network, an optical fiber network, a telecommunications network, an intranet, the Internet, a local area network (LAN), a wide area network (WAN), a wireless local area network (WLAN), a metropolitan area network (MAN), a wide area network (WAN), a public switched telephone network (PSTN), a Bluetooth network, a ZigBee network, a near field communication (NFC) network, or a similar network. In some embodiments, the network 120 can include one or more network access points. For example, the network 120 can include a wired or wireless network access point, and one or more components of the client 300 and the server 200 can be connected to the network 120 to exchange data and / or information.
[0038] like Figure 1 As shown, the user 110 makes operation requests such as writing, reading and deleting data on the key value on the client 300; the operation request is transmitted to the server 200 through the network 120; the server 200 executes the instructions of the data compression method based on key-value storage described in this specification, compresses and stores the written data, or decompresses and outputs the read data.
[0039] Figure 2 A schematic diagram of a device for data compression based on key-value storage is shown. The device may be a server 200, a sub-server, or a client 300. In the following description, the server 200 is used as an example to introduce the device.
[0040] The server 200 can execute the data compression method based on key-value storage described in this specification. The data compression method based on key-value storage is introduced in other parts of this specification. For example, in Figure 3 and Figure 7 The method P200 for data compression based on key-value storage is introduced in the description.
[0041] like Figure 2 As shown, the server end 200 includes at least one storage medium 230 and at least one processor 220. In some embodiments, the server end 200 may further include a communication port 250 and an internal communication bus 210. Meanwhile, the server end 200 may further include an I / O component 260.
[0042] The internal communication bus 210 may connect various system components, including the storage medium 230 and the processor 220 .
[0043] The I / O component 260 supports input / output between the server 200 and other components.
[0044] The storage medium 230 may include a data storage device. The data storage device may be a non-temporary storage medium or a temporary storage medium. For example, the data storage device may include one or more of a disk 232, a read-only storage medium (ROM) 234, or a random access storage medium (RAM) 236. The storage medium 230 also includes at least one instruction set stored in the data storage device. The instruction is a computer program code, and the computer program code may include a program, a routine, an object, a component, a data structure, a process, a module, etc. for executing the method for data compression based on key-value storage provided in this specification.
[0045] The communication port 250 is used for data communication between the server 200 and the outside world. For example, the server 200 can be connected to the network 120 through the communication port 250.
[0046] At least one processor 220 is connected to at least one storage medium 230 through an internal communication bus 210. At least one processor 220 is used to execute the above-mentioned at least one instruction set. When the system 100 is running, at least one processor 220 reads the at least one instruction set and executes the method P200 for data compression based on key-value storage provided in this specification according to the instructions of the at least one instruction set. The processor 220 can execute all the steps included in the method P200 for data compression based on key-value storage. The processor 220 can be in the form of one or more processors. In some embodiments, the processor 220 can include one or more hardware processors, such as a microcontroller, a microprocessor, a reduced instruction set computer (RISC), an application-specific integrated circuit (ASIC), an application-specific instruction set processor (ASIP), a central processing unit (CPU), a graphics processing unit (GPU), a physical processing unit (PPU), a microcontroller unit, a digital signal processor (DSP), a field programmable gate array (FPGA), an advanced RISC machine (ARM), a programmable logic device (PLD), any circuit or processor capable of performing one or more functions, etc., or any combination thereof. For the purpose of illustration only, only one processor 220 is described in the server 200 in this specification. However, it should be noted that the server 200 in this specification may also include multiple processors, and therefore, the operations and / or method steps disclosed in this specification may be performed by one processor as described in this specification, or may be performed jointly by multiple processors. For example, if the processor 220 of the server 200 in this specification performs step A and step B, it should be understood that step A and step B may also be performed jointly or separately by two different processors 220 (for example, the first processor performs step A, the second processor performs step B, or the first and second processors perform steps A and B together).
[0047] Although the above structure describes the server 200, this structure is also applicable to the client 300.
[0048] Figure 3A flow chart of a method P200 for data compression based on key-value storage is shown. As mentioned above, the method P200 is applied to the server side 200, and is used to compress and store the key-value data in the storage system of the server side 200. The storage system can be a memory storage system and a hard disk storage system, or it can be a cache storage system. The server side 200 can execute the method P200 for data compression based on key-value storage provided in this specification. Specifically, the processor 220 in the server side 200 can read the instruction set stored in its local storage medium and / or the server side 200, and then execute the method P200 for data compression based on key-value storage provided in this specification according to the provisions of the instruction set. The method P200 may include executing the following steps by at least one processor 220:
[0049] S210: Generate a current dictionary based on multiple key values in the storage system of the server 200.
[0050] When compressing key value data in the storage system, the server 200 needs to generate a compression dictionary used for compression. The server 200 can extract high-frequency strings based on a large amount of key value data in the storage system to generate a compression dictionary used for current compression, namely the current dictionary. Figure 4 A flow chart of generating a current dictionary is shown. Figure 4 As shown, step S210 may include:
[0051] S212: Select N key values from the multiple key values in the storage system as training data.
[0052] The current dictionary can be trained based on the key-value data in the storage system. The server side 200 can extract a portion of the key-value data from the storage system as training data. Specifically, the server side 200 can randomly extract multiple key-value data from the storage system as training data. The server side 200 can also classify a large amount of key-value data in the storage system according to the attribute characteristics of the key-value data, and randomly extract multiple key-value data from each type of key-value data as the training data. For the convenience of presentation, we mark the number of key-value data in the training data as N, where N is an integer greater than 1.
[0053] S213: Select M key values from the multiple key values in the storage system as verification data.
[0054] In order to avoid the occurrence of occasional data in the random extraction process of the training data, the server side 200 can extract a part of the key-value data from the storage system as the verification data, which is used to verify the compression efficiency of the compression dictionary trained by the training data. The occasional data can be that the similarity between a large number of key-value data appears in the random extraction process of the training data is high. The probability of the occurrence of the occasional data is low. When occasional data appears in the training data, the compression dictionary trained by the training data has a high compression efficiency for the training data, but a low compression efficiency for other data other than the training data, resulting in a low overall compression efficiency for all data in the storage system. In order to avoid the occurrence of the occasional data, the server side 200 sets the verification data. The server side 200 compresses the verification data using the compression dictionary trained by the training data to verify the validity of the compression dictionary. For the convenience of description, we mark the number of key-value data in the verification data as M. In order to improve the comprehensiveness of the verification data, the key-value data in the verification data may not overlap with the key-value data in the training data. Of course, the key value data in the verification data may overlap with the key value data in the training data in a small amount, and the overlap degree cannot exceed the set threshold. Otherwise, it will affect the verification effect of the verification data on the compression dictionary. The number N of key value data in the training data and the number M of key value data in the verification data may be equal or unequal.
[0055] The server side 200 may collect the training data and the verification data offline or online, which is not limited in this specification.
[0056] S215: Setting dictionary training parameters, and training a dictionary based on the dictionary training parameters and the training data to obtain a plurality of candidate dictionaries.
[0057] The server side 200 can set parameters for dictionary training, such as the size of the dictionary, the step size of the training, the compression level of the training dictionary, etc. The server side 200 can set multiple sets of dictionary training parameters. The server side 200 can perform training based on the multiple sets of dictionary training parameters and the training data to obtain multiple candidate dictionaries. The multiple candidate dictionaries correspond to the multiple sets of dictionary training parameters. Each set of dictionary training parameters corresponds to a candidate dictionary. The multiple sets of dictionary training parameters can be set manually based on experience, or can be obtained through machine learning.
[0058] S217: Selecting a candidate dictionary with the highest compression efficiency from the multiple candidate dictionaries as the current dictionary.
[0059] In order to ensure that the overall compression efficiency of the current dictionary for the multiple key-value data in the storage system meets the usage requirements, the server side 200 needs to select the candidate dictionary with the highest compression efficiency from the multiple candidate dictionaries as the current dictionary. The server side 200 can select the candidate dictionary with the highest compression efficiency as the current dictionary based on the compression efficiency of each candidate dictionary in the multiple candidate dictionaries for the training data during the training process. Specifically, step S217 may include:
[0060] S217 - 2 : Selecting a candidate dictionary with the highest compression efficiency from the multiple candidate dictionaries as a target dictionary.
[0061] Specifically, the server side 200 can gradually use each set of dictionary training parameters in the multiple sets of dictionary training parameters to perform dictionary training on the training data, and generate a candidate dictionary corresponding to the current dictionary training parameters in each dictionary training; the server side 200 can compare the compression efficiency of the candidate dictionary corresponding to the current dictionary training parameters with the compression efficiency of the target dictionary, and use the dictionary with high compression efficiency as the target dictionary, that is, when the compression efficiency of the candidate dictionary corresponding to the current dictionary training parameters is higher than the target dictionary, the compression efficiency of the candidate dictionary corresponding to the current dictionary training parameters is used as the target dictionary, and when the compression efficiency of the candidate dictionary corresponding to the current dictionary training parameters is lower than the target dictionary, the target dictionary is kept unchanged; when all dictionary training parameters have been trained, the server side 200 can obtain the final target dictionary. It should be noted that before the first training starts, the target dictionary is empty, the compression efficiency of the target dictionary is the lowest, and the ratio of the data size before compression of all data stored in the storage system to the data size after compression of all data is 1.
[0062] The server 200 may also use the multiple sets of dictionary training parameters to train the training data to obtain the multiple candidate dictionaries; sort the compression efficiencies of the multiple candidate dictionaries from high to low; and use the compression dictionary corresponding to the first-ranked compression efficiency as the target dictionary.
[0063] S217 - 4 : Verify the compression efficiency of the target dictionary based on the verification data.
[0064] S217-6: Use the target dictionary as the current dictionary.
[0065] In order to avoid occasional data in the training data, the server side 200 sets the verification data to verify the compression efficiency of the target dictionary. Specifically, the server side 200 can use the target dictionary to compress the key data in the verification data to obtain the compression efficiency of the target dictionary on the verification data. The server side 200 can compare the compression efficiency of the target dictionary on the verification data with the compression efficiency of the target dictionary on the training data; when the difference between the compression efficiency of the target dictionary on the verification data and the compression efficiency of the target dictionary on the training data exceeds a preset critical value, the server side 200 can determine that there is occasional data in the training data, and the server side 200 will re-extract the training data and the verification data from the storage system, re-train the dictionary, and generate the target dictionary; when the difference between the compression efficiency of the target dictionary on the verification data and the compression efficiency of the target dictionary on the training data does not exceed the preset critical value, the server side 200 can determine that there is no occasional data in the training data, and the server 200 can use the target dictionary as the current dictionary.
[0066] It should be noted that the server side 200 can select multiple groups of training data or multiple groups of verification data. The server side 200 can generate multiple candidate dictionaries through training based on the multiple groups of training data and the multiple groups of dictionary training parameters. Each group of dictionary training parameters corresponds to multiple candidate dictionaries. According to the compression efficiency of the multiple candidate dictionaries corresponding to each group of dictionary training parameters, the training data corresponding to the compression dictionary with abnormal compression efficiency is deleted. The compression dictionary with abnormal compression efficiency can be a compression dictionary whose compression efficiency of the abnormal compression dictionary is significantly higher or significantly lower than that of other training data. The server 200 can select the candidate dictionary with the highest compression efficiency from the multiple candidate dictionaries corresponding to the remaining training data as the current dictionary. The setting of the multiple groups of training data can avoid the occurrence of occasional data, ensure the effectiveness of the current dictionary, and improve the efficiency of the current dictionary in compressing the data of the storage system.
[0067] The server 200 uses the multiple groups of verification data to verify the compression efficiency of the target dictionary and generates multiple verification compression efficiencies, each verification compression efficiency corresponding to a group of verification data. The server 200 can delete abnormal verification data from the multiple groups of verification data. The abnormal verification data can be a verification compression efficiency that is significantly higher or significantly lower than the verification compression efficiency of other verification data. The setting of the multiple groups of verification data can avoid the occurrence of occasional data in the verification data, ensure the validity of the current dictionary, and improve the efficiency of the current dictionary in compressing the storage system data.
[0068] In summary, the method P200 and system 100 for data compression based on key-value storage provided in this specification can generate the current dictionary based on dictionary training of a large amount of data in the storage system. Therefore, the current dictionary has high applicability and can be applied to all data in the storage system. The traditional solution of generating a compression dictionary for data compression on the client 300 requires generating a dictionary for each data, and storing the dictionary corresponding to the data together with the compressed key-value data corresponding to the data in the storage system, which results in additional storage space consumption. The method P200 and system 100 generate a unified dictionary by analyzing the data stored on the server side 200. There is no need to generate a corresponding compression dictionary for each key-value data, which avoids the additional storage space consumption caused by putting the dictionary into the compressed key-value data, greatly improves the compression efficiency, and still has a good compression effect on small data. Moreover, since the compression dictionary has been generated in advance through offline analysis, the time consumption of data compression has been significantly improved compared with the compression of the client 300, which greatly saves compression time and reduces delay. Especially for cache storage systems, since the data in the cache storage system is highly mobile, has many data types, and has large content differences, the compression dictionary generated based on the server side 200 provided by the method P200 and the system 100 can be applicable to all types of data in the cache storage system, greatly improving the compression efficiency and saving compression time.
[0069] S230: Receive the key-value pair sent by the client 300.
[0070] After the server 200 generates the current dictionary, it can use the current dictionary to compress all key-value data in the storage system and store the compressed data. The server 200 can also receive new key-value pair data sent by the client 300, and compress and store the new key-value pair data.
[0071] S250: Use the current dictionary to perform data compression on the key value in the key-value pair, and store the data in the storage system.
[0072] Figure 5 FIG. 2 shows a flow chart of compressing new data according to an embodiment of the present specification. Figure 5 As shown, step S250 may include executing, by at least one processor 220 of the server 200:
[0073] S252: Verify the key-value data in the key-value pair. The verification may include sensitive word verification, etc. If the verification passes, the key-value data is compressed; if the verification fails, the process ends without writing the key-value data.
[0074] S254: Use the current dictionary to perform data compression on the key-value data. If the compression is successful, write the compressed data into the storage system; if the compression is unsuccessful, write the original data of the key-value data into the storage system. When the key-value data does not contain the character string in the current dictionary, the key-value data cannot be compressed, that is, the compression is unsuccessful.
[0075] like Figure 3 As shown, the method P200 may also include executing, by at least one processor 220 of the server 200:
[0076] S270: Determine that the compression efficiency of the storage system decreases, and update the current dictionary.
[0077] The server side 200 can monitor the compression efficiency of the current dictionary on the storage system. The compression efficiency can be the overall compression efficiency of the current dictionary on all data in the storage system. The monitoring can be real-time monitoring, periodic monitoring, or monitoring at the moment when the data in the storage system changes, and so on. When the overall compression efficiency of the current dictionary on the storage system decreases, the server side 200 can automatically update the current dictionary so that the compression efficiency of the current dictionary meets the usage requirements. The decrease in the overall compression efficiency of the current dictionary on the storage system can be that the overall compression efficiency of the current dictionary on the storage system at the current moment decreases relative to the overall compression efficiency at the previous moment, or that the overall compression efficiency of the current dictionary on the storage system is lower than the threshold of the overall compression efficiency preset by the server side 200.
[0078] Figure 6 FIG. 2 shows a flow chart of updating a current dictionary according to an embodiment of the present specification. Figure 6 As shown, step S270 may include executing, by at least one processor 220 of the server 200:
[0079] S272: Calculate the overall compression efficiency of the current dictionary on the storage system at the current moment.
[0080] The server 200 may monitor the overall compression efficiency of the current dictionary on the storage system, and calculate the overall compression efficiency of the current dictionary on the storage system at the current moment.
[0081] S274: Determine whether the overall compression efficiency of the current dictionary for the storage system at the current moment decreases by more than a target threshold compared with the overall compression efficiency at the previous moment.
[0082] The server side 200 may compare the overall compression efficiency of the current dictionary on the storage system at the current moment with the overall compression efficiency of the current dictionary on the storage system at the previous moment. The previous moment may be the most recent moment before the current moment when the server side 200 monitors the overall compression efficiency of the storage system. When the overall compression efficiency of the current dictionary on the storage system at the current moment decreases by more than the target threshold relative to the overall compression efficiency of the current dictionary on the storage system at the previous moment, the server side 200 may determine that the overall compression efficiency of the current dictionary on the storage system has decreased.
[0083] S276: Update the current dictionary. Step S276 may include:
[0084] S276-2: Generate a candidate update dictionary based on multiple key values in the storage system of the server at the current moment.
[0085] The server side 200 may generate the candidate update dictionary in the same manner as the current dictionary. That is, based on the multiple key-value data in the storage system at the current moment, the server side 200 may randomly extract a portion of the key-value data as training data and another portion of the key-value data as verification data. The method for extracting the training data and the verification data may be consistent with step S212 and step S213. The server side 200 may set multiple sets of dictionary training parameters, perform dictionary training based on the multiple sets of dictionary training parameters and the training data, and generate multiple candidate dictionaries. The method for generating the candidate dictionary may be consistent with step S215. The server side 200 may select the dictionary with the highest compression efficiency from the multiple candidate dictionaries as the candidate dictionary. the target dictionary; the server side 200 can use the verification data to verify the compression efficiency of the target dictionary; when the difference between the compression efficiency of the target dictionary for the verification data and the compression efficiency of the target dictionary for the training data does not exceed the preset critical value, the server side 200 can use the target dictionary as the candidate update dictionary; when the difference between the compression efficiency of the target dictionary for the verification data and the compression efficiency of the target dictionary for the training data exceeds the preset critical value, the server side 200 will re-extract the training data and the verification data from the storage system, re-train the dictionary, and generate the target dictionary.
[0086] S276-4: Use the candidate update dictionary to compress the multiple key values in the storage system.
[0087] After generating the candidate update dictionary, the server side 200 uses the candidate update dictionary to compress multiple key-value data in the storage system to obtain the overall compression efficiency of the candidate update dictionary on the storage system at the current moment.
[0088] S276-6: Determine that the overall compression efficiency of the candidate updated dictionary for the storage system is higher than the overall compression efficiency of the current dictionary for the storage system at the current moment.
[0089] S276-8: Use the candidate update dictionary as the current dictionary.
[0090] The server side 200 may compare the overall compression efficiency of the candidate update dictionary for the storage system at the current moment with the overall compression efficiency of the current dictionary for the storage system at the current moment; when the overall compression efficiency of the candidate update dictionary for the storage system at the current moment is higher than the overall compression efficiency of the current dictionary for the storage system at the current moment, or the increase in the overall compression efficiency of the candidate update dictionary for the storage system at the current moment relative to the overall compression efficiency of the current dictionary for the storage system at the current moment exceeds a preset threshold, or when the overall compression efficiency of the candidate update dictionary for the storage system at the current moment is higher than the overall compression efficiency of the current dictionary for the storage system at the current moment and is higher than the overall compression efficiency threshold preset by the server side 200, the server side 200 may replace the current dictionary with the candidate update dictionary; otherwise, the server side 200 re-extracts training data and verification data based on multiple key-value data in the storage system, and regenerates the candidate update dictionary.
[0091] like Figure 6 As shown, step S270 may also include executing, by at least one processor 220 of the server 200:
[0092] S278: Decompress the compressed key value stored in the storage system using the current dictionary before updating.
[0093] S279: Using the updated current dictionary, compress the key value decompressed by the current dictionary before the update to obtain an updated compressed key value.
[0094] When the current dictionary is updated, in order to reduce the space of the key-value data in the storage system, the server side 200 can replace the data compressed by the current dictionary before the update with the data compressed by the updated current dictionary. Specifically, the server side 200 first uses the current dictionary before the update to decompress the compressed key-value data, and then uses the updated current dictionary to compress the decompressed data again. Before all the compressed key-value data in the storage system are replaced with the data compressed by the updated current dictionary, the storage system can retain the current dictionary before the update. When the client 300 sends a read request to the server side 200 before all the compressed key-value data in the storage system are replaced with the data compressed by the updated current dictionary, the server side 200 can first parse the key value that the client 300 requires to read, analyze whether the compression dictionary used by the compressed key-value data corresponding to the key value is the current dictionary before the update or the current dictionary after the update, and then use the correct compression dictionary to decompress the compressed key-value data corresponding to the key value to obtain the key value read by the client 300.
[0095] In summary, the method P200 and system 100 for data compression based on key-value storage provided in this specification can monitor the overall compression efficiency of the data in the storage system. When the overall compression efficiency of the data in the storage system decreases, the server 200 can detect it in time and immediately update the current dictionary, so that the overall compression efficiency of the data in the storage system after the update of the current dictionary is restored or even higher, so as to meet the usage requirements and further reduce the storage space occupied by the data. Therefore, the method P200 and system 100 for data compression based on key-value storage provided in this specification can improve the overall compression efficiency of the storage system, reduce the storage space occupied by the data, reduce the cost of data storage, and reduce the time consumed in data compression.
[0096] like Figure 3 As shown, the method P200 may also include executing, by at least one processor 220 of the server 200:
[0097] S290: Read the target key value in the storage system.
[0098] The server 200 can not only receive the new key-value pair data sent by the client 300, and compress the key-value data in the new key-value pair data and store it in the storage system, but also receive the key-value data reading request sent by the client 300, read the compressed key-value data corresponding to the key-value data requested to be read by the client 300 from the storage system, and decompress it using the corresponding compression dictionary to obtain the key-value data requested to be read by the client 300. For the convenience of description, we mark the client that sends the key-value data reading request as the target client, and the client 300 includes the target client; we mark the key-value data requested to be read by the target client as the target key value, and the multiple key values in the storage system include the target key value.
[0099] Figure 7 FIG. 2 shows a flow chart of data reading according to an embodiment of the present specification. Figure 7 As shown, step S290 may include:
[0100] S292: Receive a read request for the target key value sent by the target client.
[0101] After receiving the read request for the target key value sent by the target client, the server side 200 needs to first parse the target key value data and analyze whether the target key value data is compressed; if the target key value data is not compressed, the server side 200 sends the original data corresponding to the target key value data to the target client; if the target key value data is compressed and stored in the storage system, the server side 200 needs to decompress the compressed key value data of the target key value.
[0102] S294: Decompress the compressed key value of the target key value using the current dictionary to obtain the target key value.
[0103] S296: Send the target key value to the target client.
[0104] After determining that the target key value is compressed key value data, the server end 200 needs to decompress the compressed key value data of the target key value. Specifically, the server end 200 can obtain the compressed key value data corresponding to the target key value data in the storage system; the server end 200 can use the current dictionary used when the key value data was compressed to decompress the compressed key value data; after the server end 200 successfully decompresses the compressed key value data, it sends the decompressed key value data to the target client; when the server end 200 fails to decompress the compressed key value data, it sends an empty message and a prompt message of data reading failure to the target client.
[0105] In summary, the method P200 and system 100 for data compression based on key-value storage provided in this specification can generate the current dictionary based on dictionary training of a large amount of data in the storage system. Therefore, the current dictionary has high applicability and can be applied to all data in the storage system. The traditional solution of generating a compression dictionary for data compression on the client 300 requires generating a dictionary for each data, and storing the dictionary corresponding to the data together with the compressed key-value data corresponding to the data in the storage system, which results in additional storage space consumption. The method P200 and system 100 generate a unified dictionary by analyzing the data stored on the server side 200. There is no need to generate a corresponding compression dictionary for each key-value data, which avoids the additional storage space consumption caused by putting the dictionary into the compressed key-value data, greatly improves the compression efficiency, and still has a good compression effect on small data. Moreover, since the compression dictionary has been generated in advance through offline analysis, the time consumption of data compression has been significantly improved compared with the compression of the client 300, which greatly saves compression time and reduces delay. Especially for cache storage systems, since the data in cache storage systems is highly fluid, has many data types, and has large content differences, the compression dictionary generated based on the server side 200 provided by the method P200 and the system 100 can be applicable to all types of data in the cache storage system, greatly improving the compression efficiency and saving compression time. In addition, the method P200 and the system 100 can monitor the overall compression efficiency of the data in the storage system. When the overall compression efficiency of the data in the storage system decreases, the server side 200 can detect it in time and immediately update the current dictionary, so that the updated current dictionary can restore or even increase the overall compression efficiency of the data in the storage system to meet the usage requirements and further reduce the storage space occupied by the data. Therefore, the method P200 and the system 100 for data compression based on key-value storage provided in this specification can improve the overall compression efficiency of the storage system, reduce the storage space occupied by the data, reduce the cost of data storage, and reduce the time spent on data compression.
[0106] On the other hand, the present specification provides a non-transitory storage medium, storing at least one set of executable instructions for data compression based on key-value storage, when the executable instructions are executed by the processor, the executable instructions instruct the processor to implement the steps of the method P200 for data compression based on key-value storage described in the present specification. In some possible implementations, various aspects of the present specification can also be implemented in the form of a program product, which includes a program code. When the program product is run on the server end 200, the program code is used to enable the server end 200 to perform the steps of data compression based on key-value storage described in the present specification. The program product for implementing the above method can use a portable compact disk read-only memory (CD-ROM) and include program code, and can be run on the server end 200. However, the program product of the present specification is not limited to this. In the present specification, the readable storage medium can be any tangible medium containing or storing a program, which can be used by an instruction execution system (such as a processor 220) or used in combination with it. The program product can use any combination of one or more readable media. The readable medium can be a readable signal medium or a readable storage medium. The readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination thereof. More specific examples of readable storage media include: an electrical connection with one or more conductors, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. The computer-readable storage medium may include a data signal propagated in a baseband or as part of a carrier wave, wherein a readable program code is carried. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. The readable storage medium may also be any readable medium other than a readable storage medium, which may send, propagate, or transmit a program for use by or in combination with an instruction execution system, device, or device. The program code contained on the readable storage medium may be transmitted using any suitable medium, including but not limited to wireless, wired, optical cable, RF, etc., or any suitable combination thereof. The program code for performing the operations of this specification can be written in any combination of one or more programming languages, including object-oriented programming languages—such as Java, C++, etc., and conventional procedural programming languages—such as "C" language or similar programming languages.The program code may be executed entirely on the server 200, partially on the server 200, as a separate software package, partially on the server 200 and partially on a remote computing device, or entirely on a remote computing device or server (server 200). In the case of a remote computing device, the remote computing device may be connected to the server 200 via the network 120, or may be connected to an external computing device.
[0107] The above is a description of a specific embodiment of the present specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require a specific order or a continuous order to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0108] In summary, after reading this detailed disclosure, those skilled in the art will appreciate that the foregoing detailed disclosure may be presented only by way of example and may not be limiting. Although not explicitly stated herein, those skilled in the art will appreciate that this specification requires various reasonable changes, improvements and modifications to the embodiments. These changes, improvements and modifications are intended to be proposed by this specification and are within the spirit and scope of the exemplary embodiments of this specification.
[0109] In addition, certain terms in this specification have been used to describe embodiments of this specification. For example, "one embodiment", "an embodiment" and / or "some embodiments" mean that a particular feature, structure or characteristic described in conjunction with the embodiment may be included in at least one embodiment of this specification. Therefore, it can be emphasized and should be understood that two or more references to "an embodiment" or "one embodiment" or "an alternative embodiment" in various parts of this specification do not necessarily refer to the same embodiment. In addition, specific features, structures or characteristics may be appropriately combined in one or more embodiments of this specification.
[0110] It should be understood that in the foregoing description of the embodiments of this specification, in order to help understand a feature and for the purpose of simplifying this specification, this specification combines various features in a single embodiment, drawing or its description. However, this does not mean that the combination of these features is necessary. When reading this specification, it is entirely possible for a person skilled in the art to extract some of the features and understand them as separate embodiments. In other words, the embodiments in this specification can also be understood as the integration of multiple secondary embodiments. This is also true when the content of each secondary embodiment is less than all the features of a single aforementioned disclosed embodiment.
[0111] Each patent, patent application, patent application publication, and other materials, such as articles, books, specifications, publications, documents, articles, etc., cited herein may be incorporated herein by reference in its entirety for all purposes, except for any prosecution document history related thereto, any equivalent that may be inconsistent or conflicting with this document, or any equivalent prosecution document history that may have a limiting effect on the broadest scope of the claims now or later associated with this document. For example, if there is any inconsistency or conflict between the description, definition, and / or use of a term associated with any of the incorporated materials and the term, description, definition, and / or use associated with this document, the term in this document shall control.
[0112] Finally, it should be understood that the embodiments of the application disclosed herein are explanations of the principles of the embodiments of this specification. Other modified embodiments are also within the scope of this specification. Therefore, the embodiments disclosed in this specification are only used as examples and not as limitations. Those skilled in the art can adopt alternative configurations according to the embodiments in this specification to implement the applications in this specification. Therefore, the embodiments of this specification are not limited to the embodiments accurately described in the application.
Claims
1. A data compression method based on key-value storage, applied to a server, comprising: Generate a current dictionary based on multiple key values in the storage system of the server side, including extracting common high-frequency character strings based on key value data in the storage system of the server side to generate a unified current dictionary, wherein the current dictionary is applicable to all data in the storage system, and the current dictionary is a dictionary with the highest compression efficiency among multiple candidate dictionaries, wherein the multiple candidate dictionaries are obtained by training dictionaries based on dictionary training parameters and training data, wherein the training data is obtained by selecting N key values from the multiple key values in the storage system, wherein N is an integer greater than 1; Receive the key-value pairs sent by the client; as well as The key values in the key-value pairs are compressed using the current dictionary and stored in the storage system.
2. The method of claim 1, wherein: The storage system includes a cache storage system.
3. The method of claim 1, wherein: The generating a current dictionary based on a plurality of key values in the storage system of the server includes: Selecting the N key values from the multiple key values in the storage system as the training data; Setting the dictionary training parameters, training the dictionary based on the dictionary training parameters and the training data, to obtain the plurality of candidate dictionaries; and A candidate dictionary with the highest compression efficiency is selected from the multiple candidate dictionaries as the current dictionary.
4. The method of claim 3, wherein: The generating a current dictionary based on a plurality of key values in the storage system of the server further includes: Selecting M key values from the multiple key values in the storage system as verification data, where M is an integer greater than 1; The step of selecting a candidate dictionary with the highest compression efficiency from the multiple candidate dictionaries as the current dictionary includes: Selecting a candidate dictionary with the highest compression efficiency from the multiple candidate dictionaries as a target dictionary; verifying the compression efficiency of the target dictionary based on the verification data; and The target dictionary is used as the current dictionary.
5. The method of claim 4, wherein: The M is equal to the N.
6. The method of claim 1, wherein: Also includes: It is determined that the compression efficiency of the storage system decreases, and the current dictionary is updated.
7. The method of claim 6, wherein: The determining that the compression efficiency of the storage system decreases and updating the current dictionary includes: Calculating the overall compression efficiency of the current dictionary on the storage system at the current moment; Determining that the overall compression efficiency of the current dictionary for the storage system at the current moment decreases by more than a target threshold compared with the overall compression efficiency at a previous moment; and The current dictionary is updated.
8. The method of claim 7, wherein: The updating of the current dictionary comprises: Generate a candidate update dictionary based on multiple key values in the storage system of the server at the current moment; compressing the plurality of key values in the storage system using the candidate update dictionary; Determining that the overall compression efficiency of the candidate updated dictionary on the storage system is higher than the overall compression efficiency of the current dictionary on the storage system at the current moment; and The candidate update dictionary is used as the current dictionary.
9. The method of claim 7, wherein: The determining that the compression efficiency of the storage system decreases and updating the current dictionary further includes: decompressing the compressed key value stored in the storage system using the current dictionary before updating; and The key value decompressed by the current dictionary before the update is compressed using the updated current dictionary to obtain an updated compressed key value.
10. The method of claim 1, wherein: Also includes: Read the target key value in the storage system.
11. The method of claim 10, wherein: The reading of the target key value in the storage system includes: receiving a read request for the target key value sent by a target client, wherein the client includes the target client, and the multiple key values include the target key value; Decompressing the compressed key value corresponding to the target key value using the current dictionary to obtain the target key value; and The target key value is sent to the target client.
12. A data compression system based on key-value storage, comprising a server side, wherein the server side comprises: at least one storage medium including at least one instruction set for data compression based on key-value storage; as well as at least one processor, in communication with the at least one storage medium, Wherein, when the system is running, the at least one processor reads the at least one instruction set and executes the key-value storage-based data compression method described in any one of claims 1-11 according to the instructions of the at least one instruction set.
Citation Information
Patent Citations
Text compression method and text compression device
CN102567322A
Method and device for providing a dynamic compression dictionary and electronic equipment
CN107645538A
Method and device for generating compression dictionary
CN107994907A
Live broadcast platform training data processing method and device, storage medium and equipment
CN110532466A
Data compression method and device, compression server and storage medium
CN111193752A
