Response method, electronic device, and storage medium
By allowing file gaps in CDN nodes to store uncached data requested by users, the problem of storage waste and reduced throughput caused by segmented requests is solved, achieving more efficient storage space utilization and improved throughput.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-04-21
- Publication Date
- 2026-03-20
AI Technical Summary
CDN nodes' responses to segmented requests can easily lead to wasted storage space, poor caching system performance, and reduced throughput.
Allowing locally cached files to have file holes allows you to request only the uncached data requested by the user from the origin server and store it in the file hole, thus avoiding the storage of unrequested data and simplifying the data processing flow.
It improves the utilization of local storage space and the performance of the caching system, reduces latency, lowers the probability of network timeout, and increases throughput.
Smart Images

Figure CN116760897B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] Embodiments of the present application relate to the technical field of communication, and in particular, to a responding method, an electronic device and a storage medium. BACKGROUND
[0002] A content delivery network (CDN) is located between a user and a source station, and is mainly used to provide acceleration services for the user. That is, after the CDN node receives a request for some data from the user for the first time, the CDN node requests the corresponding data from the source station and caches the data locally. Thus, when the user requests the cached data from the CDN node again, the CDN node does not need to request the data from the source station again, but reads and returns the data from the local cache to the user, thereby realizing the acceleration function.
[0003] Among them, the user usually initiates a request to the CDN node through the hyper text transfer protocol (HTTP). However, there is a special request in HTTP, that is, a segment request, which requests only the data in one or more intervals of a file, rather than the complete data of the file. For example, the browser initiates a segment request, so that the file can be downloaded from the interrupted position, and the downloaded file part does not need to be downloaded again, so that the user can pause and continue to download the file at any time, and the same content is not downloaded repeatedly.
[0004] However, the response of the CDN node to the segment request can easily cause problems such as waste of storage space, poor performance of the cache system, and reduction of throughput. SUMMARY
[0005] Embodiments of the present application provide a responding method, an electronic device and a storage medium, which are at least beneficial to improve the utilization rate of local storage space and the performance of the cache system, and improve the throughput.
[0006] According to some embodiments of the present application, the embodiments of the present application provide a responding method, applied to a CDN node, the method comprising: receiving a user request, the user request being used to request data in a target interval of a target file; in a case that the target file has been cached locally and there is a file hole in the target interval of the target file cached locally, requesting target data corresponding to the file hole in the target interval from a source station, to respond to the user request according to the target data; and storing the target data in the file hole corresponding to the target file.
[0007] According to some embodiments of the present application, another aspect of the embodiments of the present application further provides an electronic device, comprising: at least one processor; and a memory connected with the at least one processor in communication; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the response method as described above.
[0008] According to some embodiments of the present application, another aspect of the embodiments of the present application further provides a computer readable storage medium, which stores a computer program, and the computer program is executed by a processor to implement the response method as described above.
[0009] The technical solutions provided by the embodiments of the present application have at least the following advantages:
[0010] In the case that the target file is cached locally and there is a file hole in the target interval of the locally cached target file, the source station is requested for target data corresponding to the file hole in the target interval, so as to respond to the user request according to the target data, that is, the source station is requested for data requested by the user and not cached in the local cache, and the data not requested by the user is no longer stored in advance, so that all the data cached in the local cache is the data requested by the user, and there is no need to wait for the download of the data not requested, thereby saving the storage space occupied by the local cache, improving the utilization of the local storage space and the performance of the cache system, reducing the time delay, and reducing the probability of network timeout. At the same time, since the file hole is allowed to exist in the locally cached target file, after the target data is requested from the source station, the target data can be stored in the file hole corresponding to the locally cached target file, and one target file corresponds to only one file in the local cache, so that the number of cached files is not increased, and the CDN of massive files can be used smoothly, which is conducive to improving the throughput. BRIEF DESCRIPTION OF DRAWINGS
[0011] One or more embodiments are illustrated by way of example in the drawings, which are not limiting of the embodiments and reference numerals in the drawings indicate like elements, unless otherwise specified herein. The drawings are not necessarily to scale, lo
[0012] Figure 1 is a flowchart of a response method provided by the embodiments of the present application;
[0013] Figure 2 is a schematic diagram of a locally cached target file and different target intervals involved in the response method provided by the embodiments of the present application;
[0014] Figure 3 is a flowchart of a response method provided by the embodiments of the present application, which includes a step of determining an overlap condition;
[0015] Figure 4 is a flow chart of a response method provided by an embodiment of the present application, comprising a step of storing data being requested from a source station;
[0016] Figure 5 is a flow chart of a response method provided by an embodiment of the present application, comprising a step of creating a target file;
[0017] Figure 6 is a flow chart of a response method provided by an embodiment of the present application, comprising a step of obtaining valid data;
[0018] Figure 7 is a flow chart of a response method provided by an embodiment of the present application, comprising a step of detecting whether a target interval is an empty set;
[0019] Figure 8 is a flow chart of a response method provided by an embodiment of the present application, comprising a step of determining that a file hole exists;
[0020] Figure 9 is a flow chart of a response method provided by an embodiment of the present application, comprising a step of requesting data of a target file located in a target interval from a source station;
[0021] Figure 10 is a flow chart of a response method provided by an embodiment of the present application, comprising a step of adding a file hole;
[0022] Figure 11 is a flow chart of a response method provided by an embodiment of the present application, comprising a step of creating a cache record;
[0023] Figure 12 is a structural schematic diagram of a CDN node provided by an embodiment of the present application;
[0024] Figure 13 is a structural schematic diagram of an electronic device provided by an embodiment of the present application. DETAILED DESCRIPTION
[0025] As can be known from the background, the response of the CDN node to the segmented request can easily lead to the problems of waste of storage space, poor performance of the cache system, and reduction of throughput.
[0026] The analysis shows that the reason for the above problems is at least that the CDN node has two main implementation ways to respond to the segment request: 1. The CDN node requests the complete data of the file from the source station and caches after receiving the segment request for the first time, so as to respond to the corresponding segment request by obtaining the data in one or more intervals required by the segment request from the complete data of the file and returning it to the user; 2. Without requesting the complete data of the file from the source station, considering that the data in the file is requested in different orders by the segment request, in order to facilitate local caching and response, the one or more intervals required by the segment request are split into multiple small intervals for source request and the data in different small intervals is stored as different files independently in the local, so that the segment request is responded by multiple data in small intervals. However, if the first way is used to respond, part of the data in the file will not be requested by the user, part of the memory is wasted in storing data that will not be used, and the network timeout caused by the need to wait for the source and caching of the previous data will make the disconnection more likely to occur. If the second way is used to respond, the number of cached files is greatly increased, which affects the throughput, and different segment requests request different intervals, so it is difficult to provide a unified splitting standard to fit the intervals requested by different segment requests.
[0027] To solve the above problems, the embodiments of the present application provide a response method, an electronic device and a storage medium. The locally cached file allows file holes, and the target data in the file holes in the user request is requested when the source is returned, instead of the entire file or the divided data, so that the data cached locally is all data requested by the user, improving the local storage space, avoiding resource waste caused by caching data not requested by the user, and avoiding timeout problems caused by waiting for data not requested by the user. After obtaining the target data by returning the source, the target data will be stored in the file holes corresponding to the target file in the local cache, instead of being stored as multiple files, and the target file always has only one file in the local storage, which is conducive to improving the throughput.
[0028] To make the purpose, technical solutions and advantages of the embodiments of the present application clearer, the embodiments of the present application will be described in detail below with reference to the drawings. However, those skilled in the art can understand that in the embodiments of the present application, many technical details are proposed in order to make the reader better understand the present application. However, the technical solutions claimed by the present application can be realized even without these technical details and various changes and modifications based on the following embodiments.
[0029] The division of the following embodiments is for the convenience of description, and should not constitute any limitation on the specific implementation modes of the present application. The various embodiments can be combined with each other and referenced to each other on the premise of no contradiction.
[0030] The present application embodiment provides a response method, applied to a CDN node. In some embodiments, the flowchart thereof is as shown in Figure 1 The method comprises the following steps:
[0031] Step 101, receiving a user request, the user request being used to request data in a target interval of a target file.
[0032] The target file is a file involved in the user request, which can be any file required by a user. The file is relative to a source station, for example, when the user request is a video, the target file is a video file in which the video is located in the source station.
[0033] In some embodiments, the target interval can be represented by an offset value in the target file, for example, the file size of the target file is 10M, and the target interval can be (1M, 5M], (4M, 10M], (5.6M, 7M), etc.
[0034] In some embodiments, the user request is a segment request, that is, the target interval is a proper subset of the interval in which the target file is located.
[0035] It can be understood that, unlike other requests, the segment request has a Range header, so as to indicate the position of the requested data through the Range header. Therefore, in some cases, after receiving the request from the user, the CDN node can determine whether the received request is the user request involved in the present application embodiment by detecting whether the request has the Range header, so as to determine whether the request is responded according to the response method provided by the present application embodiment. In this way, when integrated with the protocol, it is not necessary to make too many changes to the existing protocol, which is conducive to reducing the deployment cost and difficulty.
[0036] In some embodiments, the user request can also include a segment request, or a request for complete data of a file, that is, the target interval is a subset of the interval in which the target file is located.
[0037] In the case where it is detected that the user request has the Range header, it is determined that it is a segment request, and the target interval can be determined by analyzing the Range header. In the case where the user request does not have the Range header, it is determined that it is a segment request or a request for complete data of a file, and [0, X] is taken as the target interval, X being the file size of the target file.
[0038] Thus, the response method provided in this application adopts a unified response method for segmented requests and requests for complete data of the request file, which helps to reduce the complexity of implementation.
[0039] Step 102: If the target file is already cached locally and there are file gaps in the target range, request the target data corresponding to the file gaps in the target range from the origin server, and respond to the user request based on the target data.
[0040] File gaps are intervals in locally cached target files that do not contain actual valid data. Target data refers to the data requested by the user that falls within file gaps in the locally cached target file.
[0041] For example, such as Figure 2 As shown, if the target file of size 100M in the local cache of the CDN node has been obtained and stored in the intervals (0M, 20M), (30M, 60M), and (80M, 100M) by requesting data from the origin server, and the intervals (20M, 30M) and (60M, 80M) have not been requested from the origin server, then the intervals (0M, 20M), (30M, 60M), and (80M, 100M) are the intervals where valid data is located, and the intervals (20M, 30M) and (60M, 80M) are file gaps. Therefore, the target file cached locally has no file gaps and no target data in target interval 1 (10M, 16M); the target file cached locally has file gaps (66M, 76M) in target interval 2 (66M, 76M), and the target data is the data in the target file located in interval (66M, 76M); the target file has file gaps (20M, 30M) in target interval 3 (10M, 50M), and the target data is the data in the target file located in interval (20M, 30M); the target file has file gaps (25M, 30M) and file gaps (60M, 80M) in target interval 4 (25M, 90M), and the target data is the data in the target file located in intervals (25M, 30M) and (60M, 80M).
[0042] In other words, when a user's request involves data that is not cached locally on the CDN node, the requested, uncached data will be retrieved from the origin server, rather than the entire file. This avoids caching data not requested by the user locally, reducing wasted storage space on the CDN node and improving its storage utilization. Furthermore, CDN nodes are allowed to store files with file gaps in their local cache. This allows storage space for data not retrieved from the origin server to be stored as file gaps, eliminating the need to partition the data and store the target file as multiple files, thus improving throughput.
[0043] In some embodiments, as shown in Figure 3 In some embodiments, as shown in
[0044] In step 1021, in the case that the target file has been cached locally and the locally cached target file has file holes in the target interval, the overlap between the target data and the data being requested from the source station is determined.
[0045] The overlap between the target data and the data being requested from the source station means that the target data and the data being requested from the source station have the same data.
[0046] It can be understood that, for the target file, the data in the same interval is the same data. That is, in some examples, the overlap between the target data and the data being requested from the source station can be that the intersection between the interval to which the target data belongs and the interval to which the data being requested from the source station belongs in the target file is not empty.
[0047] In this way, the overlap between the target data and the data being requested from the source station can be efficiently realized through simple set operations, which is conducive to reducing the implementation difficulty, improving the processing efficiency, thereby improving the response efficiency of the user request, reducing the time delay, and reducing the possibility of network timeout and connection interruption.
[0048] In some examples, determining the overlap between the target data and the data being requested from the source station can be determining the overlapping part and the non-overlapping part of the target data and the data being requested from the source station, so that subsequent corresponding processing can be performed on the overlapping part and the non-overlapping part, thereby improving the processing efficiency.
[0049] In some embodiments, the data being requested from the source station is recorded in the cache information of the locally cached target file, so that the data being requested from the source station can be determined by searching the record, and then the overlap between the target data and the data being requested from the source station is determined.
[0050] In some examples, the data being requested from the source station recorded in the cache information of the locally cached target file can be the user request corresponding to the data being requested from the source station and the interval in the target file to which the data being requested from the source station belongs.
[0051] In order to facilitate those skilled in the art to better understand the implementation of determining the target data and the data being requested from the source station, the following will be described.
[0052] First, it is detected whether the interval to which the data being requested from the source station belongs includes the start position of the interval in which the target data is located. Then, in the case where the interval to which the data being requested from the source station belongs includes the start position of the interval in which the target data is located, it is determined that the interval formed from the start position of the interval in which the target data is located to the second reference value is the part of the target data overlapping the data being requested from the source station, so as to wait for the source station to return the data in the interval formed from the start position of the interval in which the target data is located to the second reference value, or, in the case where the interval to which the data being requested from the source station belongs does not include the start position of the interval in which the target data is located, it is determined that the interval formed from the start position of the interval in which the target data is located to the second reference value is the part of the target data not overlapping the data being requested from the source station, so as to request the source station for the data in the interval formed from the start position of the interval in which the target data is located to the second reference value. Then, the start position of the interval to which the target data belongs is updated to the second reference value and the step of detecting whether the interval to which the data being requested from the source station belongs includes the start position of the interval in which the target data is located is executed again until the interval in which the target data is located is an empty set.
[0053] wherein the second reference value is the larger one between x3 and x4, x3 is the start position of the interval in which the target data is located, and x4 is the start position of the data being requested from the source station which is the smallest in start position and larger than the start position of the interval in which the target data is located.
[0054] Thus, the overlapping condition of the target data and the data being requested from the source station can be sequentially determined through simple and efficient set operations, and the omission is avoided, and the implementation difficulty is low and the efficiency is higher.
[0055] In step 1022, in the case where the target data and the data being requested from the source station exist overlapping, the source station is waited for returning the data being requested from the source station, and after the data being requested from the source station is received, the part of the target data overlapping the data being requested from the source station is acquired.
[0056] In step 1023, in the case where the target data and the data being requested from the source station exist partial non-overlapping, the source station is requested for the part of the target data not overlapping the data being requested from the source station.
[0057] In order for those skilled in the art to better understand the above-mentioned embodiments, the following will be exemplified.
[0058] As Figure 2As shown, in the local cache of the CDN node, the interval (0M, 20M), the interval (30M, 60M) and the interval (80M, 100M) of the target file are valid data, the interval (0, 20M) and the interval (80M, 100M) are file holes, the target interval 3 is the target interval involved in the user request received in advance, and the target interval 4 is the target interval involved in the user request received while responding to the user request corresponding to the target interval 3. According to the response method provided in the above embodiment, the data being requested from the source station is the data of the target file located in the interval (20M, 30M), and the target data is the data located in the interval (25M, 30M) and the interval (60M, 80M). At this time, the two have an overlap, the overlapping part is the data of the target file located in the interval (25M, 30M), the part of the target data that does not overlap with the data being requested from the source station is the data of the target file located in the interval (60M, 80M), at this time, the data of the target file located in the interval (20M, 30M) is waited to be returned by the source station to obtain the data of the target file located in the interval (25M, 30M), and the data of the target file located in the interval (60M, 80M) also needs to be requested from the source station to respond according to the obtained data of the target file located in the interval (25M, 30M) and the interval (60M, 80M).
[0059] It can be understood that the CDN node can receive multiple requests initiated by different users, and these requests can be initiated at any time. Therefore, the user request can be received in the process of receiving and responding to some requests, and these requests can overlap with the data requested by the user request. Especially, these requests and the data requested by the user request can overlap at the file hole. Therefore, the same data can be requested from the source station multiple times.
[0060] The above embodiment determines the overlapping part of the target data and the data being requested from the source station, and initiates a request to the source station only for the non-overlapping part, without initiating a second request to the source station for the overlapping part. That is, the overlapping data requested by different requests is combined and returned to the source in the process of responding to different requests, so that each data is requested from the source station only once, the same data is avoided from being requested from the source station multiple times, resources are saved, the amount of data requested from the source station is reduced, and the efficiency of returning to the source and the efficiency of responding to the user request are improved.
[0061] Of course, in some embodiments, the target data can also be requested from the source station without being combined and returned to the source. In this way, the processing process of the CDN node is more simple, the implementation difficulty is lower, it is more beneficial to deploy on the existing CDN equipment, and it is beneficial to reduce the cost. Here, it will not be described one by one.
[0062] It can be understood that, in order to facilitate efficient determination of whether the target file has a file hole in the local cache of the CDN node, the local cache of the CDN node can also store information indicating the interval in which the file hole is located. That is, in some embodiments, the interval in which the file hole of the target file is located, and / or the interval in which the valid data is located, etc. can also be stored in the local cache of the CDN node, so as to determine the file hole and determine whether the target interval of the target file has a file hole in the local cache of the CDN node. In particular, when the interval in which the file hole is located and the interval in which the valid data is located are both stored in the CDN node, it can also be detected whether the two intervals coincide to detect whether the interval in which the file hole is located and the interval in which the valid data is located are incorrect.
[0063] In order to facilitate determination of the target file it corresponds to, the information indicating the interval in which the file hole is located can be stored as cache information of the target file in the local cache, and the creation time, valid time, file size, etc. of the target file can also be stored.
[0064] In some cases, the information indicating the interval in which the file hole is located is stored in a red-black tree, a B+ tree, a skip list, etc. so as to sequentially indicate the interval in which the file hole is located. Figure 2 For example, if a 100M target file has file holes in the interval (20M, 30M) and the interval (60M, 80M), the red-black tree, B+ tree, or skip list, etc. storing the information indicating the interval in which the file hole of the target file is located is read, and (20M, 30M) and (60M, 80M) are sequentially parsed. In this way, by ordering the file holes, it is easier to determine whether the target interval has a file hole, which is conducive to efficiently responding to user requests.
[0065] Step 103, storing the target data in the file hole corresponding to the target file.
[0066] In this way, the data requested by the user located in the file hole is obtained by back-to-source, and is stored in the corresponding file hole. In this way, the target file in the local cache of the CDN node only corresponds to one file, so that the number of files in the CDN node can be reduced to the greatest extent, and the throughput will not be affected by too many files. This is conducive to improving the throughput of the CDN and improving the response efficiency.
[0067] In some embodiments, in the case of merging back-to-source, the storage of the target data can also be realized by merging. At this time, as shown in Figure 4 The target data is stored in the file hole corresponding to the target file, which can be realized by the following methods:
[0068] Step 1031, in the case that the target data overlaps with the data being requested from the source station, storing the data being requested from the source station in the file hole corresponding to the target file.
[0069] That is, the storage of the data being requested from the source station also realizes the storage of the part of the target data that overlaps with the data being requested from the source station.
[0070] Step 1032, in the case that the target data does not overlap with the data being requested from the source station, storing the part of the target data returned by the source station that does not overlap with the data being requested from the source station in the file hole corresponding to the target file.
[0071] In this way, the storage of the target data is divided into two parts: the storage of the part of the target data that overlaps with the data being requested from the source station, and the storage of the part of the target data that does not overlap with the data being requested from the source station. The storage of the part of the target data that overlaps with the data being requested from the source station is realized through the storage of the data being requested from the source station, that is, the data in the target file is stored only once in the local cache of the CDN node, and the overlapping data requested by different requests is merged into one cache, which is beneficial to save resources and improve the cache efficiency of the CDN node.
[0072] In some embodiments, as shown in FIG. 10B, the response method further includes the following steps after receiving the user request: Figure 5
[0073] Step 104, in the case that the target file is not cached, creating a new target file in the local cache and requesting the data in the target file located in the target interval from the source station to respond to the user request according to the data in the target file located in the target interval returned by the source station.
[0074] In this way, when the data in the target file is requested for the first time, the target file is created first, and then the source is returned, so that the request received in the process of responding to the request for the data in the target file for the first time can be determined whether it can be returned to the source through the currently created target file, without causing the CDN node to have no target file record in the local cache due to the data in the target file that is requested for the first time not being returned by the source station, resulting in the inability to return to the source.
[0075] In some embodiments, as shown in FIG. 10B, the response method further includes the following steps after receiving the user request: Figure 6
[0076] It can be understood that, as shown in FIG. 10B, step 105, in the case that the target file in the local cache has valid data in the target interval, obtaining the valid data in the target interval from the target file in the local cache to respond to the user request according to the valid data in the target interval. Figure 2 As shown, the target file in the local cache of the CDN node can have valid data in the target interval. In the case that the target file in the local cache has valid data in the target interval, the valid data in the target interval is obtained from the local cache, which is more efficient in data obtaining and is conducive to improving the response efficiency to the user request.
[0077] Of course, the above is only a description of the hollow file and the valid data respectively. In some embodiments, the target file in the local cache can have both file hollow and valid data in the target interval. In this case, the target data is requested from the source station, and the valid data of the target file in the target interval is obtained from the local cache of the CDN node, and then the obtained data is returned to the user to respond to the user request, which will not be described here.
[0078] In some embodiments, as shown in the method for responding to the user request, the method further comprises: Figure 7 As shown, after receiving the user request, the responding method further comprises:
[0079] Step 106, in the case that the target file has been cached locally, detecting whether the file hollow of the target file in the local cache includes the starting position of the target interval. If yes, executing step 107, if no, executing step 108.
[0080] Step 107, taking the interval formed from the starting position of the target interval to the first reference value as a file hollow in the target interval.
[0081] Step 108, determining that the interval formed from the starting position of the target interval to the first reference value does not belong to the file hollow.
[0082] Step 109, updating the starting position of the target interval to the first reference value.
[0083] Step 1010, detecting whether the target interval is empty. If yes, executing step 102, if no, executing step 106.
[0084] That is, returning to the step of detecting whether the file hollow of the target file in the local cache includes the starting position of the target interval until the target interval is empty.
[0085] In this embodiment, the first reference value is the larger value between x1 and x2, x1 is the ending position of the target interval, and x2 is the starting position of the file hollow with the smallest starting position and the starting position greater than the starting position of the target interval.
[0086] Thus, through simple and efficient set operations, the file hollow interval and the valid data interval of the target file of the user request in the CDN node can be sequentially determined, avoiding omission, and the implementation difficulty is low and the efficiency is higher.
[0087] It should be noted that this embodiment is only a specific description of one implementation. It is understood that in some embodiments, it may be as follows: Figure 7 As shown, after sequentially executing step 107, steps 102 and 103 are executed, and after executing step 103, steps 109 and 1010 are executed. At this point, if the judgment result of step 1010 is "yes", then it is determined that a response has been completed for the current user request. In some embodiments, such as Figure 7 As shown, after executing step 109 sequentially, steps 102 and 103 continue to be executed. After executing step 103, steps 109 and 1010 are executed. At this point, if the judgment result of step 1010 is "yes", then it is determined that the response to the current user request has been completed. That is, every time a file gap in the target file is identified in the target range, data is retrieved sequentially from the source, which is beneficial for sequentially retrieving data from the target file from the source server. This will not be elaborated further here.
[0088] That is, in some embodiments, such as Figure 8 As shown, after defining the interval from the start position of the target interval to the first reference value as a file hole within the target interval, the response method further includes:
[0089] Step 1011: Take the data located in the interval formed from the starting position of the target interval to the first reference value as the target data, request the target data from the source station and return it to the user.
[0090] After determining that the interval from the start of the target interval to the first reference value does not belong to a file hole, the response method also includes:
[0091] Step 1012: Read the data from the local cache located in the interval formed from the starting position of the target interval to the first reference value.
[0092] Step 1013: End the response to the user request.
[0093] In other words, the target data and the valid data cached locally on the CDN node are determined sequentially and retrieved in the corresponding manner. The data is then sent to the user sequentially without requiring the user to determine the order, making the process simpler and enabling users to be unaware of the CDN node's processing.
[0094] In some embodiments, the system can simultaneously determine the target data and the valid data cached locally on the CDN node, request the target data from the origin server and read the valid data for the target range from the local cache of the CDN node, and return the obtained data to the user. This eliminates the need to wait for prior data and improves the efficiency of data acquisition.
[0095] In some embodiments, after all target data and valid data in the local cache of the CDN node are determined, the source station is requested for data or the data is obtained from the local cache of the CDN node, which is beneficial to reduce the number of requests to the source station.
[0096] Of course, the above is only a specific description, and in other embodiments, other ways can also be implemented, which will not be described here.
[0097] In some embodiments, as shown in FIG. 1, the local cache of the target file carries the maximum offset value of the valid data, and before detecting whether the file hole of the local cache of the target file includes the start position of the target interval, the response method further includes: Figure 9
[0098] Step 1014, detecting whether the start position of the target interval is greater than the maximum offset value of the valid data, if yes, performing step 106, and if no, performing step 1015.
[0099] The maximum offset value of the valid data is the offset value of the last valid data in the target file in the local cache of the CDN node in the target file. As shown in FIG. 1, if the 100M target file in the local cache of the CDN node has valid data in the interval (80M, 100M), the maximum offset value of the valid data is 100M; if the 100M target file in the local cache of the CDN node has valid data in the interval (60M, 80M) and the interval (80M, 100M) is a file hole, the maximum offset value of the valid data is 80M. Figure 2
[0100] Step 1015, requesting the data in the target file located in the target interval from the source station to respond to the user request according to the data returned by the source station.
[0101] In the case that the start position of the target interval is greater than the maximum offset value of the valid data, it can be determined that the data requested by the user request is not stored in the CDN node, and all data needs to be requested from the source station, without other detection and judgment. In this way, the response process in the case that the start position of the target interval is greater than the maximum offset value of the valid data is simplified, and the response efficiency is improved.
[0102] In some embodiments, as shown in FIG. 1, before the data in the target file located in the target interval is requested from the source station, the mapping method further includes: Figure 10
[0103] Step 1016, adding a file hole from the maximum offset value of the valid data to the end position of the target interval in the local cache of the target file.
[0104] It can be understood that although the start position of the target interval is greater than the maximum offset value of the valid data, that is, the interval from the maximum offset value of the valid data to the start position of the target interval is not requested from the source station and will be maintained as a file hole, and the target interval is also a file hole before the source station returns the data of the target file located in the target interval, so the interval from the maximum offset value of the valid data to the end position of the target interval is regarded as a file hole.
[0105] That is, in the local cache of the CDN node, a space with the same size as the target file is not used at the beginning to store the data of the target file, but the size of the target file in the local cache is gradually increased with the data requested by the user, thereby improving the space utilization of the CDN node.
[0106] In order to enable those skilled in the art to better understand the above-mentioned embodiments, the following will be exemplified.
[0107] As shown in Figure 2 , for the first user request for the 100M target file, if the target interval thereof is target interval 1 (10M, 16M), at this time, the CDN node creates a file with a size of (0, 16M) as the target file in the local cache, and (0, 16M) is not a file hole before receiving the data returned by the source station, after receiving the data returned by the source station, (0, 10M) is a file hole, (10M, 16M) is valid data, and the maximum offset value of the valid data is 16M. Then, if the target interval of the second user request for the target file is target interval 3 after the first user request, the CDN node will increase the file hole from the maximum offset value of the valid data to the end position of the target interval in the target file in the local cache, that is, increase the interval (16M, 50M) and set it as a file hole, until the storage of the interval (16M, 50M) becomes valid data after receiving and storing the data returned by the file, and the maximum offset value of the valid data is changed to 50M.
[0108] Compared with the way of creating a target file with a file size of 100M in the local cache of the CDN node and occupying a storage space of 100M after receiving the first user request for the 100M target file, the above-mentioned embodiment adapts the storage space occupation of the CDN node to the data requested by the user, can gradually increase the size of the target file in the local cache with the data requested by the user, and is beneficial to improve the space utilization of the CDN node.
[0109] In order to enable those skilled in the art to better understand the response method provided by the above-mentioned embodiments, the following will be exemplified in combination with Figure 11 the implementation thereof. As shown in Figure 11 , in some embodiments, the response method comprises the following steps:
[0110] Step 1101, receiving a user request, the user request is used to request data of a target file located in a target interval.
[0111] Step 1102, judging whether the target file is cached in a local cache of the node, if not, executing step 1103, if yes, executing step 1104.
[0112] Step 1103, creating a new cache record and initializing, to store data returned by a source station in the target file of the local cache and update the cache record after requesting data of the target file located in the target interval from the source station.
[0113] The information recorded in the cache record can include: a maximum offset value of valid data, an interval to which a file hole in the target file belongs, a user request corresponding to data currently requested from the source station and an interval to which the data currently requested from the source station corresponds, a request for data currently requested from the source station in response to other requests and an interval of the data currently requested.
[0114] The initialization is that the maximum offset value of valid data is set to 0, and the rest are set to null.
[0115] Step 1104, detecting whether a file hole of the target file cached in the local cache includes a start position of the target interval, if not, executing step 1105, if yes, executing step 1106.
[0116] It should be noted that before step 1104, the maximum offset value of valid data can be detected first according to the foregoing embodiment to determine whether to execute step 1104 or directly request data of the target file located in the target interval from the source station and increase the file hole of the target file. Here, it will not be repeated.
[0117] Step 1105, reading data from the start position of the target interval until the length of the read data reaches length, and updating the start position of the target interval to the start position of the target interval+length.
[0118] That is, it is determined that the interval with a length of length starting from start does not belong to the file hole.
[0119] Wherein, start is the start position of the target interval, and length is the length of valid data with start as the start position. The calculation method of length is as follows:
[0120] In the case that start is greater than or equal to the maximum offset value of the valid data, it is determined that the data at start does not belong to the valid data, there is no valid data with start as the starting position in the target interval, and length = 0.
[0121] In the case that start is less than the maximum offset value of the valid data, the cache record of the target file in the local cache is queried to determine the hole interval of the target file in the local cache. Further, in the case that the hole interval contains start, there is no valid data with start as the starting position in the target interval, and length = 0; in the case that the hole interval does not contain start, there is valid data with start as the starting position in the target interval, at this time, the interval in which the file hole of the first target file greater than start is located is queried, if the query result is not empty, length = the starting position of the interval in which the file hole of the first target file greater than start is located - start, if the query result is empty, length = the maximum offset value of the valid data - start. After the current length is determined, it is further judged whether start + length is greater than end, if yes, length is updated as end - start, if no, it is not updated. Wherein, end is the ending position of the target interval.
[0122] Step 1106, starting from the data at the starting position of the target interval, it is detected whether it overlaps with the data being requested from the source station, if yes, step 1107 is executed, if no, step 1108 is executed.
[0123] In some cases, the user requests corresponding to the data being requested from the source station recorded in the aforementioned cache record and the intervals of the data being requested from the source station corresponding to each request can be traversed to determine whether the data at start of the target interval is the data being requested from the source station.
[0124] Step 1107, the user requests and the part overlapping with the data being requested from the source station are recorded in the waiting area and the starting position of the target interval is updated, so that after the data being requested from the source station is returned by the source station, the part overlapping with the data being requested from the source station is obtained from the data being requested from the source station according to the notification and the waiting area record is updated.
[0125] The record in the waiting area is the request of the data being requested from the source station in response to other requests recorded in the aforementioned cache record and the interval of the data being requested corresponding to each request.
[0126] That is, in some cases, the interval formed from the start position of the interval where the target data is located to the second reference value can be determined as the part of the target data that overlaps with the data being requested from the source station, as described in the previous embodiments, and the data in the interval formed from the start position of the interval where the target data is located to the second reference value is waited for to be returned by the source station, so that the corresponding data can be continuously acquired.
[0127] In step 1108, the part that does not overlap with the data being requested from the source station is added to the back source list and the start position of the target interval is updated, so that after the part that does not overlap with the data being requested from the source station is requested from the source station according to the back source list, the part that does not overlap with the data being requested from the source station is stored in the file hole of the target file in the local cache, and the cache record and the request record in the waiting area are updated.
[0128] In the case where the data needs to be requested from the source station, the start position of the target interval can be updated in the following manner: the file hole of the target file is queried and the maximum offset that needs to be back sourced from the start is calculated, the maximum offset is the start position of the file hole whose first start position is greater than the start of the target file among all the file holes of the target file, and the offset is recorded as end if there is no file hole whose start position is greater than the start of the target file or the first start position is greater than the end of the file hole whose first start position is greater than the start of the target file. The interval (start, offset) is taken as the interval to which the data that needs to be requested from the source station belongs, and the current user request record is recorded in the back source list.
[0129] In addition, the cache record is updated mainly in the following manner: in the case where the start is greater than the maximum offset value of the valid data of the target file, an interval record is added in the local cache of the target file and recorded as a file hole, the start position of the interval is the maximum offset value of the valid data of the target file, and the end position is the start. In the case where the start is not greater than the maximum offset value of the valid data of the target file, the interval (start, offset) contained in the file hole of the target file is deleted or updated, and finally it is judged whether the maximum offset value of the valid data of the target file in the local cache is less than offset, and if so, the maximum offset value of the valid data of the target file in the local cache is set to offset.
[0130] In step 1109, it is detected whether the start position of the target interval reaches the end position of the target interval, and if so, step 1110 is executed, and if not, step 1104 is executed.
[0131] In step 1110, the data currently acquired is returned to the user.
[0132] The embodiment obtains all data for responding to the user request, and then returns the obtained data to the user to realize the response. In other embodiments, a piece of data can be returned to the user after being obtained, that is, the data obtained or requested is returned to the user after step 1107 and step 1108, and step 1110 is changed to end the response to the current user. Here, it is not necessary to be described one by one.
[0133] Of course, the above embodiment and example are mainly described by taking the cache record of the target file in the local cache of the CDN node as an example, and the cache record of the target file in the local cache of the CDN node can also not include the file hole in other embodiments, but include the valid data interval. In this way, the maximum offset value of the valid data does not need to be recorded additionally.
[0134] The step division of the above method is only for clear description. In implementation, one step can be combined or some steps can be split and decomposed into multiple steps, as long as the same logical relationship is included, which is within the protection scope of the patent. Irrelevant modifications or irrelevant designs are added to the algorithm or flow, but the core design of the algorithm and flow is not changed, which is within the protection scope of the patent.
[0135] Another aspect of the embodiment of the application also provides a CDN node, as shown in the figure, comprising: Figure 12 as shown in the figure, comprising:
[0136] The receiving module 1201 is configured to receive a user request, and the user request is used to request data of a target file located in a target interval.
[0137] The back-to-source module 1202 is configured to, in a case where the target file is locally cached and the locally cached target file has a file hole in the target interval, request target data corresponding to the file hole in the target interval from a source station, and respond to the user request according to the target data.
[0138] The storage module 1203 is configured to store the target data in the file hole corresponding to the target file.
[0139] It is not difficult to find that the embodiment is a node embodiment corresponding to the foregoing embodiment, and the embodiment can be implemented in cooperation with the foregoing embodiment. The related technical details mentioned in the foregoing embodiment are still valid in the embodiment. In order to reduce repetition, they will not be described here. Correspondingly, the related technical details mentioned in the embodiment can also be applied to the foregoing embodiment.
[0140] It is worth mentioning that each module involved in the embodiment is a logical module. In actual application, one logical unit can be one physical unit, or a part of one physical unit, or a combination of multiple physical units. In addition, in order to highlight the innovative part of the present application, units not closely related to solving the technical problems proposed in the present application are not introduced in the embodiment, but this does not mean that there are no other units in the embodiment.
[0141] Another aspect of the embodiment of the present application also provides an electronic device, such as Figure 13 As shown in the figure, the electronic device comprises at least one processor 1301 and a memory 1302 connected with the at least one processor 1301; wherein the memory 1302 stores instructions executable by the at least one processor 1301, and the instructions are executed by the at least one processor 1301 to enable the at least one processor 1301 to perform the response method described in any of the above method embodiments.
[0142] The memory 1302 and the processor 1301 are connected in a bus mode, and the bus can include any number of interconnected buses and bridges. The bus connects one or more processors 1301 and various circuits of the memory 1302 together. The bus can also connect various other circuits such as peripheral devices, voltage regulators, and power management circuits, which are well known in the art, and therefore will not be further described herein. The bus interface provides an interface between the bus and the transceiver. The transceiver can be one element or multiple elements such as multiple receivers and transmitters, which provide a unit for communicating with various other devices on a transmission medium. Data processed by the processor 1301 is transmitted on a wireless medium through an antenna, and further, the antenna also receives data and transmits the data to the processor 1301.
[0143] The processor 1301 is responsible for managing the bus and general processing, and can also provide various functions including timing, peripheral interface, voltage regulation, power management, and other control functions. The memory 1302 can be used to store data used by the processor 1301 in performing operations.
[0144] Another aspect of the embodiment of the present application also provides a computer readable storage medium storing a computer program. The computer program is executed by the processor to implement the API management method described in any of the above embodiments.
[0145] That is, a person skilled in the art can understand that all or part of the steps in the method of the above-mentioned embodiments can be completed by a program instructing the relevant hardware, the program being stored in a storage medium and including a plurality of instructions for causing an apparatus (which can be a single-chip microcomputer, a chip, etc.) or a processor to execute all or part of the steps of the method described in the various embodiments of the present application. The aforementioned storage medium includes a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and various media that can store program codes.
[0146] A person of ordinary skill in the art can understand that the above-mentioned embodiments are specific embodiments for implementing the present application, and in actual applications, various changes can be made in form and details without departing from the spirit and scope of the present application.
Claims
1. A response method, characterized in that, Applied to CDN nodes, the method includes: Receive a user request, the user request being used to request data located in the target range in the target file; If the target file is already cached locally and there are file gaps in the target range, the system requests target data corresponding to the file gaps in the target range from the origin server to respond to the user request based on the target data; wherein, the locally cached target file is a single file, and the file gaps are used to indicate the range in the single file where no valid data has been cached. After receiving the target data, the target data is stored in the file hole location corresponding to the single file to fill the file hole; The step of requesting the target data corresponding to the file holes in the target range from the source station includes: Determine the overlap between the target data and the data being requested from the source server; If the target data overlaps with the data being requested from the source station, wait for the source station to return the data being requested from the source station, so that after receiving the data being requested from the source station, the overlapping part of the target data and the data being requested from the source station can be obtained; If the target data and the data being requested from the source station do not overlap in some parts, the target data is requested from the source station for the portion that does not overlap with the data being requested from the source station.
2. The response method according to claim 1, characterized in that, The step of storing the target data in the file hole location corresponding to the single file after receiving the target data includes: If the target data overlaps with the data being requested from the source server, the data being requested from the source server is stored in the file hole corresponding to the target file. If the target data and the data being requested from the source server do not overlap, the portion of the target data returned by the source server that does not overlap with the data being requested from the source server is stored in the file hole corresponding to the target file.
3. The response method according to any one of claims 1 to 2, characterized in that, After receiving the user request, the method further includes: If the target file is not cached, the target file is created in the local cache and the origin server is requested to retrieve the data in the target file that is located in the target range. The user request is responded to based on the data in the target file that is located in the target range returned by the origin server.
4. The response method according to any one of claims 1 to 2, characterized in that, After receiving the user request, the method further includes: If valid data exists in the target range in the locally cached target file, the valid data located in the target range is retrieved from the locally cached target file to respond to the user request based on the valid data located in the target range.
5. The response method according to any one of claims 1 to 2, characterized in that, After receiving the user request, the method further includes: Detect whether the file holes of the target file in the local cache include the starting position of the target interval; If a file hole in the target file is detected to include the starting position of the target interval, the interval formed from the starting position of the target interval to the first reference value is taken as a file hole in the target interval; If the detected file hole in the target file does not include the starting position of the target interval, it is determined that the interval formed from the starting position of the target interval to the first reference value does not belong to the file hole; Update the starting position of the target interval to the first reference value update and return to the step of detecting whether the file hole of the target file in the local cache includes the starting position of the target interval, until the target interval is an empty set; The first reference value is the larger value between x1 and x2, where x1 is the end position of the target interval and x2 is the starting position of the file hole with the smallest starting position and a starting position greater than the starting position of the target interval.
6. The response method according to claim 5, characterized in that, The method further includes, before detecting whether the file holes in the locally cached target file include the start position of the target interval, the maximum offset value of the target file carrying valid data in the locally cached target file, and the following: Detect whether the starting position of the target interval is greater than the maximum offset value of the valid data; The step of detecting whether the file holes in the locally cached target file include the starting position of the target interval includes: If the starting position of the target interval is not greater than the maximum offset value of the valid data, check whether the file hole of the target file in the local cache includes the starting position of the target interval; After detecting whether the starting position of the target interval is greater than the maximum offset value of the valid data, the method further includes: If the starting position of the target interval is greater than the maximum offset value of the valid data, request the data in the target file located in the target interval from the source station, and respond to the user request based on the data returned by the source station.
7. The response method according to claim 6, characterized in that, Before requesting the data located in the target range in the target file from the source station, the method further includes: Add a file hole in the locally cached target file, from the maximum offset of the valid data to the end position of the target interval.
8. The response method according to claim 5, characterized in that, After defining the interval formed from the starting position of the target interval to the first reference value as a file hole in the target interval, the method further includes: The data located in the interval formed from the starting position of the target interval to the first reference value is used as the target data, so as to request the target data from the source station and return it to the user; After determining that the interval formed from the starting position of the target interval to the first reference value does not belong to a file hole, the method further includes: Read data from the local cache located in the interval from the start of the target interval to the first reference value.
9. An electronic device, characterized in that, include: At least one processor; as well as, A memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor to enable the at least one processor to perform the response method as described in any one of claims 1 to 8.
10. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it implements the response method of any one of claims 1 to 8.
Citation Information
Patent Citations
File transmission method and apparatus based on NDN cache optimization
CN104967677A
Large file HTTP-Range downloading method, cache server and system
CN105791366A
Channel package acquisition method, electronic equipment and storage medium
CN115801769A
Byte range caching
US9807468B2