Method and system for realizing cluster data batch processing based on file interaction
Patent Information
- Application Number
- CN202410852627.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-28
- Publication Date
- 2024-10-11
AI Technical Summary
针对现有技术中存在的技术问题,本发明提供一种基于文件交互实现集群数据批量处理的方法及系统,用以解决现有技术中在处理大量数据时遇到的耗时长、调整方案操作风险大、不可通过增加主机数量、自由调整批量处理模式为单机或集群的问题
本发明提供的一种基于文件交互实现集群数据批量处理的方法及系统,通过基于文件交互方式的集群批量设计思路,可以实现由单台主机处理数据转变多集群多台主机共同处理数据。避免cpu核数、内存等基础设施的参数调整。可通过简单的增加主机信息情况下实现集群批量处理能力扩容。
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data processing, and in particular to a method and system for realizing cluster data batch processing based on file interaction. Background Art
[0002] At present, when processing a large amount of customer order data, a single JVM is used to use multi-threading technology for concurrent processing, that is, to run and process data in a single host. This method is acceptable for situations where the data volume is medium and the business logic calculation complexity is relatively simple. However, with the development of business, there are more and more scenarios, more and more complex calculation processes, and the number of data is gradually increasing rapidly. The existing solution will encounter the situation where batch operation takes longer and longer. At the same time, the existing solution will gradually optimize and improve the running speed by adjusting the number of concurrent threads, as well as adjusting the CPU parameters, memory parameters and other infrastructure, but this solution also has many problems and risks, as follows: Adjusting the number of concurrent threads requires code modification, testing, packaging, deployment and other release processes, which takes a long time. Modifying the number of threads requires empirical modification based on the existing number of CPU cores. The number of CPU cores in the production environment and the test environment are inconsistent, and the conclusions of the test environment debugging may not be applicable to the production environment. After adjusting the number of threads, stress testing and simulation are required, which takes a lot of time and is not suitable for emergency processing in the production environment. Cluster joint processing cannot be achieved by deploying multiple machines. Summary of the invention In view of the technical problems existing in the prior art, the present invention provides a method and system for realizing cluster data batch processing based on file interaction, so as to solve the problems encountered in the prior art when processing large amounts of data, such as long time consumption, high operational risk of adjusting the scheme, and inability to increase the number of hosts and freely adjust the batch processing mode to a single machine or a cluster.
[0003] According to a first aspect of the present invention, the present invention provides a method for implementing cluster data batch processing based on file interaction, comprising the following steps: Step 1: Configure the host group address port information, number of threads and host group required to implement batch program in the configuration file; Step 2: Configure batch information related table files in the database: batch information configuration table for controlling batch operation mode, batch operation registration table for recording batch operation status, and FTP service configuration information table for file interaction; Step 3: Use Java to build the basic components and main task management functions for data coordination management; Step 4: Based on the information in the configuration file and the data table, complete cluster host information parsing and data acquisition, and complete cluster data batch processing based on file interaction and cluster hosts.
[0004] Based on the above technical solution, the present invention can also make the following improvements.
[0005] Optionally, in step 1, the host group address port information and the number of threads for batch processing are configured in the configuration file, including: Step 1.1: Configure a host group information in the configuration file to define the host information or host group information required by the business batch processing program; Step 1.2: When the JVM of the cluster is started, the loading code parses the configuration file to obtain the host group information; this includes: each host starts a node, elects a master node through an election algorithm, and the other nodes serve as the reserve nodes of the master node, that is, the slave nodes. At the same time, they monitor the working master node. If the master node responsible for the work is abnormal, the other slave nodes receive the monitoring event and try to seize the master node responsible for the main work. The other slave nodes that have not been snatched will be responsible for monitoring the new master node status.
[0006] Optionally, the information of the host group includes an IP address and a port, and the IP address and the port are written in the format of "ip:port;". Optionally, in step 2, the batch information configuration table configures the batch processing mode to be a single machine processing mode and a cluster processing mode; wherein, The single-machine processing method uses the host where the master is located for processing; The cluster processing method uses the parsed host group to perform post-data distribution processing.
[0007] Optionally, in step 2, the data distribution mode configured in the batch information table is divided into a non-distribution mode and a hash distribution mode, wherein: The non-distribution mode must be used when the stand-alone processing method is used; The hash distribution mode uses a consistent hash algorithm combined with the host group information parsed in the steps to perform data volume hash calculation.
[0008] Optionally, in step 3, the main task management function, when the batch program is executed, includes: Step 3.1: The main task of the master node loads the configuration information in the batch information table and analyzes the distribution mode of the configuration data in the batch information table; if it is a non-distribution mode, the execution process is handed over to the batch program to take over the data processing; if it is a hash distribution mode, the master node calls the basic component of data coordination management and uses a consistent hash algorithm to calculate the key value of the batch data to be processed according to the number of hosts; Step 3.2: The master node is responsible for writing the grouped data set into a file, obtaining the FTP service information, and uploading the file to the file server via FTP.
[0009] Optionally, in step 4, completing cluster host information parsing and data acquisition based on the information in the configuration file and the data table, and completing batch processing of cluster data based on file interaction and cluster hosts includes: Step 4.1: Register the batch ID number, batch name, data distribution mode, and running status in the batch information configuration table. The running status defaults to "Not Started"; Step 4.2: Configure the ftp server's IP, port, path, username, and password; Step 4.3: Define the SQL statement used to uniquely determine the data in the main task; after the main task runs, update the execution status of the batch to "data preparation" in the batch information configuration table; Step 4.4: The main task performs hash calculation and distributes data according to the input items, and distributes data according to the number of clusters, that is, each host has a copy of the data; after completing the hash calculation, the main task writes the data into files respectively, uploads the distributed data to the file server via FTP, updates the status in the batch information configuration table to "data distribution", and updates the file name and total data volume corresponding to each host batch in the batch operation registration table; Step 4.5: Each host subtask in the cluster obtains the corresponding file from the file server according to the FTP configuration information and the file name. After successful acquisition, the status in the batch information table is updated to "data processing", and all data fields corresponding to the key value in the file are obtained from the database line by line according to the key value in the file. Data calculation and processing are performed in combination with the business code. After the processing is completed, the "processed data volume" and "error stack" in the registration table are written. After the data processing of all clusters is completed, the batch status is updated to "completed".
[0010] Optionally, in step 4.3, the SQL statement is used to obtain a keyword set of all data required in the batch information configuration table as an input item of the data distribution algorithm.
[0011] According to a second aspect of the present invention, a system for implementing cluster data batch processing based on file interaction is provided, comprising: The first data processing module is used to configure the host group address port information, the number of threads and the host group required to implement the batch program for processing the batch in the configuration file; The second data processing module is used to configure batch information table files in the database, including a batch information configuration table for controlling the batch operation mode, a batch operation registration table for recording the batch operation status, and an FTP service configuration information table for file interaction; The third data processing module is used to use Java to build basic components and main task management functions for data overall management; The fourth data processing module is used to complete cluster host information parsing and data acquisition based on the information in the configuration file and the data table, and complete batch processing of cluster data based on file interaction and cluster hosts.
[0012] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the method for batch processing of cluster data based on file interaction as described above is implemented.
[0013] Technical effects and advantages of the present invention: The present invention provides a method and system for realizing cluster data batch processing based on file interaction. Through the cluster batch design idea based on file interaction, it can realize the transformation from single host processing data to multiple clusters and multiple hosts jointly processing data. It avoids the parameter adjustment of infrastructure such as CPU core number and memory. The cluster batch processing capacity can be expanded by simply adding host information. DETAILED DESCRIPTION
[0014] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution in the present invention is described clearly and completely. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0015] It is understandable that, based on the defects in the background technology, the embodiment of the present invention proposes a method for implementing cluster data batch processing based on file interaction, including the following steps: Step 1: Configure the host group address port information, number of threads and host group required to implement batch program in the configuration file; In the above technical solution: Step 1 includes the following steps: Step 1.1: Configure a host group information in the configuration file to define the host information or host group information required by the business batch processing program. The host group information includes the IP address and port, and is written in the format of "ip:port;" Step 1.2: When the JVM of the cluster is started, the loading code parses the configuration file to obtain the host group information; this includes: each host starts a node, elects a master node through an election algorithm, and the other nodes serve as the reserve nodes of the master node, that is, the slave nodes. At the same time, they monitor the working master node. If the master node responsible for the work is abnormal, the other slave nodes receive the monitoring event and try to seize the master node responsible for the main work. The other slave nodes that have not been snatched will be responsible for monitoring the new master node status.
[0016] The host group can also realize dynamic expansion of the host group, wherein the information of the host group includes an IP address and a port, and the IP address and the port are written in the format of "ip:port;".
[0017] Step 2: Configure batch information table files in the database: including: a batch information configuration table for controlling the batch operation mode, a batch operation registration table for recording the batch operation status, and an FTP service configuration information table for file interaction; In the above technical solution: the batch processing mode configured in the batch information configuration table is divided into two processing modes: one is a single-machine processing mode, that is, using the host where the master node is located for processing; the other is a cluster processing mode, that is, using the host group parsed in step 1.2 for data distribution and post-processing; The data distribution method configured in the batch information table is divided into two modes: one is a non-distribution mode, which must be used when using the single-machine processing method in step 2.1; the other is a hash distribution mode, which uses a consistent hash algorithm combined with the host group information parsed in step 1.2 to perform data volume hash calculation.
[0018] The ftp service configuration table is used to configure information of the file server.
[0019] Step 3: Use Java to build the basic components and main task management functions for data coordination management; In the above technical solution, the batch program execution of the main task management function is divided into the following two steps: Step 3.1. The master task of the master node loads the configuration information in the batch information table and analyzes the distribution mode of the batch. If it is a non-distribution mode, the execution process is handed over to the batch program to take over the data processing; if it is a hash distribution mode, the master node calls the basic component of data overall management and uses a consistent hash algorithm to calculate the key value of the data to be processed in the batch according to the number of hosts; Step 3.2. The master node is responsible for writing the grouped data set into files, obtaining FTP service information, and uploading the files to the file server via FTP.
[0020] Step 4: Based on the information in the configuration file and the data table, complete cluster host information parsing and data acquisition, and complete cluster data batch processing based on file interaction and cluster hosts.
[0021] In this implementation step, this embodiment completes cluster host information parsing, data acquisition, data coordination and splitting, data file distribution, sub-task data file acquisition and data processing based on the information in the configuration file and the data table, completes the batch processing of cluster data based on file interaction and cluster hosts, and utilizes a large number of host resources to shorten the time required for processing massive data.
[0022] In the above technical solution: Step 4 specifically includes the following steps: Step 4.1: Define the batch name and number, and register the batch ID number, batch name, data distribution mode, and running status in the batch information configuration table. The running status defaults to "Not Started".
[0023] Step 4.2: Configure the ftp server's IP, port, path, username, and password; Step 4.2: Write the main task code and define the key SQL statement that can be used to uniquely identify the data in the main task. This statement is used to obtain the keyword set of all the data required for the batch as the input item of the subsequent data distribution algorithm. After the main task runs, the execution status of the batch will be updated in the batch information configuration table as "data preparation", which means that the main task program obtains keywords according to the established SQL.
[0024] Step 4.3: The master task performs hash calculations and distributes data based on the input items in step 4.2, and distributes data according to the number of clusters, that is, each host has a copy of the data. After completing the hash calculation, the master task writes the data into files, and the number of files is consistent with the number of hosts in step 1.1, and then uploads the distributed data to the file server via FTP, updates the status in the batch information configuration table to "data distribution", and updates the file name and total data volume corresponding to each host batch in the batch operation registration table.
[0025] Step 4.4: Each host subtask in the cluster obtains the corresponding file from the file server according to the FTP configuration information and the file name in step 4.3. After the acquisition is successful, the status in the batch information table is updated to "data processing", and all data fields corresponding to the key value in the file are obtained from the database line by line, and data calculation and processing are performed in combination with the business code. After the processing is completed, the "processed data volume" and "error stack" in the registration table are written. After the data processing of all clusters is completed, the status of the batch is updated to "completed".
[0026] In summary, the embodiment of the present invention can realize the transformation from processing data by a single host to processing data by multiple hosts in multiple clusters through the cluster batch design idea based on the file interaction mode. It avoids the parameter adjustment of the infrastructure such as the number of CPU cores and memory. The cluster batch processing capacity can be expanded by simply adding host information.
[0027] According to a second aspect of the present invention, a system for implementing cluster data batch processing based on file interaction is provided, comprising: The first data processing module is used to configure the host group address port information, the number of threads and the host group required to implement the batch program for processing the batch in the configuration file; The second data processing module is used to configure batch information table files in the database, including a batch information configuration table for controlling the batch operation mode, a batch operation registration table for recording the batch operation status, and an FTP service configuration information table for file interaction; The third data processing module is used to use Java to build basic components and main task management functions for data overall management; The fourth data processing module is used to complete cluster host information parsing and data acquisition based on the information in the configuration file and the data table, and complete batch processing of cluster data based on file interaction and cluster hosts.
[0028] It can be understood that the system for implementing cluster data batch processing based on file interaction provided by the present invention corresponds to the method for implementing cluster data batch processing based on file interaction provided by the aforementioned embodiments. The relevant technical features of the system for implementing cluster data batch processing based on file interaction can refer to the relevant technical features of the method for implementing cluster data batch processing based on file interaction, which will not be repeated here.
[0029] In addition, an embodiment of the present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that when the processor executes the program, it implements a method for batch processing of cluster data based on file interaction as described above.
[0030] In addition, the logic instructions in the above-mentioned memory can be implemented in the form of software functional units and can be stored in a computer-readable storage medium when sold or used as an independent product. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc., which can store program code.
[0031] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0032] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for realizing cluster data batch processing based on file interaction, characterized in that: The following steps are involved: Step 1: Complete the cluster host information and batch program concurrent quantity distribution information in the configuration file; Including host group address port, number of threads and host groups required to implement batch programs; Step 2: Configure the batch information table file in the database; It includes a batch information configuration table for controlling the batch operation mode, a batch operation registration table for recording the batch operation status, and an FTP service configuration information table for file interaction; Step 3: Use Java to build the basic components and main task management functions for data coordination management; Step 4: Based on the information in the configuration file and the data table, complete cluster host information parsing and data acquisition, and complete cluster data batch processing based on file interaction and cluster hosts.
2. According to claim 1, a method for realizing cluster data batch processing based on file interaction is characterized in that: In step 1, the host group address port information and thread number for batch processing are configured in the configuration file, including: Step 1.1: Configure a host group information in the configuration file to define the host information or host group information required by the business batch processing program; Step 1.2: When the JVM of the cluster is started, the loading code parses the configuration file to obtain the host group information; this includes: each host starts a node, elects a master node through an election algorithm, and the other nodes serve as the reserve nodes of the master node, that is, the slave nodes. At the same time, they monitor the working master node. If the master node responsible for the work is abnormal, the other slave nodes receive the monitoring event and try to seize the master node responsible for the main work. The other slave nodes that have not been snatched will be responsible for monitoring the new master node status.
3. The method for realizing cluster data batch processing based on file interaction according to claim 2, characterized in that: The host group can realize dynamic expansion of the host group, wherein the information of the host group includes an IP address and a port, and the IP address and the port are written in the format of "ip:port;".
4. The method for realizing cluster data batch processing based on file interaction according to claim 1, characterized in that: In step 2, the batch processing mode configured in the batch information configuration table is divided into a single machine processing mode and a cluster processing mode; wherein, The single-machine processing method uses the host where the master node is located for processing; The cluster processing method uses the parsed host group to perform post-data distribution processing.
5. The method for realizing cluster data batch processing based on file interaction according to claim 4 is characterized in that: In step 2, the data distribution mode configured in the batch information table is divided into a non-distribution mode and a hash distribution mode, wherein: The non-distribution mode must be used when the stand-alone processing method is used; The hash distribution mode uses a consistent hash algorithm combined with the host group information parsed in the steps to perform data volume hash calculation.
6. The method for realizing cluster data batch processing based on file interaction according to claim 1, characterized in that: In step 3, the main task management function, when the batch program is executed, includes: Step 3.1: The main task of the master node loads the configuration information in the batch information table and analyzes the distribution mode of the configuration data in the batch information table; if it is a non-distribution mode, the execution process is handed over to the batch program to take over the data processing; if it is a hash distribution mode, the master node calls the basic component of data coordination management and uses a consistent hash algorithm to calculate the key value of the batch data to be processed according to the number of hosts; Step 3.2: The master node is responsible for writing the grouped data set into a file, obtaining the FTP service information, and uploading the file to the file server via FTP.
7. The method for realizing cluster data batch processing based on file interaction according to claim 1, characterized in that: In step 4, the cluster host information parsing and data acquisition are completed based on the information in the configuration file and the data table, and the batch processing of cluster data is completed based on the file interaction and the cluster host, including: Step 4.1: Register the batch ID number, batch name, data distribution mode, and running status in the batch information configuration table. The running status defaults to "Not Started"; Step 4.2: Configure the ftp server's IP, port, path, username, and password; Step 4.3: Define the SQL statement used to uniquely determine the data in the main task; after the main task runs, update the execution status of the batch to "data preparation" in the batch information configuration table; Step 4.4: The main task performs hash calculation and distributes data according to the input items, and distributes data according to the number of clusters, that is, each host has a copy of the data; after completing the hash calculation, the main task writes the data into files respectively, uploads the distributed data to the file server via FTP, updates the status in the batch information configuration table to "data distribution", and updates the file name and total data volume corresponding to each host batch in the batch operation registration table; Step 4.5: Each host subtask in the cluster obtains the corresponding file from the file server according to the FTP configuration information and the file name. After successful acquisition, the status in the batch information table is updated to "data processing", and all data fields corresponding to the key value in the file are obtained from the database line by line according to the key value in the file. Data calculation and processing are performed in combination with the business code. After the processing is completed, the "processed data volume" and "error stack" in the registration table are written. After the data processing of all clusters is completed, the batch status is updated to "completed".
8. The method for realizing cluster data batch processing based on file interaction according to claim 1, characterized in that: In step 4.3, the SQL statement is used to obtain a keyword set of all data required in the batch information configuration table as an input item of the data distribution algorithm.
9. A system for realizing cluster data batch processing based on file interaction, characterized in that: include: A first data processing module, used to configure the host group address port information and the number of threads for batch processing in the configuration file; The second data processing module is used to configure batch information table files in the database, including a batch information configuration table for controlling the batch operation mode, a batch operation registration table for recording the batch operation status, and an FTP service configuration information table for file interaction; The third data processing module is used to use Java to build basic components and main task management functions for data overall management; The fourth data processing module is used to complete cluster host information parsing and data acquisition based on the information in the configuration file and the data table, and complete batch processing of cluster data based on file interaction and cluster hosts.
10. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, a method for batch processing of cluster data based on file interaction as described in any one of claims 1 to 8 is implemented.
