A non-invasive log compression optimization method and system
Patent Information
- Application Number
- CN202511735167.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-25
- Publication Date
- 2026-09-25
- Estimated Expiration
- 2045-11-25
AI Technical Summary
[0007]本发明的目的在于提供一种无侵入式的日志压缩优化方法及系统,以解决现有压缩效率低、复杂度高、兼容性差难以大规模部署的技术问题
[0035]本发明与现有技术相比,本发明提供的一种无侵入式的日志压缩优化方法及系统,通过 “熵驱动聚集冗余 + 分层搜索最优序列”,较原始序列(无优化)与通用压缩算法结合时,压缩效率显著提升;无需修改现有压缩 / 解压缩流程,仅需在数据写入存储前增加 “字段重排” 步骤,可直接集成至现有数据处理;适配各类结构化数据,解决了高级压缩技术通用性不足的问题;通过 “采样评估 + 分组搜索” 降低计算复杂度,降低计算开销,支持多进程并行处理,满足大规模数据处理需求;支持配置核心参数(如分组大小、迭代深度),实现 “压缩比 - 压缩速度” 的灵活调整,适配不同场景需求;优化后的字段序列虽不直接加密,但字段排列顺序与数据特征(如低熵字段分布)为特定系统专有,第三方获取重排后的数据后,若无对应的序列信息,难以快速理解数据结构,间接起到数据混淆与日志保护的作用,具备轻量级数据保护能力。
Smart Images

Figure CN121301297B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of data compression technology, and in particular relates to a non-intrusive log compression optimization method and system. Background Technology
[0002] With the development of internet technology and enterprise digitalization, the volume of structured data (such as network logs and business CSV tables) is increasing exponentially. This type of data records key business interactions or network behavior information and is the core support for fault diagnosis, security tracing, and trend analysis. However, the massive amount of data puts enormous pressure on storage resources, transmission bandwidth, and cost control, making efficient compression technology an inevitable requirement.
[0003] Currently, the industry mainly uses two types of compression schemes to process structured data:
[0004] (1) General compression algorithms: such as gzip, bzip2, lzma, etc., whose core principle is to use the character-level redundancy of data to achieve compression. gzip is based on the DEFLATE algorithm (LZ77 repeating substring replacement + Huffman coding), which has the advantage of fast compression speed and significant effect on short text and continuous high redundancy data. bzip2 optimizes character sorting through Burrows-Wheeler transformation to improve the compression ratio but is slower. lzma uses dictionary compression, which can usually achieve the highest compression ratio, but has a large computational overhead. The reason why such algorithms are widely used is that they are simple to deploy, highly compatible, and do not require modification of the existing data processing flow. However, general compression algorithms do not utilize the core characteristics of structured data: First, the values of some fields (such as the "response return code" of DNS logs and the "protocol type" of NetFlow logs) are highly concentrated and have extremely high redundancy. Second, some fields (such as "timestamp", "IP address" and "domain name") have shared prefixes / suffixes (such as the date prefix of the timestamp, the network segment prefix of the IP address, and the ".com" suffix of the domain name). These features were not effectively mined by the algorithm, resulting in limited compression of structured data. For example, gzip typically achieves a compression ratio of less than 5:1 for DNS logs and less than 10:1 for NetFlow logs.
[0005] (2) Advanced compression techniques: such as template-based compression (Logzip, LogShrink) and numerical encoding compression (Denum). Template-based compression extracts fixed text templates from logs, replaces the template parts with short identifiers, and retains only variable content, reducing redundant text. Numerical encoding compression (such as Denum) designs regular encoding rules for numerical fields such as timestamps and IP addresses, converting long strings into short codes. Although these techniques can improve the compression ratio, they have significant drawbacks: ① High deployment complexity, requiring the maintenance of template / encoding mapping tables and modification of existing compression / decompression pipelines; ② Poor compatibility, with strong dependence on data formats (e.g., Denum has poor adaptability to string-intensive DNS logs, resulting in a decrease in compression ratio); ③ Disruption of the original data order, requiring the generation of additional index files to achieve lossless recovery, increasing system maintenance costs; ④ Insufficient versatility, only adapting to specific data types (e.g., Logzip is only for log files and cannot be migrated to CSV tables).
[0006] Therefore, there is an urgent need for a lightweight, low-deployment-cost, and highly versatile field sequence optimization solution that can mine fields from structured data through automated means. Summary of the Invention
[0007] The purpose of this invention is to provide a non-intrusive log compression optimization method and system to solve the technical problems of low compression efficiency, high complexity, poor compatibility and difficulty in large-scale deployment of existing compression methods.
[0008] To achieve one of the above-mentioned objectives, one embodiment of the present invention provides a non-intrusive log compression optimization method, the method comprising:
[0009] Based on the configured sampling parameters, several files are randomly selected from the source data, and each file is divided into several segments. The first few lines of each segment are extracted as data blocks, and all extracted data blocks are merged to form a sample file.
[0010] Based on information entropy, the field redundancy of the sample file is quantified to generate an initial sequence with preliminary compression friendliness;
[0011] The initial sequence is divided into several groups according to a set window size, and a full permutation is performed within each group to generate several candidate sequences;
[0012] Based on each candidate sequence, the fields of the sample file are rearranged, and the rearranged sample file is compressed. The candidate sequence corresponding to the smallest compressed file is selected as the segmentation optimization sequence.
[0013] Based on the segmented optimization sequence, the fields of the source data are rearranged to optimize the compression effect.
[0014] As a further improvement to one embodiment of the present invention, the configuration of the sampling parameters includes,
[0015] The number of randomly selected files, the number of segments in each file, and the number of lines extracted from each segment.
[0016] As a further improvement to one embodiment of the present invention, the step of generating an initial sequence with preliminary compression friendliness by quantifying the field redundancy of the sample file based on information entropy includes,
[0017] For each field in the sample file, calculate the corresponding entropy value according to the information entropy formula;
[0018] Select the field with the largest entropy value as the starting point of the initial sequence;
[0019] For the last field of the current initial sequence, calculate its joint entropy with all fields that have not been added to the initial sequence, and select the field with the smallest joint entropy to add to the initial sequence, until all fields have been added.
[0020] As a further improvement of one embodiment of the present invention, the joint entropy is the entropy value after concatenating the two fields.
[0021] As a further improvement to one embodiment of the present invention, the method further includes,
[0022] For the segmented optimization sequence, each field is temporarily removed and then inserted into all other possible positions to generate several candidate sequences;
[0023] For each candidate sequence, the sample file is rearranged by field, and the rearranged sample file is compressed. If there is a candidate sequence whose compressed file is smaller than the segmented optimization sequence, then the candidate sequence is used as the new segmented optimization sequence, and the process returns to the previous step until the set iterative convergence condition is met. The current segmented optimization sequence is then output as the optimal field sequence. If there is no candidate sequence whose compressed file is smaller than the segmented optimization sequence, then the current segmented optimization sequence is output as the optimal field sequence.
[0024] Based on the optimal field sequence, the fields of the source data are rearranged to optimize the compression effect.
[0025] To achieve one of the above-mentioned objectives, an embodiment of the present invention also provides a non-intrusive log compression optimization system, the system comprising a sampling module, an initial sequence generation module, a segmentation optimization module, and a field rearrangement module;
[0026] The sampling module is used to randomly select several files from the source data based on the configured sampling parameters, divide each file into several segments, extract the first few lines of each segment as data blocks, and merge all the extracted data blocks to form a sample file.
[0027] The initial sequence generation module is used to quantify the field redundancy of sample files based on information entropy and generate an initial sequence with preliminary compression friendliness.
[0028] The segmentation optimization module is used to divide the initial sequence into several groups according to a set window size, and perform full permutation within each group to generate several candidate sequences; based on each candidate sequence, the sample file is rearranged in terms of fields, and the rearranged sample file is compressed, and the candidate sequence corresponding to the smallest compressed file is selected as the segmentation optimization sequence;
[0029] The field rearrangement module is used to rearrange the fields of the source data based on the segmented optimization sequence in order to optimize the compression effect.
[0030] As a further improvement of one embodiment of the present invention, the system further includes a local insertion optimization module;
[0031] The local insertion optimization module is used to temporarily remove each field from the segmented optimization sequence and insert it into all other possible positions to generate several candidate sequences. Based on each candidate sequence, the fields of the sample file are rearranged, and the rearranged sample file is compressed. If there is a candidate sequence whose compressed file is smaller than the segmented optimization sequence, then the candidate sequence is used as the new segmented optimization sequence, and the process returns to the previous step until the set iterative convergence condition is met. The current segmented optimization sequence is then output as the optimal field sequence. If there is no candidate sequence whose compressed file is smaller than the segmented optimization sequence, then the current segmented optimization sequence is output as the optimal field sequence.
[0032] The field rearrangement module is used to rearrange the fields of the source data based on the optimal field sequence in order to optimize the compression effect.
[0033] To achieve one of the above-mentioned objectives, an embodiment of the present invention also provides an electronic device, including a memory and a processor, characterized in that the memory stores a computer program that can run on the processor, and when the program is executed on the processor, it implements the steps in the non-intrusive log compression optimization method described above.
[0034] To achieve one of the above-mentioned objectives, an embodiment of the present invention also provides a storage medium storing a computer program, characterized in that the computer program, when executed by a processor, implements the steps in the non-intrusive log compression optimization method described above.
[0035] Compared with existing technologies, this invention provides a non-intrusive log compression optimization method and system. Through "entropy-driven aggregation of redundancy + hierarchical search for the optimal sequence," it significantly improves compression efficiency when combined with the original sequence (without optimization) and a general compression algorithm. It requires no modification to existing compression / decompression processes; only a "field rearrangement" step needs to be added before data is written to storage, allowing direct integration into existing data processing. It adapts to various types of structured data, solving the problem of insufficient versatility in advanced compression technologies. Through "sampling evaluation + group search," it reduces computational complexity and overhead, supports multi-process parallel processing, and meets the needs of large-scale data processing. It supports configuring core parameters (such as group size and iteration depth) to flexibly adjust the "compression ratio - compression speed," adapting to different scenario requirements. Although the optimized field sequence is not directly encrypted, the field arrangement order and data characteristics (such as low-entropy field distribution) are specific to the system. If a third party obtains the rearranged data but lacks the corresponding sequence information, it will be difficult to quickly understand the data structure, indirectly playing a role in data obfuscation and log protection, providing lightweight data protection capabilities. Attached Figure Description
[0036] Figure 1 This is an overall flowchart of the non-intrusive log compression optimization method described in this invention.
[0037] Figure 2 This is a schematic diagram of the architecture of the non-intrusive log compression optimization system described in this invention. Detailed Implementation
[0038] The present invention will now be described in detail with reference to the specific embodiments shown in the accompanying drawings. However, these embodiments do not limit the present invention, and any structural, methodological, or functional modifications made by those skilled in the art based on these embodiments are included within the scope of protection of the present invention.
[0039] Embodiments of the present invention are described in detail below. Examples of these embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention, and should not be construed as limiting the present invention.
[0040] In Embodiment 1 of the present invention, the present invention provides a non-intrusive log compression optimization method, such as... Figure 1 As shown, the method includes,
[0041] Based on the configured sampling parameters, several files are randomly selected from the source data, and each file is divided into several segments. The first few lines of each segment are extracted as data blocks, and all extracted data blocks are merged to form a sample file.
[0042] Based on information entropy, the field redundancy of the sample file is quantified to generate an initial sequence with preliminary compression friendliness;
[0043] The initial sequence is divided into several groups according to a set window size, and a full permutation is performed within each group to generate several candidate sequences;
[0044] Based on each candidate sequence, the fields of the sample file are rearranged, and the rearranged sample file is compressed. The candidate sequence corresponding to the smallest compressed file is selected as the segmentation optimization sequence.
[0045] Based on the segmented optimization sequence, the fields of the source data are rearranged to optimize the compression effect.
[0046] Furthermore, the method of the present invention also includes:
[0047] For the segmented optimization sequence, each field is temporarily removed and then inserted into all other possible positions to generate several candidate sequences;
[0048] For each candidate sequence, the sample file is rearranged by field, and the rearranged sample file is compressed. If there is a candidate sequence whose compressed file is smaller than the segmented optimization sequence, then the candidate sequence is used as the new segmented optimization sequence, and the process returns to the previous step until the set iterative convergence condition is met. The current segmented optimization sequence is then output as the optimal field sequence. If there is no candidate sequence whose compressed file is smaller than the segmented optimization sequence, then the current segmented optimization sequence is output as the optimal field sequence.
[0049] Based on the optimal field sequence, the fields of the source data are rearranged to optimize the compression effect.
[0050] In one specific embodiment of the present invention, taking five lines of raw data from a DNS log as an example (fields include: request IP, request domain name, time, response return code, response IP, response port, separator "|", including newline characters, occupying a total of 920 bytes):
[0051] 2409:8934:1a12:9247:6535:af08:84b0:dfd6|aaid.amap.com|20230822145622|5|2409:8034:2000:0000:0000:0000:0000:0003|53
[0052] 2409:8934:5b40:1c35:949f:c94d:44f1:6d4b|pull-vol-cn-base.s.volcfcdn dvs.com|20230822145622|0|2409:8034:2000:0000:0000:0000:0000:0003|53
[0053] 112.51.74.232|loc.map.baidu.com|20230822145622|0|211.138.151.161|53
[0054] 223.104.53.61|pull-rtmp-f26.douyincdn.com|20230822145622|0|112.5.230.54|53
[0055] 2409:8a34:4c05:3c4a:285c:9a6e:5fd8:592e|push-rtmp-f5-io.flive.douyi ncdn.com|20230822145622|0|2409:8034:2000:0000:0000:0000:0000:0001|53
[0056] Compression goal: Through field sequence optimization, reduce the size of the above data after gzip compression by more than 20% compared to the original sequence, without significantly reducing the compression / decompression speed.
[0057] Based on the above-mentioned original data and compression target, the non-intrusive log compression optimization method provided by this invention is used for processing. The specific steps are as follows:
[0058] I. Sampling to obtain representative data samples
[0059] To avoid repeatedly compressing and evaluating the full dataset (and reduce computational costs), a "block-level random sampling" strategy is adopted, with the following steps:
[0060] 1.1 Randomly select M files from the source data directory (covering different time periods to ensure sample representativeness).
[0061] 1.2. Divide each selected file into several segments of a fixed size of N lines / block;
[0062] 1.3 Extract the first L lines of each segment as a data block, merge all data blocks to generate a sample file (total sample size is approximately M×N×L=45000, experimental parameters are 3×15×1000=45000 lines, balancing representativeness and computational efficiency).
[0063] The generated sample files have the following characteristics: they retain the field distribution characteristics of the original data (such as "Response Return Code" field being "0" or "5" 90% of the time, and "Response Port" being "53" 95% of the time), and can replace the full data for subsequent sequence optimization.
[0064] The "block-level random sampling" method of this invention selects representative samples from the source data (sampling parameters are configurable: the number of random files is 3 by default, the number of segments per file is 15 by default, and the number of rows per segment is 1000 by default), controlling the sample size to 10,000-100,000 rows, which can balance representativeness and computational efficiency and avoid the high overhead of full data evaluation.
[0065] II. Based on information entropy, quantify field redundancy to generate an initial sequence with preliminary compression friendliness.
[0066] 2.1 Single-column entropy calculation: For each field of the sample file, calculate the entropy value according to the information entropy formula (the lower the entropy value, the more concentrated the field value distribution, and the higher the redundancy):
[0067] H(F x )=−∑ i p i log2p i
[0068] Among them, F x For the target field, m is F x The number of distinct values of p i Let be the probability of the i-th value occurring.
[0069] Taking the example DNS log as an example, the entropy values of each field are calculated as shown in Table 1:
[0070] Table 1
[0071] Fields Request IP Requested domain name time Response return code Response IP Response port Entropy (H) 5.8 7.2 2.1 0.6 4.3 0.3
[0072] 2.2 Initial Field Selection: Select the field with the highest entropy value ("Request Domain Name", H=7.2) as the starting point of the sequence. It should be noted that high-entropy fields are more flexible and easier to combine with low-entropy fields later to eliminate redundancy.
[0073] 2.3 Iterative “Find a Friend”: For the last field of the current sequence, calculate its “joint entropy” with all fields that have not been added (the entropy value after concatenating two fields; the lower the joint entropy, the higher the redundancy of the field combination), and select the field with the smallest joint entropy to add to the sequence until all fields are sorted.
[0074] Example iteration process:
[0075] Initial sequence: [request domain name]
[0076] Calculate the joint entropy of "request domain" and other fields: H(request domain + response port) = 3.1 (minimum) → Update the sequence to [request domain, response port]
[0077] Calculate the joint entropy of "Response Port" and the remaining fields: H(Response Port + Response Code) = 0.8 (minimum) → Update the sequence to [Request Domain, Response Port, Response Code]
[0078] Repeated iterations eventually generate the initial sequence: [request domain name, response port, response code, time, response IP, request IP].
[0079] Generate initial sequence code snippets:
[0080] def FindFirstMaxEntropyColumn(sdf):
[0081] # Calculate the single-column entropy for each field
[0082] colEntroDict = {col: Entropy(sdf[col].tolist()) for col insdf.columns}
[0083] # Choose the field with the highest entropy value as the starting point
[0084] return max(colEntroDict.keys(), key=lambda x: colEntroDict[x])
[0085] def FindFriend(sdf, colIDSeq, colName):
[0086] maxh = sys.maxsize
[0087] nextCol = None
[0088] # Calculate the joint entropy of the current last field and other fields.
[0089] for col in sdf.columns:
[0090] if col in colIDSeq:
[0091] continue
[0092] combined = (sdf[colName] + sdf[col]).tolist() # Concatenate field values
[0093] h = Entropy(combined)
[0094] if h < maxh:
[0095] maxh = h
[0096] nextCol = col
[0097] return nextCol
[0098] This invention uses the single-column entropy and joint entropy of a field to aggregate and arrange low-entropy (high-redundancy) fields, generating an initial sequence with preliminary compression friendliness and reducing the complexity of subsequent searches. The single-column entropy is calculated using the information entropy calculation formula, and the joint entropy is calculated based on the concatenation of field value strings, ensuring that the entropy value can accurately reflect the redundancy of the field.
[0099] III. Grouping Optimization of Initial Sequence
[0100] For the initial sequence, a strategy of "grouping and permutation + parallel evaluation" is adopted to reduce the complexity of the permutation (from n! to ∑|G_i|!, where |G_i| is the group size). The steps are as follows:
[0101] 3.1 Field Grouping: Divide the initial sequence into several groups according to a fixed window size k=3 (configurable). Example: The initial sequence [request domain name, response port, response code, time, response IP, request IP] is divided into 2 groups:
[0102] G1=[request domain name, response port, response return code], G2=[time, response IP, request IP].
[0103] 3.2. Permutations within a group: Generate all possible permutations for each group (the number of permutations for G1 is 3!=6, and the number of permutations for G2 is 3!=6), for a total of 6×6=36 candidate sequences.
[0104] 3.3 Parallel Compression Evaluation: Start CPU_num=7 processes (matching the number of CPU cores, configurable), and perform the following operations for each candidate sequence:
[0105] ① Rearrange the fields of the sample file according to the candidate sequence;
[0106] ② Compress the rearranged sample file using a target compression method (such as gzip);
[0107] ③ Record the size of the compressed file;
[0108] 3.4 Optimization Sequence Selection: Select the candidate sequence with the smallest compressed volume as the "segmented optimized sequence". In the example, the segmented optimized sequence is: [Response Port, Response Return Code, Request Domain Name, Time, Request IP, Response IP] (the compressed sample volume is reduced by 12% compared to the initial sequence).
[0109] Parallel segmented search code snippet:
[0110] def BrutalSearch(sdf, leftList, midList, rightList):
[0111] # Generate all permutations within the group
[0112] perms = permutations(midList)
[0113] # Build task list
[0114] tasks = [(leftList + list(p) + rightList, sdf) for p in perms]
[0115] # Multi-process parallel evaluation
[0116] with concurrent.futures.ProcessPoolExecutor(max_workers=cpu_num)as executor:
[0117] results = executor.map(Work, tasks) # Work: Rearrangement + Compression + Size Calculation
[0118] # Filtering the optimal sequence
[0119] optSize = sys.maxsize
[0120] OptSeq = None
[0121] For size, seq in results:
[0122] if size < optSize:
[0123] optSize = size
[0124] OptSeq = seq
[0125] return (OptSeq, optSize)
[0126] def Work(task):
[0127] seq, sdf = task[0], task[1]
[0128] pid = os.getpid()
[0129] temp_file = f' / tmp / sample_{pid}.csv'
[0130] # Reorder by sequence and save temporary files
[0131] sdf.reindex(columns=seq).to_csv(temp_file, index=False, sep='|')
[0132] # Compress with gzip and calculate size
[0133] gz_file = temp_file + '.gz'
[0134] subprocess.run(f'gzip -n < {temp_file} > {gz_file}', shell=True)
[0135] size = os.path.getsize(gz_file)
[0136] # Clean up temporary files
[0137] os.remove(temp_file)
[0138] os.remove(gz_file)
[0139] return (size, seq)
[0140] This invention groups the field sequence into fixed window sizes, generates full permutations for each group, and evaluates and compresses the volume in parallel, reducing the search complexity from n! to ∑|G_i|! (where |G_i| is the group size, defaulting to 6), controlling computational overhead while ensuring optimization performance; it supports multi-process parallel evaluation, with the number of processes matching the number of CPU cores, thus improving search efficiency.
[0141] IV. Optimize partial insertion and iteratively adjust field positions.
[0142] For the "segmented optimized sequence", a local search using "single field removal-reinsertion" is used to correct cross-group field relevance that the grouping strategy may have missed. The steps are as follows:
[0143] 4.1 Single-field adjustment: For each field in the sequence, temporarily remove it from the sequence and then insert it into all other possible positions (n-1 positions in total, where n is the number of fields), generating n×(n-1) candidate sequences. In the example, n=6, generating 6×5=30 candidate sequences.
[0144] 4.2 Compression Evaluation and Iteration: For each candidate sequence, evaluate the compression volume using sample files. If a better sequence (smaller compression volume) exists, update the sequence and repeat step 4.1. If no better sequence is found after 15 iterations of search_round_limit (configurable), or if there is no change after 3 consecutive iterations, stop the search and generate the "final optimal field sequence".
[0145] 4.3 Convergence Verification: In the example, after 5 iterations, the final optimal field sequence is generated: [Response Port, Response Return Code, Time, Request Domain Name, Response IP, Request IP] (the compressed sample volume is reduced by 8% compared to the segmented optimized sequence).
[0146] Local insertion optimization code snippet:
[0147] def BrutalSearch_Phase2(sdf, colIDSeq, ntry, optSize):
[0148] global candidates
[0149] # The iteration depth has reached the upper limit; return the current sequence.
[0150] if ntry >= search_round_limit:
[0151] return colIDSeq
[0152] tasks = []
[0153] # Generate "remove-reinsert" candidate sequences
[0154] for i in range(len(colIDSeq)):
[0155] field = colIDSeq[i]
[0156] seq = copy.deepcopy(colIDSeq)
[0157] seq.remove(field)
[0158] for j in range(len(seq) + 1):
[0159] tempSeq = copy.deepcopy(seq)
[0160] tempSeq.insert(j, field)
[0161] # Avoid duplicate evaluations
[0162] if tuple(tempSeq) not in candidates:
[0163] candidates[tuple(tempSeq)] = 0
[0164] tasks.append((tempSeq, sdf))
[0165] # Parallel evaluation of candidate sequences
[0166] OptSeq = None
[0167] with concurrent.futures.ProcessPoolExecutor(max_workers=cpu_num)as executor:
[0168] results = executor.map(Work, tasks)
[0169] For size, seq in results:
[0170] if size < optSize:
[0171] optSize = size
[0172] OptSeq = seq
[0173] # Continue iterating if a better sequence exists.
[0174] if OptSeq:
[0175] print(f"Iterated {ntry} times: The optimal sequence is updated to {OptSeq}, and the compressed size is {optSize} bytes")
[0176] return BrutalSearch_Phase2(sdf, OptSeq, ntry + 1, optSize)
[0177] # No better sequence found, stop iteration
[0178] print("No better sequence found, search terminated")
[0179] return colIDSeq
[0180] Based on the segmented optimization sequence, this invention performs a local search of "removing and re-inserting all possible positions" for each field, iteratively updating the optimal sequence until convergence (the iteration depth is configurable, with a default of 15 times); the convergence condition includes "upper limit of iterations" or "no better sequence for 3 consecutive iterations", avoiding invalid calculations.
[0181] V. Parallel rewriting: All data is rearranged according to the optimal field sequence.
[0182] Rewrite all structured data in the source directory according to the "final optimal field sequence" as follows:
[0183] 5.1 Directory Initialization: Create a subdirectory named according to "random seed - compression method" (e.g., ". / dst / 0 / gzip") in the target directory to avoid file overwriting.
[0184] 5.2 Multi-process rewriting: Start CPU_num=7 processes, each process reads a source file, rearranges the fields according to the final optimal sequence (in the example, the original sequence [request IP, request domain name, time, response code, response IP, response port] is rearranged to [response port, response code, time, request domain name, response IP, request IP]), generates a new file and saves it to the target subdirectory.
[0185] 5.3 Integrity Verification: After the rewrite is completed, compare the total number of lines and the total number of field values in the source file and the new file to ensure that no data is lost or tampered with.
[0186] Example of rewritten data (corresponding to the original 5 lines of DNS log):
[0187] 53|5|20230822145622|aaid.amap.com|2409:8034:2000:0000:0000:0000:0000:0003|2409:8934:1a12:9247:6535:af08:84b0:dfd6
[0188] 53|0|20230822145622|pull-vol-cn-base.s.volcfcdndvs.com|2409:8034:20 00:0000:0000:0000:0000:0003|2409:8934:5b40:1c35:949f:c94d:44f1:6d4b
[0189] 53|0|20230822145622|loc.map.baidu.com|211.138.151.161|112.51.74.232
[0190] 53|0|20230822145622|pull-rtmp-f26.douyincdn.com|112.5.230.54|223.104.53.61
[0191] 53|0|20230822145622|push-rtmp-f5-io.flive.douyincdn.com|2409:8034:2 000:0000:0000:0000:0000:0001|2409:8a34:4c05:3c4a:285c:9a6e:5fd8:592e
[0192] This invention improves compression performance through a "field rearrangement" preprocessing step without modifying existing compression / decompression processes. It is compatible with common compression algorithms such as gzip, bzip2, and lzma, as well as advanced compression algorithms such as Denum. The compression volume assessment is based on the actual compression results of the target compressor, ensuring that the optimized sequence is compatible with specific compression algorithms.
[0193] Further verification of the compression effect: The rewritten 5 lines of data (including newline characters) occupied 880 bytes, and the size after gzip compression was 182 bytes; while the original sequence was compressed to 236 bytes. The compression ratio increased from 4.0:1 to 4.8:1, the size was reduced by 23%, and the compression speed increased from 53.7MB / s to 55.5MB / s, and the decompression speed increased from 310.5MB / s to 315.7MB / s.
[0194] Experimental results on five datasets (NetFlow, DNS, Firewall, IoTSec, and IDS) show that when the compression optimization method of this invention is combined with gzip, the compression speed is improved by 0%-27% and the decompression speed is improved by 0%-19%; when combined with bzip2, although the compression speed may decrease by 0%-24%, the compression ratio is improved by 3%-16%; when combined with lzma, the compression speed is basically the same (±3%), and the decompression speed is improved by 0%-19%, demonstrating the advantage of the method in balancing compression and speed.
[0195] In summary, compared with existing technologies (general compression algorithms, advanced compression techniques), the compression optimization method of this invention can achieve the following effects:
[0196] (1) Significantly improved compression efficiency: By “entropy-driven aggregation of redundancy + hierarchical search for optimal sequence”, the compression ratio is improved by 4%-32% when combined with the original sequence (without optimization) and general compression algorithms (e.g., when NetFlow logs are compressed with lzma, the compression ratio is improved from 13.54 to 17.86); when combined with more advanced compression technologies (e.g. Denum), the compression ratio is further improved by 6%-20%, and there is no need to modify the encoding rules of Denum, making it more compatible.
[0197] (2) Low deployment cost and strong compatibility: No need to modify the existing compression / decompression process, only need to add the "field rearrangement" step before writing data to storage, and it can be directly integrated into the existing data processing pipeline; it is compatible with various structured data such as network logs, CSV tables, and JSON flattened data, and solves the problem of insufficient universality of advanced compression technologies (such as Logzip and Denum).
[0198] (3) Controllable computational overhead and high efficiency: The computational complexity is reduced by “sampling evaluation + group search”. For example, the search complexity of 12 fields is reduced from 12! (479001600) to 6!+6! (720+720=1440), and the computational overhead is reduced by 99.9997%. It supports multi-process parallel processing, and the time for sequence optimization of 100GB of data can be controlled within 30 minutes, which meets the needs of large-scale data processing.
[0199] (4) Flexible balance between compression and speed: Supports configuration of core parameters (such as group size and iteration depth) to achieve flexible adjustment of "compression ratio - compression speed" - for example, in real-time transmission scenarios, the iteration depth can be reduced (k=5) and the compression speed can be increased by 27%; in archive storage scenarios, the iteration depth can be increased (k=15) and the compression ratio can be increased by 32%, adapting to different scenario requirements.
[0200] (5) Lightweight data protection capability: Although the optimized field sequence is not directly encrypted, the field arrangement order and data characteristics (such as low-entropy field distribution) are specific to the system. If a third party obtains the rearranged data, it will be difficult to quickly understand the data structure without the corresponding sequence information, which indirectly plays the role of data obfuscation and log protection.
[0201] It should be noted that the compression optimization method of this invention is not only applicable to network logs, but can also be adapted to structured data such as CSV tables (e.g., e-commerce order data, with fields including "order ID, user ID, product category, order time, payment amount") and JSON flattened data (e.g., API interface return data, with flattened fields including "code, msg, data.user.id, data.user.name"). Only the sampling parameters (e.g., the delimiter, default ",", can be configured to "|", "\t", etc.) need to be adjusted for adaptation. Recommended parameter configurations for different data types are as follows:
[0202] (1) Network logs (number of fields 10-20): group size k=6, iteration depth k=15, number of sampled files S_nf=3;
[0203] (2) CSV table (5-10 fields): group size k=4, iteration depth k=10, number of sampled files S_nf=2;
[0204] (3) JSON flattened data (number of fields 20-50): group size k=8, iteration depth k=20, number of sampled files S_nf=4.
[0205] In a second embodiment of the present invention, the present invention provides a non-intrusive log compression optimization system, such as... Figure 2As shown, the system includes a sampling module, an initial sequence generation module, a segmentation optimization module, and a field rearrangement module;
[0206] The sampling module is used to randomly select several files from the source data based on the configured sampling parameters, divide each file into several segments, extract the first few lines of each segment as data blocks, and merge all the extracted data blocks to form a sample file.
[0207] The initial sequence generation module is used to quantify the field redundancy of sample files based on information entropy and generate an initial sequence with preliminary compression friendliness.
[0208] The segmentation optimization module is used to divide the initial sequence into several groups according to a set window size, and perform full permutation within each group to generate several candidate sequences; based on each candidate sequence, the sample file is rearranged in terms of fields, and the rearranged sample file is compressed, and the candidate sequence corresponding to the smallest compressed file is selected as the segmentation optimization sequence;
[0209] The field rearrangement module is used to rearrange the fields of the source data based on the segmented optimization sequence in order to optimize the compression effect.
[0210] Furthermore, the system also includes a local insertion optimization module;
[0211] The local insertion optimization module is used to temporarily remove each field from the segmented optimization sequence and insert it into all other possible positions to generate several candidate sequences. Based on each candidate sequence, the fields of the sample file are rearranged, and the rearranged sample file is compressed. If there is a candidate sequence whose compressed file is smaller than the segmented optimization sequence, then the candidate sequence is used as the new segmented optimization sequence, and the process returns to the previous step until the set iterative convergence condition is met. The current segmented optimization sequence is then output as the optimal field sequence. If there is no candidate sequence whose compressed file is smaller than the segmented optimization sequence, then the current segmented optimization sequence is output as the optimal field sequence.
[0212] The field rearrangement module is used to rearrange the fields of the source data based on the optimal field sequence in order to optimize the compression effect.
[0213] In a third embodiment of the present invention, the present invention provides an electronic device, including a memory and a processor, characterized in that the memory stores a computer program that can run on the processor, and when the program is executed on the processor, it implements the steps in the non-intrusive log compression optimization method described above.
[0214] In a fourth embodiment of the present invention, the present invention provides a storage medium storing a computer program, characterized in that the computer program, when executed by a processor, implements the steps in the non-intrusive log compression optimization method described above.
[0215] In summary, this invention provides a non-intrusive log compression optimization method and system. Its core process is "sampling representative data → entropy-driven initial sequence generation → hierarchical search for the optimal sequence → parallel data rewriting." It automatically generates field sequences compatible with existing compression algorithms, improving compression efficiency without altering the existing compression process. This invention is compatible with various structured data types, including network logs (DNS logs, NetFlow logs, firewall logs, IDS logs), CSV table data, and flattened JSON data. By automatically generating the optimal field sequence, it improves the compression efficiency of general compression algorithms such as gzip, bzip2, and lzma, as well as advanced compression algorithms such as Denum, reducing the storage cost and transmission bandwidth consumption of structured data. It is suitable for scenarios requiring large-scale storage or transmission of structured data, such as network operations and maintenance, security detection, log archiving, and data warehouse management, and can solve the problem of limited compression efficiency in existing general compression algorithms due to their failure to utilize the structured characteristics of data.
[0216] Those skilled in the art will understand that, for the sake of convenience and brevity, the specific working process of the modules described above can be referred to the corresponding process in the aforementioned method implementation, and will not be repeated here.
[0217] The modules described as separate components may or may not be physically separate. Similarly, the components shown as modules may or may not be physical modules; they may be located in one place or distributed across multiple network modules. Some or all of the modules can be selected to achieve the purpose of this embodiment, depending on actual needs.
[0218] Furthermore, the functional modules in the various embodiments of this application can be integrated into one processing module, or each module can exist physically separately, or two or more modules can be integrated into one module. The integrated module can be implemented in hardware or in a combination of hardware and software functional modules.
[0219] The integrated modules implemented as software functional modules described above can be stored in a computer-readable storage medium. These software functional modules, stored in a storage medium, include several instructions to cause a computer system (which may be a personal computer, server, or network system, etc.) or processor to execute some steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0220] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application.
Claims
1. A non-intrusive log compression optimization method, characterized in that: include, Based on the configured sampling parameters, several files are randomly selected from the source data, and each file is divided into several segments. The first few lines of each segment are extracted as data blocks, and all extracted data blocks are merged to form a sample file. Based on information entropy, the field redundancy of the sample file is quantified to generate an initial sequence with preliminary compression friendliness; The initial sequence is divided into several groups according to a set window size, and a full permutation is performed within each group to generate several candidate sequences; Based on each candidate sequence, the fields of the sample file are rearranged, and the rearranged sample file is compressed. The candidate sequence corresponding to the smallest compressed file is selected as the segmentation optimization sequence. For the segmented optimization sequence, each field is temporarily removed and then inserted into all other possible positions to generate several candidate sequences; For each candidate sequence, the sample file is rearranged by field, and the rearranged sample file is compressed. If there is a candidate sequence whose compressed file is smaller than the segmented optimization sequence, then the candidate sequence is used as the new segmented optimization sequence, and the process returns to the previous step until the set iterative convergence condition is met. The current segmented optimization sequence is then output as the optimal field sequence. If there is no candidate sequence whose compressed file is smaller than the segmented optimization sequence, then the current segmented optimization sequence is output as the optimal field sequence. Based on the optimal field sequence, the source data is rearranged to optimize the compression effect; The step of quantifying the field redundancy of sample files based on information entropy to generate an initial sequence with preliminary compression friendliness includes, For each field in the sample file, calculate the corresponding entropy value according to the information entropy formula; Select the field with the largest entropy value as the starting point of the initial sequence; For the last field of the current initial sequence, calculate its joint entropy with all fields that have not been added to the initial sequence, and select the field with the smallest joint entropy to add to the initial sequence, until all fields have been added.
2. The method according to claim 1, characterized in that: The configuration of the sampling parameters includes, The number of randomly selected files, the number of segments in each file, and the number of lines extracted from each segment.
3. The method according to claim 1, characterized in that: The joint entropy is the entropy value obtained by concatenating the two fields.
4. A non-intrusive log compression optimization system, using the method as described in any one of claims 1 to 3, characterized in that: It includes a sampling module, an initial sequence generation module, a segmentation optimization module, a local insertion optimization module, and a field rearrangement module; The sampling module is used to randomly select several files from the source data based on the configured sampling parameters, divide each file into several segments, extract the first few lines of each segment as data blocks, and merge all the extracted data blocks to form a sample file. The initial sequence generation module is used to quantify the field redundancy of sample files based on information entropy and generate an initial sequence with preliminary compression friendliness. The segmentation optimization module is used to divide the initial sequence into several groups according to a set window size, and perform full permutation within each group to generate several candidate sequences; based on each candidate sequence, the sample file is rearranged in terms of fields, and the rearranged sample file is compressed, and the candidate sequence corresponding to the smallest compressed file is selected as the segmentation optimization sequence; The local insertion optimization module is used to temporarily remove each field from the segmented optimization sequence and insert it into all other possible positions to generate several candidate sequences. Based on each candidate sequence, the fields of the sample file are rearranged, and the rearranged sample file is compressed. If there is a candidate sequence whose compressed file is smaller than the segmented optimization sequence, then the candidate sequence is used as the new segmented optimization sequence, and the process returns to the previous step until the set iterative convergence condition is met. The current segmented optimization sequence is then output as the optimal field sequence. If there is no candidate sequence whose compressed file is smaller than the segmented optimization sequence, then the current segmented optimization sequence is output as the optimal field sequence. The field rearrangement module is used to rearrange the fields of the source data based on the optimal field sequence in order to optimize the compression effect.
5. An electronic device, comprising a memory and a processor, characterized in that: The memory stores a computer program that can run on the processor, and when the program is executed on the processor, it implements the steps of the method as described in any one of claims 1-3.
6. A storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, it implements the steps of the method as described in any one of claims 1-3.
Citation Information
Patent Citations
Methods, systems, and media for network model inspection using entropy-based BDD compression
CN115867898A
Compressing massive relational data
US20110153623A1
