Disclosure of Invention
The invention aims to provide a skip pre-reading method, a skip pre-reading device, skip pre-reading equipment and a storage medium, wherein in a scene of realizing read operation in a skip mode, the data reading speed can be improved in a certain program in a data pre-reading mode, so that the reading performance is improved.
In order to achieve the above object, the present invention provides the following technical solutions:
A skip pre-reading method, comprising:
receiving a read request, if the read request corresponding data is stored locally, reading the read request corresponding data locally, otherwise, reading the read request corresponding data from a target file;
After the data corresponding to the read request is read, judging whether the current read mode is a skip mode, if so, predicting the position and the length of the read data to be read after the current moment based on the skip mode, and pre-reading the data corresponding to the position and the length of the read data in the target file, and storing the pre-read data in a local area, otherwise, determining that the pre-read operation is not needed, wherein the pre-read operation is the operation of pre-reading the corresponding data from the target file.
Preferably, determining whether the current read mode is a skip mode includes:
If the data length and the step length of the data read by the current read operation and the last read operation are the same, determining that the current read mode is a skip read mode, wherein the step length of any read operation is the data length between the read starting position of any read operation and the read ending position of the last read operation of any read operation, and the read operation is the operation of reading the data corresponding to any read request after receiving any read request.
Preferably, predicting the pre-read data position and the pre-read data length of the data to be read after the current time based on the skip mode includes:
If the first pre-reading operation is needed to be performed currently, determining that the pre-reading data position is the position after the reading end position of the last reading operation is shifted by the step length, wherein the pre-reading data length is the data length of the last reading operation;
If the n-th pre-reading operation in the plurality of continuous pre-reading operations is needed to be performed currently, determining that the pre-reading data positions are respectively shifted by 1 to n times from the reading end position of the last pre-reading operation by the step length, wherein the pre-reading data length corresponding to each pre-reading data position is the data length of the 1-th pre-reading operation in the plurality of continuous pre-reading operations.
Preferably, after predicting the position of the read-ahead data to be read after the current time based on the skip mode, the method further includes:
If the object used for realizing the storage of the target file is larger than the period of the skip mode, reading the object where each pre-read data position is located in a whole object reading mode, and storing the pre-read data locally, otherwise, executing the step of pre-reading the pre-read data position and the data corresponding to the pre-read data length in the target file.
Preferably, the method further comprises:
After each pre-reading operation and reading operation, updating the skip record information recorded in the skip record structure, wherein the skip record information comprises a step length, a data length and a read end position.
Preferably, before updating the skip record information recorded in the skip record structure, the method further comprises:
Opening the target file, creating a handle, and creating the skip record structure in the handle;
The method further comprises the steps of:
And closing the target file and the handle, and clearing the skip record structure.
Preferably, after the data corresponding to the read request is read locally, the method further includes:
And clearing the data corresponding to the read request stored locally.
A skip pre-reading device, comprising:
The reading module is used for receiving a reading request, if the reading request corresponding data is stored locally, the reading request corresponding data is read locally, otherwise, the reading request corresponding data is read from the target file;
The first pre-reading module is used for judging whether the current reading mode is a skip reading mode after reading the data corresponding to the reading request, if so, predicting the pre-reading data position and the pre-reading data length of the data to be read after the current moment based on the skip reading mode, pre-reading the data corresponding to the pre-reading data position and the pre-reading data length from the target file, and storing the pre-read data locally, otherwise, determining that the pre-reading operation is not needed, wherein the pre-reading operation is the operation of pre-reading the corresponding data from the target file.
A skip pre-read device, comprising:
a memory for storing a computer program;
A processor for implementing the steps of the skip pre-read method as described in any of the preceding claims when executing said computer program.
A computer readable storage medium having stored thereon a computer program which when executed by a processor performs the steps of the skip pre-read method as described in any of the preceding claims.
The application provides a skip read pre-reading method, device, equipment and storage medium, wherein the method comprises the steps of receiving a read request, if the read request corresponding data is stored locally, locally reading the read request corresponding data, otherwise, reading the read request corresponding data from a target file, judging whether a current read mode is a skip read mode after reading the read request corresponding data, if so, predicting the pre-reading data position and the pre-reading data length of the data to be read after the current moment based on the skip read mode, pre-reading the pre-reading data position and the pre-reading data length corresponding data in the target file, and storing the pre-reading data locally, otherwise, determining that pre-reading operation is not needed, wherein the pre-reading operation is the operation of pre-reading the corresponding data from the target file. According to the application, after the corresponding data of the read request is read each time, whether the current read mode is the skip mode is judged, and when the judgment result is yes, the corresponding data is read from the target file based on the skip mode and then stored locally, so that when the corresponding read request of the data is received subsequently, the corresponding data can be read locally, and the data reading speed can be greatly improved compared with the data reading realized by the access file through the local realization of the data reading.
Detailed Description
The following description of the embodiments of the present invention will be made clearly and completely with reference to the accompanying drawings, in which it is apparent that the embodiments described are only some embodiments of the present invention, but not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
Referring to fig. 1, a flowchart of a skip pre-reading method according to an embodiment of the present invention may include:
And S11, receiving a read request, if the read request corresponding data is stored locally, reading the read request corresponding data locally, otherwise, reading the read request corresponding data from the target file.
The skip pre-reading method provided by the embodiment of the application can be applied to a distributed file system, the target file is any file such as video, streaming media and the like which need to be accessed in the distributed file system, the execution main body of the skip pre-reading method can be a corresponding skip pre-reading device, and the skip pre-reading device can be arranged in a storage server of the distributed file system, so that the execution main body of the skip pre-reading method can be the storage server.
The storage server receives the read request, if the data corresponding to the read request is already stored locally, the data corresponding to the read request can be read locally, and the data corresponding to the read request is returned to the sending end of the read request, otherwise, the data corresponding to the read request is read from the target file, and the data corresponding to the read request is returned to the sending end of the read request. The method comprises the steps of receiving a storage server, wherein the storage server receives a reading request from the storage server, and the reading request comprises an identifier of data to be read, so that corresponding data can be positioned based on the identifier, and further data reading is achieved.
And S12, after the corresponding data of the read request is read, judging whether the current read mode is a skip mode, if so, executing the step S13, and if not, executing the step S14.
The read mode is a mode for reading data, and can be realized based on the read operation characteristic of the skip mode when judging whether the current mode is the skip mode, can be realized based on a preset mark, and can be realized in other modes set according to actual needs. Specifically, when the read operation characteristic based on the skip mode is implemented, since the read operation of the skip mode is generally the same in length of data read each time and the step length is the same when the data is read each time, whether the corresponding data is read in the skip mode or not can be judged based on the read operation and the last read operation, wherein the step length of any read operation is the data length between the start position of the data read by any read operation in the target file and the end position of the data read by the last read operation in the target file, whether the read operation is required to be implemented in the skip mode or not can be designated in advance when the read operation is implemented based on the preset mark, and the corresponding mark is set, so that whether the read operation is required to be implemented in the skip mode or not can be known based on the mark.
S13, predicting the pre-read data position and the pre-read data length of the data to be read after the current moment based on the skip mode, pre-reading the data corresponding to the pre-read data position and the pre-read data length in the target file, and storing the pre-read data locally.
If the current skip mode is determined, the data length and the step length of each time of data reading in the skip mode are the same, so that the position and the length of the data which needs to be read in the next time or even in the subsequent time can be determined based on the same, the corresponding data are pre-read based on the same and then stored locally, and after the corresponding read requests of the data are received, the corresponding data of the read requests can be directly read locally and returned, and compared with the data read from the target file, the speed of data reading can be greatly improved.
And S14, determining that the pre-reading operation is not needed, wherein the pre-reading operation is an operation of pre-reading corresponding data from the target file.
In the embodiment of the application, the reading and the pre-reading refer to different actions, the reading is the reading of the data corresponding to the read request from the local or target file, the pre-reading is the data to be read after the predicted current moment from the target file, the corresponding reading operation is the operation of reading the corresponding data, namely the operation of reading the data corresponding to the read request from the local or target file, and the pre-reading operation is the operation of pre-reading the corresponding data, namely the operation of pre-reading the data to be read after the predicted current moment from the target file.
According to the application, after the corresponding data of the read request is read each time, whether the current read mode is the skip mode is judged, and when the judgment result is yes, the corresponding data is read from the target file based on the skip mode and then stored locally, so that when the corresponding read request of the data is received subsequently, the corresponding data can be read locally, and the data reading speed can be greatly improved compared with the data reading realized by the access file through the local realization of the data reading.
The skip pre-reading method provided by the embodiment of the invention judges whether the current reading mode is a skip mode or not, and can comprise the following steps:
If the data length and the step length of the data read by the current read operation and the last read operation are the same, determining that the current read mode is a skip read mode, wherein the step length of any read operation is the data length between the read starting position of any read operation and the read ending position of the last read operation of any read operation, and the read operation is the operation of reading the data corresponding to any read request after receiving any read request.
When determining whether the read operation performed at the current time and within a period of time before the current time is the read operation of the skip mode, whether the current read mode is the skip mode can be determined based on whether the data length and the step length of the current read operation and the data length and the step length of the last read operation are the same, so that the judgment of whether the current read mode is the skip mode is simply, conveniently and effectively realized through the characteristics of the two read operations. The read start position is the start position of the read data or the pre-read data in the target file, and the read end position is the end position of the read data or the pre-read data in the target file.
The skip pre-reading method provided by the embodiment of the invention predicts the pre-reading data position and the pre-reading data length of the data to be read after the current moment based on the skip mode, and comprises the following steps:
if the first pre-reading operation is needed to be performed currently, determining that the pre-reading data position is the position after the reading end position of the last reading operation is shifted by the step length, wherein the pre-reading data length is the data length of the last reading operation;
If the n-th pre-reading operation in the continuous pre-reading operations is needed to be performed currently, determining that the pre-reading data positions are respectively shifted by 1 to n times of step length from the reading end position of the last pre-reading operation, wherein the pre-reading data length corresponding to each pre-reading data position is the data length of the 1 st pre-reading operation in the continuous pre-reading operations.
If the current skip mode is judged for the first time, in order to avoid invalid read data (namely, the pre-read data is not the data which needs to be read by the sending end of the read request) caused by the change of the read operation in the later period, the data in the period of one skip mode can be pre-read first in the application, and if the current skip mode is judged for a plurality of times continuously, the duration time of the skip mode is longer, the possibility of the change of the later period read operation is smaller, so that the application can pre-read the data in the period of a plurality of skip modes, and therefore, under the condition that the possibility of the later period still being in the skip mode is larger, more pre-read data are provided for reading, and the high hit rate of the pre-read data is ensured to a certain extent when the pre-reading is realized.
The method comprises the steps of reading data in a skip mode, wherein one cycle of the skip mode is the sum of the length and the step length of the data read by a certain read operation, the position of the pre-read data is the initial position of the data to be pre-read in a target file, the length of the pre-read data is the length of the data to be pre-read in the target file, n is a positive integer which is not 1, so that when the later stage is still in the skip mode, the data in a plurality of cycles possibly read in the future are read, namely, the position of the pre-read data is the position of the last pre-read data after one step length is shifted backwards (backward is the direction from the initial position to the end position of the data), the position of the pre-read data after two step lengths is shifted backwards, and the position of the pre-read data after n step lengths is shifted backwards, and the data corresponding to the pre-read data length is read at each pre-read data position, so that the effective pre-reading of the data is realized.
In addition, the first pre-reading operation may be a first pre-reading operation which is not performed with any pre-reading operation before the current moment, or may be a first pre-reading operation when there is a reading operation between the last pre-reading operation and the current pre-reading operation when the pre-reading operation is not continuously performed, and of course, other defining modes of the first pre-reading operation meeting the requirements may be set according to the actual needs, which are all within the protection scope of the present invention.
The skip pre-reading method provided by the embodiment of the invention can further comprise the following steps after predicting the pre-reading data position of the data to be read after the current moment based on the skip mode:
If the object used for realizing the object file storage is larger than the period of the skip mode, the object where each pre-read data position is located is pre-read in a whole object reading mode, and the pre-read data is stored locally, otherwise, the step of pre-reading the pre-read data position and the data corresponding to the pre-read data length in the object file is executed.
The distributed file system can be specifically realized in an object storage mode, the target file is stored in an object storage mode, if the size of the object is larger than the period of the skip mode, the object needs to be accessed for multiple times, so that in order to reduce the access times of the object, in the embodiment of the application, the object where the data needing to be pre-read is located, namely, the whole object where the data needing to be pre-read is located, can be read in a whole object mode, and when the size of the object is not larger than the period of the skip mode, the pre-reading of the data can be realized in the mode of the embodiment. Therefore, for skip dense requests (a plurality of small blocks of objects skip), the pre-reading can avoid the pressure of small blocks IO to a network disk, thereby reducing the pressure of a read scene network and the disk, further reducing the access times of access objects and improving the reading performance.
The skip pre-reading method provided by the embodiment of the invention can further comprise the following steps:
after each pre-reading operation and reading operation, updating the skip record information recorded in the skip record structure, wherein the skip record information comprises a step length, a data length and a read end position.
It should be noted that, in order to facilitate obtaining corresponding information quickly when judging whether the read operation is in the skip mode, determining the position of the pre-read data, the length of the pre-read data, and the like, the application may be provided with a skip record structure in advance, so that the step length, the read end position, the data length, and other information of each pre-read operation or read operation are recorded in the skip record structure, thereby facilitating quick implementation of corresponding steps.
The skip pre-reading method provided by the embodiment of the invention can further comprise the following steps before the skip record information recorded in the skip record structure is updated:
opening the target file, creating a handle, and creating a skip record structure in the handle;
The skip pre-reading method can further comprise the following steps:
closing the target file and the handle, and clearing the skip record structure.
It should be noted that, the creating of the skip record structure may specifically be creating a handle corresponding to the target file when the target file is opened, so as to create the skip record structure in the handle, thereby facilitating storage and inquiry of the skip record structure. Where a Handle (Handle) is an identifier that is used to identify an object or item, it may be used to describe a form, file, etc., it is noted that the Handle cannot be constant.
The skip pre-reading method provided by the embodiment of the invention can further comprise the following steps after the data corresponding to the read request is read locally:
and clearing the data corresponding to the read request stored locally.
It should be noted that, in order to ensure that the local storage server can have sufficient storage space, and realize the storage of the data that is not accessed, in the embodiment of the present application, after the local data of the storage server is read each time, the accessed data is cleared, so as to realize the cyclic and effective use of the local storage space.
In a specific application scenario, the general steps of a skip pre-reading method provided in the embodiment of the present invention may be shown in fig. 2, and specifically include:
1. Creating a handle after opening (open) the target file;
2. When a handle is created, creating a skip record structure and recording the current skip condition, wherein the skip record structure is stored in the handle;
3. updating skip record information in a skip record structure when each reading operation is performed, identifying a skip mode based on the skip record information, and calculating a skip data position so as to realize pre-reading;
4. and closing the handle when the file is closed, and simultaneously clearing the skip record structure.
An example diagram when implementing skip mode identification may be as shown in fig. 3 (where skip information is skip record information, and a pre-read position is a pre-read data position), which may specifically include:
1. the skip record information mainly includes skip_len (step size), last_read (read end position of last read operation), last_read_len (data length of data read by last read operation or pre-read operation, which may be simply referred to as read length), skip_num (skip number), readadhead _pos (read end position of last pre-read operation, i.e. end position of last pre-read operation);
2. after the first reading request comes, updating the current reading length of the last_read_len record;
3. after the second reading request comes, recording skip_len and last_read_len;
4. after the third reading request comes, if the skip_len and last_read_len are found to be the same as the last time, the current reading mode is considered to be a skip mode, and the skip_num count is updated to be 1;
5. When the skip_num count is greater than 1, the current read mode is considered to be the skip mode, the pre-read data position is calculated, and pre-reading is initiated.
An exemplary diagram when implementing pre-reading of data may be as shown in fig. 4, and may specifically include:
1. After determining a skip mode, firstly, preliminarily calculating a pre-reading data position and a pre-reading data length, recording new pre-reading information (comprising readadhead _pos), further determining that the pre-reading data position is a reading end position (readahead _pos) of the last pre-reading operation, if the pre-reading data position is the first pre-reading operation, the pre-reading length is a reading length (last_ readahead _len) of the last pre-reading operation, if the pre-reading data position is the continuous pre-reading operation, the pre-reading data length is doubled by readahead _len each time (the pre-reading data length of the last pre-reading operation), the maximum length is 200M, the minimum length is 1 cycle (skip_len+len, len is the reading data length of the single read operation), and the pre-reading data position is aligned to the cycle;
2. the prereading position is refined, and two different prereading IO are adopted according to the cycle of the skip mode and the size of an object (obj):
1) The period is less than the obj size, more than two read requests are initiated by each object on average, and the whole object initiates pre-reading at the moment, namely the pre-reading data position preliminarily calculated in the step 1 is the pre-reading data position to be initiated at the time;
2) And (3) the cycle is greater than the obj size, each object initiates less than 1 read request on average, a plurality of skip read prereads are adopted at the moment, and the position to be actually read is selected according to the step length and the read length according to the preread data position preliminarily calculated in the step (1), so that the preread position is split into a plurality of preread skip fragments.
3. And initiating pre-reading according to the calculated pre-reading data position.
The application records the characteristic of the read operation (namely IO characteristic) to determine the skip mode, and simultaneously carries out whole object pre-reading or skip pre-reading according to the skip period and the size of the bottom object, thereby improving the pre-reading and reading performance and reducing the network disk consumption for small-step skip scenes.
The embodiment of the invention also provides a skip pre-reading device, as shown in fig. 5, which may include:
a reading module 11, configured to receive a read request, if the read request corresponding data is already stored locally, read the read request corresponding data locally, otherwise, read the read request corresponding data from the target file;
The first pre-reading module 12 is configured to determine whether the current reading mode is a skip reading mode after reading the data corresponding to the reading request, if so, predict a pre-reading data position and a pre-reading data length of the data to be read after the current time based on the skip reading mode, pre-read the data corresponding to the pre-reading data position and the pre-reading data length in the target file, and store the pre-read data locally, otherwise, determine that the pre-reading operation is not needed, where the pre-reading operation is an operation of pre-reading the corresponding data from the target file.
The skip pre-reading device provided by the embodiment of the invention, the first pre-reading module may include:
the first determining unit is used for determining that the current reading mode is a skip reading mode if the data length and the step length of the data read by the current reading operation and the last reading operation are the same, wherein the step length of any reading operation is the data length between the reading starting position of any reading operation and the reading ending position of the last reading operation of any reading operation, and the reading operation is the operation of reading the data corresponding to any reading request after any reading request is received.
The skip pre-reading device provided by the embodiment of the invention, the first pre-reading module may include:
And the second determining unit is used for determining that the read-out data position is the position after the read-out end position of the last read operation deviates from the step length if the read-out operation is required to be performed at present, determining that the read-out data position is the position after the read-out end position of the last read operation deviates from the step length by 1 to n times if the read-out operation is required to be performed at present for the nth read-out operation in a plurality of continuous read-out operations, and determining that the read-out data length corresponding to each read-out data position is the data length of the 1 st read-out operation in the plurality of continuous read-out operations.
The skip pre-reading device provided by the embodiment of the invention can further comprise:
And the second pre-reading module is used for pre-reading the object where each pre-reading data position is located in a whole object reading mode after predicting the pre-reading data position of the data to be read after the current moment based on the skip mode, if the object used for realizing the storage of the target file is larger than the period of the skip mode, and storing the pre-read data in a local mode, otherwise, executing the step of pre-reading the pre-reading data position and the data corresponding to the pre-reading data length in the target file.
The skip pre-reading device provided by the embodiment of the invention can further comprise:
and the updating module is used for updating the skip record information recorded in the skip record structure after each pre-reading operation and each reading operation, wherein the skip record information comprises a step length, a data length and a reading end position.
The skip pre-reading device provided by the embodiment of the invention can further comprise:
the opening module is used for opening the target file, creating a handle and creating a skip record structure in the handle before updating the skip record information recorded in the skip record structure;
and the closing module is used for closing the target file and the handle and clearing the skip record structure.
The skip pre-reading device provided by the embodiment of the invention can further comprise:
and the clearing module is used for clearing the locally stored read request corresponding data after the locally read request corresponding data.
The embodiment of the invention also provides skip pre-reading equipment, which can comprise:
a memory for storing a computer program;
a processor for implementing the steps of any one of the skip pre-read methods as described above when executing a computer program.
The embodiment of the invention also provides a computer readable storage medium, wherein a computer program is stored on the computer readable storage medium, and when the computer program is executed by a processor, the steps of the skip pre-reading method can be realized.
It should be noted that, for the explanation of the relevant parts in the skip pre-reading device, the skip pre-reading device and the storage medium provided in the embodiments of the present invention, please refer to the detailed explanation of the corresponding parts in the skip pre-reading method provided in the embodiments of the present invention, and the detailed explanation is omitted here. In addition, the parts of the above technical solutions provided in the embodiments of the present invention, which are consistent with the implementation principles of the corresponding technical solutions in the prior art, are not described in detail, so that redundant descriptions are avoided.
The previous description of the disclosed embodiments is provided to enable any person skilled in the art to make or use the present invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the invention. Thus, the present invention is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.