Method and system for realizing multi-thread copy operation of resource tree
Through multi-threaded parallel processing of resource tree copy operations, the use of global caches and counters, combined with paging storage, the problem of low resource tree synchronization performance in the existing technology is solved, and the efficiency and response performance of large resource tree copying are significantly improved.
Patent Information
- Application Number
- CN202310183734.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-02-24
- Publication Date
- 2024-08-27
AI Technical Summary
The existing technology has low performance during the synchronization process of the resource tree, resulting in the problem of system interface response timeout. Especially in the large resource tree replication scenario, the existing non-relational caching technology solution cannot meet the replication performance requirements.
The multi-threaded copy operation method is adopted, by establishing a global cache and a global sequence, using multi-threads to process the copy operations of the second-level and third-level nodes in parallel, and combining counters and paging storage to improve the efficiency of resource tree copying.
Significantly improves the time response performance of large resource tree copy operations and solves the problem of low performance. Through multi-thread processing and paging storage, it can reduce time consumption by an order of magnitude and improve system performance.
Smart Images

Figure CN118550679A
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of resource tree database and data processing, and in particular to a method and system for realizing multi-threaded copy operation of resource tree. Background Art
[0002] The software development and operation and maintenance process often involves the use of scenarios where various data resources need to be copied, especially scenarios where content in the form of resource trees needs to be copied. For example, in the security monitoring industry, a third-party resource tree is connected and synchronized to a local integration platform. This requires synchronization of a large number of resources and the tree structure data formed by the resources.
[0003] In the prior art, the synchronization mode for resource trees is generally from top to bottom, and copy and write step by step. First, it is necessary to find and obtain the top node of the resource tree, and obtain a new primary key id after writing into the target library to find the secondary node of the resource tree, and supplement the target pid as the primary key id of the top node, loop through and write into the target library, and then write the secondary nodes into the target library one by one in a hierarchical manner, obtain a new primary key id, then find the third-level nodes under the secondary nodes, and supplement the primary key id of the secondary nodes, and continue to loop through and write into the target library. Such execution often requires a lot of time, including the acquisition time of the database connection, the execution time of the database data, the serial waiting time of the tree-shaped hierarchical structure data dependency assembly, etc. For the large resource tree replication process, it is likely to cause the system interface response timeout problem. Although the prior art has disclosed a technical solution for improving replication performance by code redundancy under non-relational cache technology (such as redis, memcache, etc.), it still cannot meet the copy needs of large resource trees. Summary of the invention
[0004] In order to solve the shortcomings of the prior art, the present invention proposes a method and system for realizing multi-threaded copy operation of resource trees. By configuring sequences for resource tree contents respectively, batch multi-threaded resource tree replication is realized, the time response performance of large resource tree copy operation is improved, and the problem of poor copy performance of large resource trees is solved.
[0005] To achieve the above objectives, the technical solutions adopted by the present invention include:
[0006] A method for implementing a multi-threaded copy operation of a resource tree, characterized by comprising:
[0007] S1. Establish a global cache and a global sequence corresponding to the global cache, wherein the global sequence is an increasing sequence;
[0008] S2. Use the global sequence as the default primary key rule to set the target database primary key ID, use the source database top-level node data and the target database primary key ID to assemble the top-level node parameters and store them in the global cache;
[0009] S3. Use the top-level node parameters to identify and obtain the number of secondary nodes corresponding to the top-level node data of the source library, and establish a corresponding first counter in the first thread according to the number of secondary nodes;
[0010] S4, executing a copy operation of the secondary node data, and starting a second thread corresponding to the copy operation, where the second thread is a child thread under the first thread;
[0011] S5. Determine whether the copy operation of the secondary node data is completed. When it is determined that the copy operation of the secondary node data is completed, use the second thread to operate the first counter to reduce the number of records in the first counter by 1.
[0012] S6. Determine whether the number of records in the first counter is 0. When it is determined that the number of records in the first counter is 0, call the top-level node parameters from the global cache to assemble all the secondary node data to obtain the copied data, and store the copied data in the target library.
[0013] Furthermore, the step S4 further includes:
[0014] Multiple different secondary node data copy operations are executed simultaneously, and multiple second threads corresponding to each copy operation are opened respectively.
[0015] Further, the copy operation of executing the secondary node data includes:
[0016] The secondary node data and the top node ID as the parent identifier are assembled into secondary node parameters and stored in the global cache;
[0017] The secondary node data is stored in the global cache according to the secondary node parameters.
[0018] Furthermore, the copying operation of executing the secondary node data also includes:
[0019] Use the secondary node parameters to identify the number of third-level nodes corresponding to the secondary node data of the source library, and establish a corresponding second counter in the second thread according to the number of third-level nodes;
[0020] Simultaneously executing a plurality of different third-level node data copy operations, and operating a second counter according to whether the third-level node data copy operations are completed;
[0021] It is determined whether the number of records in the second counter is 0. When it is determined that the number of records in the second counter is 0, it is confirmed that the copy operation of the corresponding secondary node data is completed.
[0022] Furthermore, storing the copied data in the target library includes:
[0023] Perform paging operations on the copied data;
[0024] Store multiple different pages to the target library at the same time.
[0025] Furthermore, storing the multiple different pages into the target library includes:
[0026] Establish a paging counter based on the number of pages;
[0027] Execute multiple storage operations of different pages at the same time, and operate the page counter according to whether the storage operation of the page is completed;
[0028] It is determined whether the number of records in the paging counter is 0. When it is determined that the number of records in the paging counter is 0, it is confirmed that the copied data has been stored in the target library.
[0029] The present invention also relates to an operating system for realizing multi-threaded copy of resource tree, characterized in that it comprises:
[0030] A cache management module, used to establish and operate a global cache and a global sequence corresponding to the global cache;
[0031] Node parameter management module, used to assemble and manage node parameters;
[0032] A counter setting module is used to establish corresponding counters according to node parameters;
[0033] A copy judgment module is used to judge whether the copy operation of the node data is completed;
[0034] A counter determination module, used to determine whether the number of records in the first counter is 0;
[0035] The copy execution module is used to assemble and obtain the copy data and store the copy data in the target library.
[0036] The present invention also relates to a computer-readable storage medium, characterized in that a computer program is stored on the storage medium, and the computer program implements the above method when executed by a processor.
[0037] The present invention also relates to an electronic device, characterized in that it comprises a processor and a memory;
[0038] The memory is used to store global cache and copy data;
[0039] The processor is used to execute the above method by calling the global cache and copying data.
[0040] The present invention also relates to a computer program product, comprising a computer program and / or instructions, characterized in that the computer program and / or instructions implement the steps of the above method when executed by a processor.
[0041] The beneficial effects of the present invention are:
[0042] The method and system for implementing multi-threaded copy operation of a resource tree described in the present invention configure sequences for the contents of the resource tree respectively, fully utilize the surplus performance of the CPU, implement batch multi-threaded resource tree copying, improve the time response performance of large resource tree copy operations, and improve the time consumption performance by orders of magnitude during paging multi-threaded batch writing, thereby solving the problem of low performance of large resource tree copying. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] Figure 1 The present invention is a flowchart of a method for implementing a multi-threaded copy operation of a resource tree.
[0044] Figure 2 This is a schematic diagram of the structure of the resource tree multi-threaded copy operating system implemented by the present invention. DETAILED DESCRIPTION
[0045] In order to more clearly understand the content of the present invention, it will be described in detail with reference to the drawings and embodiments.
[0046] The first aspect of the present invention relates to a process of steps as follows Figure 1 The method for implementing a multi-threaded copy operation of a resource tree includes:
[0047] S1. Establish a global cache and a global sequence corresponding to the global cache, wherein the global sequence is an increasing sequence.
[0048] S2. Use the global sequence as the default primary key rule to set the target library primary key ID, use the source library top-level node data and the target library primary key ID to assemble the top-level node parameters and store them in the global cache.
[0049] If there is no parent node for the top-level node, its parent node is set to null.
[0050] S3. Use the top-level node parameters to identify the number of secondary nodes corresponding to the top-level node data of the source library, and establish a corresponding first counter in the first thread according to the number of secondary nodes.
[0051] For example, there are n secondary nodes. First, create a CountDownLatch (first counter) with the number of n in the first thread, start the child thread when copying the secondary node, and execute countDownLatch.countDown() when a secondary node is written.
[0052] S4. Execute the copy operation of the secondary node data, and start the second thread corresponding to the copy operation, the second thread is a child thread under the first thread. Specifically, more than a plurality of parallel secondary nodes simultaneously execute the copy operation of multiple different secondary node data, and respectively start multiple second threads corresponding to each copy operation, including using the secondary node source data and the parent node primary key id as the parent identifier (parentId) of the secondary node to assemble the target secondary data and store it in the global cache. It can be seen that the copy operation logic for the secondary node is essentially similar to that of the top-level node. First, the secondary node data, the new global id and the parent node id (as) are assembled as the secondary node parameters and put into the global cache.
[0053] Furthermore, when executing the copy operation of the secondary node data, you can choose to perform multi-threaded copying as needed, use the secondary node parameters, identify the number of third-level nodes corresponding to the secondary node data of the source library, and establish a corresponding second counter in the second thread according to the number of third-level nodes; perform multiple different third-level node data copy operations at the same time, and operate the second counter according to whether the copy operation of the third-level node data is completed; determine whether the number of records in the second counter is 0, and when the number of records in the second counter is 0, confirm that the copy operation of the corresponding secondary node data is completed, that is, through recursive operation, when the lower-level operation is completed, the upper-level counter can execute -1. Similarly, when there are lower-level nodes, a similar method can be used to perform multi-threaded copy operations.
[0054] If multi-threaded copying is not selected, the third-level and fourth-level nodes can be directly written in a recursive manner until the last-level node, which serves as a marking point for the completion of the second-level node copy writing.
[0055] S5. Determine whether the copy operation of the secondary node data is completed. When it is determined that the copy operation of the secondary node data is completed, use the second thread to operate the first counter and reduce the number of records in the first counter by 1. For nodes at a lower level, the recursive rule can be followed. If there is a lower level, the lower level thread is started. If not, the corresponding counter needs to be operated by -1 after each thread is executed. In the specific execution, the number of levels to be split can be determined according to the data hierarchy structure and the system CPU performance.
[0056] S6. Determine whether the number of records in the first counter is 0. When it is determined that the number of records in the first counter is 0, call the top-level node parameters from the global cache to assemble all the secondary node data to obtain the copied data, and store the copied data in the target library.
[0057] Preferably, storing the copied data in the target library includes: performing paging operations on the copied data; and storing multiple different pages in the target library at the same time. In particular, establishing a paging counter according to the number of pages; performing storage operations on multiple different pages at the same time, and operating the paging counter according to whether the paging storage operations are completed; judging whether the number of records in the paging counter is 0, and when judging that the number of records in the paging counter is 0, confirming that the copied data has been stored in the target library.
[0058] For example, you can use paging (for example, 1,000 records per page) and multi-threading (one thread per page) to write data in batches to the target database in the main thread. Create a CountDownLatch with the number of pages in the main thread, and execute the countDown method after each page is written until the number of CountDownLatch is consumed and the batch writing is completed.
[0059] By using the above method to copy the resource tree, the surplus performance of the CPU can be fully utilized, especially for a CPU with multi-core and multi-thread processing capabilities, the copy performance can be greatly improved, and the time-consuming performance can be improved by orders of magnitude when paging multi-thread batch writing is performed.
[0060] Another aspect of the present invention also relates to an operating system for implementing a multi-threaded copy of a resource tree, the structure of which is as follows: Figure 2 As shown, including:
[0061] A cache management module, used to establish and operate a global cache and a global sequence corresponding to the global cache;
[0062] Node parameter management module, used to assemble and manage node parameters;
[0063] A counter setting module is used to establish corresponding counters according to node parameters;
[0064] A copy judgment module is used to judge whether the copy operation of the node data is completed;
[0065] A counter determination module, used to determine whether the number of records in the first counter is 0;
[0066] The copy execution module is used to assemble and obtain the copy data and store the copy data in the target library.
[0067] By using this system, the above-mentioned operation processing method can be executed and the corresponding technical effects can be achieved.
[0068] An embodiment of the present invention also provides a computer-readable storage medium capable of implementing all the steps in the method in the above embodiment, wherein a computer program is stored on the computer-readable storage medium, and when the computer program is executed by a processor, all the steps in the method in the above embodiment are implemented.
[0069] An embodiment of the present invention also provides an electronic device for executing the above method. As an implementation device of the method, the electronic device has at least a processor and a memory, and in particular, the memory stores data and related computer programs required for executing the method, such as global cache and copy data, etc., and the processor calls the data and programs in the memory to execute all steps of the implementation method and obtains the corresponding technical effect.
[0070] Preferably, the electronic device may include a bus architecture, the bus may include any number of interconnected buses and bridges, and the bus will include various circuits linked together by one or more processors and memories. The bus may also link together various other circuits such as peripherals, voltage regulators, and power management circuits, which are all well known in the art and are therefore not further described herein. The bus interface provides an interface between the bus and the receiver and transmitter. The receiver and transmitter may be the same component, i.e., a transceiver, providing a unit for communicating with various other systems over a transmission medium. The processor is responsible for managing the bus and general processing, while the memory may be used to store data used by the processor when performing operations.
[0071] In addition, the electronic device may further include components such as a communication module, an input unit, an audio processor, a display, and a power supply. The processor (or controller, operation control) used may include a microprocessor or other processor device and / or a logic device, which receives input and controls the operation of various components of the electronic device; the memory may be one or more of a cache, a flash memory, a hard drive, a removable medium, a volatile memory, a non-volatile memory, or other suitable devices, which may store the above-mentioned related data information, and may also store a program for executing related information, and the processor may execute the program stored in the memory to realize information storage or processing, etc.; the input unit is used to provide input to the processor, for example, it may be a key or a touch input device; the power supply is used to provide power to the electronic device; the display is used to display display objects such as images and text, for example, it may be an LCD display. The communication module is a transmitter / receiver that sends and receives signals via an antenna. The communication module (transmitter / receiver) is coupled to the processor to provide input signals and receive output signals, which may be the same as the case of a conventional mobile communication terminal. Based on different communication technologies, multiple communication modules may be provided in the same electronic device, such as a cellular network module, a Bluetooth module and / or a wireless local area network module, etc. The communication module (transmitter / receiver) is also coupled to a speaker and a microphone via an audio processor to provide an audio output via the speaker and receive an audio input from the microphone, thereby realizing a common telecommunication function. The audio processor may include any suitable buffer, decoder, amplifier, etc. In addition, the audio processor is also coupled to a central processor, so that recording can be performed on the machine through the microphone, and the sound stored on the machine can be played through the speaker.
[0072] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0073] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A system that specifies the functions of a box or multiple boxes.
[0074] These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer-readable memory produce a product including an instruction system, which is implemented in the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0075] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps of the functions specified in a box or multiple boxes. Although the preferred embodiments of the present invention have been described, those skilled in the art may make additional changes and modifications to these embodiments once they know the basic creative concept. Therefore, the attached claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the present invention.
[0076] The above is only a preferred specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any changes or substitutions that can be easily thought of by a person skilled in the art within the technical scope disclosed by the present invention should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.
Claims
1. A method for implementing a multi-threaded copy operation of a resource tree, characterized in that: include: S1. Establish a global cache and a global sequence corresponding to the global cache, wherein the global sequence is an increasing sequence; S2. Use the global sequence as the default primary key rule to set the target database primary key ID, use the source database top-level node data and the target database primary key ID to assemble the top-level node parameters and store them in the global cache; S3. Use the top-level node parameters to identify and obtain the number of secondary nodes corresponding to the top-level node data of the source library, and establish a corresponding first counter in the first thread according to the number of secondary nodes; S4, executing a copy operation of the secondary node data, and starting a second thread corresponding to the copy operation, where the second thread is a child thread under the first thread; S5. Determine whether the copy operation of the secondary node data is completed. When it is determined that the copy operation of the secondary node data is completed, use the second thread to operate the first counter to reduce the number of records in the first counter by 1. S6. Determine whether the number of records in the first counter is 0. When it is determined that the number of records in the first counter is 0, call the top-level node parameters from the global cache to assemble all the secondary node data to obtain the copied data, and store the copied data in the target library.
2. The method according to claim 1, characterized in that The step S4 further comprises: Multiple different secondary node data copy operations are executed simultaneously, and multiple second threads corresponding to each copy operation are opened respectively.
3. The method according to claim 1, characterized in that The copy operation of executing the secondary node data includes: The secondary node data and the top node ID as the parent identifier are assembled into secondary node parameters and stored in the global cache; The secondary node data is stored in the global cache according to the secondary node parameters.
4. The method according to claim 3, characterized in that The copy operation of executing the secondary node data also includes: Use the secondary node parameters to identify the number of third-level nodes corresponding to the secondary node data of the source library, and establish a corresponding second counter in the second thread according to the number of third-level nodes; Simultaneously executing a plurality of different third-level node data copy operations, and operating a second counter according to whether the third-level node data copy operations are completed; It is determined whether the number of records in the second counter is 0. When it is determined that the number of records in the second counter is 0, it is confirmed that the copy operation of the corresponding secondary node data is completed.
5. The method according to claim 1, characterized in that The storing the copied data in the target library comprises: Perform paging operations on the copied data; Store multiple different pages to the target library at the same time.
6. The method according to claim 5, characterized in that The storing of the plurality of different pages into the target library comprises: Establish a paging counter based on the number of pages; Execute multiple storage operations of different pages at the same time, and operate the page counter according to whether the storage operation of the page is completed; It is determined whether the number of records in the paging counter is 0. When it is determined that the number of records in the paging counter is 0, it is confirmed that the copied data has been stored in the target library.
7. An operating system for implementing a multi-threaded copy of a resource tree, characterized in that: include: A cache management module, used to establish and operate a global cache and a global sequence corresponding to the global cache; Node parameter management module, used to assemble and manage node parameters; A counter setting module is used to establish corresponding counters according to node parameters; A copy judgment module is used to judge whether the copy operation of the node data is completed; A counter determination module, used to determine whether the number of records in the first counter is 0; The copy execution module is used to assemble and obtain the copy data and store the copy data in the target library.
8. A computer-readable storage medium, characterized in that: The storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.
9. An electronic device, characterized in that: including a processor and a memory; The memory is used to store global cache and copy data; The processor is used to execute the method according to any one of claims 1 to 6 by calling the global cache and copying data.
10. A computer program product comprising a computer program and / or instructions, characterized in that: When the computer program and / or the instructions are executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
