File transmission method and device, electronic equipment and storage medium
By using shared memory disks and thread pool mechanisms in big data processing, the problem of low transmission efficiency caused by a large number of files in a single directory in real-time computing file transmission is solved, and file transmission is made efficient and stable.
Patent Information
- Application Number
- CN202311633872.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-11-30
- Publication Date
- 2024-10-18
AI Technical Summary
In the process of big data processing, when transferring files generated by real-time calculations, a large number of files in a single file directory causes the file directory to be unable to display file information, reducing the transmission rate and efficiency.
A shared memory disk is used for file storage and transmission. By obtaining file information and determining the capacity occupancy of the shared memory disk, the file information is stored in the working directory when the storage requirements are met, and the file information is sent to the external receiving end through the thread pool and detected regularly. Communication connection exception and processing failed file.
Ensure the integrity and efficiency of file transfer, improve the file processing speed and stability of the system, and make the file transfer process convenient and efficient.
Smart Images

Figure CN118796499A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the technical field of communication technology, and in particular to a method, device, electronic device and storage medium for file transmission. Background Art
[0002] In the process of processing big data files, there are two data processing methods: real-time computing and offline computing. Real-time computing is mainly used in scenarios with strong timeliness. It is generally responsible for real-time computing of data. The results of real-time computing can be used for subsequent offline computing in data warehouses. The output of the results has multiple forms, including message queues, memory databases, local files, etc. In the process of processing files, the local files generated by real-time computing need to be transferred to the directory of the specified machine for subsequent system calls to related files.
[0003] In the related art, the target file is transmitted through multiple threads, the main thread detects the file directory of the target file in real time, queries the file information under the file directory as needed, puts the untransmitted file information into a shared queue, and the sub-thread obtains the untransmitted file information from the shared queue and transmits it. However, the file directory of the transmitted file is a single directory. When the file directory contains a large number of files during the file transmission process, the file directory will not be able to display the file information under the file directory, resulting in incomplete file information of the transmitted file, thereby reducing the file transmission rate and affecting the file transmission efficiency. Summary of the invention
[0004] The embodiments of the present disclosure at least provide a method, device, electronic device and storage medium for file transmission.
[0005] In a first aspect, an embodiment of the present disclosure provides a method for file transmission, including:
[0006] Acquire file information of an externally input target file; wherein the file information is used to indicate file content information of the target file and an external receiving end of the target file;
[0007] Determine first capacity occupancy information of a shared memory disk; wherein the shared memory disk is a memory space used to store the target file;
[0008] When it is determined based on the first capacity occupancy information that the shared memory disk meets the first storage requirement, storing the file information of the target file in a first working directory of the shared memory disk;
[0009] Sending file information of the target file stored in the first working directory to the external receiving end.
[0010] In an optional implementation manner, sending the file information of the target file stored in the first working directory to the external receiving end includes:
[0011] Traversing the file information stored in the first working directory, obtaining the file information to be sent at the current moment, and determining a sending rule for the file information to be sent;
[0012] Determine the thread pool corresponding to the file information to be sent according to the sending rule;
[0013] The file information to be sent is added to a queue to be sent corresponding to the thread pool, and the file information to be sent in the queue to be sent is sent to the external receiving end through the thread pool.
[0014] In an optional implementation manner, the method further includes:
[0015] In the process of transmitting the to-be-sent file information in the to-be-sent queue to the external receiving end through the thread pool, regularly detecting whether there is an abnormality in the communication connection between the thread pool and the external receiving end;
[0016] When an abnormality is detected in the communication connection, the information of the to-be-sent files that failed to be sent in the to-be-sent queue is transferred to a sending failure directory of the target hard disk.
[0017] In an optional implementation manner, after transferring the information of the to-be-sent files that failed to be sent in the to-be-sent queue to the failed-to-send directory of the target hard disk, the method further includes:
[0018] When it is detected that the communication connection is normal and that the shared memory disk meets the second storage requirement, the information of the to-be-sent files that failed to be sent in the sending failure directory is transferred to the first working directory.
[0019] In an optional implementation manner, the method further includes:
[0020] When it is determined based on the first capacity occupancy information that the shared memory disk does not meet the first storage requirement, the file information of the target file is stored in a buffer directory of the target hard disk.
[0021] In an optional implementation manner, the method further includes:
[0022] Regularly detecting the capacity occupancy information of the shared memory disk to obtain second capacity occupancy information;
[0023] When it is determined based on the second capacity occupancy information that the shared memory disk meets the second storage requirement, part of the file information stored in the buffer directory is transferred to the first working directory.
[0024] In an optional implementation manner, the method further includes:
[0025] After acquiring the file information of the externally input target file, the file information is backed up to a backup directory of the target hard disk.
[0026] In a second aspect, an embodiment of the present disclosure provides a device for file transmission, including:
[0027] An acquisition unit, used for acquiring file information of an externally input target file; wherein the file information is used for indicating file content information of the target file and an external receiving end of the target file;
[0028] A determination unit, configured to determine first capacity occupancy information of a shared memory disk; wherein the shared memory disk is a memory space used to store the target file;
[0029] a storage unit, configured to store file information of the target file in a first working directory of the shared memory disk when it is determined that the shared memory disk meets a first storage requirement based on the first capacity occupancy information;
[0030] A sending unit is used to send the file information of the target file stored in the first working directory to the external receiving end.
[0031] In a third aspect, an embodiment of the present disclosure further provides an electronic device, comprising: a processor, a memory and a bus, wherein the memory stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor and the memory communicate via the bus, and when the machine-readable instructions are executed by the processor, the steps of the above-mentioned first aspect, or any possible implementation of the first aspect are performed.
[0032] In a fourth aspect, an embodiment of the present disclosure further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the above-mentioned first aspect or any possible implementation of the first aspect are executed.
[0033] In an embodiment of the present application, file information of an externally input target file is first obtained, and first capacity occupancy information of a shared memory disk storing the target file is determined; when it is determined that the shared memory disk meets the first storage requirement based on the first capacity occupancy information, the file information of the target file is stored in a first working directory of the shared memory disk, and the file information of the target file stored in the first working directory is sent to an external receiving end.
[0034] In the above implementation mode, a shared memory disk is used to store file information of externally input target files, a large number of files can be stored and processed, and the integrity of the file information of the target files is retained. The first capacity information of the shared memory disk is determined based on the file information of the target files. When it is determined that the first capacity information meets the first storage requirement, the file information of the target file is moved to the first working directory, thereby improving the file processing speed and system stability of the system and making the file transfer process convenient and efficient.
[0035] In order to make the above-mentioned objectives, features and advantages of the present disclosure more obvious and easy to understand, preferred embodiments are specifically cited below and described in detail with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] In order to more clearly illustrate the technical solutions of the embodiments of the present disclosure, the following is a brief introduction to the drawings required for use in the embodiments. The drawings herein are incorporated into the specification and constitute a part of the specification. These drawings illustrate embodiments consistent with the present disclosure and are used together with the specification to illustrate the technical solutions of the present disclosure. It should be understood that the following drawings only illustrate certain embodiments of the present disclosure and should not be regarded as limiting the scope. For ordinary technicians in this field, other relevant drawings can also be obtained based on these drawings without creative work.
[0037] Figure 1 A flowchart of a file transmission method provided by an embodiment of the present disclosure is shown;
[0038] Figure 2 A system architecture diagram of a file transmission method provided by an embodiment of the present disclosure is shown;
[0039] Figure 3 An overall processing flow chart of a file transmission method provided by an embodiment of the present disclosure is shown;
[0040] Figure 4 A flowchart of a receiving module of a file transmission method provided by an embodiment of the present disclosure is shown;
[0041] Figure 5 A flow chart of a sending module of a file transmission method provided by an embodiment of the present disclosure is shown;
[0042] Figure 6 A flowchart of buffer scheduling of a file transmission method provided by an embodiment of the present disclosure is shown;
[0043] Figure 7 A flowchart of a failed retransmission of a file transmission method provided by an embodiment of the present disclosure is shown;
[0044] Figure 8 A schematic diagram of a file transmission device provided by an embodiment of the present disclosure is shown;
[0045] Fig. 9 A schematic diagram of an electronic device provided by an embodiment of the present disclosure is shown. DETAILED DESCRIPTION
[0046] In order to make the purpose, technical scheme and advantages of the embodiments of the present disclosure clearer, the technical scheme in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings in the embodiments of the present disclosure. Obviously, the described embodiments are only part of the embodiments of the present disclosure, rather than all of the embodiments. The components of the embodiments of the present disclosure generally described and shown in the drawings here can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present disclosure provided in the drawings is not intended to limit the scope of the present disclosure for protection, but merely represents the selected embodiments of the present disclosure. Based on the embodiments of the present disclosure, all other embodiments obtained by those skilled in the art without making creative work belong to the scope of protection of the present disclosure.
[0047] It should be noted that similar reference numerals and letters denote similar items in the following drawings, and therefore, once an item is defined in one drawing, further definition and explanation thereof is not required in subsequent drawings.
[0048] The term "and / or" herein only describes an association relationship, indicating that three relationships may exist. For example, A and / or B may represent three situations: A exists alone, A and B exist at the same time, and B exists alone. In addition, the term "at least one" herein represents any combination of at least two of any one or more of a plurality of. For example, including at least one of A, B, and C may represent including any one or more elements selected from the set consisting of A, B, and C.
[0049] In the process of processing big data files, there are two data processing methods: real-time computing and offline computing. Real-time computing, also known as stream computing and streaming processing, is mainly used in scenarios with strong timeliness. Generally, real-time computing is performed on data. The results of real-time computing can be used for subsequent offline computing in data warehouses. The output of the results has multiple forms, including message queues, memory databases, local files, etc. In the process of processing files, the local files generated by real-time computing need to be transferred to the directory of the specified machine for subsequent system calls to related files.
[0050] In the related art, files are transferred through multiple threads, the main thread monitors the file directory in real time, queries the files in the file directory as needed, determines whether the queried files have been transferred, puts the untransmitted files into a shared queue, and the sub-threads obtain and transfer them from the shared queue, and also processes through multiple intermediate components to complete the file transfer. However, the input directory for the transferred files is a single directory. When a single directory of the operating system contains a large number of files, the system command will be unable to list the files in the directory, causing the program to crash, thereby reducing the file transfer rate, and the system architecture is complex, affecting the efficiency of file transfer.
[0051] Based on the above research, the present disclosure provides a method, device, electronic device and storage medium for file transmission. In an embodiment of the present application, firstly, file information of an externally input target file is obtained, and first capacity occupancy information of a shared memory disk storing the target file is determined, and then, when it is determined according to the first capacity occupancy information that the shared memory disk meets the first storage requirement, the file information of the target file is stored in the first working directory of the shared memory disk, and finally, the file information of the target file stored in the first working directory is sent to an external receiving end.
[0052] In the above implementation mode, a shared memory disk is used to store file information of externally input target files, a large number of files can be stored and processed, and the integrity of the file information of the target files is retained. The first capacity information of the shared memory disk is determined based on the file information of the target files. When it is determined that the first capacity information meets the first storage requirement, the file information of the target file is moved to the first working directory, thereby improving the file processing speed and system stability of the system and making the file transfer process convenient and efficient.
[0053] To facilitate understanding of this embodiment, a file transmission method disclosed in the embodiment of the present disclosure is first introduced in detail. The execution subject of the file transmission method provided in the embodiment of the present disclosure is generally an electronic device with certain computing capabilities. In some possible implementations, the file transmission method can be implemented by a processor calling a computer-readable instruction stored in a memory.
[0054] See also Figure 1FIG. 1 is a flowchart of a file transmission method provided by an embodiment of the present disclosure, wherein the method includes steps S101 to S104, wherein:
[0055] Step S101: Acquire file information of an externally input target file; wherein the file information is used to indicate file content information of the target file and an external receiving end of the target file;
[0056] Here, the target file may be a real-time file obtained through real-time calculation of big data, or may be a file obtained from other systems. The embodiment of the present application does not specifically limit the method for generating the target file.
[0057] Here, the file content information includes the file name, file content, and file receiving time of the target file.
[0058] After obtaining the file information of the externally input target file, the file information of the externally input target file can be stored in an input directory, wherein the input directory is a directory under a shared memory disk, and the path of the input directory can be described as: / dev / shm / a.
[0059] In the above implementation, by acquiring the file information of the externally input target file and determining the file name of the target file and the corresponding external receiving end, the file reading and writing rate can be improved when processing a large number of files.
[0060] Step S102: determining first capacity occupancy information of a shared memory disk; wherein the shared memory disk is a memory space used to store the target file;
[0061] Here, the first capacity occupancy information may be the file volume of the target file stored in the input directory, and the remaining space capacity of the shared memory disk may be obtained through the first capacity occupancy information.
[0062] Step S103: when it is determined based on the first capacity occupancy information that the shared memory disk meets the first storage requirement, the file information of the target file is stored in the first working directory of the shared memory disk.
[0063] Here, when it is determined that the first capacity occupancy information is less than the first capacity threshold, it is determined that the shared memory disk meets the first storage requirement, and at this time, the file information of the target file can be stored in the first working directory. The first working directory can be a directory in the shared memory disk for storing file information to be transmitted, and the path of the first working directory can be described as: / dev / shm / b.
[0064] When it is determined that the first capacity occupancy information is greater than or equal to the first capacity threshold, it is determined that the shared memory disk does not meet the first storage requirement. At this time, it is necessary to reduce the occupied capacity of the shared memory disk to increase the transmission rate of the shared memory disk.
[0065] In the embodiment of the present application, the first capacity threshold may be set to a value such as 60%, 65%, or 70%, and the corresponding first capacity threshold may be set according to the size of the transferred file, which is not specifically limited here.
[0066] Step S104: Sending the file information of the target file stored in the first working directory to the external receiving end.
[0067] Here, the external receiving end is a receiving end of an external receiving unit, which is used to receive the file information of the target file. In an embodiment of the present application, the corresponding file information can be sent to the external receiving end in the order in which the target files are sent. The external receiving end can sort the file information of the target file in the order of receiving time, so as to facilitate the search for the corresponding file in the external receiving unit.
[0068] It can be seen from the above description that in the embodiment of the present application, the remaining space capacity of the shared memory disk can be determined according to the first capacity occupancy information of the shared memory disk, thereby obtaining the capacity occupancy of the shared memory disk. If it is determined according to the remaining space capacity that the shared memory disk meets the first storage requirement, the method of sending the file information of the target file stored in the first working directory to the external receiving end can ensure the efficient transmission of the shared memory disk, improve the stability of the system, and improve the resource utilization and system stability of the system.
[0069] In an optional implementation, the step S104 sends the file information of the target file stored in the first working directory to the external receiving end, including:
[0070] Step S21: traverse the file information stored in the first working directory, obtain the file information to be sent at the current moment, and determine the sending rule of the file information to be sent;
[0071] Step S22: determining the thread pool corresponding to the file information to be sent according to the sending rule;
[0072] Step S23: adding the file information to be sent to the queue to be sent corresponding to the thread pool, and sending the file information to be sent in the queue to be sent to the external receiving end through the thread pool.
[0073] Here, the file information includes the file name, file content, file receiving time and the external receiving end corresponding to the target file.
[0074] Here, the file information to be sent can be understood as the file information in the first working directory to be sent to the external receiving end at the current moment. The file information can be traversed according to the sending order of the file information stored in the first working directory to determine the file information to be sent at each moment.
[0075] After determining the file information to be sent at the current moment, the sending rule of the file information to be sent can be determined. The sending rule is used to indicate the corresponding relationship between the file information, the thread pool, the queue to be sent and the external receiving end. The thread pool is a thread pool for sending file information, and each thread pool needs to create a corresponding queue to be sent.
[0076] Through the sending rule, the thread pool used to send the file information, the queue to be sent of the thread pool, and the external receiving end corresponding to the file information can be determined.
[0077] Here, the thread pool is a form of multi-threaded processing, each thread pool corresponds to a queue to be sent, and the threads in the thread pool can read the files in the queue to be sent for sending. Among them, one thread can correspond to one file information to be sent, or multiple threads can correspond to one file information to be sent.
[0078] In an embodiment of the present application, after determining the sending rule, the thread pool corresponding to the file information to be sent can be determined according to the sending rule, and the file information to be sent can be added to the queue to be sent corresponding to the thread pool.
[0079] In the above implementation, the accuracy of file transfer is improved by matching the corresponding relationship between the thread pool, the queue to be sent and the external receiving end through the sending rules of the file information to be sent. The files in the queue to be sent are read by multiple threads in the thread pool for sending, which reduces the consumption of system resources, improves the rate of file transfer, and ensures the efficient operation of the system.
[0080] In an optional embodiment, the method further comprises:
[0081] Step S31: in the process of transmitting the to-be-sent file information in the to-be-sent queue to the external receiving end through the thread pool, regularly detecting whether there is an abnormality in the communication connection between the thread pool and the external receiving end;
[0082] Step S32: when it is detected that the communication connection is abnormal, the information of the files to be sent that have failed to be sent in the queue to be sent is transferred to the failed sending directory of the target hard disk.
[0083] Here, the abnormality in the communication connection between the thread pool and the external receiving end means that all threads in the thread pool are unavailable. In other words, if it is determined that there is no available connection between the thread pool and the external receiving end, it can be determined that the abnormality in the communication connection between the thread pool and the external receiving end.
[0084] Here, the sending failure directory is used to store the target file that fails to be sent when the thread pool and the external receiving end are abnormal. The sending failure directory is a directory under the target hard disk, and the path of the sending failure directory can be: / data / err.
[0085] In the embodiment of the present application, in the process of transmitting the to-be-sent file information in the to-be-sent queue to the external receiving end through the thread pool, it is also possible to detect whether there is an abnormality in the communication connection between the thread pool and the external receiving end at a preset time interval. If an abnormality is detected, the file information in the to-be-sent queue that has not yet been sent to the external receiving end can be transferred to the sending failure directory of the target hard disk.
[0086] In the above implementation, by periodically detecting whether there are any abnormalities in the communication connection between the thread pool and the external receiving end, the files that fail to be sent under abnormal circumstances are processed, the transmission rate of the file transmission is improved, and the files that fail to be sent are transferred to the sending failure directory, thereby ensuring the integrity of the file information and reducing system resource consumption.
[0087] In an optional implementation manner, after transferring the to-be-sent file information that fails to be sent in the to-be-sent queue to a failed-to-send directory of the target hard disk, the specific method further includes:
[0088] Step S41: when it is detected that the communication connection is normal and the shared memory disk meets the second storage requirement, the information of the to-be-sent files that failed to be sent in the sending failure directory is transferred to the first working directory.
[0089] From the above description, it can be seen that in the process of transmitting the file information to be sent in the queue to be sent to the external receiving end through the thread pool, if it is detected that there is an abnormality in the communication connection between the thread pool and the external receiving end, then the file information in the queue to be sent that has not yet been sent to the external receiving end can be transferred to the failed sending directory of the target hard disk.
[0090] Afterwards, if it is detected that the communication connection between the thread pool and the external receiving end has returned to normal, it is possible to detect whether the shared memory disk meets the second storage requirement. If it is detected that the second storage requirement is met, the information of the files to be sent that failed to be sent in the sending failure directory can be transferred to the first working directory.
[0091] Here, the used space capacity of the shared memory disk can be obtained, wherein, if it is determined that the used space capacity is lower than the second capacity threshold, it is determined that the second storage requirement is met, and at this time, the to-be-sent file information that failed to be sent in the sending failure directory can be transferred to the first working directory. When the used space capacity of the shared memory disk is higher than the second capacity threshold, hibernation needs to be executed, and the used space capacity of the shared memory disk is re-detected after the hibernation ends until it is detected that the shared memory disk meets the second storage requirement.
[0092] Here, the first capacity threshold is different from the second capacity threshold, and the second capacity threshold is used to indicate the critical capacity value for moving the to-be-sent file information in the failed-sending directory to the first working directory. Here, the second capacity threshold is set to values such as 45%, 50%, and 55%, and the corresponding second capacity threshold can be set according to the size of the transferred file.
[0093] In the above implementation, when it is detected that the communication connection between the thread pool and the external receiving end is normal, if it is determined that the shared memory disk meets the second storage requirement, the information of the files to be sent that failed to be sent in the sending failure directory is sent to the first working directory, thereby improving the transmission success rate of the target file, ensuring the integrity of the target file, and making the file transfer process convenient and efficient.
[0094] In an optional embodiment, the method further comprises:
[0095] Step S51: when it is determined based on the first capacity occupancy information that the shared memory disk does not meet the first storage requirement, the file information of the target file is stored in a buffer directory of the target hard disk.
[0096] Here, the buffer directory is the file information of the target file stored in the shared memory disk. When the capacity of the shared memory disk is detected to be higher than the first capacity threshold, the file information stored in the shared memory disk is saved in the target hard disk. This can reduce the actual disk operation and effectively protect the disk from damage caused by repeated read and write operations.
[0097] In the above implementation, the capacity occupancy information of the shared memory disk is monitored and the capacity occupancy of the shared memory disk is queried. If the shared memory disk does not meet the first storage requirement (i.e., the capacity is higher than the capacity critical value), the capacity of the shared memory disk is reduced by moving files to ensure efficient transmission of the shared memory disk and improve the stability of the system.
[0098] In an optional embodiment, the method further comprises:
[0099] Step S61: regularly detecting the capacity occupancy information of the shared memory disk to obtain second capacity occupancy information;
[0100] Step S62: when it is determined based on the second capacity occupancy information that the shared memory disk meets the second storage requirement, part of the file information stored in the buffer directory is transferred to the first working directory.
[0101] Here, the second capacity occupancy information is the file volume of the target file stored in the buffer directory, and the remaining space capacity of the shared memory disk can be obtained according to the second capacity occupancy information.
[0102] Here, the partial file information is the file information of the partial target file that needs to be transferred when it is detected that the shared memory disk meets the second storage requirement.
[0103] The receiving time of the target file is obtained by reading the file information of the target file in the buffer directory, and the target files are arranged in the order of receiving time. The first received target file is used as the first file to be transferred, and then the corresponding target files are transferred in sequence according to the receiving time. The transfer operation is stopped when the capacity of the shared memory disk is higher than the second capacity threshold.
[0104] In the above implementation, by detecting the second capacity occupancy information of the shared memory disk, when the second capacity occupancy information meets the second storage requirement, the file information of the target file is sent to the first working directory, thereby improving the transmission success rate of the target file, ensuring the integrity of the target file, and making the file transfer process convenient and efficient.
[0105] In an optional embodiment, the method further comprises:
[0106] Step S71: after acquiring the file information of the externally input target file, backing up the file information to the backup directory of the target hard disk.
[0107] Here, the backup directory is used to temporarily back up the file information of the externally input target file.
[0108] In the above implementation, the target file information is backed up to the target hard disk by temporarily backing up the target file information, thus overcoming the problem of data loss due to power failure of the shared memory disk and ensuring data security while high-speed reading and writing.
[0109] like Figure 2 As shown, the file transmission system includes an external input layer, a transmission service layer, and an external receiving unit layer.
[0110] The external input layer includes one or more target files, which are obtained through external real-time calculation. The transmission service layer includes a receiving module, a sending module, a scheduling module and a storage medium, and the storage medium includes a shared memory disk and a target hard disk. The external receiving unit layer includes one or more hosts and directories of external receiving ends.
[0111] Here, the processing of each module in the file transfer system is mainly described as follows:
[0112] S1: File transfer system initialization.
[0113] Here, the initialization process includes four processes: loading the system configuration file, creating the system directory, initializing the thread pool with the external receiving end, and initializing the sending rules.
[0114] Among them, loading the system configuration file can obtain the configuration information of the corresponding file, and the obtained configuration information includes the file name of the target file, the file format of the target file, the sleep cycle corresponding to the corresponding file, and the host and directory of the external receiving end corresponding to the target file.
[0115] The created system directory is shown in Table 1 below, including the directory name, the path where the system directory is located, and the description of the system directory. The shared memory disk, shared memory shm (Shared Memory), and / dev / shm in Table 1 are temporary file system features in the Linux operating system. Here, the input directory and the first working directory can also be called the memory directory, that is, the directory under the shared memory disk, and the memory directory refers to the directory under / dev / shm / .
[0116] Table 1
[0117]
[0118] The specific process of initializing the thread pool with the external receiving end is: obtain the IP, port, transmission protocol and other information of the external receiving end in the configuration, create an interface between the external receiving end and the thread pool, and connect the thread pool. Each thread pool needs to create a queue to be sent, and the thread pool will read the files in the queue for sending. The thread pool will periodically self-check. When a thread in the thread pool cannot communicate with the external receiving end, the thread will be marked as unavailable, that is, the connection is unavailable.
[0119] The specific process of initializing the sending rule is: obtain the association between the file name and the external receiving end in the configuration, and clarify the external receiving end to which the file information needs to be sent, that is, the relationship of file name <=> connection thread pool <=> waiting queue <=> external receiving end. After that, the file information matching the file name will be added to the waiting queue of the corresponding thread pool for the thread pool to send to the external receiving end.
[0120] S2: External input.
[0121] Through real-time calculation of the external input layer, the file information of the target file to be transmitted is obtained. After that, the external input layer can output the file information of the target file to the input directory and back up the file information to the backup directory of the target hard disk to prevent data loss due to power failure of the shared memory disk ( / dev / shm).
[0122] S3: Traffic buffering.
[0123] The receiving module loops through the input directory to obtain file information. After that, it determines the size between the first capacity occupancy information of the current shared memory disk ( / dev / shm) and the first capacity threshold; if it is determined that the first capacity occupancy information is greater than the first capacity threshold, the file information of the target file is buffered in the buffer directory of the target hard disk; if it is determined that the first capacity occupancy information is less than the first capacity threshold, the file information of the target file is moved to the first working directory for the thread pool to send.
[0124] S4: Rule matching.
[0125] The sending module loops through and obtains the file information in the first working directory, obtains the file information to be sent at the current moment, and determines the thread pool that matches the file information to be sent and the matching queue to be sent according to the initialized sending rules (i.e., the relationship of file name <=> connection thread pool <=> queue to be sent <=> external receiving end); thereafter, the file information to be sent can be added to the corresponding queue to be sent for the thread pool to send.
[0126] S5: Send.
[0127] The thread pool connected to the sending module will read the corresponding queue to be sent, obtain the information of the file to be sent, and send the information of the file to be sent to the designated machine directory of the external receiving end. The thread pool will periodically self-check to determine whether the connection in the thread pool is available (if the communication is normal, it is considered available). If it is determined that there is no available connection, the information of the file to be sent that failed to be sent in the queue to be sent will be transferred to the failed sending directory of the target hard disk, and the processed files in the backup directory of the target hard disk will be deleted (the backup files will be deleted whether the connection pool is available), including files that were successfully sent and failed.
[0128] S6: Buffer scheduling.
[0129] In an embodiment of the present application, the scheduling module can periodically detect the occupancy of the shared memory disk ( / dev / shm). Here, after transferring the to-be-sent file information that failed to be sent in the to-be-sent queue to the failed sending directory of the target hard disk, the second capacity occupancy information obtained by the scheduling module from detecting the shared memory disk can be obtained. Among them, if it is determined that the second capacity occupancy information is less than the second capacity threshold, the file information buffered in the buffer directory of the target hard disk is moved to the first working directory for sending.
[0130] Through S7: Resend upon failure.
[0131] In the embodiment of the present application, the scheduling module can also regularly detect whether the connection in the thread pool is available (communication is normal). Combined with the occupancy of the shared memory disk ( / dev / shm), the abnormally sent files in the failed sending directory of the mobile target hard disk are resent.
[0132] Combine the following Figure 3 The above process is described as follows:
[0133] S301: External real-time calculation of input file information.
[0134] S302: Store the file information into the input directory.
[0135] S303: The receiving module scans the input directory.
[0136] S304: Determine whether the shared memory disk meets the first storage requirement.
[0137] If the answer is yes, execute step S305; otherwise, execute step S309.
[0138] S305: Move the file information to the first working directory.
[0139] S306: The sending module scans the file information in the first working directory to obtain the file information to be sent at the current moment.
[0140] S307: Determine whether the thread pool is available.
[0141] If the answer is yes, execute step S308; otherwise, execute step S312.
[0142] After executing step S307, first execute step S312, and then execute step S314.
[0143] S308: Send the file information to the external receiving end through the thread pool.
[0144] S309: Move the file information to the buffer directory.
[0145] S310: The scheduling module detects second capacity occupancy information of the shared memory disk.
[0146] S311: Determine whether the second capacity occupancy information is less than a second capacity threshold.
[0147] If it is determined that the condition is established, step S305 is executed; otherwise, hibernation is performed and step S311 is executed again.
[0148] S312: Move the file to the sending failure directory.
[0149] S313: The scheduling module detects the second capacity occupancy information of the shared memory disk and the available status of the thread pool.
[0150] S314: Determine whether the second capacity occupancy information is less than the second capacity threshold and whether the thread pool is available.
[0151] If it is determined that the condition is established, step S305 is executed; otherwise, hibernation is executed and step S314 is executed again.
[0152] S315: Delete the file information in the backup directory.
[0153] S316: Back up the file information to the backup directory.
[0154] It can be seen from the above description that the technical solution disclosed in the present invention has the following advantages:
[0155] 1. High-speed and stable transmission of massive files. The present invention uses a shared memory disk as a working directory to break through the disk IO bottleneck and improve the efficiency of file reading, writing and transmission; it refines the concurrent granularity from the aspects of file name, destination host and destination directory, increases concurrent threads and improves the transmission rate.
[0156] 2. Traffic peak elimination. The present invention will detect the occupancy of the shared memory disk, and buffer data to the target hard disk during traffic peaks to avoid traffic shocks; during traffic troughs, the buffered data will be resent to achieve traffic peak elimination and valley filling, thus improving system stability and resource utilization.
[0157] 3. The system is lightweight and efficient. The present invention utilizes the basic characteristics of the operating system (such as shared memory) and basic file operation instructions to build system services without other intermediate components, so it is relatively lightweight; the basic instructions are also relatively efficient.
[0158] Combine the following Figure 4 The above receiving module process is described, and the specific process is described as follows
[0159] S401: Scan the input directory.
[0160] S402: Acquire first capacity occupancy information of a shared memory disk.
[0161] S403: Determine whether the first capacity occupancy information is greater than a first capacity threshold.
[0162] If the answer is yes, execute step S404; otherwise, execute step S405.
[0163] S404: Move the file information of the target file to the buffer directory.
[0164] S405: Move the file information of the target file to the first working directory.
[0165] After executing the above steps, re-execute step S401.
[0166] Combine the following Figure 5 The above sending module process is described, and the specific process is described as follows:
[0167] S501: Initialize the sending rules of the thread pool.
[0168] S502: Scan the first working directory.
[0169] S503: Match the target file with the thread pool according to the rules.
[0170] S504: The thread pool reads the queue to be sent and obtains the list to be sent.
[0171] S505: Determine whether the thread pool has at least one available connection.
[0172] If the answer is yes, execute step S506; otherwise, execute step S507.
[0173] S506: Send the file information to an external receiving end.
[0174] S507: Move the file information to a subdirectory of the sending failure directory on the target hard disk; wherein the subdirectory is named according to the thread pool instance rule so as to be resent when a subsequent connection is available.
[0175] S508: Delete the processed files in the backup directory; the processed files include files that are sent successfully or failed to be sent.
[0176] After executing the above steps, re-execute step S502.
[0177] Combine the following Figure 6 The above scheduling module process is described. The scheduling module execution process is divided into a buffer scheduling process and a failure retransmission process. The specific process of buffer scheduling is described as follows:
[0178] S601: Acquire second capacity occupancy information of a shared memory disk.
[0179] S602: Determine whether the second capacity occupancy information is less than a second capacity threshold.
[0180] If the answer is yes, execute step S603; otherwise, execute step S604.
[0181] S603: Move some files in the buffer directory of the target hard disk to the first working directory.
[0182] S604: Execute hibernation, wherein the hibernation time can be obtained by reading the configuration information of the target file, or the hibernation time can be set according to the file size of the target file.
[0183] After executing the above steps, re-execute step S601.
[0184] The specific process of failed retransmission is described as follows Figure 7 As shown:
[0185] S701: Obtain second capacity occupancy information of a shared memory disk.
[0186] S702: Determine whether the second capacity occupancy information is less than a second capacity threshold.
[0187] If the answer is yes, execute step S703; otherwise, execute step S704.
[0188] S703: Scan the subdirectories of the sending failure directory of the target hard disk.
[0189] S704: Execute hibernation.
[0190] S705: Determine whether all subdirectories of the directory that failed to be sent have been scanned.
[0191] If the answer is yes, execute step S701; otherwise, execute step S706.
[0192] S706: Obtain the thread pool instance corresponding to the subdirectory.
[0193] S707: Determine whether at least one connection in the thread pool is available.
[0194] If the answer is yes, execute step S708; otherwise, execute step S705.
[0195] S708: Scan the files in the subdirectory.
[0196] S709: Move the file to the first working directory.
[0197] After executing the above steps, re-execute step S701.
[0198] In the above implementation mode, a shared memory disk is used to store file information of externally input target files, a large number of files can be stored and processed, and the integrity of the file information of the target files is retained. The first capacity information of the shared memory disk is determined based on the file information of the target files. When it is determined that the first capacity information meets the first storage requirement, the file information of the target file is moved to the first working directory, thereby improving the file processing speed and system stability of the system and making the file transfer process convenient and efficient.
[0199] Those skilled in the art will appreciate that, in the above method of specific implementation, the order in which the steps are written does not imply a strict execution order and does not constitute any limitation on the implementation process. The specific execution order of the steps should be determined by their functions and possible internal logic.
[0200] Based on the same inventive concept, an embodiment of the present disclosure also provides a file transfer device corresponding to the file transfer method. Since the principle of solving the problem by the device in the embodiment of the present disclosure is similar to the above-mentioned file transfer method in the embodiment of the present disclosure, the implementation of the device can refer to the implementation of the method, and the repeated parts will not be repeated.
[0201] Reference Figure 8 As shown, it is a schematic diagram of a file transmission provided by an embodiment of the present disclosure, the device comprises: an acquisition unit 10, a determination unit 20, a storage unit 30, and a sending unit 40; wherein,
[0202] The acquisition unit 10 is used to acquire file information of an externally input target file; wherein the file information is used to indicate file content information of the target file and an external receiving end of the target file;
[0203] The determination unit 20 is used to determine first capacity occupancy information of a shared memory disk; wherein the shared memory disk is a memory space used to store the target file;
[0204] The storage unit 30 is used to store the file information of the target file in a first working directory of the shared memory disk when it is determined based on the first capacity occupancy information that the shared memory disk meets the first storage requirement;
[0205] The sending unit 40 is used to send the file information of the target file stored in the first working directory to the external receiving end.
[0206] In an embodiment of the present application, file information of an externally input target file is first obtained, and first capacity occupancy information of a shared memory disk storing the target file is determined. Then, when it is determined based on the first capacity occupancy information that the shared memory disk meets the first storage requirement, the file information of the target file is stored in a first working directory of the shared memory disk, and finally the file information of the target file stored in the first working directory is sent to an external receiving end.
[0207] In the above implementation mode, a shared memory disk is used to store file information of externally input target files, a large number of files can be stored and processed, and the integrity of the file information of the target files is retained. The first capacity information of the shared memory disk is determined based on the file information of the target files. When it is determined that the first capacity information meets the first storage requirement, the file information of the target file is moved to the first working directory, thereby improving the file processing speed and system stability of the system and making the file transfer process convenient and efficient.
[0208] In a possible implementation manner, the sending unit 40 is further configured to:
[0209] Traversing the file information stored in the first working directory, obtaining the file information to be sent at the current moment, and determining a sending rule for the file information to be sent;
[0210] Determine the thread pool corresponding to the file information to be sent according to the sending rule;
[0211] The file information to be sent is added to a queue to be sent corresponding to the thread pool, and the file information to be sent in the queue to be sent is sent to the external receiving end through the thread pool.
[0212] In a possible implementation manner, the sending unit 40 is further configured to:
[0213] In the process of transmitting the to-be-sent file information in the to-be-sent queue to the external receiving end through the thread pool, regularly detecting whether there is an abnormality in the communication connection between the thread pool and the external receiving end;
[0214] When an abnormality is detected in the communication connection, the information of the to-be-sent files that failed to be sent in the to-be-sent queue is transferred to a sending failure directory of the target hard disk.
[0215] In a possible implementation manner, the sending unit 40 is further configured to:
[0216] When it is detected that the communication connection is normal and that the shared memory disk meets the second storage requirement, the information of the to-be-sent files that failed to be sent in the sending failure directory is transferred to the first working directory.
[0217] In a possible implementation manner, the storage unit 30 is further configured to:
[0218] When it is determined based on the first capacity occupancy information that the shared memory disk does not meet the first storage requirement, the file information of the target file is stored in a buffer directory of the target hard disk.
[0219] In a possible implementation manner, the storage unit 30 is further configured to:
[0220] Regularly detecting the capacity occupancy information of the shared memory disk to obtain second capacity occupancy information;
[0221] When it is determined based on the second capacity occupancy information that the shared memory disk meets the second storage requirement, part of the file information stored in the buffer directory is transferred to the first working directory.
[0222] In a possible implementation manner, the acquisition unit 10 is further configured to:
[0223] After acquiring the file information of the externally input target file, the file information is backed up to a backup directory of the target hard disk.
[0224] For descriptions of the processing flow of each module in the device and the interaction flow between each module, reference may be made to the relevant descriptions in the above method embodiment, which will not be described in detail here.
[0225] Corresponds to Figure 1 The file transmission method in the present disclosure also provides an electronic device 90, such as Fig. 9 FIG. 1 is a schematic diagram of the structure of an electronic device 90 provided in an embodiment of the present disclosure, including:
[0226] Processor 91, memory 92, and bus 93; memory 92 is used to store execution instructions, including memory 901 and external memory 902; memory 901 here is also called internal memory, which is used to temporarily store operation data in processor 91 and data exchanged with external memory 902 such as hard disk. Processor 91 exchanges data with external memory 902 through memory 901. When the electronic device 90 is running, the processor 91 communicates with the memory 92 through bus 93, so that the processor 91 executes the following instructions:
[0227] Acquire file information of an externally input target file; wherein the file information is used to indicate file content information of the target file and an external receiving end of the target file;
[0228] Determine first capacity occupancy information of a shared memory disk; wherein the shared memory disk is a memory space used to store the target file;
[0229] When it is determined based on the first capacity occupancy information that the shared memory disk meets the first storage requirement, storing the file information of the target file in a first working directory of the shared memory disk;
[0230] Sending file information of the target file stored in the first working directory to the external receiving end.
[0231] The embodiment of the present disclosure also 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 of the file transfer method described in the above method embodiment are executed. The storage medium can be a volatile or non-volatile computer-readable storage medium.
[0232] The embodiments of the present disclosure also provide a computer program product, which carries a program code. The instructions included in the program code can be used to execute the steps of the file transfer method described in the above method embodiment. For details, please refer to the above method embodiment, which will not be repeated here.
[0233] The computer program product may be implemented in hardware, software or a combination thereof. In one optional embodiment, the computer program product is implemented as a computer storage medium. In another optional embodiment, the computer program product is implemented as a software product, such as a software development kit (SDK).
[0234] Those skilled in the art can clearly understand that, for the convenience and simplicity of description, the specific working process of the system and device described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here. In the several embodiments provided in the present disclosure, it should be understood that the disclosed system, device and method can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some communication interfaces, and the indirect coupling or communication connection of the device or unit can be electrical, mechanical or other forms.
[0235] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0236] In addition, each functional unit in each embodiment of the present disclosure may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0237] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a non-volatile computer-readable storage medium that is executable by a processor. Based on this understanding, the technical solution of the present disclosure, 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 enabling an electronic 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 disclosure. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0238] Finally, it should be noted that the above-described embodiments are only specific implementation methods of the present disclosure, which are used to illustrate the technical solutions of the present disclosure, rather than to limit them. The protection scope of the present disclosure is not limited thereto. Although the present disclosure is described in detail with reference to the above-described embodiments, ordinary technicians in the field should understand that any technician familiar with the technical field can still modify the technical solutions recorded in the above-described embodiments within the technical scope disclosed in the present disclosure, or can easily think of changes, or make equivalent replacements for some of the technical features therein; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present disclosure, and should be included in the protection scope of the present disclosure. Therefore, the protection scope of the present disclosure shall be subject to the protection scope of the claims.
Claims
1. A method for file transfer, It is characterized in that include: Acquire file information of an externally input target file; wherein the file information is used to indicate file content information of the target file and an external receiving end of the target file; Determine first capacity occupancy information of a shared memory disk; wherein the shared memory disk is a memory space used to store the target file; When it is determined based on the first capacity occupancy information that the shared memory disk meets the first storage requirement, storing the file information of the target file in a first working directory of the shared memory disk; Sending file information of the target file stored in the first working directory to the external receiving end.
2. The method according to claim 1, It is characterized in that The sending the file information of the target file stored in the first working directory to the external receiving end includes: Traversing the file information stored in the first working directory, obtaining the file information to be sent at the current moment, and determining a sending rule for the file information to be sent; Determine the thread pool corresponding to the file information to be sent according to the sending rule; The file information to be sent is added to a queue to be sent corresponding to the thread pool, and the file information to be sent in the queue to be sent is sent to the external receiving end through the thread pool.
3. The method according to claim 2, It is characterized in that The method further comprises: In the process of transmitting the to-be-sent file information in the to-be-sent queue to the external receiving end through the thread pool, regularly detecting whether there is an abnormality in the communication connection between the thread pool and the external receiving end; When an abnormality is detected in the communication connection, the information of the to-be-sent files that failed to be sent in the to-be-sent queue is transferred to a sending failure directory of the target hard disk.
4. The method according to claim 3, It is characterized in that After transferring the information of the files to be sent that failed to be sent in the to-be-sent queue to the failed-to-send directory of the target hard disk, the method further includes: When it is detected that the communication connection is normal and that the shared memory disk meets the second storage requirement, the information of the to-be-sent files that failed to be sent in the sending failure directory is transferred to the first working directory.
5. The method according to claim 1, It is characterized in that The method further comprises: When it is determined based on the first capacity occupancy information that the shared memory disk does not meet the first storage requirement, the file information of the target file is stored in a buffer directory of the target hard disk.
6. The method according to claim 5, It is characterized in that The method further comprises: Regularly detecting the capacity occupancy information of the shared memory disk to obtain second capacity occupancy information; When it is determined based on the second capacity occupancy information that the shared memory disk meets the second storage requirement, part of the file information stored in the buffer directory is transferred to the first working directory.
7. The method according to claim 1, It is characterized in that The method further comprises: After acquiring the file information of the externally input target file, the file information is backed up to a backup directory of the target hard disk.
8. A device for file transmission, It is characterized in that include: An acquisition unit, used for acquiring file information of an externally input target file; wherein the file information is used for indicating file content information of the target file and an external receiving end of the target file; A determination unit, configured to determine first capacity occupancy information of a shared memory disk; wherein the shared memory disk is a memory space used to store the target file; a storage unit, configured to store file information of the target file in a first working directory of the shared memory disk when it is determined that the shared memory disk meets a first storage requirement based on the first capacity occupancy information; A sending unit is used to send the file information of the target file stored in the first working directory to the external receiving end.
9. An electronic device, It is characterized in that include: A processor, a memory and a bus, wherein the memory stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor and the memory communicate via the bus, and when the machine-readable instructions are executed by the processor, the steps of the file transfer method as described in any one of claims 1 to 7 are performed.
10. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of file transmission as claimed in any one of claims 1 to 7 are executed.
