Data processing method, device, equipment and storage medium
Through file cutting and dynamic memory allocation technology, the problem of memory overflow and excessive time-consuming in processing extremely large financial files is solved, the processing efficiency is improved, exceptions are reduced, and efficient file processing is achieved.
Patent Information
- Application Number
- CN202311770974.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-20
- Publication Date
- 2024-09-06
- Estimated Expiration
- 2043-12-20
AI Technical Summary
Existing technologies can easily cause memory overflow or take too long when processing extremely large financial files, affecting the normal development of online business.
Determine the file cutting strategy by obtaining file information, cut the file into sub-files, and parse according to the memory blocks of the sub-files to avoid directly loading large files for processing, and dynamically adjust memory allocation to improve processing efficiency.
It effectively avoids memory overflow and excessive time-consuming, improves file processing efficiency, solves slow or abnormal communication caused by network bandwidth and machine memory limitations, and reduces time-consuming business processing.
Smart Images

Figure CN117762873B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a data processing method, device, equipment and storage medium. Background Art
[0002] With the rapid development of consumer finance business, the analysis and storage of super-large accounting files or data reconciliation often need to consider the bottleneck problems of program deployment server performance and memory usage. Directly loading a single file into memory to process the scene is likely to cause memory overflow or take too long, thus affecting the normal online business. Therefore, how to handle super-large financial files has become a technical problem that needs to be solved urgently. Summary of the invention
[0003] The main purpose of the present invention is to provide a data processing method, device, equipment and storage medium, aiming to solve the technical problem that memory overflow is easily caused when processing large files in the prior art.
[0004] To achieve the above object, the present invention provides a data processing method, which comprises the following steps:
[0005] Acquire file information of a file to be processed, and determine a file cutting strategy for the file to be processed according to the file information;
[0006] Perform file segmentation on the to-be-processed file based on the file segmentation strategy to obtain a target sub-file after segmentation;
[0007] Parsing the target sub-file according to the target memory block corresponding to the target sub-file to obtain a parsing result;
[0008] A file processing result of the file to be processed is determined according to the parsing result.
[0009] Optionally, the step of performing file segmentation on the to-be-processed file based on the file segmentation strategy to obtain a target sub-file after segmentation includes:
[0010] When the file cutting strategy is to cut according to the file size, determining the file size of the to-be-processed file according to the file information;
[0011] Get the preset file standard size;
[0012] Determine the number of files of the target sub-file according to the file size and the preset file standard size;
[0013] Determine the target file size of the target sub-file according to the number of files and the file size;
[0014] The file to be processed is split according to the target file size to obtain the split target sub-files.
[0015] Optionally, the step of performing file segmentation on the to-be-processed file based on the file segmentation strategy to obtain a target sub-file after segmentation includes:
[0016] When the file cutting strategy is to cut according to the file line number, the number of file lines of the to-be-processed file is determined according to the file information;
[0017] Get the preset number of sub-files;
[0018] Determine the target file line number of the target sub-file according to the preset sub-file number and the file line number;
[0019] Determine the starting line number and the ending line number of the target subfile according to the number of lines of the target file, the preset number of subfiles and the number of lines of the file to be processed;
[0020] The target subfile is determined according to the starting line number and the ending line number.
[0021] Optionally, the step of obtaining file information of the file to be processed and determining a file cutting strategy for the file to be processed according to the file information includes:
[0022] Get the file information of the file to be processed;
[0023] Determine the file size of the file to be processed according to the file information;
[0024] When the file size is greater than a preset file cutting threshold, the file cutting strategy of the to-be-processed file is to cut according to the file size;
[0025] When the file size is less than or equal to the preset file cutting threshold, the file cutting strategy of the to-be-processed file is to cut according to the file line number.
[0026] Optionally, before the step of parsing the target sub-file according to the target memory block corresponding to the target sub-file, the step further includes:
[0027] Determine the memory size required for processing the file to be processed according to the file information;
[0028] Obtain the number of files of the target sub-file;
[0029] Determine the target memory size required for processing the target subfile according to the memory size and the number of files;
[0030] A target memory block corresponding to the target sub-file is determined and processed according to the target memory size.
[0031] Optionally, the target memory size determines the step of processing the target memory block corresponding to the target sub-file, including:
[0032] Sort the currently available memory blocks and obtain the sorting results;
[0033] A target memory block corresponding to the target sub-file is selected and processed from the sorting result according to the target memory size.
[0034] Optionally, before the step of sorting the currently available memory blocks to obtain the sorting result, the step further includes:
[0035] Get the current running status information;
[0036] Inputting the current running state information into a preset memory prediction algorithm to obtain current available memory and memory demand predicted by the preset memory prediction algorithm;
[0037] Memory is allocated according to the currently available memory and the memory requirement to obtain a currently available memory block.
[0038] In addition, to achieve the above object, the present invention further provides a data processing device, the device comprising:
[0039] An acquisition module, used for acquiring file information of a file to be processed, and determining a file cutting strategy of the file to be processed according to the file information;
[0040] A cutting module, used for cutting the file to be processed based on the file cutting strategy to obtain a target sub-file after cutting;
[0041] A parsing module, used for parsing the target sub-file according to the target memory block of the target sub-file to obtain a parsing result;
[0042] The processing result generating module is used to determine the file processing result of the file to be processed according to the parsing result.
[0043] In addition, to achieve the above-mentioned purpose, the present invention also proposes a data processing device, which includes: a memory, a processor, and a data processing program stored in the memory and executable on the processor, wherein the data processing program is configured to implement the steps of the data processing method described above.
[0044] In addition, to achieve the above-mentioned purpose, the present invention further proposes a storage medium, on which a data processing program is stored, and when the data processing program is executed by a processor, the steps of the data processing method described above are implemented.
[0045] The present invention obtains file information of a file to be processed, determines a file cutting strategy for the file to be processed according to the file information; performs file cutting on the file to be processed based on the file cutting strategy to obtain a target sub-file after cutting; performs file parsing on the target sub-file according to a target memory block corresponding to the target sub-file to obtain a parsing result; and determines a file processing result for the file to be processed according to the parsing result. Compared with the existing method of directly performing memory allocation post-processing on files, the above method of the present invention can split files for post-processing, avoid memory overflow or excessive time consumption caused by directly loading file processing scenarios, improve file processing efficiency, solve slow or even abnormal communication caused by network bandwidth limitations and machine memory limitations, and reduce the time consumption for processing services. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] Figure 1 It is a structural diagram of a data processing device in a hardware operating environment involved in an embodiment of the present invention;
[0047] Figure 2 It is a flowchart of a first embodiment of a data processing method of the present invention;
[0048] Figure 3 It is a flowchart of a second embodiment of a data processing method of the present invention;
[0049] Figure 4 It is a flowchart of a third embodiment of a data processing method of the present invention;
[0050] Figure 5 It is a logic flow chart of intelligent memory allocation of the third embodiment of the data processing method of the present invention;
[0051] Figure 6 It is a structural block diagram of the first embodiment of the data processing device of the present invention.
[0052] The realization of the purpose, functional features and advantages of the present invention will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0053] It should be understood that the specific embodiments described herein are only used to explain the present invention, and are not used to limit the present invention.
[0054] Reference Figure 1 , Figure 1 The present invention is a schematic diagram of the data processing device structure of the hardware operating environment involved in the embodiment of the present invention.
[0055] like Figure 1As shown, the data processing device may include: a processor 1001, such as a central processing unit (CPU), a communication bus 1002, a user interface 1003, a network interface 1004, and a memory 1005. Among them, the communication bus 1002 is used to realize the connection and communication between these components. The user interface 1003 may include a display screen (Display), an input unit such as a keyboard (Keyb oard), and the optional user interface 1003 may also include a standard wired interface and a wireless interface. The network interface 1004 may optionally include a standard wired interface and a wireless interface (such as a wireless fidelity (Wireless-Fid elity, WI-FI) interface). The memory 1005 may be a high-speed random access memory (Random Access Memory, RAM), or a stable non-volatile memory (Non-Volatile Me mory, NVM), such as a disk memory. The memory 1005 may also be a storage device independent of the aforementioned processor 1001.
[0056] Those skilled in the art will understand that Figure 1 The structure shown in the figure does not constitute a limitation on the data processing device, and may include more or less components than shown in the figure, or combine some components, or arrange the components differently.
[0057] like Figure 1 As shown, the memory 1005 as a storage medium may include an operating system, a network communication module, a user interface module, and a data processing program.
[0058] exist Figure 1 In the data processing device shown, the network interface 1004 is mainly used for data communication with the network server; the user interface 1003 is mainly used for data interaction with the user; the processor 1001 and the memory 1005 in the data processing device of the present invention can be set in the data processing device, and the data processing device calls the data processing program stored in the memory 1005 through the processor 1001, and executes the data processing method provided by the embodiment of the present invention.
[0059] Based on the above data processing device, an embodiment of the present invention provides a data processing method, referring to Figure 2 , Figure 2 FIG. 1 is a flow chart of a first embodiment of a data processing method according to the present invention.
[0060] In this embodiment, the data processing method includes the following steps:
[0061] Step S10: Obtain file information of the file to be processed, and determine a file cutting strategy for the file to be processed according to the file information.
[0062] It should be noted that the execution subject of this embodiment can be a computing service device with data processing, network communication and program running functions, such as a mobile phone, a tablet computer, a personal computer, etc., or an electronic device or data processing device that can realize the above functions. The following takes the data processing device as an example to illustrate this embodiment and the following embodiments.
[0063] It should be noted that the file information may include relevant information such as the file type, file size, and number of file lines of the file to be processed. The file to be processed may be an accounting file, a database backup or recovery file, an image or video file, a log file, etc. The file cutting strategy for determining the file to be processed based on the file information may be to determine the number of file cuts based on the file size in the file information, that is, to cut the file to be processed into several sub-files, or to determine whether to cut the file to be processed according to the number of lines of the file to be processed or according to the file size of the file to be processed based on the file size in the file information. Specifically, when the file size of the file to be processed is greater than a preset file size threshold, the file cutting strategy is determined to be cutting according to the file size; when the file size of the file to be processed is less than or equal to the preset file size threshold, the file cutting strategy is determined to be cutting according to the number of lines of the file. Wherein, the preset file size threshold is a pre-set file size. When the file to be processed is large, if the file is split by the number of lines, it is necessary to read the file first to obtain the number of lines of the file to be processed. At this time, since the file to be processed is large, the operation of determining the number of lines of the file to be processed will occupy a large amount of resources. Therefore, when the file size of the file to be processed is greater than the preset file size threshold, the file splitting strategy is determined to be split according to the file size, so there is no need to determine the number of lines of the file to be processed, thereby reducing resource usage.
[0064] Furthermore, in order to improve the efficiency of cutting the file, the step S10 may include: obtaining file information of the file to be processed;
[0065] Determine the file size of the file to be processed according to the file information;
[0066] When the file size is greater than a preset file cutting threshold, the file cutting strategy of the to-be-processed file is to cut according to the file size;
[0067] When the file size is less than or equal to the preset file cutting threshold, the file cutting strategy of the to-be-processed file is to cut according to the file line number.
[0068] It should be noted that the preset file cutting threshold may be a preset file size threshold, which is used to determine the file cutting strategy. In order to ensure the continuity of the data, that is, each piece of data is complete, when the file size is less than or equal to the preset file cutting threshold, the file cutting strategy of the to-be-processed file is to cut according to the file line number. When the file size is greater than the preset file cutting threshold, since cutting according to the file line number requires pre-calculating the line number of the to-be-processed file, when the file size is large, calculating the line number will occupy resources. Therefore, when the file size is greater than the preset file cutting threshold, the file cutting strategy of the to-be-processed file is to cut according to the file size.
[0069] Step S20: performing file segmentation on the to-be-processed file based on the file segmentation strategy to obtain target sub-files after segmentation.
[0070] It should be noted that the file to be processed is cut based on the file cutting strategy to obtain the target sub-file after cutting. The number of file cuts can be determined according to the file cutting strategy, and the file to be processed is cut according to the number of file cuts to obtain the target sub-file after cutting.
[0071] Further, in order to improve the efficiency of file cutting, the step S20 may include: when the file cutting strategy is to cut according to the file size, determining the file size of the to-be-processed file according to the file information;
[0072] Get the preset file standard size;
[0073] Determine the number of files of the target sub-file according to the file size and the preset file standard size;
[0074] Determine the target file size of the target sub-file according to the number of files and the file size;
[0075] The file to be processed is split according to the target file size to obtain the split target sub-files.
[0076] It should be noted that the file size of the file to be processed may be the byte size of the file to be processed. The preset file standard size may be the file size of a preset target sub-file. For example: the default is 200M for one sub-file. The file number of the target sub-file determined according to the file size and the preset file standard size may be obtained by dividing the preset file standard size by the file size and rounding up to obtain the file number of the target sub-file. The target file size of the target sub-file determined according to the file number and the file size may be obtained by dividing the file number by the file size to obtain the average file size of the target sub-file, that is, the target file size. The file segmentation of the file to be processed according to the target file size to obtain the target sub-file after segmentation may be performed according to the target file size, and the byte output sub-file of the target file size is taken from the front to the back in the file to be processed according to the target file size, and the file number of the target sub-file is taken out cyclically to obtain the target sub-file after segmentation. In order to ensure the continuity of data, when the to-be-processed file is cut according to the target file size and the target sub-file after cutting is obtained, the bytes of the given number of bytes of the target file are taken backward according to the target file size to output the sub-file, and the file is cut according to the number of files. That is, when the sub-file is cut from the to-be-processed file according to the target file size, the number of bytes of the target file size is not strictly taken as the sub-file according to the target file size, but when the to-be-processed file is cut according to the target file size, the number of rows occupied by the data of the target file size in the to-be-processed file is determined, and the to-be-processed file is cut by row to ensure the continuity of data. For example, if the target file size is 200M, when the to-be-processed file is cut, the 200M byte is in the middle of the 23rd row, the target sub-file is not generated strictly according to the 200M byte size, but the 0-22 rows of data are randomly taken as the first target sub-file, or the 0-23 rows of data are taken as the first target sub-file. For the last target sub-file, the remaining data in the to-be-processed file is directly cut into the last target sub-file.
[0077] In the specific implementation, the files to be processed are cut according to their total fileSize size, and the number of files num is calculated by rounding up the remainder of fileSize divided by the standard size 200M, and then the average number of bytes avgSize of each sub-file is calculated according to fileSize / num. Then, based on the average number of bytes avgSize, the given number of bytes per line is taken to output the sub-file, and the file number is looped to cut the files.
[0078] Step S30: parsing the target sub-file according to the target memory block corresponding to the target sub-file to obtain a parsing result.
[0079] It should be noted that the target memory block may be a memory block used to parse the target sub-file. The memory block required to parse the target sub-file may be determined according to the size of the target sub-file, and then a minimum memory block larger than the memory block may be selected as the target memory block. The target sub-file may be parsed according to the target memory block corresponding to the target sub-file to obtain the parsing result, which may be obtained by loading the target sub-file into the target memory block and parsing the target sub-file.
[0080] Furthermore, in order to solve the slow or even abnormal communication caused by network bandwidth limitation and machine memory limitation and reduce the time consumption of processing business, the target memory block corresponding to the target sub-file can be determined by dynamic memory allocation. Specifically, the step of dynamically allocating the corresponding target memory block to the target sub-file can be:
[0081] 1. Collect data: Use 10G files and 5G sample files to use JMX monitoring tools to collect various performance indicator data of JVM runtime, namely target indicators, including CPU usage, memory usage, and garbage collection time. The daily average value of 30 days of operation is used as the collected data;
[0082] 2. Determine the target indicator: Use the business response time requirement and operating performance as a range to guide the target value of JVM configuration. Specifically, control the CPU usage within a certain range, control the memory usage within the death threshold of the machine alarm, and reduce the garbage collection time.
[0083] 3. Build a model: Based on the sample data and target indicators collected in step 1, build a mathematical model to describe the relationship between JVM configuration parameters and file component operation performance indicators. Use regression analysis machine learning algorithm to build the model. Y = β0 + β1X1 + β2X2 + ... + βnXn, where Y represents the performance indicator, X1, X2, ..., Xn represent JVM configuration parameters, and β0, β1, β2, ... βn represent regression coefficients.
[0084] 4. Training model: Use historical data to train the model, and adjust the model parameters through optimization algorithms so that the model can accurately predict the relationship between JVM configuration parameters and performance indicators. Collect 20 days of daily average data, substitute the values of JVM configuration parameters and performance indicators into the formula, and use the least squares method to estimate the regression coefficient. By solving the regression coefficient, the relationship between JVM configuration parameters and performance indicators can be obtained.
[0085] 5. Verify the model: The remaining 10-day daily average values are used as a test set to verify the accuracy of the model. Compare the model prediction results with the actual performance indicator data to evaluate the model's predictive ability.
[0086] 6. Application model: Apply the trained model to the actual JVM environment, and predict the optimal JVM configuration parameters based on the performance indicator data collected in real time. The JVM configuration parameters may include the number of threads and the dynamically allocated memory size corresponding to each thread. The number of threads may be equal to the number of target sub-files.
[0087] 7. Automatic adjustment: Automatically adjust the JVM configuration parameters according to the optimal JVM configuration parameters predicted by the model to achieve the optimal performance indicators. Modify the heap memory size, new generation size, and permanent generation size through the Java Management Extensions (JMX) interface.
[0088] 8. The program calls the startup application shell script to automatically and gracefully restart the application after JVM adjustment.
[0089] 9. Monitoring effect: After restarting, continue to monitor the usage of system resources to determine whether the expected effect has been achieved. If resource usage still exceeds the threshold, you can continue to adjust the JVM configuration and restart the JVM.
[0090] The program implementation may include the following steps: importing the JVMAutOModel model class, creating a model instance, defining the input data class InputData (i.e., the target sub-file information to be predicted) according to the model requirements, and using the obtained JVM configuration parameters to start the application (i.e., the data processing device); OutputData out putData = model.predict(inputData); / / Call the model method to make predictions; Extract new JVM configuration parameters from the output StringjvmConfigParam = outputData.getJvmConfigParam(); / / Get JVM configuration parameters according to the model output definition; ProcessBuilder processBuilder.start(); / / Start the application using the new JVM configuration parameters.
[0091] This embodiment includes dynamically adjusting memory and standardizing the process of splitting and parsing large files. It can process files after cutting, avoid directly loading file processing scenarios that cause memory overflow or excessive time consumption, improve file processing efficiency, solve network bandwidth limitations, slow communication or even abnormal situations caused by machine memory limitations, and reduce business processing time.
[0092] In a specific implementation, the above-mentioned method of this embodiment can be encapsulated as a component. The business end can call the component through a hook function. The component can be used to intelligently cut the files to be processed, and the number of threads allocated by the thread pool can be dynamically adjusted by real-time monitoring of the machine memory size to perform multi-threaded cutting and distributed parsing. The optimal JVM memory information configuration parameters can then be dynamically calculated to implement the cutting and parsing tasks performed by running the component.
[0093] Step S40: determining a file processing result of the file to be processed according to the analysis result.
[0094] It should be noted that determining the file processing result of the to-be-processed file according to the parsing result may be determining the parsing results of each target sub-file corresponding to the to-be-processed file, and generating the file processing result of the to-be-processed file according to the parsing results of each target sub-file.
[0095] This embodiment obtains the file information of the file to be processed, determines the file cutting strategy of the file to be processed according to the file information; performs file cutting on the file to be processed based on the file cutting strategy to obtain the target sub-file after cutting; performs file parsing on the target sub-file according to the target memory block corresponding to the target sub-file to obtain the parsing result; determines the file processing result of the file to be processed according to the parsing result. Compared with the existing method of directly performing memory allocation post-processing on the file, the above method of this embodiment can split the file for post-processing, avoid memory overflow or excessive time consumption caused by direct loading of file processing scenarios, improve file processing efficiency, solve the slow or even abnormal communication caused by network bandwidth limitations and machine memory limitations, and reduce the time consumption of processing business.
[0096] refer to Figure 3 , Figure 3 FIG. 4 is a flow chart of a second embodiment of a data processing method according to the present invention.
[0097] Based on the above first embodiment, in this embodiment, step S20 includes:
[0098] Step S201: when the file segmentation strategy is segmentation according to file line numbers, the number of file lines of the to-be-processed file is determined according to the file information.
[0099] It should be noted that determining the number of file lines of the to-be-processed file according to the file information may be calculating the total number of lines of the to-be-processed file.
[0100] Step S202: Obtain the preset number of sub-files.
[0101] It should be noted that the preset number of sub-files may be the preset number of sub-files to be cut when the file to be processed is cut. For example, it is preset to cut the file to be processed into 10 sub-files for processing. In order to improve the efficiency of file processing, the preset number of sub-files may also be set to be determined according to the file size of the file to be processed. For example, when the file size is less than the preset first threshold, the preset number of sub-files is A, when the file size is greater than or equal to the preset first threshold and less than the preset second threshold, the preset number of sub-files is B, and when the file size is greater than or equal to the preset second threshold, the preset number of sub-files is C, wherein the preset first threshold, the preset second threshold A, B and C may all be preset values.
[0102] Step S203: determining the target file line number of the target sub-file according to the preset sub-file number and the file line number.
[0103] It should be noted that the target file line number of the target sub-file determined according to the preset sub-file number and the file line number may be obtained by dividing the preset sub-file number by the file line number and rounding up. The target file line number may be the file line number of the to-be-processed file contained in the target sub-file. For example, when the target file line number is 10, each target sub-file contains 10 lines of data in the to-be-processed file.
[0104] Step S204: determining the starting line number and the ending line number of the target sub-file according to the number of lines of the target file, the preset number of sub-files and the number of lines of the file to be processed.
[0105] It should be noted that the determining of the starting line number and the ending line number of the target sub-file according to the number of lines of the target file, the preset number of sub-files and the number of lines of the file to be processed may be performed by using the following formula to determine the starting line number and the ending line number of the target sub-file:
[0106] StartLine=i*PartSize+1
[0107] EndLine=min((i+1)*PartSize,N)
[0108] Among them, StartLine is used to represent the starting line number, EndLine is used to represent the ending line number, i is used to represent the i-th target sub-file, PartSize is used to represent the number of target file lines, and N is used to represent the number of target file lines.
[0109] In a specific implementation, assume that the line number to be cut is N, and cut it into L parts. The size of each part can be calculated using the following formula: PartSize = ceil(N / L), where the "ceil" function means rounding up. The starting line number and the ending line number of each part are calculated as follows: for the i-th part (i from 0 to L-1), StartLine = i*PartSize+1; EndLine = min((i+1)*PartSize, N), where the min function returns the smaller of the two numbers. Through the above formula, the line number N can be evenly cut into L parts, and the size of each part is as equal as possible. The starting line number and the ending line number of each part can be used to identify the range of data to be processed, and in parallel computing or distributed systems, the cut data, that is, the target sub-file, can be assigned to different tasks or nodes for processing.
[0110] Step S205: Determine the target subfile according to the starting line number and the ending line number.
[0111] It should be noted that determining the target sub-file according to the starting line number and the ending line number may be generating the target sub-file by extracting corresponding data from the to-be-processed file according to the starting line number and the ending line number of each target sub-file.
[0112] In this embodiment, when the file cutting strategy is to cut according to the file line number, the number of file lines of the to-be-processed file is determined according to the file information; the preset number of sub-files is obtained; the target file line number of the target sub-file is determined according to the preset number of sub-files and the number of file lines; the starting line number and the ending line number of the target sub-file are determined according to the target file line number, the preset number of sub-files and the number of file lines of the to-be-processed file; the target sub-file is determined according to the starting line number and the ending line number. This embodiment cuts the to-be-processed file according to the number of file lines of the to-be-processed file to obtain multiple target sub-files, and then obtains the file processing result of the to-be-processed file by performing file processing on the target sub-files respectively, which can avoid memory leakage when the to-be-processed file is large.
[0113] refer to Figure 4 , Figure 4 FIG. 4 is a flow chart of a third embodiment of a data processing method according to the present invention.
[0114] Based on the above embodiments, in this embodiment, before step S30, the method further includes:
[0115] Step S001: determining the memory size required for processing the file to be processed according to the file information.
[0116] It should be noted that determining the memory size required to process the file to be processed according to the file information may be determining the file size of the file to be processed according to the file information, and predicting the memory size required to process the file to be processed according to the file size.
[0117] Step S002: Obtain the file quantity of the target sub-file.
[0118] It should be noted that the number of target sub-files may be the number of target sub-files obtained after the to-be-processed file is split according to the above-mentioned file splitting steps.
[0119] Step S003: determining a target memory size required for processing the target sub-file according to the memory size and the number of files.
[0120] It should be noted that the target memory size required for processing the target subfile according to the memory size and the number of files may be determined by dividing the number of files by the memory size to obtain the target memory size required for processing the target subfile. The target memory size may be the memory size required for processing the target subfile.
[0121] Furthermore, in order to avoid the situation where the actual required memory size is larger than the target memory size due to special circumstances such as the presence of other imported files in the target subfile, in this embodiment, the actual memory size corresponding to the target subfile can be predicted and parsed by a preset memory prediction algorithm. Specifically, the target memory size and the target subfile can be input into the preset memory prediction algorithm to obtain the actual memory size corresponding to the target subfile output by the preset memory prediction algorithm. The actual memory size is used as the target memory size.
[0122] The preset memory prediction algorithm may be an algorithm trained in advance based on sample data for predicting the memory size actually required during file parsing. The sample data may include a sample file, a target memory size corresponding to the sample file, and an actual memory size used for parsing corresponding to the sample file.
[0123] Step S004: determining a target memory block corresponding to the target sub-file for processing according to the target memory size.
[0124] It should be noted that the target memory block corresponding to the target sub-file to be processed according to the target memory size may be selected from various memory blocks in the data processing device as the target memory block corresponding to the target sub-file. In order to avoid the pre-allocated target memory block size being insufficient during actual processing, the memory may be increased in real time according to actual file processing information during actual processing.
[0125] Furthermore, in order to improve the utilization of memory, before step S004, the method further includes: sorting the currently available memory blocks to obtain a sorting result;
[0126] A target memory block corresponding to the target sub-file is selected and processed from the sorting result according to the target memory size.
[0127] It should be noted that the currently available memory block may be an available memory block in the data processing device. The sorting of the currently available memory blocks may be sorting the currently available memory blocks according to the size of the currently available memory blocks. The selecting of the target memory block corresponding to the target sub-file from the sorting result according to the target memory size may be selecting the smallest currently available memory block larger than the target memory size from the sorting result according to the target memory size as the target memory block corresponding to the target sub-file. The following formula may be referred to:
[0128] Best Fit=min{(Size-ProcessSize)|(Size>=ProcessSize)}
[0129] Among them, Best Fit is used to represent the target memory block, Size is used to represent the available memory block size in the data processing device, and ProcessSize represents the size of the process, that is, the target memory size. The meaning of the formula is to find the smallest memory block that can meet the process size requirements. That is, find the minimum Size-ProcessSize value that meets the condition Size>=ProcessSize.
[0130] This embodiment traverses all available memory blocks in the data processing device to find the smallest memory block that meets the process size requirement, so that the best memory block can be selected to allocate to the process to reduce memory waste and fragmentation.
[0131] It should be understood that memory is one of the important resources in a computer system, which directly affects the performance and efficiency of the system. Traditional memory management methods are usually static, that is, a certain amount of memory is allocated when the system starts, and no adjustment is made during operation. However, this method has some problems, such as memory waste and performance bottlenecks. Dynamic adjustment of memory is a flexible memory management method that can dynamically allocate and release memory resources according to system requirements to improve system performance and efficiency. Therefore, in this embodiment, in order to dynamically allocate appropriate memory resources. The best memory adaptation algorithm is used to determine the memory allocation method, and an intelligent memory allocation thread pool is implemented to adjust the utilization of the overall memory block resources in real time. Before the step of sorting the currently available memory blocks and obtaining the sorting results described in this embodiment, it also includes:
[0132] Get the current running status information;
[0133] Inputting the current running state information into a preset memory prediction algorithm to obtain current available memory and memory demand predicted by the preset memory prediction algorithm;
[0134] Memory is allocated according to the currently available memory and the memory requirement to obtain a currently available memory block.
[0135] It should be noted that the current operating status information may include the current operating status and environmental condition information of the data processing device. The preset memory prediction algorithm may be an algorithm for predicting future memory requirements and current available memory based on the current operating status information, and the preset memory prediction algorithm may be obtained by training historical memory usage data using machine learning technology. The memory allocation based on the current available memory and the memory requirements to obtain the currently available memory block may be memory allocation to the currently available memory in the data processing device based on the memory requirements and the currently available memory to obtain a plurality of currently available memory blocks of different sizes.
[0136] In the specific implementation, before processing the file for cutting, the environment sets the initial heap memory -Xms512m, sets the maximum memory during operation -Xmx1024m, the memory limit is 4096Mi, and the maximum CPU limit is 10000M. The average reading time for direct reading and parsing of a 5.86G file test is about 55 minutes, and the CPU usage is up to 90%. Reduce the CPU to 4000M.
[0137] The same file is split into 30 sub-files by the above steps in this embodiment to test the configuration of a 200M sub-file. The test results are as follows: the total time is 38 seconds, the CPU usage of Java Visual VM monitoring is up to 13.7%, and the average running memory is about 25M. The CPU usage rate is greatly reduced by 90%, and the time consumption is shortened by about 85 times.
[0138] In the specific implementation, please refer to Figure 5 , Figure 5 This is a logic flow chart of intelligent memory allocation of the third embodiment of the data processing method of the present invention. In this embodiment, the program logic implementation uses a linked list data structure to represent the memory block, and uses a priority queue (PriorityQueue) to maintain the free size of the memory block. Specifically: create a memory block class (MemoryBlock), the attributes of which are startAddress, size, and isFree, which respectively represent the starting address, size, and status (free or allocated) of each memory block; create a memory manager class (MemoryManager) to implement optimal memory allocation, including methods for adding memory blocks, allocating memory, and releasing memory. Among them, add a memory block allocate(), implement the logic to sort the memory block list by size, and then traverse each memory block to find the first unallocated memory block of sufficient size for allocation. If a suitable memory block is found, we allocate it and return its starting address. If no suitable memory block is found, return -1 to indicate that the allocation failed. Allocate memory deallocate(), find the corresponding memory block according to the given address, and mark it as unallocated. Release memory realse(), the garbage collector automatically scans the dynamic memory of the object regularly and marks all referenced objects. After the object ends (no reference variable is associated with the object), its mark is cleared and all unmarked objects are recycled as garbage to release the memory space occupied by the garbage object. It is automatically executed only when the garbage collector is idle or out of memory.
[0139] The above dynamic method is to adaptively adjust the cutting and merging strategies according to the current memory usage. For example, when the memory usage is close to 100%, the processing can be suspended and wait for memory recovery. When the memory usage drops, the processing can be restarted. This approach requires more complex algorithm design and implementation, and may bring additional overhead. But it can better adapt to dynamic environments and provide better performance. Specifically, use the ByteBuffer cache object to deallocate(1024), utilize the best adaptation algorithm Best Fit = min{(Size-ProcessSize)|(Size>=ProcessSiz e)} to allocate, and obtain the available memory size totalSize through ManagementFactory.getMemoryMXBean.getHeapMemoryUsage(). For example, if a 4G file is cut and parsed and totalSize is approximately equal to 20*200M, it is relatively appropriate to define 20 cuts. Otherwise, continue to increase the number of removals. The number of removals is roughly applicable to the target N>=total file size / 200M. If the size of the processing cutting and parsing thread ProcessSize is obtained through threadAllocateBytes(), the memory manager MemoryManager.deall ocate() memory allocation method is called to find the minimum Size-ProcessSize value that satisfies the condition Size>=ProcessSize. Define the start address 0; the cut end address marks the average byte count of the file avgBytes 4*1024*1024 / 20, and traverse to obtain the precondition that the average byte is less than the requested memory application buffer value Size-ProcessSize value; if it is true, deallocate() will return success, mark the occupation, record the end mark of the previous cut record as the next cut start address, and so on to cut the next sub-file. If deallocate() returns -1 after traversing all memory blocks, monitor the alarm processing, increase the application replica node by adding a program to trigger the cloud container to expand the memory, or adjust the program to automatically JVM memory information.
[0140] Specifically, the memory manager is used to manage the memory in the data processing device, including adding memory blocks, allocating memory, and releasing memory after the memory completes the task (i.e., parsing the target sub-file). After obtaining the cut target sub-file, the chain head search is started, and after finding the first target memory block that meets the conditions, the target sub-file is parsed through the target memory block, and at the same time, the memory block that meets the conditions is continued to be searched for in the memory to parse the next target sub-file, until the target sub-files obtained by the cut of the file to be processed are parsed.
[0141] In the specific implementation, the parsing rules can be pre-set in this embodiment, which may include the following configuration information: 1. String path-specifies the file path for cutting, which is a required configuration. If the configuration is illegal, an exception is thrown;
[0142] 2. String type-file type supports csv file and txt file;
[0143] 3. String separator-delimiter, which is used to cut the field columns and convert the structure List according to the delimiter defined by the business;
[0144] 4. Long size-specify the size of the sub-file to be cut (the default size is 200M per sub-file);
[0145] 5. boolean skipEmptyRows - whether to skip blank rows, the default is true;
[0146] 6. boolean containsHeader - whether the first row is used as the header row, the default is false, no header row;
[0147] 7. boolean containsEnd - whether to skip the last line, the default is false;
[0148] 8. boolean errorOnDifferentFieldCount - whether to throw an exception when the number of rows is different. The default value is false;
[0149] 9. boolean excuteOpenPoolDoAnalysis - whether to enable multi-threaded analysis of sub-cut files. The default value is false and not enabled... Users can configure file analysis through the above parameters.
[0150] In this embodiment, the business processing call end can call the configured CsvTxtConfig property for configuration. Before running, the basic logic processing class CsvTxtBaseHandleService.vailData() method is loaded to verify the legality of the properties in CsvTxtConfig. The required items are used as the preconditions for process execution access. Specifically: 1.1. The file path for cutting must have a legal file. If the file is not configured or does not exist, the program will throw an exception and will not execute further;
[0151] 1.2. type-file type supports judging whether it belongs to the type in typeList, such as csv\txt; if it is not in the range, an exception is thrown and the execution is not continued;
[0152] 1.3. separator-splitter is used to cut the field column and convert the structure List according to the separator defined by the business; if it is not configured, an exception will be thrown;
[0153] 1.4. size-specify the size of the sub-file to be cut (the default size is 200M per sub-file);
[0154] 1.5. skipEmptyRows-Whether to skip blank rows, the default is true, and the total number of rows does not include blank rows;
[0155] 1.6. containsHeader - whether the first line is used as the header, the default is false, and processing starts from the first line. If true, it starts from the first line and starts from the second line;
[0156] 1.7, containsEnd-Whether to skip the last line, the default value is false;
[0157] 1.8. errorOnDifferentFieldCount-Whether to throw an exception when the number of rows is different. The default is false;
[0158] 1.9. executeOpenPoolDoAnalysis-Whether to enable multi-threaded analysis of sub-cutting files. The default is not enabled. If it is enabled, multi-threaded concurrent data processing will be enabled by default according to the number of CPU cores.
[0159] 2. Implement the process template CsvTxtAbstractTemplate object and rewrite the doAnalysis() method. Arrange and define the process standard, that is, generate the method class that executes each step in this embodiment, encapsulate each method class, set the relationship between each method class, execute each method class according to the defined rules and process, and then complete the file processing;
[0160] 3. The business implements the csvTxtHandler.excute() hook function. After excute processes standard cutting and parsing, it uses the config configuration obtained in step 1 and the process template abstractTemplate obtained in step 2 as input parameters to perform standard cutting and parsing;
[0161] 4. dosplit() method for cutting sub-files, returns the path of the file sub-object, specifically:
[0162] 4.1. Read the original file, get the total number of lines sumSize, and configure the number of cuts count.
[0163] 4.2. Calculate the number of lines that each file should contain, that is, divide the total number of lines M by n to get the average number of lines in each file, denoted as avgLines.
[0164] 4.3. Define a counter countLines to record the number of lines currently read.
[0165] 4.4. Define a file counter fileCount to record the number of files currently generated.
[0166] 4.5. Loop through each line of the original file until all lines are read:
[0167] If the number of lines countLines read so far is less than or equal to avgLines, and the file counter fileCount is less than count, the line is written to the current file.
[0168] If the number of lines countLines currently read is greater than avgLines, or the file counter fileCount is equal to count, the current file is closed, the value of the file counter fileCount is increased, and the value of the counter countLines is recounted.
[0169] 4.6. After completing the loop, write the remaining row data to the last file.
[0170] For example, there is a file mydemo.txt containing 12 lines of header description. Assuming that each record line has 9 columns, first remove the header and put it in the file subscript mydemo0.txt, which means no processing is required. The record subscript is 0 and the file content is 0; start cutting from the second line of the file, and calculate the total number of lines in the file by file.legth(), which is 11. According to the configuration config.count()=4, cut 11 / 4 into 3 files, mydemo1.txt has 3 lines, mydemo2.txt has 4 lines, and mydemo3.txt has 4 lines.
[0171] 5. doAnalysis() standard parsing sub-file method returns object business call;
[0172] 6. After the processing is completed, the cut sub-files are deleted and the processing results of the files to be processed are generated according to the parsing results of each sub-file.
[0173] This embodiment determines the memory size required for processing the to-be-processed file according to the file information; obtains the number of files of the target sub-file; determines the target memory size required for processing the target sub-file according to the memory size and the number of files; and determines the target memory block corresponding to the target sub-file according to the target memory size. This embodiment determines the target memory block corresponding to each target sub-file according to the memory size required for processing the to-be-processed file, and processes the target sub-file according to the target memory block, which can improve the utilization rate of the memory block.
[0174] This embodiment can perform standard process cutting and parsing of super-large accounting files, and can perform basic capability encapsulation, solve the slow communication and even abnormal situations caused by network bandwidth limitations and machine memory limitations, reduce the time spent on processing business, and predict the system memory resource requirements and dynamically allocate appropriate memory resources. An intelligent memory allocation thread pool is implemented to adjust the utilization rate of the overall memory block resources in real time, and then the super-large accounting files are cut according to the line number or file size, and the files are parsed according to the instructions configured according to business needs, thereby realizing intelligent standard process cutting and reading of large data files.
[0175] Reference Figure 6 , Figure 6 It is a structural block diagram of the first embodiment of the data processing device of the present invention.
[0176] like Figure 6 As shown, the data processing device proposed in the embodiment of the present invention includes:
[0177] An acquisition module 10 is used to acquire file information of a file to be processed, and determine a file cutting strategy for the file to be processed according to the file information;
[0178] A cutting module 20, configured to cut the file to be processed based on the file cutting strategy to obtain a target sub-file after cutting;
[0179] The parsing module 30 is used to parse the target sub-file according to the target memory block corresponding to the target sub-file to obtain a parsing result;
[0180] The processing result generating module 40 is used to determine the file processing result of the file to be processed according to the parsing result.
[0181] This embodiment obtains the file information of the file to be processed, determines the file cutting strategy of the file to be processed according to the file information; performs file cutting on the file to be processed based on the file cutting strategy to obtain the target sub-file after cutting; performs file parsing on the target sub-file according to the target memory block corresponding to the target sub-file to obtain the parsing result; determines the file processing result of the file to be processed according to the parsing result. Compared with the existing method of directly performing memory allocation post-processing on the file, the above method of this embodiment can split the file for post-processing, avoid memory overflow or excessive time consumption caused by direct loading of file processing scenarios, improve file processing efficiency, solve the slow or even abnormal communication caused by network bandwidth limitations and machine memory limitations, and reduce the time consumption of processing business.
[0182] It should be noted that the workflow described above is merely illustrative and does not limit the scope of protection of the present invention. In practical applications, technicians in this field can select part or all of them according to actual needs to achieve the purpose of the present embodiment, and no limitation is made here.
[0183] In addition, for technical details that are not described in detail in this embodiment, reference can be made to the data processing method provided in any embodiment of the present invention, and will not be repeated here.
[0184] Based on the above-mentioned first embodiment of the data processing device of the present invention, a second embodiment of the data processing device of the present invention is proposed.
[0185] In this embodiment, the cutting module 20 is further used to determine the file size of the to-be-processed file according to the file information when the file cutting strategy is to cut according to the file size;
[0186] Get the preset file standard size;
[0187] Determine the number of files of the target sub-file according to the file size and the preset file standard size;
[0188] Determine the target file size of the target sub-file according to the number of files and the file size;
[0189] The file to be processed is split according to the target file size to obtain the split target sub-files.
[0190] Furthermore, the cutting module 20 is further configured to determine the number of file lines of the to-be-processed file according to the file information when the file cutting strategy is to cut according to the file line number;
[0191] Get the preset number of sub-files;
[0192] Determine the target file line number of the target sub-file according to the preset sub-file number and the file line number;
[0193] Determine the starting line number and the ending line number of the target subfile according to the number of lines of the target file, the preset number of subfiles and the number of lines of the file to be processed;
[0194] The target subfile is determined according to the starting line number and the ending line number.
[0195] Furthermore, the acquisition module 10 is also used to acquire file information of the file to be processed;
[0196] Determine the file size of the file to be processed according to the file information;
[0197] When the file size is greater than a preset file cutting threshold, the file cutting strategy of the to-be-processed file is to cut according to the file size;
[0198] When the file size is less than or equal to the preset file cutting threshold, the file cutting strategy of the to-be-processed file is to cut according to the file line number.
[0199] Furthermore, the parsing module 30 is also used to determine the memory size required to process the file to be processed according to the file information;
[0200] Obtain the number of files of the target sub-file;
[0201] Determine the target memory size required for processing the target subfile according to the memory size and the number of files;
[0202] A target memory block corresponding to the target sub-file is determined and processed according to the target memory size.
[0203] Furthermore, the parsing module 30 is also used to sort the currently available memory blocks to obtain a sorting result;
[0204] A target memory block corresponding to the target sub-file is selected and processed from the sorting result according to the target memory size.
[0205] Furthermore, the analysis module 30 is also used to obtain current operation status information;
[0206] Inputting the current running state information into a preset memory prediction algorithm to obtain current available memory and memory demand predicted by the preset memory prediction algorithm;
[0207] Memory is allocated according to the currently available memory and the memory requirement to obtain a currently available memory block.
[0208] Other embodiments or specific implementations of the data processing device of the present invention may refer to the above-mentioned method embodiments and will not be described in detail here.
[0209] In addition, an embodiment of the present invention further provides a storage medium, on which a data processing program is stored. When the data processing program is executed by a processor, the steps of the data processing method described above are implemented.
[0210] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or system including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or system. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or system including the element.
[0211] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.
[0212] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as a read-only memory / random access memory, a magnetic disk, or an optical disk), and includes a number of instructions for enabling a terminal device (which can be a mobile phone, a computer, a server, an air conditioner, or a network device, etc.) to execute the methods described in each embodiment of the present invention.
[0213] The above are only preferred embodiments of the present invention, and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.
Claims
1. A data processing method, It is characterized in that The data processing method comprises the following steps: Acquire file information of a file to be processed, and determine a file cutting strategy for the file to be processed according to the file information, wherein the file cutting strategy includes cutting according to file size and cutting according to file line number; Perform file segmentation on the to-be-processed file based on the file segmentation strategy to obtain a target sub-file after segmentation; Parsing the target sub-file according to the target memory block of the target sub-file to obtain a parsing result; Determine a file processing result of the file to be processed according to the parsing result; Before the step of parsing the target sub-file according to the target memory block corresponding to the target sub-file, the method further includes: Determine the memory size required for processing the file to be processed according to the file information; Obtain the number of files of the target sub-file; Determine the target memory size required for processing the target subfile according to the memory size and the number of files; Sort the currently available memory blocks and obtain the sorting results; Selecting a target memory block corresponding to the target sub-file for processing from the sorting result according to the target memory size; Before the step of sorting the currently available memory blocks to obtain the sorting result, the method further includes: Get the current running status information; Inputting the current running state information into a preset memory prediction algorithm to obtain current available memory and memory demand predicted by the preset memory prediction algorithm; Memory is allocated according to the currently available memory and the memory requirement to obtain a currently available memory block.
2. The data processing method according to claim 1, It is characterized in that The step of performing file segmentation on the to-be-processed file based on the file segmentation strategy to obtain a target sub-file after segmentation includes: When the file cutting strategy is to cut according to the file size, determining the file size of the to-be-processed file according to the file information; Get the preset file standard size; Determine the number of files of the target sub-file according to the file size and the preset file standard size; Determine the target file size of the target sub-file according to the number of files and the file size; The file to be processed is split according to the target file size to obtain the split target sub-files.
3. The data processing method according to claim 1, It is characterized in that The step of performing file segmentation on the to-be-processed file based on the file segmentation strategy to obtain a target sub-file after segmentation includes: When the file cutting strategy is to cut according to the file line number, the number of file lines of the to-be-processed file is determined according to the file information; Get the preset number of sub-files; Determine the target file line number of the target sub-file according to the preset sub-file number and the file line number; Determine the starting line number and the ending line number of the target subfile according to the number of lines of the target file, the preset number of subfiles and the number of lines of the file to be processed; The target subfile is determined according to the starting line number and the ending line number.
4. The data processing method according to claim 1, It is characterized in that The step of obtaining file information of the to-be-processed file and determining the file cutting strategy of the to-be-processed file according to the file information includes: Get the file information of the file to be processed; Determine the file size of the file to be processed according to the file information; When the file size is greater than a preset file cutting threshold, the file cutting strategy of the to-be-processed file is to cut according to the file size; When the file size is less than or equal to the preset file cutting threshold, the file cutting strategy of the to-be-processed file is to cut according to the file line number.
5. A data processing device, It is characterized in that The data processing device comprises: An acquisition module, used for acquiring file information of a file to be processed, and determining a file cutting strategy for the file to be processed according to the file information, wherein the file cutting strategy includes cutting according to file size and cutting according to file line number; A cutting module, used for cutting the file to be processed based on the file cutting strategy to obtain a target sub-file after cutting; A parsing module, used for parsing the target sub-file according to the target memory block of the target sub-file to obtain a parsing result; A processing result generating module, used for determining a file processing result of the file to be processed according to the parsing result; The parsing module is further used to determine the memory size required for processing the file to be processed according to the file information; Obtain the number of files of the target sub-file; Determine the target memory size required for processing the target subfile according to the memory size and the number of files; Sort the currently available memory blocks and obtain the sorting results; Selecting a target memory block corresponding to the target sub-file for processing from the sorting result according to the target memory size; The analysis module is also used to obtain current running status information; Inputting the current running state information into a preset memory prediction algorithm to obtain current available memory and memory demand predicted by the preset memory prediction algorithm; Memory is allocated according to the currently available memory and the memory requirement to obtain a currently available memory block.
6. A data processing device, It is characterized in that The device comprises: a memory, a processor, and a data processing program stored in the memory and executable on the processor, wherein the data processing program is configured to implement the steps of the data processing method according to any one of claims 1 to 4.
7. A storage medium, It is characterized in that The storage medium stores a data processing program, and when the data processing program is executed by the processor, the steps of the data processing method according to any one of claims 1 to 4 are implemented.
