Data storage method, device, electronic device and storage medium
By sharding big data and adaptively adjusting the number of process threads, the problem of low big data storage efficiency is solved, efficient data writing is achieved, and writing efficiency and peak capacity are improved.
Patent Information
- Application Number
- CN201911425297.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-12-31
- Publication Date
- 2024-08-23
- Estimated Expiration
- 2039-12-31
AI Technical Summary
Existing big data storage technology lacks an adaptive mechanism when writing large-scale data, resulting in low storage efficiency, especially in the scenario of writing 1PB data, which takes a long time.
By sharding the data to be stored, determining the number of processes based on the number of data slices, and setting the number of threads for each process according to the preset storage capacity of the computing node, adaptive storage of data is achieved, and the data is stored using a multi-process and multi-thread algorithm. to the target database.
The storage efficiency of large batches of data is significantly improved, the writing efficiency is increased by 10 times, and the peak capacity is increased by 5 times, which solves the problem of lack of controllable adaptive methods in the data writing interface.
Smart Images

Figure CN113127694B
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data storage, and in particular to a data storage method, device, electronic equipment and storage medium. Background Art
[0002] As the Internet migrates to mobile terminals, the data generated by users is increasing explosively. Massive data is the cornerstone for the implementation of various artificial intelligence applications. Massive data has various characteristics, such as high throughput, fast data generation speed, and complex data attributes. Therefore, efficient storage of big data has always been a key component for conducting top-level business. The storage of big data needs to consider various factors. Among them, the most important factor is the speed of reading and writing.
[0003] At present, the optimization of read and write speed of big data storage is mainly focused on the underlying design of the database. For example, for unstructured data, non-relational databases are used for distributed storage. In addition, different databases are also designed in a hierarchical manner for the scalability of the storage system. These improvements are beneficial to the overall performance improvement of the database, but in terms of the data writing interface, there has been no good elastic design mechanism to improve the storage efficiency of big data. For example, for the two situations of writing 1TB of data to the database and writing 1PB of data to the database, the data writing interface requires an adaptive algorithm for intelligent judgment and writing to optimize the efficiency of data writing. Otherwise, it will take a long time for the scenario of writing 1PB. The technical bottleneck is that there is no controllable adaptive method for the data writing interface. This leads to low storage efficiency of large batches of data. Summary of the invention
[0004] An embodiment of the present invention provides a data storage method, which can improve the storage efficiency of large batches of data.
[0005] In a first aspect, an embodiment of the present invention provides a data storage method, the method comprising the following steps:
[0006] Acquire data to be stored, and perform sharding processing on the data to be stored to obtain the number of data shards to be stored;
[0007] Determine the number of processes for storing the data according to the number of data pieces to be stored;
[0008] Set the number of threads corresponding to each process according to the data to be stored and the storage capacity of the preset computing nodes;
[0009] The data to be stored is stored in a target database according to the number of processes and the number of threads of the data to be stored.
[0010] Optionally, the step of determining the number of processes for the data to be stored according to the number of data pieces to be stored includes:
[0011] Compare the number of data pieces to be stored with the number of cores of the preset computing node, and determine whether the number of data pieces to be stored is greater than the number of cores of the preset computing node;
[0012] If the number of data pieces to be stored is greater than the number of cores of the preset computing node, the number of cores of the preset computing node is determined as the number of processes of the data to be stored.
[0013] Optionally, after comparing the number of data pieces to be stored with the number of cores of a preset computing node and determining whether the number of data pieces to be stored is greater than the number of cores of the preset computing node, the step of determining the number of processes of the data to be stored according to the number of data pieces to be stored further includes:
[0014] If the number of data pieces to be stored is less than the number of cores of the preset computing node, the number of cores of the preset computing node is used to determine the number of processes of the data to be stored.
[0015] Optionally, the step of setting the number of threads corresponding to each process according to the data to be stored and the storage capacity of the preset computing node includes:
[0016] Get the data length of each piece of data to be stored;
[0017] The number of threads of each thread is calculated according to the data length and the storage capacity of the preset computing node.
[0018] Optionally, the step of storing the data to be stored in the target database according to the number of processes and the number of threads of the data to be stored includes:
[0019] Get the number of working processes of the process in working state;
[0020] Determine whether the number of working processes exceeds a preset number of working processes;
[0021] If the number of working processes exceeds the preset number of working processes, a preset global lock is called to control the thread corresponding to each process to store the data to be stored in the target database.
[0022] In a second aspect, an embodiment of the present invention further provides a data storage device, the device comprising:
[0023] A sharding processing module is used to obtain data to be stored, and to perform sharding processing on the data to be stored to obtain the number of data shards to be stored;
[0024] A process number determination module, used to determine the number of processes for the data to be stored according to the number of data pieces to be stored;
[0025] A thread number setting module is used to set the number of threads corresponding to each process according to the data to be stored and the storage capacity of the preset computing node;
[0026] The data storage module is used to store the data to be stored in a target database according to the number of processes and the number of threads of the data to be stored.
[0027] Optionally, the module for determining the number of processes for storing data includes:
[0028] A judging unit, configured to compare the number of data pieces to be stored with the number of cores of a preset computing node, and to judge whether the number of data pieces to be stored is greater than the number of cores of the preset computing node;
[0029] The first determining unit is used to determine the number of processes of the data to be stored based on the number of cores of the preset computing node if the number of the data pieces to be stored is less than the number of cores of the preset computing node.
[0030] Optionally, after the judging unit, the module for determining the number of pending processes further includes:
[0031] The second determining unit is used to calculate the number of threads of each thread according to the data length and the storage capacity of the preset computing node.
[0032] In a third aspect, an embodiment of the present invention further provides an electronic device, comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps in the data storage method provided in the above embodiment when executing the computer program.
[0033] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps in the data storage method provided in the above embodiment are implemented.
[0034] In an embodiment of the present invention, the data to be stored is obtained and the data to be stored is sliced to obtain the number of data slices to be stored; the number of processes of the data to be stored is determined according to the number of data slices to be stored; the number of threads corresponding to each process is set according to the data to be stored and the storage capacity of the preset computing node; the data to be stored is stored in the target database according to the number of processes of the data to be stored and the number of threads. The present invention can adaptively adjust the number of processes of the data to be stored according to the number of data slices to be stored and set the number of threads of each process according to the storage capacity of the preset computing node, and store the data to be stored in the target data based on the number of processes of the data to be stored and the processes and threads corresponding to the number of threads. Thereby, the storage efficiency of large batches of data can be improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0036] Figure 1 is a flow chart of a data storage method provided by an embodiment of the present invention;
[0037] Figure 2 yes Figure 1 A flowchart of a method provided in step 102 of the embodiment;
[0038] Figure 3 is a flow chart of a method provided in step 102 in an embodiment of the present invention;
[0039] Figure 4 yes Figure 1 A flowchart of a data method provided in step 103 of the embodiment;
[0040] Figure 5 yes Figure 1 A method flow chart provided in step 104 of the embodiment;
[0041] Figure 6 is a structural schematic diagram of a data storage device provided by an embodiment of the present invention;
[0042] Figure 7 yes Figure 6 A schematic diagram of a structure provided by a process number determination module in an embodiment;
[0043] Figure 8 It is a structural schematic diagram provided by a process number determination module in an embodiment of the present invention;
[0044] Fig. 9 yes Figure 6 A structural schematic diagram provided by a thread number setting module in an embodiment;
[0045] Fig.10 yes Figure 6 A schematic diagram of the structure of a data storage device provided by a data storage module in an embodiment;
[0046] Fig.11 It is a structural schematic diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0047] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only 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.
[0048] See also Figure 1 , Figure 1 is a flow chart of a data storage method provided by an embodiment of the present invention, such as Figure 1 As shown, the data storage method includes the following steps:
[0049] Step 101: Acquire the data to be stored, and perform sharding on the data to be stored to obtain the number of data shards to be stored.
[0050] The data to be stored may be data that needs to be stored in the target data. The data volume level of the data to be stored may be a large volume, a medium volume, a small volume, etc. The number of data slices to be stored may be the number of data slices obtained after slicing the acquired data to be stored. Each data slice to be stored contains multiple data to be stored.
[0051] Specifically, after obtaining the data to be stored, all the data to be stored are sliced according to the preset data volume, and then the number of data slices to be stored corresponding to the data slices to be stored is obtained. For example, now 1 million pieces of data to be stored are obtained, and the preset data volume is 100,000 (10 pieces of data to be stored are divided into one data slice to be stored), then the 1 million pieces of data to be stored can be divided into 10 data slices to be stored. At this time, the number of data slices to be stored is 10. Of course, the preset data volume can be set according to the amount of data to be stored.
[0052] Step 102: Determine the number of processes for storing data according to the number of data pieces to be stored.
[0053] The number of processes for the data to be stored is the number of processes configured for the data to be stored, for example, if there are 10 processes, the corresponding number of processes is 10. The process refers to a program running in a computer, and is the basic unit for capacity allocation and scheduling of the system.
[0054] For details, see Figure 2 , Figure 2 yes Figure 1 Step 102 in the embodiment provides a flow chart of a method, such as Figure 2 As shown, step 102 specifically includes the following steps:
[0055] Step 201: compare the number of data pieces to be stored with the number of cores of the preset computing node, and determine whether the number of data pieces to be stored is greater than the number of cores of the preset computing node.
[0056] Step 202: If the number of data pieces to be stored is greater than the number of cores of the preset computing node, determine the number of processes for the data to be stored to be the number of cores of the preset computing node.
[0057] The above-mentioned preset computing node may be a pre-set processor for computing and processing data, such as a CPU. The number of cores of the above-mentioned preset computing node may refer to the number of cores of the CPU. For example, common CPU cores include dual-core, quad-core, hexa-core, octa-core, and twelve-core. The number of preset computing nodes may be multiple. The number of cores of the preset computing node may also be multiple.
[0058] Specifically, after determining the number of data pieces to be stored, the number of data pieces to be stored can be compared with the number of cores of each preset computing node, and then the comparison result can be used to determine whether the number of data pieces to be stored is greater than the number of cores of the preset computing node. When the number of data pieces to be stored is greater than the number of cores of the preset computing node, the number of cores of the preset computing node can be directly determined as the number of processes. For example, the number of data pieces to be stored is 10, and the number of cores of the preset computing node is 8, and 10>8, which shows that the number of data pieces to be stored is greater than the number of cores of the preset computing node. When the number of data pieces to be stored is greater than the number of cores of the preset computing node, the number of cores of the preset computing node can be determined as the number of processes. In the example of 10>8, the number of processes can be determined to be 8.
[0059] Optional, see Figure 3 , Figure 3 is a flow chart of a method provided in step 102 in an embodiment of the present invention, Figure 2 On the basis of Figure 3 As shown, step 102 also includes the steps of:
[0060] Step 301: If the number of data pieces to be stored is less than the number of cores of the preset computing node, the number of processes of the data to be stored is determined to be the number of data pieces to be stored.
[0061] Specifically, when it is determined that the number of data pieces to be stored is less than the number of cores of the preset computing node, the number of processes can be automatically set to the number of data pieces to be stored. For example, there are 8 data pieces to be stored, and the number of cores of the preset computing node is 12, and 8<12, so it can be known that the number of data pieces to be stored is less than the number of cores of the preset computing node. At this time, the number of data pieces to be stored, 8, can be determined as the number of processes, and the number of processes is 8.
[0062] It should be noted that, when the number of preset computing nodes is 1, the number of cores of the preset computing node is compared with the number of acquired data slices to be stored, and the number of processes of the preset computing node is determined based on the comparison result.
[0063] When there are multiple preset computing nodes, the number of processes corresponding to each preset computing node is adjusted for each preset computing node according to step 102 .
[0064] Step 103: Set the number of threads corresponding to each process according to the data to be stored and the storage capacity of the preset computing node.
[0065] Among them, the storage capacity of the above-mentioned preset computing node is the memory resources that the preset computing node can currently use for computing. The storage capacity of the preset computing node can be set to 4G, 8G, 64G, 128, 256G, 1T, etc., and the storage capacity of the preset computing node can be set according to the actual computing node. The storage capacity can be preset. The more memory resources the preset computing node can currently use for computing, the more threads are set. The smaller the memory resources that the preset computing node can currently use for computing, the fewer threads are set. Among them, the number of threads can be called thread resources.
[0066] For details, see Figure 4 , Figure 4 yes Figure 1 Step 103 in the embodiment provides a flow chart of a method, such as Figure 4 As shown, step 103 specifically includes the steps of:
[0067] Step 401: Obtain the data length of each piece of data to be stored.
[0068] Step 402: Calculate the number of threads for each thread according to the data length and the storage capacity of the preset computing node.
[0069] The data length is the data size corresponding to each piece of data to be stored in the acquired data to be stored. For example, if the size of a piece of data to be stored is 4 KB, it means that the length of the piece of data to be stored is 4 KB.
[0070] Specifically, after determining the data length of each piece of data to be stored, the number of threads corresponding to each thread can be calculated in combination with the storage capacity of the preset computing node. For example, the storage capacity of the preset computing node is M. The data length of each piece of data to be stored is S, so the number of threads N can be calculated using the formula N = (MS) / S. In this way, the number of processes corresponding to the data to be stored and the number of threads corresponding to each process can be adjusted according to the data to be stored, thereby making full use of threads to pre-process the process of the data to be stored.
[0071] Step 104: store the data to be stored in the target database according to the number of processes and threads of the data to be stored.
[0072] The target database is a database for storing data to be stored. The target database may be a distributed database. A distributed database is a multi-node database. The target database can provide enough space to store the data to be stored.
[0073] Specifically, after the number of threads and the number of threads of each process are adjusted according to the data to be stored, the process data of the data to be stored can be processed through the established processes and threads, and the data to be stored can be stored in the target database.
[0074] Specifically, executing steps 101 to 104 is a multi-process and multi-thread algorithm. The multi-process and multi-thread algorithm is: in one node, multiple processes are started; and in one process, multiple threads are started.
[0075] As another implementation method, copy the data to be stored to a preset computing node, and determine the path of the preset computing node; configure the data structured node port; configure the target database port; determine the data path; read in the data; create a data table; multi-thread plus multi-thread extract the features of the data to be stored, and store it in the target database after processing the feature data; again determine whether the current preset computing node has processed the data structure; if so, repeat the determination of the data path; if not, multi-thread plus multi-thread extract the features of the data to be stored, and store it in the target database after processing the feature data. In this way, all the data to be stored are stored in the target database.
[0076] Exemplarily, certain data to be stored are tested by executing steps 101 - 104 : the test items include: 1. writing efficiency test; 2. writing capacity test.
[0077] 1. The write efficiency test is:
[0078] After actual testing, for each 4KB data to be stored, a single machine with 28 cores (CPU 3.6GHz) and 256G memory can write 10,000-20,000 records per second. For tens to hundreds of millions of data, a single machine can complete the processing within a few hours.
[0079] 2. Write capacity test:
[0080] For the test of write capacity, the peak write capacity of this patent can reach 100M / s.
[0081] Compared with the existing solution: The existing solution maintains the writing efficiency of several thousand records per second for the tested scenario. This patent improves the efficiency by 10 times. In terms of capacity, the peak capacity of the original technology writing to the database is 20M / second, and this patent improves it by 5 times.
[0082] In an embodiment of the present invention, the number of data pieces to be stored is obtained by acquiring data to be stored and performing slicing processing on the data to be stored; the number of processes is determined according to the number of data pieces to be stored; the number of threads corresponding to each process is set according to the preset storage capacity of the computing node; and the data to be stored is stored in the target database through threads. The present invention can adaptively adjust the number of processes according to the number of data pieces to be stored of the data to be stored and set the number of threads for each process according to the preset storage capacity of the computing node, and store the data to be stored in the target data based on the number of processes of the data to be stored and the processes and threads corresponding to the number of threads. Thereby, the storage efficiency of large batches of data can be improved.
[0083] See also Figure 5 , Figure 5 yes Figure 1 Step 104 in the embodiment provides a method flow chart, such as Figure 5 As shown, step 104 includes the following steps:
[0084] Step 501: Get the number of working processes of the processes in working state.
[0085] Step 502: Determine whether the number of working processes exceeds the preset number of working processes.
[0086] Step 503: If the number of working processes exceeds the preset number of working processes, a preset global lock is called to control the thread corresponding to each process to store the data to be stored in the target database.
[0087] Among them, when a process is running, it means that the process is in a working state. When multiple processes are set, it is necessary to count the number of processes in a working state. The above-mentioned preset number of working processes is a preset threshold value of the number of working processes, which is used to determine whether the number of write processes has reached a peak value. The above-mentioned preset global lock is preset, and the above-mentioned preset global lock is a Python global lock. Python is a high-level computer programming language. The implementation language in the embodiment of the present invention is specifically Python.
[0088] Specifically, after counting the number of working processes of the processes in the working state, the counted number of working processes is compared with the preset number of working processes, and it is determined whether the number of working processes exceeds the preset number of working processes. When it is determined that the number of working processes is greater than the preset number of working processes, it means that the number of working processes exceeds the preset number of working processes. If it is determined that the number of working processes is less than or equal to the preset number of working processes, it is determined that the number of working processes does not exceed the preset number of working processes. If the number of working processes exceeds the preset number of working processes, this can directly call a preset global lock that is set in advance to control each thread in each process to process the data to be stored and store it in the target database.
[0089] It should be noted that there may be resource conflicts between different threads when writing to the database. Therefore, we make full use of the function of Python global lock. We design a multi-threaded global lock. When the number of write processes in the distributed database reaches the peak, the multi-threaded global lock is activated. This global lock solves the conflict problem of multi-threaded writing.
[0090] In the embodiment of the present invention, each thread in each process is controlled by calling a preset global lock, thereby solving the conflict problem of multi-thread writing and further improving the storage efficiency of large batches of data.
[0091] See also Figure 6 , Figure 6 is a schematic diagram of the structure of a data storage device provided by an embodiment of the present invention, the data storage device 600 includes:
[0092] The shard processing module 601 is used to obtain the data to be stored, and perform shard processing on the data to be stored to obtain the number of data slices to be stored;
[0093] The process number determination module 602 is used to determine the number of processes according to the number of data pieces to be stored;
[0094] The thread number setting module 603 is used to set the number of threads corresponding to each process according to the preset computing node storage capacity;
[0095] The data storage module 604 is used to store the data to be stored in the target database through threads.
[0096] Optional, see Figure 7 , Figure 7 yes Figure 6 A schematic diagram of a structure provided by a process number determination module in an embodiment, the process number determination module 602 includes:
[0097] The judging unit 6021 is used to compare the number of data pieces to be stored with the number of cores of the preset computing node, and judge whether the number of data pieces to be stored is greater than the number of cores of the preset computing node;
[0098] The first determining unit 6022 is used to determine the number of processes of the data to be stored to be the number of cores of the preset computing node if the number of data pieces to be stored is greater than the number of cores of the preset computing node.
[0099] Optional, see Figure 8 , Figure 8 is a schematic diagram of a structure provided by a process number determination module in an embodiment of the present invention. Figure 7 On the basis of, after the judgment unit 6021, the process number determination module 602 further includes:
[0100] The second determining unit 6023 is used to determine the number of processes of the data to be stored as the number of data pieces to be stored if the number of data pieces to be stored is less than the number of cores of the preset computing node.
[0101] Optional, see Fig. 9 , Fig. 9 yes Figure 6 A structural diagram of a thread number setting module provided in the embodiment, the thread number setting module 603 includes:
[0102] The first acquisition unit 6031 is used to acquire the data length of each piece of data to be stored;
[0103] The thread number calculation module 6032 is used to calculate the thread number according to the data length and the preset computing node storage capacity.
[0104] Optional, see Fig.10 , Fig.10 yes Figure 6 A schematic diagram of a structure of a data storage device provided by a data storage module in the embodiment, wherein the data storage module 604 comprises:
[0105] The second acquisition unit 6041 is used to acquire the number of working processes of the processes in working state;
[0106] The judging unit 6042 is used to judge whether the number of working processes exceeds the preset number of working processes;
[0107] The calling unit 6043 is used to call a preset global lock if the number of working processes exceeds a preset number of working processes, so as to control the thread to store the data to be stored in the target database.
[0108] The data storage device 600 provided in the embodiment of the present invention can implement various implementation methods and corresponding beneficial effects in the above method embodiment, which will not be described again here to avoid repetition.
[0109] See also Fig.11 , Fig.117 is a schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. The electronic device 700 includes: a memory 702, a processor 701, and a computer program stored in the memory 702 and executable on the processor 701. When the processor 701 executes the computer program, the steps in the data storage method provided in the above embodiment are implemented. The processor 701 performs the following steps:
[0110] Obtain the data to be stored, and perform sharding on the data to be stored to obtain the number of data shards to be stored;
[0111] Determine the number of processes for storing data according to the number of data pieces to be stored;
[0112] Set the number of threads corresponding to each process according to the data to be stored and the storage capacity of the preset computing nodes;
[0113] The data to be stored is stored in the target database according to the number of processes and threads of the data to be stored.
[0114] Optionally, the step of determining the number of processes for storing data according to the number of data pieces to be stored, performed by the processor 701, includes:
[0115] Compare the number of data pieces to be stored with the number of cores of the preset computing node, and determine whether the number of data pieces to be stored is greater than the number of cores of the preset computing node;
[0116] If the number of data pieces to be stored is greater than the number of cores of the preset computing node, the number of cores of the preset computing node is determined as the number of processes for the data to be stored.
[0117] Optionally, after the processor 701 compares the number of data pieces to be stored with the number of cores of the preset computing node and determines whether the number of data pieces to be stored is greater than the number of cores of the preset computing node, the step of determining the number of processes for the data to be stored according to the number of data pieces to be stored further includes:
[0118] If the number of data pieces to be stored is less than the number of cores of the preset computing node, the number of cores of the preset computing node is used to determine the number of processes for the data to be stored.
[0119] Optionally, the step of setting the number of threads corresponding to each process according to the data to be stored and the storage capacity of the preset computing node, performed by the processor 701, includes:
[0120] Get the data length of each piece of data to be stored;
[0121] The number of threads for each thread is calculated based on the data length and the storage capacity of the preset computing node.
[0122] Optionally, the step of storing the data to be stored in the target database according to the number of processes and the number of threads of the data to be stored, performed by the processor 701, includes:
[0123] Get the number of working processes of the process in working state;
[0124] Determine whether the number of working processes exceeds the preset number of working processes;
[0125] If the number of working processes exceeds the preset number of working processes, the preset global lock is called to control the thread corresponding to each process to store the data to be stored in the target database.
[0126] It should be noted that the electronic device 700 may be a smart terminal, a mobile phone, a tablet computer or other device in a data storage system.
[0127] The electronic device 700 provided in the embodiment of the present invention can implement various implementations in the above method embodiment and the corresponding beneficial effects, which will not be described again here to avoid repetition.
[0128] An embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the various processes of the data storage method provided by the embodiment of the present invention are implemented, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.
[0129] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through a computer program, and the program can be stored in a computer-readable storage medium, and when the program is executed, it can include the processes of the embodiments of the above-mentioned methods. The storage medium can be a disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM).
[0130] The above disclosure is only the preferred embodiment of the present invention, which certainly cannot be used to limit the scope of the present invention. Therefore, equivalent changes made according to the claims of the present invention are still within the scope of the present invention.
Claims
1. A data storage method, characterized in that: The method comprises the following steps: Obtaining data to be stored, and slicing all the data to be stored according to a preset partitioning data amount to obtain the number of data slices to be stored, each of which contains multiple data to be stored, and the preset partitioning data amount is set according to the amount of data to be stored; Determine the number of processes for storing the data according to the number of data pieces to be stored; Set the number of threads corresponding to each process according to the data to be stored and the storage capacity of the preset computing nodes; According to the number of processes and the number of threads of the data to be stored, the data to be stored is stored in a target database, wherein the target database is a distributed database, and the distributed database is a multi-node database; when there are multiple preset computing nodes, the number of processes corresponding to each preset computing node is adjusted for each preset computing node; The step of setting the number of threads corresponding to each process according to the data to be stored and the storage capacity of the preset computing node includes: Obtain the data length of each piece of data to be stored, where the data length is the data size corresponding to each piece of data to be stored in the acquired data to be stored; The number of threads of each process is calculated according to the data length and the storage capacity of the preset computing node, and the number of threads corresponding to each process is calculated according to the data length of each data to be stored and the storage capacity of the preset computing node. The storage capacity of the preset computing node is M, and the data length of each data to be stored is S. Then the number of threads N is calculated using the formula N=(MS) / S; the storage capacity of the preset computing node is the memory resources currently available for calculation by the preset computing node.
2. The data storage method according to claim 1, characterized in that: The step of determining the number of processes for storing data according to the number of data pieces to be stored comprises: Compare the number of data pieces to be stored with the number of cores of the preset computing node, and determine whether the number of data pieces to be stored is greater than the number of cores of the preset computing node; If the number of data pieces to be stored is greater than the number of cores of the preset computing node, the number of cores of the preset computing node is determined as the number of processes of the data to be stored.
3. The data storage method according to claim 2, characterized in that: After comparing the number of data pieces to be stored with the number of cores of the preset computing node and determining whether the number of data pieces to be stored is greater than the number of cores of the preset computing node, the step of determining the number of processes of the data to be stored according to the number of data pieces to be stored further includes: If the number of data pieces to be stored is less than the number of cores of the preset computing node, the number of data pieces to be stored is used to determine the number of processes of the data to be stored.
4. The data storage method according to claim 1, characterized in that: The step of storing the data to be stored in the target database according to the number of processes and the number of threads of the data to be stored comprises: Get the number of working processes of the process in working state; Determine whether the number of working processes exceeds a preset number of working processes; If the number of working processes exceeds the preset number of working processes, a preset global lock is called to control the thread corresponding to each process to store the data to be stored in the target database.
5. A data storage device, characterized in that: The device comprises: A sharding processing module is used to obtain data to be stored, and shard all the data to be stored according to a preset amount of divided data to obtain a number of data slices to be stored, each of which contains multiple data to be stored, and the preset amount of divided data is set according to the amount of data to be stored; A process number determination module, used to determine the number of processes for the data to be stored according to the number of data pieces to be stored; A thread number setting module is used to set the number of threads corresponding to each process according to the data to be stored and the storage capacity of the preset computing node; A data storage module, used for storing the data to be stored in a target database according to the number of processes and the number of threads of the data to be stored, wherein the target database is a distributed database, and the distributed database is a multi-node database; when there are multiple preset computing nodes, the number of processes corresponding to each preset computing node is adjusted for each preset computing node; A first acquisition unit is used to acquire the data length of each piece of data to be stored, where the data length is the data size corresponding to each piece of data to be stored in the acquired data to be stored; The thread number calculation module is used to calculate the number of threads of each process according to the data length and the storage capacity of the preset computing node, and to calculate the number of threads corresponding to each thread according to the data length of each data to be stored and the storage capacity of the preset computing node. The storage capacity of the preset computing node is M, and the data length of each data to be stored is S. Then the number of threads N is calculated using the formula N=(MS) / S, and the storage capacity of the preset computing node is the memory resources currently available for calculation by the preset computing node.
6. The data storage device according to claim 5, characterized in that The process number determination module comprises: A judging unit, configured to compare the number of data pieces to be stored with the number of cores of a preset computing node, and to judge whether the number of data pieces to be stored is greater than the number of cores of the preset computing node; The first determining unit is used to determine the number of processes of the data to be stored based on the number of cores of the preset computing node if the number of the data pieces to be stored is less than the number of cores of the preset computing node.
7. The data storage device according to claim 6, wherein: After the judging unit, the process number determination module for the data to be stored further includes: The second determining unit is used to calculate the number of threads of each thread according to the data length and the storage capacity of the preset computing node.
8. An electronic device, characterized in that: include: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the data storage method according to any one of claims 1 to 4 when executing the computer program.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps in the data storage method according to any one of claims 1 to 4 are implemented.
