File uploading method, device, system, storage medium and electronic device
By dynamically adjusting the parallel number and block size according to the file data volume and network status, and updating the transmission strategy in real time, the problem of resource occupation and insufficient flexibility caused by large file uploads in the traditional file upload method is solved, and efficient and adaptive File upload process.
Patent Information
- Application Number
- CN202111576676.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-22
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2041-12-22
AI Technical Summary
The traditional file upload method can easily cause the client to freeze when processing large files, occupy a large amount of system resources, and fail to upload when the network is disconnected. The block size is fixed, and the flexibility and adaptability are poor.
Generate an upload request based on the data volume and network status of the file to be uploaded, obtain the transmission strategy fed back by the server, including parallel number and chunking information, monitor the resource consumption status during the file block upload process, and update the transmission strategy in real time to optimize the upload process.
It realizes adaptive file upload, takes into account upload speed and resource occupation, improves file upload efficiency, avoids excessive consumption of client resources, and improves the adaptability between the transmission strategy and the upload environment.
Smart Images

Figure CN114285838B_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present invention relate to the field of computer technology, and in particular to a file uploading method, device, system, storage medium and electronic device. Background Art
[0002] In daily development, there are often demands for uploading files. Small files can be uploaded directly, but large files can be uploaded using traditional methods, which can cause the client to freeze, occupy a large amount of system resources, and cause upload failure if the network is disconnected.
[0003] To address the above issues, by uploading files in chunks, large files are split into smaller individual requests, and the server completes the upload process of large files by merging the chunks.
[0004] However, the size of the blocks in the above file upload method is fixed, and the flexibility and adaptability are poor. Summary of the invention
[0005] The embodiments of the present invention provide a file uploading method, device, system, storage medium and electronic device to realize adaptive file uploading.
[0006] In a first aspect, an embodiment of the present invention provides a method for uploading a file, comprising:
[0007] Generate an upload request based on the data volume of the file to be uploaded and the network status, and send the upload request to the server, and receive a transmission strategy fed back by the server, wherein the transmission strategy includes parallel number and block information;
[0008] The to-be-uploaded file is processed in blocks based on the block information, and each file block is uploaded based on the parallel number;
[0009] During the uploading process of the file blocks, the current resource consumption status is monitored, and the transmission strategy is updated according to the current resource consumption status, and the unuploaded file blocks are uploaded based on the updated transmission strategy.
[0010] In a second aspect, an embodiment of the present invention further provides a method for uploading a file, comprising:
[0011] Receive an upload request sent by a client, and extract request parameters in the upload request, wherein the request parameters include one or more of the data volume of the file to be uploaded, the network status, and the expected transmission strategy;
[0012] Determine a transmission strategy based on the request parameters, and send the transmission strategy to the client, wherein the transmission strategy includes parallel number and block information;
[0013] Receive and store the file blocks uploaded by the client, and when receiving a transmission completion signal, merge the received multiple file blocks to obtain the uploaded file.
[0014] In a third aspect, an embodiment of the present invention further provides a method for uploading a file, comprising:
[0015] The client generates an upload request based on the data volume of the file to be uploaded and the network status, and sends the upload request to the server;
[0016] The server receives an upload request sent by a client, extracts request parameters in the upload request, determines a transmission strategy based on the request parameters, and sends the transmission strategy to the client;
[0017] The client receives the transmission strategy fed back by the server, wherein the transmission strategy includes a parallel number and block information; blocks the file to be uploaded based on the block information, and uploads each file block based on the parallel number, and during the uploading process of the file block, monitors the current resource consumption status, updates the transmission strategy according to the current resource consumption status, and uploads the unuploaded file block based on the updated transmission strategy;
[0018] The server receives and stores the file blocks uploaded by the client, and merges the received multiple file blocks to obtain the uploaded file when receiving a transmission completion signal.
[0019] In a fourth 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 when the processor executes the program, a file upload method as provided in any embodiment of the present invention is implemented.
[0020] In a fifth aspect, an embodiment of the present invention further provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements a file uploading method as provided in any embodiment of the present invention.
[0021] The technical solution of this embodiment determines the transmission strategy of the file to be uploaded according to the data volume of the file to be uploaded and the network status. The transmission strategy matches the file to be uploaded and the current upload conditions, takes into account the upload speed, and avoids occupying the client resources. Furthermore, during the file upload process, the transmission strategy is updated in real time based on the current resource consumption status of the client to optimize the transmission strategy, improve the adaptability of the transmission strategy to the upload environment, and improve the file upload efficiency while ensuring the normal operation of the client. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] Figure 1 It is a flowchart of uploading files in chunks;
[0023] Figure 2 A flowchart of a file uploading method provided by an embodiment of the present invention;
[0024] Figure 3 A flowchart of a file uploading method provided by an embodiment of the present invention;
[0025] Figure 4 It is a flowchart of a file uploading method provided by an embodiment of the present invention;
[0026] Figure 5 is a flow chart of a file uploading method provided by an embodiment of the present invention;
[0027] Figure 6 This is a structural diagram of a file uploading device provided by an embodiment of the present invention.
[0028] Figure 7 It is a structural schematic diagram of a file uploading device provided by an embodiment of the present invention;
[0029] Figure 8 It is a structural schematic diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0030] The present invention will be further described in detail below in conjunction with the accompanying drawings and embodiments. It is to be understood that the specific embodiments described herein are only used to explain the present invention, rather than to limit the present invention. It should also be noted that, for ease of description, only parts related to the present invention, rather than all structures, are shown in the accompanying drawings.
[0031] See also Figure 1 , Figure 1 This is a flowchart of file uploading in chunks. The file upload is based on the open source WebUploader.js. Before starting the upload, the chunk size parameter chunkSize is specified, and the following steps are performed based on the chunk size parameter chunkSize:
[0032] Step 1: The client uses WebUploader to obtain file information and sends attributes such as file size, md5, name, etc. to the server;
[0033] Step 2: After receiving the file, the server checks whether the file exists, creates a file directory and returns a success message to the client.
[0034] Step 3: The client uses WebUploader to divide the file into chunks and upload the chunks to the server, where the size of the file chunk is determined based on a pre-specified chunk size parameter chunkSize;
[0035] Step 4: The server saves the received blocks in the block directory;
[0036] Step 5: After the end, the client notifies the server that the upload is complete. The server merges the block files and deletes the blocks, completing the block upload process.
[0037] The above file upload method has the following technical problems: 1) If the file is large and the number of fragments is large, the single-threaded upload will cause the block upload request to queue up and take a long time. 2) If the multi-threaded method is used for block upload, it will consume more thread resources and may cause additional thread switching resource consumption and thread safety issues.
[0038] In view of the above technical problems, an embodiment of the present invention provides a method for uploading files, see Figure 2 , Figure 2 This is a flowchart of a file uploading method provided by an embodiment of the present invention. This embodiment is applicable to the case of adaptively uploading files. The method can be executed by the file uploading device provided by the embodiment of the present invention. The file uploading device can be implemented by software and / or hardware. The file uploading device can be configured on a terminal such as a mobile phone, a PC, etc., and specifically includes the following steps:
[0039] S110, based on the data volume of the file to be uploaded and the network status, generate an upload request, send the upload request to the server, and receive a transmission strategy fed back by the server, wherein the transmission strategy includes parallel number and block information.
[0040] S120: Divide the file to be uploaded into blocks based on the block information, and upload each file block based on the parallel number.
[0041] S130. During the uploading process of the file blocks, monitor the current resource consumption status, update the transmission strategy according to the current resource consumption status, and upload the unuploaded file blocks based on the updated transmission strategy.
[0042] In this embodiment, the uploaded file can be a locally stored file or an externally imported file, which is not limited. Further, the file format of the uploaded file can be one or more of text, image, video, and audio, which is not limited.
[0043] When receiving an instruction to upload a file, the file information and the current network status are obtained, wherein the file information may include a file identifier and a file data volume, and the file identifier may be, for example, a file name or a string used to characterize the file. The file data volume may be determined by reading the file size. The network status is used to affect the upload speed of the file. The current network status may be the current network speed, or it may also be the current network type. For example, the network status may be 4G, 5G, or wifi, etc. Different network types correspond to different network speeds.
[0044] An upload request is generated based on the data volume and network status of the file to be uploaded, and the upload request is sent to the server for file upload. The server is used to create a file target, and at the same time, a transmission strategy for the file to be uploaded is generated based on the data volume and network status in the upload request, wherein the transmission strategy includes a parallel number and block information. The parallel number is the number of connections established with the server, and each connection is used to upload a file block. The block information is the size of each file block. The more parallel numbers, the faster the file upload, and the higher the requirements for network resources. The larger the block information, the larger the file block, and the higher the requirements for network resources. The data volume of the file to be uploaded is positively correlated with the parallel number and the block information, respectively, and the network speed corresponding to the network status is positively correlated with the parallel number and the block information, respectively. The server is configured with a transmission strategy determination rule, and the transmission strategy for the file to be uploaded is obtained based on the data volume and network status in the upload request and the transmission strategy determination rule.
[0045] In this embodiment, the transmission strategy of the file to be uploaded is determined by the server, and the transmission strategy matches the file to be uploaded and the current upload condition, taking the upload speed into consideration while avoiding occupation of client resources.
[0046] The server feeds back the transmission strategy to the client, and the client performs file segmentation on the file to be uploaded according to the segmentation information in the transmission strategy, and uploads the file blocks in parallel through a parallel number. In some embodiments, according to the content sequence of the file to be uploaded, an identifier is set for the file blocks obtained by segmentation, and the identifier can be used to mark each file block, and the order of each file block can be marked at the same time. For example, the identifier of the file block can be the encoding of the file block. By setting the identifier for the file block, it is convenient for the server to merge the uploaded file blocks, so as to avoid the upload order of the file blocks affecting the accuracy of the merged file.
[0047] In this embodiment, uploading each file block based on the parallel number includes: creating a connection with the server, wherein the connection number is the same as the parallel number; creating a management thread based on non-blocking I / O, the management thread is used to manage the file upload process between the client and the server, and uploading each data block in parallel through the connection with the server. The connection between the client and the server is a file upload channel, and each connection between the client and the server is used to upload a file block at a time. By creating a parallel number of connections, it is used to achieve parallel uploading of parallel number of file blocks, fully utilize the device to exert the best performance, and multiplex multiple parallel IO, so that high-configuration devices can upload faster, thereby improving the efficiency of file upload.
[0048] Based on non-blocking I / O, a management thread is created. This management thread can realize the parallel upload of multiple file blocks without causing the blocking problem of file block upload requests. The server can accept multiple client file upload requests and establish multiple connections. At the same time, the number of management threads is one, and file reading and writing are managed through one thread, which saves thread resources and ensures thread safety.
[0049] Based on the above embodiment, the transmission strategy is updated in real time according to the resource consumption during the file upload process to optimize the transmission strategy and realize the file upload. The resource consumption during the file upload process may include but is not limited to the current CPU resource usage and memory occupancy of the client.
[0050] Optionally, the transmission strategy is updated according to the current resource consumption status, including: when the current resource consumption status does not exceed the resource consumption threshold, increasing the number of parallelism and / or block information in the current transmission strategy; when the current resource consumption status exceeds the resource consumption threshold, reducing the number of parallelism and / or block information in the current transmission strategy.
[0051] The transmission strategy determined by the server is determined based on the commonality of the clients, but since each client has differences, in this embodiment, the transmission strategy is updated according to the current resource consumption status of the client to obtain a transmission strategy adapted to the current resource consumption status of the client, thereby improving the adaptability of the transmission strategy to the current client and ensuring efficient uploading of the files to be uploaded.
[0052] Preset resource consumption thresholds, where the resource consumption thresholds may include CPU resource usage thresholds and memory occupancy thresholds. Monitor the current resource consumption state in real time, that is, each resource consumption information. When each resource consumption information in the current resource consumption state does not exceed the corresponding resource consumption threshold, it indicates that the data volume of the uploaded file can be increased under the normal operation of the client, that is, increase the number of parallelism and / or block information in the current transmission strategy; when at least one resource consumption information in the current resource consumption state exceeds the corresponding resource consumption threshold, it indicates that the current file upload affects the normal operation of the client, and the resource consumption occupied by the file upload needs to be reduced, that is, reduce the number of parallelism and / or block information in the current transmission strategy.
[0053] Optionally, a unit adjustment amount for the number of parallelism and block information is pre-set, and the number of parallelism and / or block information in the transmission strategy can be adjusted based on the unit adjustment amount according to the adjustment method (for example, increase or decrease). For example, when the current resource consumption state does not exceed the resource consumption threshold, the corresponding unit adjustment amount is increased for the number of parallelism and / or block information in the current transmission strategy; when the current resource consumption state exceeds the resource consumption threshold, the corresponding unit adjustment amount is reduced for the number of parallelism and / or block information in the current transmission strategy.
[0054] Optionally, the adjustment amount of the parallel number and the block information can be determined based on the difference between the current resource consumption state and the resource consumption threshold. In the case that each resource consumption information in the current resource consumption state does not exceed the corresponding resource consumption threshold, the difference between each resource consumption information and the corresponding resource consumption threshold is used to determine the adjustment amount corresponding to each difference. The adjustment amount can be the adjustment amount of the parallel number and / or the block information. The transmission strategy is updated based on the minimum adjustment amount to ensure the normal operation of the client while maximizing the file upload speed; in the case that at least one resource consumption information in the current resource consumption state exceeds the corresponding resource consumption threshold, for the resource consumption information that exceeds the resource consumption threshold, the difference between the resource consumption information and the corresponding resource consumption threshold is determined, and the adjustment amount corresponding to each difference is determined. The adjustment amount can be the adjustment amount of the parallel number and / or the block information. The transmission strategy is updated based on the maximum adjustment amount to ensure the normal operation of the client while minimizing the file upload speed.
[0055] In some optional embodiments, the priority of adjusting the parallel number is higher than the priority of adjusting the block information. In the case of updating the transmission strategy, the parallel number is adjusted first to speed up the update of the transmission strategy.
[0056] The technical solution of this embodiment determines the transmission strategy of the file to be uploaded according to the data volume of the file to be uploaded and the network status. The transmission strategy matches the file to be uploaded and the current upload conditions, takes into account the upload speed, and avoids occupying the client resources. Furthermore, during the file upload process, the transmission strategy is updated in real time based on the current resource consumption status of the client to optimize the transmission strategy, improve the adaptability of the transmission strategy to the upload environment, and improve the file upload efficiency while ensuring the normal operation of the client.
[0057] Figure 3 This is a flowchart of a file uploading method provided by an embodiment of the present invention. This embodiment is applicable to the case of adaptively uploading files. The method can be executed by a file uploading device provided by an embodiment of the present invention. The file uploading device can be implemented by software and / or hardware. The file uploading device can be configured on an electronic device such as a server, and specifically includes the following steps:
[0058] S210: Receive an upload request sent by a client, and extract request parameters in the upload request, wherein the request parameters include one or more of the data volume of the file to be uploaded, the network status, and the expected transmission strategy.
[0059] S220. Determine a transmission strategy based on the request parameters, and send the transmission strategy to the client, wherein the transmission strategy includes parallel number and block information.
[0060] S230, receiving and storing the file blocks uploaded by the client, and merging the received multiple file blocks to obtain the uploaded file when receiving a transmission completion signal.
[0061] In this embodiment, the server determines the transmission policy corresponding to the upload request based on a preset transmission policy determination rule and request parameters in the upload request.
[0062] Optionally, the transmission strategy is determined based on the request parameters, including: inputting the data volume and network status of the file to be uploaded into a preset strategy model to obtain the transmission strategy output by the strategy model. The strategy model may be a machine learning model, and the machine learning model may be a neural network model, a deep neural network model or a logistic regression model, etc., which is not limited to this and can be determined according to user needs. The strategy model can be obtained by training based on sample data, wherein the sample data may be a sample file and the upload strategy of the sample file under different network states. The strategy model is iteratively trained with sample data to obtain a strategy model with a transmission strategy determination function. When any upload request is received, the request parameters in the upload request are read, and the data volume and network status of the file to be uploaded in the request parameters are input into the preset strategy model to obtain the transmission strategy output by the strategy model. By configuring the strategy model in the server, the transmission strategy of each upload request can be quickly determined, with fast processing speed and high accuracy.
[0063] Optionally, the transmission strategy determined based on the request parameters includes determining the expected transmission strategy as the transmission strategy; wherein the expected transmission strategy may be input by the user, may be determined by the client based on the data volume of the file to be uploaded and the network status, or may be determined by the client based on the historical transmission strategy, and there is no limitation on this. The expected transmission strategy is determined to be an executable strategy. If so, the expected transmission strategy is determined as the transmission strategy. If not, the transmission strategy is determined based on the data volume of the file to be uploaded and the network status. wherein the expected number of parallelism and the expected block information in the expected transmission strategy may be determined based on the maximum thresholds of the number of parallelism and the block information, respectively, and when the expected number of parallelism is not greater than the maximum threshold of the number of parallelism and the expected block information is not greater than the maximum threshold of the block information, the expected transmission strategy is determined to be an executable strategy.
[0064] Optionally, determining the transmission strategy based on the request parameters includes: matching the data volume and network status of the file to be uploaded in a transmission strategy library, wherein the transmission strategy library includes multiple transmission strategies and request parameter ranges corresponding to each transmission strategy. Specifically, the transmission strategy library includes transmission strategies corresponding to different data volume ranges under each network state. The network state can be a network type or a network speed segment. Matching the data volume and network status of the file to be uploaded in the transmission strategy library, specifically, matching the data volume of the file to be uploaded in multiple data volume ranges under the network state, and when determining the data volume range to which the data volume of the file to be uploaded belongs, determining the transmission strategy corresponding to the data volume range as the transmission strategy corresponding to the upload request.
[0065] The determined transmission strategy is sent to the client so that the client performs file upload based on the transmission strategy. The upload request may include a file identifier, a file directory is created based on the file identifier, and the file blocks received from the client are stored in the corresponding file directory.
[0066] On the basis of the above embodiment, the upload request also includes MD5 verification information, and the MD5 verification information is used to verify the uploaded file block. Each file block includes first verification information, and the first verification information is determined by the client for the file block based on the MD5 verification information, and the MD5 verification information can be a verification parameter, which is used to perform MD5 algorithm processing on the file block. The server processes the received uploaded file block based on the MD5 verification information in the upload request to obtain second verification information, compares the first verification information with the second verification information, and determines the validity of the uploaded file block when the first verification information and the second verification information are consistent, thereby avoiding upload errors.
[0067] When the client completes uploading all the file blocks to be uploaded, it sends a transmission completion signal to the server. Based on the transmission completion signal, the server merges the multiple file blocks in the file directory to obtain a complete uploaded file. Each file block is configured with an identifier to mark the order of the file blocks, and multiple file blocks can be merged according to the file block identifier.
[0068] The technical solution provided in this embodiment improves the flexibility and applicability of file uploading by determining an adaptive transmission strategy for the file to be uploaded and flexibly setting the block information and parallel number of the file to be uploaded.
[0069] Figure 4 1 is a flowchart of a file uploading method provided by an embodiment of the present invention. The method specifically comprises the following steps:
[0070] S310: The client generates an upload request based on the data volume of the file to be uploaded and the network status, and sends the upload request to the server.
[0071] S320: The server receives an upload request sent by the client, extracts request parameters in the upload request, determines a transmission strategy based on the request parameters, and sends the transmission strategy to the client.
[0072] S330, the client receives the transmission strategy fed back by the server, wherein the transmission strategy includes a parallel number and block information; blocks the file to be uploaded based on the block information, and uploads each file block based on the parallel number, and during the uploading process of the file block, monitors the current resource consumption status, updates the transmission strategy according to the current resource consumption status, and uploads the unuploaded file blocks based on the updated transmission strategy.
[0073] S340: The server receives and stores the file blocks uploaded by the client, and when receiving a transmission completion signal, merges the received multiple file blocks to obtain an uploaded file.
[0074] The technical solution of this embodiment is that before the client uploads the file, the relevant information of the file upload is sent to the server. The server determines the transmission strategy of the file to be uploaded according to the data volume and network status of the file to be uploaded. The transmission strategy matches the file to be uploaded and the current upload conditions, taking into account the upload speed while avoiding the occupation of client resources. Furthermore, during the file upload process, the transmission strategy is updated in real time based on the current resource consumption status of the client to optimize the transmission strategy, improve the adaptability of the transmission strategy to the upload environment, and improve the efficiency of file upload while ensuring the normal operation of the client.
[0075] Based on the above embodiments, the present invention provides a preferred embodiment. Figure 5 , Figure 5The invention is a flowchart of a file upload method. The method includes: the client sends the file size (i.e., the data volume of the file to be uploaded), md5, and network status (whether the current network is 4G or wifi) to the server. The server determines the parallel number suitable for the current situation based on the current network situation obtained (the acquisition method is not limited) and returns the parallel number size (i.e., the transmission strategy) to the client. The client divides the file into blocks, establishes multiple connections with the server according to the received parallel number size, and evenly distributes the file blocks to each connection to upload the file blocks in parallel. After receiving the blocks, the server saves them to the corresponding block directory. During the upload process, the server counts the upload rate and dynamically updates the connection number size to maximize the upload efficiency. For example, when the current resource consumption state of the client does not exceed the resource consumption threshold, the parallel number is increased, and when the current resource consumption state exceeds the resource consumption threshold, the parallel number is reduced; or, when the upload rate is less than the expected rate (which can be determined based on the data volume of the file to be uploaded and the expected transmission time), the parallel number is increased, and when the upload rate is greater than the expected rate, the parallel number is reduced to avoid the consumption of resources occupied by the transmission affecting the normal operation of the client. After receiving the parallel number sent by the server, the client adjusts the number of connections and distributes the unuploaded blocks to each newly established connection. After all connections have finished uploading, the client notifies the server that the upload is complete. The server merges the block files, verifies the file integrity, and then deletes the blocks, completing the file block upload process.
[0076] Figure 6 It is a structural schematic diagram of a file uploading device provided by an embodiment of the present invention. The file uploading device can be integrated in a terminal such as a mobile phone, a computer, etc.
[0077] The transmission strategy determination module 410 generates an upload request based on the data volume of the file to be uploaded and the network status, and sends the upload request to the server, and receives the transmission strategy fed back by the server, wherein the transmission strategy includes parallel number and block information.
[0078] The file upload module 420 divides the to-be-uploaded file into blocks based on the block information, and uploads each file block based on the parallel number.
[0079] The transmission strategy updating module 430 is used to monitor the current resource consumption status during the uploading process of the file block, update the transmission strategy according to the current resource consumption status, and upload the unuploaded file block based on the updated transmission strategy.
[0080] Optionally, the file upload module 420 is used to:
[0081] Establishing a connection with a server, wherein the number of connections is the same as the number of parallel connections;
[0082] Based on non-blocking I / O, each data block is uploaded in parallel through the connection with the server.
[0083] Optionally, the transmission strategy updating module 430 is used to:
[0084] When the current resource consumption state does not exceed the resource consumption threshold, increase the number of parallelism and / or block information in the current transmission strategy;
[0085] When the current resource consumption state exceeds the resource consumption threshold, the parallel number and / or the block information in the current transmission strategy is reduced.
[0086] Optionally, the adjustment priority of the parallel number is higher than the adjustment priority of the block information.
[0087] The file uploading device provided in the embodiment of the present invention can execute the file uploading method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of executing the file uploading method.
[0088] Figure 7 It is a structural schematic diagram of a file uploading device provided by an embodiment of the present invention. The file uploading device can be integrated in an electronic device such as a server.
[0089] The request parameter extraction module 510 is used to receive the upload request sent by the client and extract the request parameters in the upload request, wherein the request parameters include one or more of the data volume of the file to be uploaded, the network status, and the expected transmission strategy;
[0090] A transmission strategy determination module 520, configured to determine a transmission strategy based on the request parameters and send the transmission strategy to the client, wherein the transmission strategy includes parallel number and block information;
[0091] The uploaded file processing module 530 is used to receive and store the file blocks uploaded by the client, and merge the received multiple file blocks to obtain the uploaded file when receiving the transmission completion signal.
[0092] Optionally, the transmission strategy determination module 520 is used to:
[0093] Input the data volume and network status of the file to be uploaded into a preset policy model to obtain a transmission policy output by the policy model; or
[0094] determining the desired transmission strategy as the transmission strategy; or,
[0095] The data volume and network status of the file to be uploaded are matched in a transmission strategy library, wherein the transmission strategy library includes multiple transmission strategies and request parameter ranges corresponding to each transmission strategy.
[0096] The file uploading device provided in the embodiment of the present invention can execute the file uploading method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of executing the file uploading method.
[0097] Figure 8 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. Figure 8 A block diagram of an electronic device 12 suitable for use in implementing embodiments of the present invention is shown. Figure 8 The electronic device 12 shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention. The device 12 is typically an electronic device that undertakes the image classification function.
[0098] like Figure 8 As shown, the electronic device 12 is in the form of a general purpose computing device. The components of the electronic device 12 may include, but are not limited to: one or more processors 16, a storage device 28, and a bus 18 connecting various system components (including the storage device 28 and the processor 16).
[0099] Bus 18 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processor, or a local bus using any of a variety of bus architectures. For example, these architectures include, but are not limited to, Industry Standard Architecture (ISA) bus, Micro Channel Architecture (MCA) bus, Enhanced ISA bus, Video Electronics Standards Association (VESA) local bus, and Peripheral Component Interconnect (PCI) bus.
[0100] The electronic device 12 typically includes a variety of computer system readable media. These media can be any available media that can be accessed by the electronic device 12, including volatile and non-volatile media, removable and non-removable media.
[0101] The storage device 28 may include computer system readable media in the form of volatile memory, such as random access memory (RAM) 30 and / or cache memory 32. The electronic device 12 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, the storage system 34 may be used to read and write non-removable, non-volatile magnetic media ( Figure 8 not shown, usually called a "hard drive"). Although Figure 8 Not shown in the figure, a disk drive for reading and writing a removable non-volatile disk (e.g., a "floppy disk"), and an optical disk drive for reading and writing a removable non-volatile optical disk (e.g., a read-only optical disk (Compact Disc-Read Only Memory, CD-ROM), a digital video disk (Digital Video Disc-Read Only Memory, DVD-ROM) or other optical media) may be provided. In these cases, each drive may be connected to the bus 18 via one or more data medium interfaces. The storage device 28 may include at least one program product having a set (e.g., at least one) of program modules that are configured to perform the functions of various embodiments of the present invention.
[0102] A program 36 having a set (at least one) of program modules 26 may be stored, for example, in a storage device 28, such program modules 26 including but not limited to an operating system, one or more application programs, other program modules, and program data, each of which or some combination thereof may include an implementation of a gateway environment. The program modules 26 generally perform the functions and / or methods of the embodiments described herein.
[0103] The electronic device 12 may also communicate with one or more external devices 14 (e.g., keyboards, pointing devices, cameras, displays 24, etc.), may communicate with one or more devices that enable a user to interact with the electronic device 12, and / or may communicate with any device that enables the electronic device 12 to communicate with one or more other computing devices (e.g., network cards, modems, etc.). Such communication may be performed via an input / output (I / O) interface 22. In addition, the electronic device 12 may also communicate with one or more gateways (e.g., a local area network (LAN), a wide area network (WAN), and / or a public gateway, such as the Internet) via a gateway adapter 20. As shown, the gateway adapter 20 communicates with other modules of the electronic device 12 via a bus 18. It should be understood that, although not shown in the figure, other hardware and / or software modules may be used in conjunction with the electronic device 12, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, disk arrays (Redundant Arrays of Independent Disks, RAID) systems, tape drives, and data backup storage systems.
[0104] The processor 16 executes various functional applications and data processing by running the programs stored in the storage device 28, such as implementing the file uploading method provided in the above embodiment of the present invention.
[0105] An embodiment of the present invention provides a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, the file uploading method provided by the embodiment of the present invention is implemented.
[0106] Of course, the computer program stored on a computer-readable storage medium provided by an embodiment of the present invention is not limited to the method operation described above, and can also execute the file uploading method provided by any embodiment of the present invention.
[0107] The computer storage medium of the embodiment of the present invention can adopt any combination of one or more computer-readable media. The computer-readable medium can be a computer-readable signal medium or a computer-readable storage medium. The computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples (non-exhaustive list) of computer-readable storage media include: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this document, a computer-readable storage medium can be any tangible medium containing or storing a program, which can be used by an instruction execution system, device or device or used in combination with it.
[0108] A computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, which carries a computer-readable source code. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0109] Source code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wire, electrical wire, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
[0110] Computer source code for performing the operations of the present invention may be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The source code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of gateway, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0111] Note that the above are only preferred embodiments of the present invention and the technical principles used. Those skilled in the art will understand that the present invention is not limited to the specific embodiments described herein, and that various obvious changes, readjustments and substitutions can be made by those skilled in the art without departing from the scope of protection of the present invention. Therefore, although the present invention has been described in more detail through the above embodiments, the present invention is not limited to the above embodiments, and may include more other equivalent embodiments without departing from the concept of the present invention, and the scope of the present invention is determined by the scope of the appended claims.
Claims
1. A file uploading method, characterized in that: include: Generate an upload request based on the data volume of the file to be uploaded and the network status, and send the upload request to the server, and receive a transmission strategy fed back by the server, wherein the transmission strategy includes parallel number and block information; The to-be-uploaded file is processed in blocks based on the block information, and each file block is uploaded based on the parallel number; During the uploading process of the file blocks, the current resource consumption state is monitored, the transmission strategy is updated according to the current resource consumption state, and the unuploaded file blocks are uploaded based on the updated transmission strategy; Wherein, updating the transmission strategy according to the current resource consumption state includes: In the case that each resource consumption information in the current resource consumption state does not exceed the corresponding resource consumption threshold, the adjustment amount corresponding to each difference is determined according to the difference between each resource consumption information and the corresponding resource consumption threshold, and the transmission strategy is updated based on the minimum adjustment amount; wherein the resource consumption threshold includes a CPU resource utilization threshold and a memory occupancy threshold, and the adjustment amount is the adjustment amount of the parallel number and / or the block information; When at least one resource consumption information in the current resource consumption state exceeds the corresponding resource consumption threshold, the adjustment amount corresponding to each difference is determined according to the difference between the at least one resource consumption information exceeding the corresponding resource consumption threshold and the corresponding resource consumption threshold, and the transmission strategy is updated based on the maximum adjustment amount.
2. The method according to claim 1, characterized in that The uploading of each file block based on the parallel number includes: Establishing a connection with the server, wherein the number of connections is the same as the parallel number; Based on non-blocking I / O, each data block is uploaded in parallel through the connection with the server.
3. A file uploading method, characterized in that: include: The client generates an upload request based on the data volume of the file to be uploaded and the network status, and sends the upload request to the server; The server receives an upload request sent by a client, extracts request parameters in the upload request, determines a transmission strategy based on the request parameters, and sends the transmission strategy to the client; wherein the request parameters include one or more of the data volume of the file to be uploaded, the network status, and the expected transmission strategy; The client receives the transmission strategy fed back by the server, wherein the transmission strategy includes a parallel number and block information; blocks the file to be uploaded based on the block information, and uploads each file block based on the parallel number, and during the uploading process of the file block, monitors the current resource consumption status, updates the transmission strategy according to the current resource consumption status, and uploads the unuploaded file block based on the updated transmission strategy; The server receives and stores the file blocks uploaded by the client, and merges the received multiple file blocks to obtain the uploaded file when receiving a transmission completion signal; Wherein, updating the transmission strategy according to the current resource consumption state includes: In the case that each resource consumption information in the current resource consumption state does not exceed the corresponding resource consumption threshold, the client determines the adjustment amount corresponding to each difference according to the difference between each resource consumption information and the corresponding resource consumption threshold, and updates the transmission strategy based on the minimum adjustment amount; wherein the resource consumption threshold includes a CPU resource usage threshold and a memory occupancy threshold, and the adjustment amount is the adjustment amount of the parallel number and / or the block information; When at least one resource consumption information in the current resource consumption state exceeds the corresponding resource consumption threshold, the client determines the adjustment amount corresponding to each difference according to the difference between the at least one resource consumption information exceeding the corresponding resource consumption threshold and the corresponding resource consumption threshold, and updates the transmission strategy based on the maximum adjustment amount; Wherein, determining the transmission strategy based on the request parameter includes: The server inputs the data volume and network status of the file to be uploaded into a preset policy model to obtain a transmission policy output by the policy model; or The server determines the expected transmission strategy as the transmission strategy; or, The server matches the data volume and network status of the file to be uploaded in a transmission strategy library, wherein the transmission strategy library includes multiple transmission strategies and request parameter ranges corresponding to each transmission strategy.
4. A file uploading device, characterized in that: include: A transmission strategy determination module generates an upload request based on the data volume of the file to be uploaded and the network status, and sends the upload request to the server, and receives the transmission strategy fed back by the server, wherein the transmission strategy includes parallel number and block information; A file uploading module, which processes the file to be uploaded in blocks based on the block information, and uploads each file block based on the parallel number; A transmission strategy update module, used to monitor the current resource consumption status during the uploading process of the file block, update the transmission strategy according to the current resource consumption status, and upload the unuploaded file block based on the updated transmission strategy; Wherein, the transmission strategy update module is also specifically used to determine the adjustment amount corresponding to each difference according to the difference between each resource consumption information and the corresponding resource consumption threshold when each resource consumption information in the current resource consumption state does not exceed the corresponding resource consumption threshold, and update the transmission strategy based on the minimum adjustment amount; wherein the resource consumption threshold includes a CPU resource utilization threshold and a memory occupancy threshold, and the adjustment amount is the adjustment amount of the parallel number and / or the block information; When at least one resource consumption information in the current resource consumption state exceeds the corresponding resource consumption threshold, the adjustment amount corresponding to each difference is determined according to the difference between the at least one resource consumption information exceeding the corresponding resource consumption threshold and the corresponding resource consumption threshold, and the transmission strategy is updated based on the maximum adjustment amount.
5. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the file uploading method as described in any one of claims 1-2 is implemented.
6. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the file uploading method described in any one of claims 1-2 is implemented.
Citation Information
Patent Citations
Network file transmission optimization method
CN104811499A
File uploading method and device, terminal, server and readable storage medium
CN109831506A
