A file downloading method, a file caching method and a server
By redirecting file download requests in the server cluster to cached or least utilized instances, the problem of low disk space utilization in the server cluster is solved, resulting in more efficient storage resource utilization and improved user experience.
Patent Information
- Application Number
- CN202211224135.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-30
- Publication Date
- 2026-01-13
- Estimated Expiration
- 2042-09-30
AI Technical Summary
The fact that all instances in the server cluster cache the same file results in low disk space utilization and wasted storage resources.
By querying cache records in the server cluster, file download requests are redirected to instances that have already cached the file or instances with the lowest space utilization, thereby optimizing the file retrieval path and avoiding duplicate caching and wasted storage resources.
It improves the disk space utilization of the server cluster, reduces the time users spend retrieving files, and avoids waste of storage resources and data overflow.
Smart Images

Figure CN115914202B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a file download method, a file caching method, and a server. Background Technology
[0002] In the field of computer technology, instances deployed in a server cluster cache user-uploaded files in their corresponding storage spaces when providing application services to users. When a user downloads the file, the instance can retrieve the file directly from its storage space without having to download it from the storage server, thereby improving the access efficiency of the server cluster.
[0003] However, the instances handling user upload and download requests in a server cluster may not be the same. To improve access efficiency, current technology caches the same file across all instances in a server cluster. Caches of the same file across all instances significantly wastes storage space, resulting in low disk space utilization for the server cluster. Summary of the Invention
[0004] This application provides a file download method, a file caching method, and a server, which can improve the disk space utilization of a server cluster.
[0005] Firstly, this application provides a file download method applied to a server cluster. The server cluster includes multiple instances. The method includes: upon querying a cache record of a file requested for download, determining an instance that has cached the file based on the cache record; if the instance that has cached the file is a first instance, reading the file from the storage space of the first instance and sending the file to the client; or, if the instance that has cached the file is a second instance in the server cluster, redirecting the file download request to the second instance, which is used to send the file to the client according to the file download request.
[0006] In the above solution, if the first instance does not cache the file requested by the user, the user's file download request is redirected to a second instance that caches the file. The second instance then sends the file to the client, thus resolving the issue of the first instance not caching the requested file. Caching a file across the server cluster improves disk space utilization and avoids wasting storage resources. Furthermore, compared to the first instance retrieving the file from an external storage server and sending it to the client, this solution reduces the time it takes for the user to retrieve the file.
[0007] In one possible implementation, if no cached record of the file requested for download is found, the method further includes: determining the instance with the lowest space utilization in the server cluster; if the instance with the lowest space utilization is the first instance, downloading the file from the storage server in the server cluster; or, if the instance with the lowest space utilization is the third instance in the server cluster, redirecting the file download request to the third instance, which is used to download the file from the storage server according to the file download request and send the file to the client.
[0008] In the above scheme, if the server cluster does not cache the file, the instance with the lowest space utilization in the server cluster can download the file from the storage server, which can maximize the use of the storage space of each instance and further improve the disk space utilization of the server cluster.
[0009] In one possible implementation, determining the instance with the lowest space utilization in the server cluster includes: obtaining the space utilization of other instances in the server cluster via a message queue; comparing the space utilization of the first instance with the space utilization of the other instances to determine the instance with the lowest space utilization.
[0010] In the above scheme, the instances can communicate with each other through message queues to obtain the space utilization of other instances.
[0011] In one possible implementation, downloading the file from the storage server in the server cluster includes: if the storage space of the first instance meets the caching conditions, downloading the file from the storage server; or, if the storage space does not meet the caching conditions, clearing the cached files in the storage space until the storage space meets the caching conditions, and then downloading the file from the storage server.
[0012] In the above scheme, the instance caches files only when the caching conditions are met in its corresponding storage space, which can avoid the problem of data loss due to data overflow in the storage space.
[0013] In one possible implementation, the caching condition includes: the remaining storage space of the storage space is greater than a first threshold, which is determined based on the size of the file.
[0014] In one possible implementation, the cache record for the file includes the IP address of an instance that has cached the file, and determining an instance that has cached the file in the server cluster based on the cache record for the file includes determining the instance that has cached the file based on the IP address.
[0015] In the above scheme, an instance can determine the instance that has cached the file identifier corresponding to the file by using the URL address in the cache record.
[0016] In one possible implementation, the cache record of the file includes a first hash value corresponding to the file, and sending the file to the client includes: calculating a second hash value of the file; if the second hash value is the same as the first hash value, sending the file to the client.
[0017] In the above scheme, performing hash value verification before sending the file can determine whether the file has been tampered with, thus avoiding sending a tampered file to the user.
[0018] Secondly, this application also provides a file caching method applied to a server cluster. The method includes: receiving a file upload request from a client, wherein the file caching request is used to request the upload of a first file; if the storage space of a first instance meets the caching conditions, caching the first file in the storage space; or, if the storage space does not meet the caching conditions, clearing the cached second file in the storage space until the storage space meets the caching conditions.
[0019] In one possible implementation, the remaining storage space of the storage space is greater than a threshold, which is determined based on the size of the first file.
[0020] In one possible implementation, after caching the first file in the storage space, the method further includes storing the first file in a storage server in the server cluster.
[0021] Thirdly, this application also provides a server. The server includes a processor and a memory, the processor being configured to execute a computer program stored in the memory to implement the solutions in the first aspect and its possible embodiments, or to implement the solutions in the second aspect and its possible embodiments.
[0022] Fourthly, this application provides a file downloading device. The file downloading device includes a receiving module and a processing module.
[0023] The receiving module is used to receive file download requests from clients.
[0024] The processing module is used to determine the instance of the file that has been cached based on the cache record when a cache record of the file requested for download is found; if the instance of the file that has been cached is the first instance, the file is read from the storage space of the first instance and sent to the client; or, if the instance of the file that has been cached is the second instance in the server cluster, the file download request is redirected to the second instance, which is used to send the file to the client according to the file download request.
[0025] In one possible implementation, the processing module is further configured to: if no cache record of the file requested for download is found, determine the instance with the lowest space utilization in the server cluster; if the instance with the lowest space utilization is the first instance, download the file from the storage server in the server cluster; or, if the instance with the lowest space utilization is the third instance in the server cluster, redirect the file download request to the third instance, which is configured to download the file from the storage server according to the file download request and send the file to the client.
[0026] In one possible implementation, the processing module is further configured to: determine the instance with the lowest space utilization in the server cluster by: obtaining the space utilization of other instances in the server cluster through a message queue; comparing the space utilization of the first instance with the space utilization of the other instances to determine the instance with the lowest space utilization.
[0027] In one possible implementation, the processing module is further configured to: download the file from the storage server in the server cluster includes: if the storage space of the first instance meets the caching conditions, download the file from the storage server; or, if the storage space does not meet the caching conditions, clean up the cached files in the storage space until the storage space meets the caching conditions, and then download the file from the storage server.
[0028] In one possible implementation, the caching condition includes: the remaining storage space of the storage space is greater than a first threshold, which is determined based on the size of the file.
[0029] In one possible implementation, the cache record of the file includes the IP address of an instance that has cached the file, and the processing module is further configured to: determine the instance that has cached the file based on the IP address.
[0030] In one possible implementation, the cache record of the file includes a first hash value corresponding to the file, and the processing module is further configured to: calculate a second hash value of the file; if the second hash value is the same as the first hash value, send the file to the client.
[0031] Fifthly, this application also provides a file caching device. The file caching device includes a receiving module and a processing module.
[0032] The receiving module is used to receive file upload requests from clients, and the file cache request is used to request the upload of the first file.
[0033] The processing module is used to cache the first file in the storage space if the storage space of the first instance meets the caching conditions; or, if the storage space does not meet the caching conditions, to clean up the cached second file in the storage space until the storage space meets the caching conditions.
[0034] In one possible implementation, the caching condition includes: the remaining storage space of the storage space is greater than a threshold, which is determined based on the size of the first file.
[0035] In one possible implementation, after caching the first file in the storage space, the processing module is further configured to: store the first file in the storage server of the server cluster.
[0036] Sixthly, this application provides a computer-readable storage medium. The computer-readable storage medium includes instructions that, when executed on a computer, cause the computer to implement the scheme as described in the first aspect and any of its optional embodiments, or to perform the scheme as described in the second aspect and any of its optional embodiments.
[0037] In a seventh aspect, this application provides a computer program product. The computer program product includes program code that, when a computer runs the computer program product, causes the computer to implement the scheme as described in the first aspect and any of its optional embodiments, or to execute the scheme as described in the second aspect and any of its optional embodiments.
[0038] Any of the server, computer storage medium, or computer program products provided above are used to execute the methods provided above. Therefore, the beneficial effects they can achieve can be referred to the beneficial effects of the corresponding solutions in the corresponding methods provided above, and will not be repeated here. Attached Figure Description
[0039] Figure 1 This is a schematic diagram of a server cluster structure provided in an embodiment of this application;
[0040] Figure 2 This is a flowchart of a file download method provided in an embodiment of this application;
[0041] Figure 3 This is a schematic diagram illustrating an example of reading a cached file from its own storage space, provided in an embodiment of this application.
[0042] Figure 4 This is a schematic diagram illustrating an example of request redirection to other instances provided in this application embodiment;
[0043] Figure 5 This is a schematic diagram illustrating how instances send storage space information through a message queue, as provided in an embodiment of this application.
[0044] Figure 6 This is a flowchart of a file caching method provided in an embodiment of this application;
[0045] Figure 7 This is a schematic diagram of the structure of a file download device provided in an embodiment of this application;
[0046] Figure 8 This is a schematic diagram of the structure of a business platform provided in an embodiment of this application;
[0047] Figure 9 This is a schematic diagram of the structure of a server provided in an embodiment of this application. Detailed Implementation
[0048] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions in the embodiments of this application will be described below with reference to the accompanying drawings.
[0049] In the description of the embodiments of this application, the words "exemplary," "for example," or "for instance" are used to indicate examples, illustrations, or explanations. Any embodiment or design described as "exemplary," "for example," or "for instance" in the embodiments of this application should not be construed as being more preferred or advantageous than other embodiments or designs. Specifically, the use of the words "exemplary," "for example," or "for instance" is intended to present the relevant concepts in a specific manner.
[0050] In the description of the embodiments in this application, the term "and / or" is merely a description of the association relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, B existing alone, and A and B existing simultaneously. Furthermore, unless otherwise stated, the term "multiple" means two or more. For example, multiple systems refer to two or more systems, and multiple screen terminals refer to two or more screen terminals.
[0051] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature. The terms "comprising," "including," "having," and their variations all mean "including but not limited to," unless otherwise specifically emphasized.
[0052] Figure 1 This is a schematic diagram of a server cluster structure provided in an embodiment of this application.
[0053] See Figure 1This server cluster may include one or more load balancers 100, one or more business servers 200, one or more storage servers 300, and one or more database servers 400. It should be noted that... Figure 1 The number of load balancers, business servers, storage servers, and database servers in the data set is merely illustrative. In other embodiments, the server cluster may include other numbers of load balancers, business servers, storage servers, and database servers.
[0054] Within the business server 200, one or more virtual machines and / or containers can be created. Each virtual machine or container can deploy one instance, meaning one or more instances can be deployed within a single business server. The various business servers can communicate with each other via a local area network (LAN). Instances within a single business server share the computing, storage, and communication resources of that business server.
[0055] The following is about Figure 1 The functions of the load balancer 100, business server 200, storage server 300 and database server 400 shown are introduced.
[0056] The load balancer 100 is used to receive service requests sent by user clients, such as file download requests and / or file upload requests, and distribute the service requests to instances of each service server 200 in the server cluster according to the load balancing strategy. For example, the load balancer 100 can distribute the service request to each instance according to the current service load of each instance in each service server 200. The client can be running iOS, Android, Microsoft, or other operating systems. Specifically, the client can be a mobile phone, tablet computer, desktop computer, laptop computer, handheld computer, laptop, ultra-mobile personal computer (UMPC), netbook, as well as cellular phones, personal digital assistants (PDAs), augmented reality (AR) devices, virtual reality (VR) devices, artificial intelligence (AI) devices, wearable devices, in-vehicle devices, smart home devices, and / or smart city devices, etc. This embodiment does not specifically limit the specific type of client.
[0057] Each instance in the business server 200 provides business services to users based on business requests allocated by the load balancer 100. For example, when instance 211 in the business server 200 receives a file upload request from a client, it caches file 1 in the file upload request and then stores file 1 in the storage server 300. As another example, when instance 211 in the business server 200 receives a file download request from a client, if it determines that the file download request requests file 1, instance 211 retrieves file 1 from its local storage space and then sends file 1 to the client. If instance 211 does not cache file 1, it can retrieve file 1 from the storage server 300.
[0058] Storage server 300 is used to store files sent from various instances of business server 200. Storage server 300 can use object storage for files. The storage server can include multiple storage nodes, and each storage node can include multiple buckets. Each bucket can store data blocks and metadata blocks corresponding to files. The metadata blocks record the attribute information of the data blocks stored in the bucket.
[0059] In the above description, after caching file 1, instance 211 stores file 1 on storage server 300. This allows it to promptly send file 1 to the user's client the next time the user requests to download it, thereby improving access efficiency. For example, when instance 211 processes a user's file download request for file 1 in the future, it can directly send the locally cached file 1 to the user's client without downloading it from storage server 300, thus shortening the user's access time and improving access efficiency.
[0060] However, this approach has a problem: if, in the future, a file download request for file 1 is assigned to instance 212 by load balancer 100, since instance 212 has not cached the file, it will still need to download file 1 from storage server 300. Because the time it takes for instance 212 to retrieve file 1 from storage server 300 is longer than the time it takes to retrieve file 1 from its local storage, the file retrieval time for instance 212 is longer, impacting the user experience.
[0061] In one embodiment, a cache synchronization mechanism can be used between instances to address the issue of uncached user-requested files within an instance. For example, after caching file 1, instance 211 uses the data synchronization tool `remote synchronize` to synchronize file 1 to other instances in the server cluster, thereby achieving fast file backup and caching. However, since instances within a server share the server's CPU and disk, synchronizing cached files between instances consumes significant CPU resources and disk space, which can reduce the performance of the server cluster and decrease disk space utilization to some extent.
[0062] Based on this, embodiments of this application provide a file download method, a file caching method, and a server, which can solve the above-mentioned problems.
[0063] Figure 2 This is a flowchart illustrating a file download method provided in an embodiment of this application. This method can be applied to various servers in a server cluster. In this method, if an instance in the server cluster does not cache the file requested by a user, that instance can redirect the user's request to an instance that has cached the file, and other instances can then send the file to the client, thereby resolving the issue of instances not caching the requested file. Since the instances in the server cluster communicate via a local area network, by redirecting the request to other instances that have cached the file, compared to the instance retrieving the file from a storage server, the time for the user to obtain the file can be shortened, improving the user experience.
[0064] The following is about Figure 2 The document provides a detailed explanation of the file download method.
[0065] See Figure 2 The method may include the following steps S201 to S206.
[0066] Step S201: Receive a file download request from the client.
[0067] Users can initiate service requests to the server cluster through a client. These requests may include, for example, file download requests. The load balancer 100 in the server cluster receives the service requests sent by the client and distributes them according to the load of each instance in the current server cluster.
[0068] For example, when a business request is a file download request, and load balancer 100 assigns it to instance 211, instance 211 receives the file download request sent by the user through the client from load balancer 100.
[0069] In one embodiment, the file download request includes a file identifier corresponding to the file. This file identifier may include the file's message digest algorithm 5 (MD5) value.
[0070] Step S202: Query the cached record of the file to be downloaded from the database server.
[0071] After caching user files, each instance in the business server 200 can write a cached record of that file to the database server 300. In one embodiment, the database can store a file cache table, which records the cached records of files cached by each instance. In another embodiment, the database can use a distributed lock to enable concurrent writing of cached records by each instance.
[0072] In this step, when instance 211 determines that the file download request is for requesting the download of file 1, instance 211 can query the cached record of file 1 from database server 300.
[0073] If a cache record for file 1 is found, instance 211 can determine that file 1 has been cached and proceed to step S203.
[0074] If no cache record for file 1 is found, instance 211 can determine that file 1 is not cached and proceed to step S205.
[0075] Step S203: Determine the instance of the cached file based on the cache record.
[0076] The cache record may include the Uniform Resource Locator (URL) address corresponding to the file. The URL address corresponding to a file may include the Internet Protocol (IP) address of the instance that has cached that file and the cache path of that file.
[0077] In this step, instance 211 can determine the URL address of the cached file from the cache record of the file, determine the IP address of the instance that cached file 1 from the URL address, and determine the instance that cached file 1 based on the IP address.
[0078] For example, if the IP address of the instance that caches file 1 is the same as the IP address of instance 211, then the instance that caches file 1 is determined to be instance 211. If the IP address of the instance containing file 1 is the same as the IP address of instance 211, then the instance that caches file 1 is determined to be instance 212.
[0079] After determining that an instance of file 1 has been cached, instance 211 executes step S204.
[0080] Step S204: Read the file from the storage space of instance 211, or redirect the file download request to instance 212, which has cached the file, to obtain the file from instance 212.
[0081] If the instance that has cached file 1 is instance 211, it means that instance 211 has cached file 1. Figure 3 As shown, instance 211 can directly read file 1 from its own corresponding storage space. Specifically, instance 211 can determine the storage path of file 1 based on the URL address corresponding to the file identifier of file 1, and then read file 1 from the storage space based on the storage path of file 1. In one embodiment, when instance 211 determines that it is itself that has cached file 1, it can verify whether it has cached file 1 based on the file identifier of file 1.
[0082] If the instance that has cached file 1 is not instance 211, it means that instance 211 has not cached file 1. Figure 4 As shown, instance 211 can redirect the file download request to instance 212. After receiving the redirected file download request, instance 212 reads file 1 from its storage space and then sends file 1 to the client. Specifically, after receiving the redirected file download request, instance 212 can retrieve the cache record corresponding to the file identifier of file 1 from the database server based on the file identifier in the file download request. Then, it retrieves the URL address from the cache record, determines the storage path of file 1 from the URL address, and then reads file 1 from its own storage space based on the storage path. In this way, if instance 211 does not cache file 1, by redirecting the request to an instance that has cached file 1, it can reduce the time for the user to obtain file 1 and improve the user experience.
[0083] Step S205: Identify the instance with the lowest space utilization in the server cluster.
[0084] Each instance in a server cluster can be configured with a message queue. An instance can use its own message queue to send its storage space information to other instances in the server cluster, either in real-time or periodically. An instance can also use its own message queue to receive storage space information sent by other instances in the server cluster via message queues, either in real-time or periodically. For example, see... Figure 5 Instances 211, 212, 221, and 222 can send each other's storage space information via a configured message queue. One instance can determine the storage space utilization of other instances based on their storage space information.
[0085] In this step, instance 211 can determine the space utilization rate of other instances based on the storage space information of other instances in the server cluster, and then compare and analyze the space utilization rate of other instances with its own space utilization rate to determine the instance with the lowest space utilization rate.
[0086] In one embodiment, storage space information may include remaining storage space and total storage space. Therefore, instance 211 can calculate and determine the space utilization rate of other instances based on their remaining and total storage space. The formula for calculating space utilization rate is: Space Utilization Rate = Remaining Storage Space / Total Storage Space.
[0087] In one embodiment, storage space information can also directly include space utilization. Each instance can first calculate its own space utilization according to the aforementioned formula and then send it to other instances via a message queue. In this way, an instance does not need to calculate its own space utilization after obtaining the storage space information from other instances.
[0088] Step S206: Download the file from storage server 300, or redirect the file download request to instance 221 so that instance 221 downloads the file from storage server 300.
[0089] If instance 211 is the instance with the lowest space utilization in the server cluster, then instance 211 will retrieve file 1 from storage server 300. Specifically, if the remaining storage space of instance 211 is not less than the threshold, it can directly retrieve file 1 from storage server 300. If the remaining storage space of instance 211 is less than the threshold, instance 211 can clear cached files in its own storage space until the remaining storage space is not less than the threshold. This avoids data overflow when instance 211 retrieves the file. The threshold can be twice the size of the file 1 that needs to be retrieved.
[0090] In one embodiment, the file storage table may also include information such as the cache time, expiration time, update time, and download count for each cached file. Specifically, when cleaning up storage space, instance 211 can determine the files to be cleaned up by using the cache time, expiration time, download count, and update time recorded in the cache records of each file in the file cache table. For example, a file can be determined to be cleaned up when the difference between its cache time and the current time is not less than a time threshold, or the current time is not less than the expiration time, or the download count is not less than a number threshold, or the difference between its update time and the current time is not less than a time threshold. Furthermore, each instance in the server cluster can also clean up its own cached files periodically. For example, each instance can clean up its cached files every 10 minutes.
[0091] In one embodiment, the file cache record may further include the persistent state corresponding to the file identifier of the cached file. The persistent state of a file includes whether it has been stored on the storage server or not. It is understood that the instance can cache the file on storage server 300 only when the persistent state corresponding to the file identifier is that it has been stored on the storage server.
[0092] In the above scheme, after instance 211 or other instances read file 1 from their own storage space or obtain file 1 from the storage server, they send file 1 to the client. In one embodiment, the file cache table may also include the hash value of cached files. The hash value can be used to determine whether the file has been tampered with, ensuring file security. Specifically, before sending the file to the client, instance 211 may also calculate the hash value of file 1, and then compare it with the hash value of file 1 obtained from the file cache table. If the two hash values are the same, instance 211 can send file 1 to the client. The hash value can be obtained by calculating the cached file using secure hash algorithm 1 (SHA1) and / or secure hash algorithm 256 (SHA256).
[0093] In one embodiment, after receiving the redirected file download request, instance 212 or instance 221 can perform the above actions as in instance 211. Figure 2 The steps involved in obtaining file 1 are not detailed here.
[0094] The above Figure 2 In the illustrated embodiment, when an instance in the server cluster receives a file download request, if that instance does not cache the requested file, it redirects the request to another instance that has cached the file. This other instance then sends the file to the client, reducing the time it takes for the user to retrieve the file compared to obtaining it from a storage server. Furthermore, once the instance obtains the file from another instance, it can directly send it to the client, allowing the server cluster to cache the file, thus avoiding wasted storage resources and saving storage space.
[0095] Figure 6 This application provides a file caching method. This method can also be applied to instances in a server cluster. Specifically, when an instance in the server cluster receives a file upload request from a user via a client, it determines the instance to cache the file based on the storage space information of each instance. After caching the file, it stores the file in storage server 300. The following example uses instance 211 as an example, combined with... Figure 6 The steps shown below provide a detailed explanation of the method.
[0096] See Figure 6 The method includes the following steps S601-S605.
[0097] Step S601: Receive a file upload request from the client. The file upload request is used to request the upload of the first file.
[0098] Step S602: Determine whether the storage space meets the caching conditions.
[0099] In this step, the caching condition may include the remaining storage space being greater than a threshold. This threshold can be determined based on the size of the first file, for example, twice the size of the first file. If instance 211 determines that the remaining storage space is greater than twice the size of the first file, it can be determined that the storage space meets the caching condition; otherwise, it does not.
[0100] Step S603: If the caching conditions are met, cache the file in the storage space of instance 211.
[0101] Step S604: If the caching conditions are not met, clean up the cached second file in the storage space of instance 211 until the storage space meets the caching conditions, and cache the file in the storage space of instance 211.
[0102] In this step, for a detailed description of cleaning up cache files in storage space in Instance 211, please refer to the previous section. Figure 2 The description of step S206 in the illustrated method embodiment will not be repeated here. If the condition is not met, the cached files in the storage space are cleaned up until the remaining storage space is not less than the threshold, which can prevent data overflow when caching files in this instance.
[0103] Step S605: Store the first file to storage server 300.
[0104] In this step, after instance 211 caches the first file, it stores the first file to storage server 300. Instance 211 can use object storage to store the first file on storage server 300.
[0105] based on Figure 2 The illustrated file download method embodiment also provides a file download device 700. This file download device 700 is applied in a business server for executing... Figure 2 The various steps in the illustrated file download method embodiment.
[0106] Figure 7 This is a schematic diagram of the structure of a file caching device 700 provided in an embodiment of this application. Figure 7As shown, the file caching device 700 may include a receiving module 701 and a processing module 702.
[0107] The receiving module 701 is used to receive file download requests from clients.
[0108] The processing module 702 is used to determine the instance of the cached file based on the cache record when a cache record of the file requested for download is found; if the instance of the cached file is 211, the file is read from the storage space of the first instance and sent to the client; or, if the instance of the cached file is instance 212 in the server cluster, the file download request is redirected to instance 212, which is used to send the file to the client according to the file download request.
[0109] It should be noted that, Figure 7 The file caching device 700 provided in the illustrated embodiment, when executing the file caching method, is only illustrated by the division of the above-described functional modules. In practical applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. Furthermore, the file caching device 700 provided in the above embodiment and... Figure 2 The file caching method embodiments shown belong to the same concept, and their specific implementation process can be found in the method embodiments, which will not be repeated here.
[0110] based on Figure 6 The illustrated file caching method embodiment also provides a file caching device 800. This file caching device is applied to... Figure 1 The business server shown contains one or more instances deployed for execution. Figure 6 The illustrated file caching method embodiment includes various steps. The file caching device 800 may include a receiving module 801 and a processing module 802.
[0111] The receiving module 801 is used to receive the file upload request from the client, which is used to request the upload of the first file.
[0112] The processing module 802 is used to cache the first file in the storage space if the storage space of instance 211 meets the caching conditions; or, if the storage space of instance 211 does not meet the caching conditions, to clean up the cached second file in the storage space of instance 211 until the storage space of instance 211 meets the caching conditions, and to cache the first file in the storage space of instance 211.
[0113] It should be noted that the file caching device 800 described above, when executing the file caching method, is only illustrating the division of the above functional modules. In practical applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. Furthermore, the file caching device 800 provided in the above embodiment and... Figure 6 The file caching method embodiments shown belong to the same concept, and their specific implementation process can be found in the method embodiments, which will not be repeated here.
[0114] Figure 8 This is a business platform provided in an embodiment of this application. For example... Figure 8 As shown, this business platform includes multiple server clusters (e.g. Figure 8 The server clusters (1 through 3) consist of one or more load balancers, one or more business servers, one or more storage servers, and one or more database servers. Instances deployed in each server cluster can be accessed by executing... Figure 2 File download method embodiment or Figure 6 The various method steps in the illustrated file caching method embodiment are used to provide users with file download and file upload services.
[0115] In one embodiment, the files stored in different server clusters may be different. If a server cluster determines that it does not store the file requested by the user, it can retrieve the file from other server clusters. For example, if a user's file 1 is stored in server cluster 2, and the user accesses server cluster 1, since server cluster 1 does not store the requested file, server cluster 1 can send a file request to server cluster 2 to retrieve file 1.
[0116] In one embodiment, each server cluster can be deployed in a different region to achieve cross-regional file storage services.
[0117] Figure 9 This is a schematic diagram of the hardware structure of a server 900 provided in an embodiment of this application.
[0118] See Figure 9 The server 900 includes a processor 901, a memory 902, a communication interface 903, and a bus 904. The processor 901, memory 902, and communication interface 903 are connected to each other via the bus 904. The processor 901, memory 902, and communication interface 903 can also be connected using other methods besides the bus 904.
[0119] The memory 902 can be various types of storage media, such as random access memory (RAM), read-only memory (ROM), non-volatile RAM (NVRAM), programmable ROM (PROM), erasable PROM (EPROM), electrically erasable PROM (EEPROM), flash memory, optical storage, hard disk, etc.
[0120] The processor 901 can be a general-purpose processor, which can be a processor that performs specific steps and / or operations by reading and executing contents stored in memory (e.g., memory 902). For example, the general-purpose processor can be a central processing unit (CPU). The processor 901 may include at least one circuit to perform... Figure 2 or Figure 6 All or part of the steps in the method provided in the illustrated embodiments.
[0121] The communication interface 903 includes input / output (I / O) interfaces, physical interfaces, and logical interfaces for interconnecting devices within the server 900, as well as interfaces for interconnecting the server 900 with other devices (such as other servers or user equipment). The physical interface can be an Ethernet interface, a fiber optic interface, an ATM interface, etc.
[0122] The bus 904 can be any type of communication bus used to interconnect the processor 901, memory 902 and communication interface 903, such as a system bus.
[0123] The aforementioned devices can be disposed on separate chips, or at least partially or entirely on the same chip. Whether to dispose of the devices independently on different chips or integrate them on one or more chips often depends on the needs of the product design. This application does not limit the specific implementation of the aforementioned devices.
[0124] Figure 9 The server 900 shown is merely an example. In the implementation process, the server 900 may also include other components, which will not be listed in this article.
[0125] In the above embodiments, implementation can be achieved entirely or partially through software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented entirely or partially in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of the present invention are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid-state disk (SSD)).
[0126] It is understood that the various numerical designations used in the embodiments of this application are merely for descriptive convenience and are not intended to limit the scope of the embodiments of this application. It should be understood that in the embodiments of this application, the order of the process numbers does not imply the order of execution; the execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application.
[0127] The specific embodiments described above further illustrate the purpose, technical solution, and beneficial effects of this application. It should be understood that the above description is only a specific embodiment of the present invention and is not intended to limit the scope of protection of this application. Any modifications, equivalent substitutions, improvements, etc., made on the basis of the technical solution of this application should be included within the scope of protection of this application.
Claims
1. A file download method, characterized in that, Applied to a server cluster, wherein the server cluster includes one or more business servers, and the business servers include one or more instances, the method includes: Receive a file download request from a client, the file download request being used to request the acquisition of a file; If no cache record for the file is found, the instance with the lowest space utilization in the server cluster is determined based on the space utilization of each instance in the message queue. The cache record is used to indicate an instance in the server cluster that has cached the file. If the instance with the lowest space utilization in the server cluster is the first instance, the first instance downloads the file from the storage server in the server cluster, caches the file in the storage space of the first instance, reads the file from the storage space of the first instance, and sends the file to the client; If a cache record for the file is found, an instance of the file that has been cached can be determined based on the cache record; If the instance that has cached the file is the second instance in the server cluster, the file download request is redirected to the second instance, which is used to send the file to the client according to the file download request.
2. The method according to claim 1, characterized in that, If no cache record of the file is found, the method further includes: If the instance with the lowest space utilization in the server cluster is the third instance in the server cluster, the file download request is redirected to the third instance. The third instance is used to download the file from the storage server according to the file download request and send the file to the client.
3. The method according to claim 1, characterized in that, The instances that determine the lowest space utilization in the server cluster include: The space utilization rate of the first instance is compared with the space utilization rate of the other instances to determine the instance with the lowest space utilization rate.
4. The method according to claim 1, characterized in that, The downloading of the file from the storage server in the server cluster includes: If the storage space of the first instance meets the caching conditions, download the file from the storage server; or, If the storage space does not meet the caching conditions, the cached files in the storage space are cleared until the storage space meets the caching conditions, and the files are downloaded from the storage server.
5. The method according to claim 4, characterized in that, The caching conditions include: The remaining storage space of the storage space is greater than a first threshold, which is determined based on the size of the file.
6. The method according to claim 1, characterized in that, The cache record of the file includes the IP address of the instance that has cached the file, and determining the instance that has cached the file based on the cache record includes: The instance of the file that has been cached is determined based on the IP address.
7. The method according to claim 1, characterized in that, The cache record of the file includes a first hash value corresponding to the file, and sending the file to the client includes: Calculate the second hash value of the file; If the second hash value is the same as the first hash value, the file is sent to the client.
8. A file caching method, characterized in that, Applied to a server cluster, wherein the server cluster includes one or more business servers, and the business servers include one or more instances, the method includes: Receive a file upload request from the client, wherein the file cache request is used to request the upload of the first file; If the storage space of the first instance meets the caching conditions, the first file is cached in the storage space; or, If the storage space does not meet the caching conditions, the cached second file in the storage space is cleared until the storage space meets the caching conditions, and the first file is cached in the storage space. The one or more instances send the file to the client by the method of any one of claims 1-7.
9. The method according to claim 8, characterized in that, The caching conditions include: The remaining storage space of the storage space is greater than a threshold, which is determined based on the size of the first file.
10. The method according to claim 8 or 9, characterized in that, After caching the first file to the storage space, the method further includes: The first file is stored in the storage server of the server cluster.
11. A server, characterized in that, The server includes a processor and a memory, the processor being configured to execute a computer program stored in the memory to implement the method of any one of claims 1 to 7, or to implement the method of any one of claims 8 to 10.
Citation Information
Patent Citations
Data storage method and device based on redundancy mechanism and server
CN107870726A
Data processing method and device for content distribution network, and electronic equipment
CN113301081A
System and method for storing metadata for a file in a distributed storage system
US9330107B1