Method and device for optimizing Elasticsearch performance based on compression algorithm

By introducing the ZSTD compression algorithm and tuning parameters, it solves the storage space and performance optimization problems of Elasticsearch in large data volume scenarios, achieves higher storage efficiency and writing performance, and is suitable for compression effects in different application scenarios.

CN118643014APending Publication Date: 2024-09-13CHINA UNITECHS
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202410775488.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-17
Publication Date
2024-09-13

AI Technical Summary

Technical Problem

The existing Elasticsearch compression algorithm has trade-offs in terms of compression ratio and performance, and cannot optimize storage space and performance well. Especially in large data volume scenarios, writing performance and storage costs bring huge pressure.

Method used

Introduce the Zstandard (ZSTD) compression algorithm, customize the ZstdCompressionMode and ZstdCodec classes, and combine the zstd-jni dependency package to provide Java language implementation, integrate it into Elasticsearch, and register through the plug-in mechanism, and tune the compression parameters to optimize the compression ratio and storage space .

Benefits of technology

Significantly reduce storage costs, improve write performance and query performance, provide higher storage efficiency and flexible compression strategy parameters, balance speed and compression effects, and optimize ES storage space and performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118643014A
    Figure CN118643014A
Patent Text Reader

Abstract

The invention discloses an Elasticsearch performance optimization method and device based on a compression algorithm, and the method comprises the steps: introducing a zstd-jni dependency package, and providing the implementation of a Java language of a ZSTD compression algorithm; the method comprises the steps that a ZstdCompression Mode compression class is customized, a Compression Mode abstract class of Elasticsearch is inherited, compression parameters are contained in the customized ZstdCompression Mode compression class, a compression and decompression method of a zstd-jni dependent packet is called, and the compression and decompression method is achieved; the method comprises the following steps of: customizing a ZstdCodec class, inheriting a Codec class of Lucene, and carrying out compression on DocValues by using a custom ZstdCompression Mode compression class; the method comprises the following steps of: integrating a self-defined ZstdCodec class into Elasticsearch through a plug-in mechanism, and registering the self-defined ZstdCodec class; when an Elasticsearch index is created, a self-defined compression mode and compression parameters are specified through setttings, and ZSTD compression of the index and log data is achieved; the compression parameters are adjusted and optimized according to different scenes, and the compression ratio and the storage space are optimized. According to the method and the device, the ES compression algorithm is integrated with the advanced compression algorithm ZSTD in the industry, so that the storage space and the performance of the ES are optimized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of Elasticsearch storage, and in particular to a compression algorithm-based Elasticsearch performance optimization method and device. Background Art

[0002] With the surge in business data volumes, using Elasticsearch to store relevant business data has become the norm. For example, system logs are often stored in Elasticsearch. In large data volume scenarios, daily log writes can reach petabytes, placing significant pressure on Elasticsearch's write performance and storage costs.

[0003] The index in ES consists of multiple shards, each of which contains multiple segment files. Segment files are the smallest storage and search units. Segment files mainly contain:

[0004] (1) Row storage file: original text storage file and original text index file. The original text data is stored in the row storage file.

[0005] (2) Column storage file: specifically used for OLAP analysis.

[0006] (3) Index file: contains dictionary data files and inverted index files to achieve full-text search capabilities.

[0007] Row-level files account for the largest proportion, exceeding 30%. Currently, the compression algorithms supported for row-level files are LZ4 and Deflate. LZ4, the default compression algorithm supported by ES, offers excellent performance but a relatively low compression ratio. Deflate offers a higher compression ratio, but at the expense of some performance. Therefore, when choosing a compression algorithm, there is a trade-off between compression ratio and performance; it's not possible to achieve a perfect balance between compression ratio and performance. Therefore, it's necessary to introduce a new compression algorithm to optimize ES's storage space and performance. Summary of the Invention

[0008] In response to the above situation, the present invention provides an Elasticsearch performance optimization method and device based on a compression algorithm, which integrates the ES compression algorithm with the industry's advanced compression algorithm Zstandard (ZSTD), and can provide better compression ratio and performance.

[0009] To achieve the above object, the present invention adopts the following technical solutions:

[0010] In one embodiment of the present invention, a method for optimizing Elasticsearch performance based on a compression algorithm is proposed. The method includes:

[0011] Introducing the zstd-jni dependency package to provide a Java language implementation of the ZSTD compression algorithm;

[0012] Customize the ZstdCompressionMode compression class, inherit the CompressionMode abstract class of Elasticsearch, and include compression parameters in the custom ZstdCompressionMode compression class. Call the compression and decompression methods of the zstd-jni dependency package to implement the compression and decompression methods.

[0013] Customize the ZstdCodec class, inherit the Lucene Codec class, and use the custom ZstdCompressionMode compression class to compress DocValues;

[0014] Integrate the custom ZstdCodec class into Elasticsearch through the plug-in mechanism and register the custom ZstdCodec class;

[0015] When creating an Elasticsearch index, specify a custom compression mode and compression parameters through settings to implement ZSTD compression of index and log data;

[0016] Adjust compression parameters according to different scenarios to optimize compression ratio and storage space.

[0017] Furthermore, in the compression method, the compression method of the zstd-jni dependency package is called to compress the data according to the compression level and block size in the compression parameters; in the decompression method, the decompression method of the zstd-jni dependency package is called to decompress the data.

[0018] Furthermore, implement the onIndexModule callback function of the plug-in and call the registerCodec method through the CodecService instance in the function parameter to register the custom ZstdCodec class.

[0019] Furthermore, compression parameters are tuned according to different scenarios to optimize compression ratio and storage space, including:

[0020] Adjust the block size appropriately according to business needs and improve the compression ratio by increasing the block size;

[0021] Select an appropriate compression level based on CPU usage and reduce storage space by increasing the compression level.

[0022] In one embodiment of the present invention, a device for optimizing Elasticsearch performance based on a compression algorithm is also proposed, the device comprising:

[0023] ES integrates the ZSTD compression algorithm module, which is used to introduce the zstd-jni dependency package and provide a Java language implementation of the ZSTD compression algorithm. It also customizes the ZstdCompressionMode compression class, which inherits Elasticsearch's CompressionMode abstract class. The customized ZstdCompressionMode compression class contains compression parameters and calls the compression and decompression methods of the zstd-jni dependency package to implement the compression and decompression methods. It also customizes the ZstdCodec class, which inherits Lucene's Codec class and uses the customized ZstdCompressionMode compression class to compress DocValues. It integrates the customized ZstdCodec class into Elasticsearch through the plug-in mechanism and registers the customized ZstdCodec class. When creating an Elasticsearch index, it specifies the customized compression mode and compression parameters through settings to implement ZSTD compression of index and log data.

[0024] The compression parameter tuning module is used to tune compression parameters according to different scenarios to optimize the compression ratio and storage space.

[0025] Furthermore, in the compression method, the compression method of the zstd-jni dependency package is called to compress the data according to the compression level and block size in the compression parameters; in the decompression method, the decompression method of the zstd-jni dependency package is called to decompress the data.

[0026] Furthermore, implement the onIndexModule callback function of the plug-in and call the registerCodec method through the CodecService instance in the function parameter to register the custom ZstdCodec class.

[0027] Furthermore, compression parameters are tuned according to different scenarios to optimize compression ratio and storage space, including:

[0028] Adjust the block size appropriately according to business needs and improve the compression ratio by increasing the block size;

[0029] Select an appropriate compression level based on CPU usage and reduce storage space by increasing the compression level.

[0030] In one embodiment of the present invention, a computer device is also proposed, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the aforementioned Elasticsearch performance optimization method based on the compression algorithm is implemented.

[0031] In one embodiment of the present invention, a computer-readable storage medium is further provided, wherein the computer-readable storage medium stores a computer program for executing an Elasticsearch performance optimization method based on a compression algorithm.

[0032] Beneficial effects:

[0033] 1. Improved storage efficiency: The ZSTD compression algorithm uses dictionary compression and a multi-level compression strategy. By referencing matching items in the dictionary and using different compression levels, it can effectively reduce storage space usage. By using the ZSTD compression algorithm to compress row-stored files in ES, you can significantly reduce storage costs and provide higher storage efficiency.

[0034] 2. Improving write performance: ES faces challenges with write performance when processing large amounts of data. Using the ZSTD compression algorithm can reduce the amount of data to be written, thereby reducing the time and resource consumption required for write operations. The ZSTD compression algorithm offers fast compression and decompression speeds, and by fully leveraging hardware parallelism and an optimized encoding process, it can improve ES write performance.

[0035] 3. Improved query performance: By compressing index files, especially inverted index files, disk I / O operations and network transmission overhead can be reduced. The high-speed compression and decompression characteristics of the ZSTD compression algorithm can speed up the reading and parsing of data, thereby improving query performance and response speed.

[0036] 4. Flexible Compression Strategy Parameters: The ZSTD compression algorithm provides a set of compression strategy parameters that can be adjusted based on the actual application scenario and business data characteristics. For example, you can increase the block size to improve the compression ratio, increase the compression level to reduce storage space, and select the appropriate compression level based on CPU usage. This flexibility enables the ZSTD compression algorithm to balance speed and compression effectiveness in different application scenarios to achieve optimal performance. BRIEF DESCRIPTION OF THE DRAWINGS

[0037] Figure 1 This is a flow chart of the Elasticsearch performance optimization method based on the compression algorithm of the present invention;

[0038] Figure 2 This is a diagram of the data storage structure of Elasticsearch according to an embodiment of the present invention;

[0039] Figure 3 This is a Lucene data file composition diagram according to an embodiment of the present invention;

[0040] Figure 4 This is a schematic diagram of the structure of the Elasticsearch performance optimization device based on the compression algorithm of the present invention;

[0041] Figure 5 It is a schematic diagram of the computer device structure of the present invention. DETAILED DESCRIPTION

[0042] The principles and spirit of the present invention will be described below with reference to several exemplary embodiments. It should be understood that these embodiments are provided solely to enable those skilled in the art to better understand and implement the present invention, and are not intended to limit the scope of the present invention in any way. Rather, these embodiments are provided to make this disclosure more thorough and complete, and to fully convey the scope of the present disclosure to those skilled in the art.

[0043] Those skilled in the art will appreciate that the embodiments of the present invention may be implemented as a system, apparatus, device, method, or computer program product. Therefore, the present disclosure may be implemented in the following forms: entirely in hardware, entirely in software (including firmware, resident software, microcode, etc.), or in a combination of hardware and software.

[0044] According to an embodiment of the present invention, a method for optimizing the performance of Elasticsearch based on a compression algorithm is proposed, which integrates the industry's advanced compression algorithm Zstandard (ZSTD) into the ES compression algorithm. ZSTD is a fast compression algorithm with adjustable compression levels, which may provide better compression ratio and performance in some cases. ZSTD is based on FSE encoding at the bottom layer and has excellent compression and decompression speed. The implementation of the ZSTD algorithm has been highly optimized. Through instruction sets such as SIMD, it can fully utilize hardware parallelism. At the same time, the encoding process relies heavily on bit shift operations to complete state switching, thereby improving processing speed. ZSTD uses a dictionary compression algorithm. By referencing matching items in the dictionary, it can greatly reduce the storage space of duplicate data and improve the compression ratio. At the same time, ZSTD adopts a multi-level compression strategy, applying different compression algorithms at different compression levels, and can flexibly balance speed and compression ratio in different application scenarios. At the same time, a set of compression strategy parameters is provided, and the compression strategy parameters can be adjusted according to the actual application scenario and business data to achieve the best effect.

[0045] The principles and spirit of the present invention are explained in detail below with reference to several representative embodiments of the present invention.

[0046] Figure 1 This is a flow chart of the Elasticsearch performance optimization method based on the compression algorithm of the present invention. Figure 1 As shown, the method includes:

[0047] 1. Introduce the zstd-jni dependency package to provide the Java language implementation of the ZSTD compression algorithm.

[0048] zstd-jni is a Java calling interface based on the zstd native library. It supports Zstd compression and decompression in Java.

[0049] 2. Customize the ZstdCompressionMode compression class, inherit the CompressionMode abstract class, include the compression parameter Config in the customized ZstdCompressionMode compression class, call the compression and decompression methods of zstd-jni, and implement the compress (compression) and decompress (decompression) methods.

[0050] The custom ZstdCompressionMode compression class is a ZSTD compression mode implementation class. This invention integrates the ES compression algorithm with the ZSTD compression algorithm, making it a key implementation class. Specifically, ZstdCompressionMode is a ZSTD compression mode class used to implement the ZSTD compression mode. It inherits from the CompressionMode abstract class in Elasticsearch and implements compression and decompression interface methods.

[0051] CompressionMode is an abstract compression mode class in Elasticsearch, which defines an interface for data compression.

[0052] 3. Customize the ZstdCodec class, inherit the Lucene Codec class, and use ZstdCompressionMode to compress components such as DocValues ​​(document values).

[0053] The ZstdCodec class is a ZSTD codec class, a custom Codec implementation class that enables the ZSTD algorithm and other built-in compression algorithms to belong to a complete analysis and indexing system.

[0054] Lucene is an open-source full-text search engine library that provides the underlying search and indexing capabilities of Elasticsearch.

[0055] Codec is a codec that represents a complete analysis and index writing system in Elasticsearch.

[0056] 4. Integrate the ZstdCodec class into Elasticsearch through the Plugin mechanism and register the custom ZstdCodec class.

[0057] Plugin refers to the plugin mechanism in Elasticsearch, which is an extension mechanism defined by Elasticsearch. It allows developers to implement extension components and dynamically load them, such as new codecs.

[0058] 5. When creating an index, specify the custom compression mode and compression parameters (compression level and block size) through settings to implement ZSTD compression of index and log data.

[0059] settings refers to the Elasticsearch index settings.

[0060] 6. Adjust compression parameters according to different scenarios:

[0061] (1) Increasing the chunk size can improve the compression ratio but increase latency. The chunk size can be adjusted appropriately based on business needs.

[0062] (2) Increasing the compression level can further reduce storage space, but will increase CPU consumption. You can choose an appropriate compression level based on CPU usage.

[0063] By customizing the compression algorithm and effectively utilizing the high-speed compression characteristics of the ZSTD compression algorithm, the goal of optimizing ES storage and performance is achieved.

[0064] It should be noted that although the operations of the method of the present invention are described in a specific order in the above embodiments and drawings, this does not require or imply that these operations must be performed in this specific order, or that all illustrated operations must be performed to achieve the desired results. Additionally or alternatively, certain steps may be omitted, multiple steps may be combined into one step, and / or one step may be broken down into multiple steps.

[0065] In order to more clearly explain the above-mentioned Elasticsearch performance optimization method based on the compression algorithm, a specific embodiment is described below. However, it should be noted that this embodiment is only for better illustrating the present invention and does not constitute an improper limitation of the present invention.

[0066] Example:

[0067] First, explain the data storage structure of Elasticsearch, such as Figure 2As shown in the figure, Elasticsearch provides data retrieval capabilities through indexes, which are logical units for organizing and storing data. Each index contains multiple shards, each of which is a Lucene index instance. Each shard consists of a set of segment files, which are the smallest storage and search unit. Segment files are composed of a set of physical files, including the following two parts:

[0068] (1) Inverted index: stores the mapping relationship between terms and document IDs, supporting full-text search.

[0069] (2) Document storage: stores the field values ​​and metadata information of documents.

[0070] like Figure 3 As shown, Lucene's data files mainly consist of the following files:

[0071] (1) Row storage files: This includes the original text storage file and the original text index file. The original text storage file is the .fdt file. All the original data written by the user is stored in this file. Because it accounts for a large proportion, to save storage, Lucene supports LZ4 compression and ZIP compression on the original text storage; the original text index file is the .fdx file. It stores the location information of the original text data in the original text storage file and establishes a connection between the doc id and the original text to support fast access and positioning.

[0072] (2) Column-based files: These are .dvd files, often used in some OLAP analysis engines. Column-based files organize data by column. Data from the same column (Field) in different documents is stored adjacently, which can accelerate aggregate analytical queries on that column. Furthermore, since adjacent columns are of the same type, unified encoding optimization can be performed during storage, improving compression and reducing disk space usage.

[0073] (3) Index-related files: ES relies on word segmentation to generate inverted indexes, giving it powerful full-text search capabilities. Among the index-related files, the key files include: dictionary data files & inverted index files. The dictionary data file, i.e., the .tim file, can extract word segmentation information from user data through the user-configured index segmenter and store it in the .tim file. Word segmentation information in the same column is stored adjacently and organized in blocks; the inverted index file, i.e., the .doc file, is also called an "inverted zipper table". It records the list of documents associated with each word segmentation, enabling fast inverted search from word to document.

[0074] Among the above files, row files account for the largest proportion, usually exceeding 30%, and some indexes even account for more than 70%. Therefore, the present invention determines to focus on optimizing the compression coding of index files.

[0075] The ZSTD compression algorithm was chosen because its underlying implementation is based on FSE encoding, which offers excellent compression and decompression speeds. The ZSTD compression algorithm is highly optimized, leveraging instruction sets like SIMD to fully exploit hardware parallelism. The encoding process relies heavily on bit shift operations to switch states, thereby increasing processing speed. The ZSTD compression algorithm utilizes a dictionary compression algorithm that significantly reduces the storage space for duplicate data by referencing matching entries in the dictionary, thereby improving the compression ratio. Furthermore, the ZSTD compression algorithm employs a multi-level compression strategy, applying different compression algorithms at different compression levels, enabling a flexible balance between speed and compression ratio in different application scenarios.

[0076] After a compression test on a 1GB log file, we found that compared to the ZIP algorithm, the ZSTD compression algorithm increased compression speed by 4.5 times and decompression speed by 1.5 times, while the compression ratio was almost the same. The test results are shown in Table 1 below:

[0077] Table 1

[0078] Compression algorithm Average compression time (ms) Average decompression time (ms) Compression ratio ZSTD 1690 1183 1.95 LZ4 1678 1151 1.32 ZIP 7618 1791 1.97

[0079] 1. ES integrates ZSTD compression algorithm

[0080] Steps to implement the ZSTD compression algorithm in Elasticsearch using zstd-jni:

[0081] (1) First, the zstd-jni dependency package needs to be introduced into the present invention. This dependency package provides a Java language implementation of the ZSTD compression algorithm.

[0082] (2) Next, you need to customize the CompressionMode. To do this, you need to create a new class called ZstdCompressionMode, which inherits from the Elasticsearch CompressionMode abstract class.

[0083] In the ZstdCompressionMode class, add a member variable, Config, for compression configuration parameters. The Config parameter contains the compression level (compression_level) and chunk size (chunk_size). These parameter values ​​are read from the index's settings configuration. Users can set the optimal compression parameters based on the needs of different business scenarios.

[0084] Next, implement the compress and decompress methods for compression and decompression. In the compress method, call the zstd-jni compression method to compress the data according to the compression level (compression_level) and chunk size (chunk_size) configured in the Config parameter. In the decompress method, call the zstd-jni decompression method to decompress the data. In the constructor, specify a name for the compression mode, such as "zstd", to implement a custom compression mode.

[0085] (3) Next, you need to implement a custom Codec. Create a Java class called ZstdCodec that inherits from Lucene's Codec class and overrides the constructor. Internally, instantiate a custom ZstdCompressionMode so that the ZSTD algorithm is used when compressing components such as DocValues.

[0086] (4) Finally, integrate the custom ZstdCodec into Elasticsearch through the plugin mechanism. You need to implement the plugin's onIndexModule callback function and call the registerCodec method with the CodecService instance passed as a parameter to register the custom ZstdCodec class. To load the plugin, you also need to declare the plugin name in the Elasticsearch configuration file. This completes the integration of the ZSTD compression algorithm.

[0087] onIndexModule: Index module construction callback function, which is the callback method defined by the Plugin extension interface in Elasticsearch.

[0088] CodecService: Codec service is a service interface used to manage and register codec components.

[0089] registerCodec: The codec registration method is defined by the CodecService interface and is used to register a codec implementation class.

[0090] (5) When creating an index, you can specify a custom compression mode (codec), compression level (compression_level), and chunk size (chunk_size) through the settings parameter, so that Elasticsearch uses the ZSTD algorithm implemented by zstd-jni when performing compression operations. In this way, you can use the flexible compression interface provided by Elasticsearch and the ZSTD compression implementation provided by zstd-jni to achieve customized compression effects for index and log data.

[0091] The following is an example configuration of the settings parameters:

[0092] {

[0093] "settings": {

[0094] "index": {

[0095] "codec": "zstd",

[0096] "compression_level": 3,

[0097] "chunk_size": "60" / / Unit: kb

[0098] }

[0099]

[0100] In the above example, the compression mode (codec) is set to "zstd", the compression level (compression_level) is set to 3, and the chunk size (chunk_size) is set to "16kb". You can adjust the values ​​of these parameters as needed to obtain the best compression effect.

[0101] 2. Compression parameter tuning

[0102] Through different scenarios and parameter tuning tests, this paper determines the compression parameter optimization method of the ZSTD algorithm, which mainly includes:

[0103] (1) Chunk Size Tuning

[0104] Row files are organized in chunks, typically tens of KB in size. The LZ4 algorithm uses a 16KB chunk size, while the ZIP algorithm uses a 60KB chunk size. After setting the index compression format to ZSTD and importing batches of online data, the compression ratios for different chunk sizes are shown in Table 2:

[0105] Table 2

[0106]

[0107]

[0108] Increasing the ChunkSize can expand the shared dictionary data within the data interval, achieving better compression. However, this also increases random access latency and CPU consumption. In practice, appropriate adjustments should be made based on the concurrent access volume of the service. If you have high requirements for random access latency, you can choose a relatively small chunk size. If you are more concerned about optimizing storage space, you can choose a larger chunk size.

[0109] Therefore, when determining the ChunkSize, you need to comprehensively consider various factors and adjust it based on actual needs. If you are sensitive to random access latency and CPU consumption, you can choose a smaller ChunkSize. If you prioritize optimizing storage space, you can choose a larger ChunkSize. Choose an appropriate ChunkSize based on your business characteristics and performance requirements to balance compression effectiveness and system resource consumption.

[0110] (2) ZSTD compression level tuning

[0111] The ZSTD compression algorithm uses a multi-level compression strategy, offering compression level options ranging from 1 to 22. A higher compression level indicates a higher compression ratio, but also slower compression and decompression speeds and increased CPU usage. When importing test data, different compression levels were set and performance was compared. Increasing the compression level can reduce storage requirements. For example, adjusting the compression level to 9 reduces the storage requirements of .fdt files by approximately 10% and the overall index storage requirements by 5%. At this point, CPU usage is roughly the same as that of ZIP. The following is the results in Table 3:

[0112] Table 3

[0113]

[0114] The results in Table 3 above show that increasing the compression level improves the compression ratio, but also slows compression and decompression speeds and increases CPU usage. Therefore, choosing a compression level requires a trade-off based on your specific situation. If you're sensitive to compression and can tolerate slower compression and decompression speeds and higher CPU usage, you can choose a higher compression level. If you're more concerned about compression and decompression speed and CPU usage, you can choose a lower compression level.

[0115] Consider business needs and system resources comprehensively and select an appropriate compression level to achieve a balance between compression ratio and performance.

[0116] Based on the same inventive concept, the present invention also proposes an Elasticsearch performance optimization device based on a compression algorithm. The implementation of this device can refer to the implementation of the above-mentioned method, and the repeated parts will not be repeated here. The term "module" used below can refer to a combination of software and / or hardware that implements a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, implementation in hardware, or a combination of software and hardware, is also possible and contemplated.

[0117] Figure 4 This is a schematic diagram of the structure of the Elasticsearch performance optimization device based on the compression algorithm of the present invention. Figure 4 As shown, the device includes:

[0118] ES integrates the ZSTD compression algorithm module 101, which is used to introduce the zstd-jni dependency package and provide a Java language implementation of the ZSTD compression algorithm. It also customizes the ZstdCompressionMode compression class, which inherits the Elasticsearch CompressionMode abstract class. The customized ZstdCompressionMode compression class contains compression parameters and calls the compression and decompression methods of the zstd-jni dependency package to implement the compression and decompression methods. It also customizes the ZstdCodec class, which inherits the Lucene Codec class and uses the customized ZstdCompressionMode compression class to compress DocValues. It integrates the customized ZstdCodec class into Elasticsearch through the plug-in mechanism and registers the customized ZstdCodec class. When creating an Elasticsearch index, it specifies the customized compression mode and compression parameters through settings to implement ZSTD compression of index and log data.

[0119] In the compression method, the compression method of the zstd-jni dependency package is called to compress the data according to the compression level and block size in the compression parameters; in the decompression method, the decompression method of the zstd-jni dependency package is called to decompress the data;

[0120] Implement the onIndexModule callback function of the plug-in, and call the registerCodec method through the CodecService instance in the function parameter to register the custom ZstdCodec class.

[0121] The compression parameter tuning module 102 is used to tune compression parameters according to different scenarios to optimize the compression ratio and storage space, including:

[0122] Adjust the block size appropriately according to business needs and improve the compression ratio by increasing the block size;

[0123] Select an appropriate compression level based on CPU usage and reduce storage space by increasing the compression level.

[0124] It should be noted that while the above detailed description mentions several modules of the Elasticsearch performance optimization device based on a compression algorithm, this division is merely exemplary and not mandatory. In practice, according to embodiments of the present invention, the features and functions of two or more modules described above may be embodied in a single module. Conversely, the features and functions of a single module described above may be further divided and embodied by multiple modules.

[0125] Based on the above invention concept, Figure 5 As shown, the present invention also proposes a computer device 200, including a memory 210, a processor 220, and a computer program 230 stored in the memory 210 and executable on the processor 220. When the processor 220 executes the computer program 230, the aforementioned Elasticsearch performance optimization method based on the compression algorithm is implemented.

[0126] Based on the aforementioned inventive concept, the present invention further proposes a computer-readable storage medium, which stores a computer program for executing the aforementioned Elasticsearch performance optimization method based on the compression algorithm.

[0127] The Elasticsearch performance optimization method and device based on the compression algorithm proposed in this invention have the following highlights:

[0128] 1. Improved storage efficiency: The ZSTD compression algorithm uses dictionary compression and a multi-level compression strategy. By referencing matching items in the dictionary and using different compression levels, it can effectively reduce storage space usage. By using the ZSTD compression algorithm to compress row-stored files in ES, you can significantly reduce storage costs and provide higher storage efficiency.

[0129] 2. Improving write performance: ES faces challenges with write performance when processing large amounts of data. Using the ZSTD compression algorithm can reduce the amount of data to be written, thereby reducing the time and resource consumption required for write operations. The ZSTD compression algorithm offers fast compression and decompression speeds, and by fully leveraging hardware parallelism and an optimized encoding process, it can improve ES write performance.

[0130] 3. Improved query performance: By compressing index files, especially inverted index files, disk I / O operations and network transmission overhead can be reduced. The high-speed compression and decompression characteristics of the ZSTD compression algorithm can speed up the reading and parsing of data, thereby improving query performance and response speed.

[0131] 4. Flexible Compression Strategy Parameters: The ZSTD compression algorithm provides a set of compression strategy parameters that can be adjusted based on the actual application scenario and business data characteristics. For example, you can increase the block size to improve the compression ratio, increase the compression level to reduce storage space, and select the appropriate compression level based on CPU usage. This flexibility enables the ZSTD compression algorithm to balance speed and compression effectiveness in different application scenarios to achieve optimal performance.

[0132] In summary, the ES performance optimization method based on the ZSTD compression algorithm can improve storage efficiency, write performance, query performance, and flexible compression strategy parameters, thereby optimizing ES storage space and performance.

[0133] Although the spirit and principles of the present invention have been described with reference to several specific embodiments, it should be understood that the present invention is not limited to the specific embodiments disclosed, and the division into various aspects does not mean that the features of these aspects cannot be combined to benefit. Such division is only for the convenience of expression. The present invention is intended to cover various modifications and equivalent arrangements included within the spirit and scope of the appended claims.

[0134] Regarding the limitation of the protection scope of the present invention, those skilled in the art should understand that, based on the technical solution of the present invention, various modifications or variations that can be made by those skilled in the art without creative work are still within the protection scope of the present invention.

Claims

1. A method for optimizing Elasticsearch performance based on a compression algorithm, characterized in that: The method includes: Introduce the zstd-jni dependency package to provide the Java language implementation of the ZSTD compression algorithm; Customize the ZstdCompressionMode compression class, inherit the CompressionMode abstract class of Elasticsearch, and include compression parameters inside the custom ZstdCompressionMode compression class. Call the compression and decompression methods of the zstd-jni dependency package to implement the compression and decompression methods. Customize the ZstdCodec class, inherit the Lucene Codec class, and use the custom ZstdCompressionMode compression class to compress DocValues; Integrate the custom ZstdCodec class into Elasticsearch through the plug-in mechanism and register the custom ZstdCodec class; When creating an Elasticsearch index, specify a custom compression mode and compression parameters through settings to implement ZSTD compression of index and log data; Adjust compression parameters according to different scenarios to optimize compression ratio and storage space.

2. The Elasticsearch performance optimization method based on compression algorithm according to claim 1, characterized in that: In the compression method, call the compression method of the zstd-jni dependency package to compress the data according to the compression level and block size in the compression parameters; In the decompression method, call the decompression method of the zstd-jni dependency package to decompress the data.

3. The Elasticsearch performance optimization method based on compression algorithm according to claim 1, characterized in that: Implement the onIndexModule callback function of the plug-in, and call the registerCodec method through the CodecService instance in the function parameter to register the custom ZstdCodec class.

4. The Elasticsearch performance optimization method based on compression algorithm according to claim 1, characterized in that: Tune compression parameters according to different scenarios to optimize compression ratio and storage space, including: Adjust the block size appropriately according to business needs and increase the compression ratio by increasing the block size; Select the appropriate compression level based on CPU usage and reduce storage space by increasing the compression level.

5. An Elasticsearch performance optimization device based on a compression algorithm, characterized in that: The device includes: ES integrates the ZSTD compression algorithm module to introduce the zstd-jni dependency package and provide the Java language implementation of the ZSTD compression algorithm; customizes the ZstdCompressionMode compression class, inherits the CompressionMode abstract class of Elasticsearch, and contains compression parameters. It calls the compression and decompression methods of the zstd-jni dependency package to implement the compression and decompression methods; customizes the ZstdCodec class, inherits the Codec class of Lucene, and uses the customized ZstdCompressionMode compression class to compress DocValues; integrates the customized ZstdCodec class into Elasticsearch through the plug-in mechanism, and registers the customized ZstdCodec class; when creating an Elasticsearch index, specifies the customized compression mode and compression parameters through settings to implement ZSTD compression of index and log data; The compression parameter tuning module is used to tune compression parameters according to different scenarios to optimize the compression ratio and storage space.

6. The Elasticsearch performance optimization device based on compression algorithm according to claim 5, characterized in that: In the compression method, call the compression method of the zstd-jni dependency package to compress the data according to the compression level and block size in the compression parameters; In the decompression method, call the decompression method of the zstd-jni dependency package to decompress the data.

7. The Elasticsearch performance optimization device based on compression algorithm according to claim 5, characterized in that: Implement the onIndexModule callback function of the plug-in, and call the registerCodec method through the CodecService instance in the function parameter to register the custom ZstdCodec class.

8. The Elasticsearch performance optimization device based on compression algorithm according to claim 5, characterized in that: Tune compression parameters according to different scenarios to optimize compression ratio and storage space, including: Adjust the block size appropriately according to business needs and increase the compression ratio by increasing the block size; Select the appropriate compression level based on CPU usage and reduce storage space by increasing the compression level.

9. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the method according to any one of claims 1 to 4 is implemented.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program for executing the method according to any one of claims 1 to 4.

Citation Information

Patent Citations

  • Decompression method and system of search engine, medium and electronic equipment

    CN115185901A

  • Index compression method and device and index decompression method and device

    CN116881213A

  • Inverted index hybrid compression method based on HBase database

    CN117708118A