Patent Description:
The present invention relates to the field of peer to peer (P2P) network technology, and in particular to a method for downloading resources.

In the related art, a P2P node directly writes data of a resource to a magnetic disk when downloading the resource. When a resource is downloaded in this manner, even scattered and fragmented data is written directly to a magnetic disk. Therefore, data of the resource often needs be written to and read from the magnetic disk repeatedly, not only causing great consumption to the magnetic disk, but also leading to low utilization of the magnetic disk.

However, among all kinds of nodes of a P2P network, many have a poor storage capacity, such as a mobile terminal and an OTT terminal. Magnetic disks of these P2P nodes have disadvantages such as slow read and write, a small storage capacity, and a limited number of reads and writes, and too many writes will lead to bad blocks and even bad cards. Life of a magnetic disk of such a P2P node will definitely be reduced to a large extent if data is written to the magnetic disk no matter whether the downloading task is complete.

In summary, for P2P nodes with a poor storage capacity, how to reduce magnetic disk consumption in the process of downloading a resource is an urgent technical problem to be solved.

Further information on transfering resources on a P2P network, such as playing videos and file sharing, can be obtained from <CIT>, and from <CIT>. <CIT> is considered to represent the closest prior art and its disclosure forms the basis of the preamble of claim <NUM>.

The present application is intended to address at least one of the technical issues in the related art.

Further optional features of preferred embodiments of the invention are defined in the dependent claims.

In the following description, Embodiments <NUM>, <NUM> and <NUM> and Example <NUM> are not according to the invention as claimed and are present for illustration purposes only.

The technical scheme of the present application will be described in more detail below with reference to the accompanying drawings and embodiments.

It is noted that, provided that no conflict exists, embodiments of the present application and each feature of the embodiments may be combined with one another, all falling within the protection scope of the present application. Additionally, although a logical sequence is shown in the flowchart, in some cases, the illustrated or described steps can be performed in an order different from that described herein.

In a typical configuration, a computing device of a client or a server can include one or a plurality of processors (CPUs), input/output interfaces, a network interface, and a memory.

The memory may include a computer-readable medium in the form of a non-permanent memory, a random-access memory (RAM), a non-volatile memory, and/or the like, such as a read-only memory (ROM) or a flash memory (flash RAM). The memory is an example of the computer-readable medium. The memory can include a module <NUM>, a module <NUM>,. a module N (N is an integer greater than <NUM>).

The computer-readable medium includes permanent and non-permanent storage media and removable and non-removable storage media. The storage medium can implement the information storage by means of any method or technique. The information may be a computer-readable instruction, a data structure, a module of a program, or other data. Examples of the storage medium of a computer include, but are not limited to, a phase change memory (PRAM), a static random access memory (SRAM), a dynamic random access memory (DRAM), other types of random access memories (RAMs), a read-only memory (ROM), an electrically erasable programmable read-only memory (EEPROM), a flash memory or other memory technologies, and can be used for storing information accessible by a computing device. According to the definitions herein, the computer-readable medium does not include transitory computer-readable media, such as a modulated data signal and a carrier wave.

The P2P nodes described in the present application can be any device capable of implementing the functions of the P2P nodes. The device can be a PC terminal, an Over The Top (OTT) terminal, an Android terminal, or other system terminals. In other words, the computing device can be, but is not limited to, an OTT device, a mobile terminal, a tablet computer, a mobile Internet device, and a wearable device that provide a user with various application services via the Internet, or other hardware entities or virtual devices on which a P2P program can be deployed.

The resource requester described in the present application can be a hardware entity or a virtual device capable of acquiring a resource via an accelerator. The resource requester can be, but is not limited to, an application integrated with an accelerator, for example, a player acquiring a video file via an accelerator.

Terms involved herein are explained as follows.

"P2P" refers to a distributed application architecture allocating tasks and workloads among peers, and is a networking or network type formed by a peer-to-peer computing model at an application layer.

"P2P node" refers to each terminal in a P2P network system.

"Accelerator" refers to a P2P program running on a P2P node, and the P2P program can be a dynamic or static library integrated in an application, such as a software development kit (SDK) integrated in Youku App on a mobile phone, IKU client on a PC, etc. The P2P program can also be an independent executable program.

"P2P node downloading resources" refers to a P2P node provided with an accelerator for downloading resources.

"P2P node uploading resources" refers to a P2P node provided with an accelerator for uploading resources.

"First-frame time" refers to the elapsed time from receiving a request from a player to returning the first frame of video data.

<FIG> shows an exemplary application environment architecture for the technical scheme of the present application. A P2P network includes n (n is an integer not less than <NUM>) P2P nodes, including a P2P node <NUM>, a P2P node <NUM>, a P2P node <NUM>,. a P2P node n. The P2P node <NUM>, as a P2P node uploading resources, can distribute a resource to a resource server so that other P2P nodes can download the resource from the resource server, and can submit a log to a log server so that the P2P node <NUM> can be regularly maintained. The P2P node <NUM>, as a P2P node downloading resources, can perform processing such as identity authentication and configuration updating through a login server, and can also acquire, by requesting resources from the resource server, a node list of P2P nodes uploading resources. In an example shown in <FIG>, the P2P node <NUM> selects the P2P node <NUM> from the node list to download a resource, and then the P2P node <NUM> completes the downloading of the resource by requesting data from the P2P node <NUM> and receiving data transmitted by the P2P node <NUM>. In <FIG>, a connection server is responsible for communication connections among P2P nodes in a P2P network.

In the related art, among all kinds of terminal nodes in a P2P network, many have a poor storage capacity, such as a mobile terminal and an OTT terminal. These nodes have disadvantages such as slow read and write, a small storage capacity, and a limited number of reads and writes, and too many writes will lead to bad blocks and even bad cards, thereby reducing the life of a tf card and compromising the stability of a system. Therefore, some filtering is required to be performed on resources to be written, that is, detected incomplete videos are filtered out in advance rather than being written to a magnetic disk, thus reducing the magnetic disk consumption and the magnetic disk space occupied by these incomplete videos.

In addition, video display experience has an extremely important indicator, first-frame time, that is, time consumed to acquire the first frame of video data. The video display experience may be compromised if an accelerator performs too many steps and spends too much time in downloading data. Moreover, in the downloading process by an accelerator, it is relatively time-consuming to calculate the free space of a magnetic disk, eliminate resources, and create files, especially in some tf cards with poor performance. Therefore, improving the first-frame time requires some optimization of current resource storage steps.

In summary, the following aspects need to be considered when storing a resource: designing a good storage policy, ensuring the completeness of local resources, improving the utilization of the magnetic disk space, and reducing the first-frame time.

At present, a P2P node directly writes a resource to a magnetic disk after downloading the resource. Generally speaking, a resource storage scheme of writing a resource directly to a magnetic disk is a sequential storage method, i.e., opening a file -> receiving data -> writing the data in -> closing the file. That is, the resource storage scheme is: first, obtaining a file size of a resource from a server (for example, a resource server) or a CDN before downloading data; then, determining whether the current free space of a magnetic disk is sufficient according to the file size and, if not, eliminating resources until the free space is sufficient for storage; next, creating a resource file on the magnetic disk and opening the file, and upon receipt of the downloaded data, writing the data to the magnetic disk through an opened file handle; and finally, closing the file after the data has been completely received.

The above scheme is not optimal in terms of performance. Firstly, a file needs to be created regardless of whether a downloading task is complete (namely, whether the downloading task can download a complete resource, such as a complete video file). An entire file has to be created even if a play request happens to be the last <NUM> KB of data. In this way, an incomplete video file will be written to a magnetic disk, causing both magnetic disk consumption and low magnetic disk utilization. Secondly, in the whole process of downloading a resource, it is relatively time-consuming to analyze the free space of a magnetic disk, eliminate resources, and create files, especially time-consuming in an SD card with poor read and write performance, taking a few hundred milliseconds or so, which will significantly compromise the first-frame time for playing a video.

In conclusion, at least one or more of the following technical problems exist in the related art: <NUM>) frequently writing to a magnetic disk causes so much consumption to the magnetic disk that the life of the magnetic disk will be reduced; <NUM>) lots of incomplete resources will be buffered in a magnetic disk, resulting in low utilization of the magnetic disk space; and <NUM>) the need of performing time-consuming processes before storing a resource, such as analyzing the free space of a magnetic disk, eliminating resources, and creating files, results in a long downloading process and failure to return the resource to a player in time, thereby extending the first-frame time. For the above technical problems, the present application proposes the following technical scheme that can achieve at least one of the following effects by delaying writing to a magnetic disk: <NUM>) reducing the number of writes to a magnetic disk and avoiding frequent writes to the magnetic disk for the purpose of effectively extending the magnetic disk life; <NUM>) enhancing the completeness of resources buffered in a magnetic disk and improving utilization of the magnetic disk space; and <NUM>) delaying the execution of time-consuming steps, such as analyzing the free space of a magnetic disk, eliminating resources, and creating files, for the purpose of significantly reducing the first-frame time and improving the user experience.

The technical scheme of the present application is explained in detail below.

A method for downloading resources, applied to a P2P network. As shown in <FIG>, the method may include:.

In this embodiment, in the process of downloading resources, the received data is put into a memory first; data in the memory is directly provided to a resource requester; the first-frame data is directly read from the memory; thus, time-consuming steps, such as analyzing the free space of a magnetic disk, eliminating resources, and creating files, are avoided, thereby reducing the first-frame time and improving the user experience. In addition, by putting data into a memory, the number of writes to a magnetic disk can also be reduced, thereby decreasing the magnetic disk consumption and extending the magnetic disk life.

In a practical application, one resource corresponds to one downloading task; each resource has a unique resource ID; a downloading task is associated with a resource through the resource ID. A resource ID is carried in a downloading request provided by a resource requester and an accelerator can initiate a corresponding downloading task according to the resource ID.

The memory described in this embodiment is not a real-time system memory but a memory allocated to a downloading task. Different downloading tasks are independent of each other and each downloading task manages its own memory. In order not to affect the normal use of an application, an upper limit of use of memory is preset for an accelerator. The upper limit of use of memory is preset in units of tasks, that is, the upper limit of use of memory refers to an upper limit for scheduling the memory for each task of the accelerator. In this embodiment, "memory is full" means that memory data for one downloading task reaches the above upper limit of use of memory. For example, if an upper limit of use of memory for an accelerator is preset as <NUM> MB, it means that each task of the accelerator (for example, one downloading task) has <NUM> MB memory for scheduling, and the memory for a downloading task being full means that the memory currently used for the downloading task has reached <NUM> MB.

In terms of memory use, in this embodiment, data of a downloading task is written to a memory by recycling of memory blocks, to control the size of the memory, reduce the allocation and release of the memory, and improve the efficiency in using the memory. That is, in this embodiment, the writing the data of the downloading task to a memory can include: initially allocating one or a plurality of fixed-sized memory blocks to the downloading task, and writing the data of the downloading task to the memory through recycling of the memory block(s). In particular, the acquiring data of the downloading task and writing the data of the downloading task to a memory can include: initially allocating one or a plurality of fixed-sized memory blocks to the downloading task; writing the data of the downloading task to the memory block(s) upon receipt of the data; when the memory block(s) is/are full, releasing part or all of the memory block(s) for use by subsequent data received; and repeating such an operation until the downloading task is completed.

In a practical application, writing data of a downloading task to a memory by means of recycling the memory block(s) can include: initially allocating fixed-size memory block(s), with an initial state of the memory block(s) being set as "free"; writing data to the "free" memory block(s) upon receipt of the data and identifying the memory block(s) as "in use" after the data has been written to the memory block(s); reading data in all or part of the full memory block(s) when the memory block(s) is/are full and resetting the state of the memory block(s) as "free" for use by the newly received data, so that data of the current downloading task can be stored by recycling of memory block(s) initially allocated to the current downloading task, thus avoiding frequent allocation and releasing of memory for the current downloading task; and finally, when the entire downloading task is completed, reading data in the memory block(s) (e.g., writing the data to a magnetic disk and/or outputting the data to a resource requester) and releasing the memory block(s) for subsequent use.

Here, the currently received data can be directly written to the free memory block(s) if the free memory block(s) is/are sufficient to store the currently received data; all or part of the full memory block(s) will be released (that is, data in the memory block(s) can be read, and then written to a magnetic disk or directly returned to a resource request and the currently received data will be stored in the released memory block(s) if all the memory blocks are full or the current free memory block(s) is/are not sufficient to store the currently received data.

For example, for <NUM> memory blocks initially allocated, each having a size of <NUM> MB, when four pieces of data, such as <NUM> MB to 1st MB, 1st MB to 2nd MB, 2nd MB to 3rd MB, and 3rd MB to 4th MB, are received, memory blocks <NUM>, <NUM>, <NUM>, and <NUM> are created for storing the data, and a bitmap data structure is used for recording the use of data in each memory block at the same time. When it is found that the memory for the current downloading task has reached a preset upper limit of use upon receipt of data of the 5th MB, according to data in a bitmap, data in memory block(s) already used is read and written to a magnetic disk or returned to a resource requester, so that the memory block(s) is/are released to store the data of the 5th MB. Similarly, when further data is received, data in the full memory block(s) is read in turn (written to a magnetic disk and/or returned to a resource requester), and the currently received data is put into the released memory block(s); information recorded in a corresponding bitmap is updated at the same time.

In this embodiment, after the data is read from the memory and provided to the resource requester, a memory block occupied by the data in the memory is released.

In this embodiment, after data in the memory is written to a magnetic disk, a memory block occupied by the data in the memory is released.

In this embodiment, during the downloading process, the received data is not directly written to a magnetic disk, but is stored in a memory and written to the magnetic disk with delay. The operation of writing data to a magnetic disk is triggered when the memory for the downloading task is full.

In one implementation, the method can further include: determining whether the downloading task is complete when data in the memory reaches a preset upper limit of use, where the downloading task being complete indicates that a complete resource is able to be acquired by the downloading task, and filtering out the downloading task when the downloading task is incomplete so that the data in the memory will not be written to a magnetic disk.

In one implementation, the method can further include: determining whether the downloading task is complete when data in the memory reaches a preset upper limit of use, where the downloading task being complete indicates that a complete resource is able to be acquired by the downloading task, and writing the data in the memory to a magnetic disk when it is determined that the downloading task is complete.

In the above implementations of this embodiment, the determination of which downloading tasks are incomplete is triggered when a memory for a downloading task is full of data. A resource downloaded for an incomplete downloading task will not be available for distribution, so that such an incomplete downloading task is filtered out rather than being written to a magnetic disk, while data for a complete downloading task is written to a magnetic disk. In this way, filtering out incomplete downloading tasks and only writing data of complete downloading tasks to a magnetic disk can avoid waste of the magnetic disk space and improve utilization of the magnetic disk space.

In this embodiment, the downloading task is filtered by setting a downloading mode of the downloading task. In one implementation, the filtering out the downloading task when the downloading task is incomplete so that the data in the memory will not be written to a magnetic disk can include: setting a downloading mode of the downloading task as a memory mode when the downloading task is incomplete, where the data in the memory will not be written to the magnetic disk in the memory mode. In another implementation, the writing the data in the memory to a magnetic disk when the downloading task is complete can include: setting a downloading mode of the downloading task as a mode of magnetic disk + memory when the downloading task is complete, where the data in the memory will be written to the magnetic disk in the mode of magnetic disk + memory.

The magnetic disk is not written to in the memory mode and is written to in the mode of "magnetic disk + memory. " In a practical application, a main purpose of writing to a magnetic disk is to distribute a resource to other P2P nodes, provided that the resource is complete. An incomplete resource is not available for distribution as the correctness of data cannot be determined due to incompleteness. The downloading tasks filtered out herein are primarily ones for incomplete resources not available for distribution.

In one implementation, data of a downloading task resides in a memory block in the memory mode. Data in the memory is erased after data in the memory block has been transmitted to a resource requester, and the memory is free for use by new data after data in the entire memory block has been erased.

In another implementation, data of the downloading task is first stored in a memory block in the mode of "magnetic disk + memory. " When a memory block is full of data, data in the memory block is written to a magnetic disk. Data in the memory block is erased after being written to the magnetic disk. The memory is free for use by new data after data in the entire memory block has been erased.

In this embodiment, a downloading mode of the downloading task can be set by resetting a downloading mode parameter of the downloading task after it is determined whether the downloading task is complete.

For example, one downloading mode parameter can be set for each downloading task, and the downloading mode parameter can indicate the above two downloading modes. For example, a downloading mode parameter set to be "<NUM>" indicates that the downloading mode is set as the memory mode, and a downloading mode parameter set to be "<NUM>" indicates that the downloading mode is set as the mode of "magnetic disk + memory. " In addition, other means can also be employed, which are not limited herein.

For example, a downloading mode parameter can be set as the one indicating the mode of "magnetic disk + memory" at the beginning of a downloading task and, after it has been determined that the downloading task is incomplete, the downloading mode parameter of the downloading task is reset as the one indicating the memory mode. In this way, during the execution of the downloading task, the received data is put into the memory, but data in the memory will not be written to a magnetic disk. Initial setting of the downloading mode parameter for a downloading task is maintained after it has been determined that the downloading task is complete. In this way, during the execution of the downloading task, the received data in the mode of "magnetic disk + memory" is put into the memory and will be written to a magnetic disk.

It is noted that the completeness of a downloading task in this embodiment refers to the completeness of a resource that can be acquired by the downloading task. The downloading task being complete indicates that a complete resource can be acquired by the downloading task, and the downloading task being incomplete indicates that a complete resource cannot be acquired by the downloading task. Here, the resource refers to a file that can be independently downloaded, and the complete resource refers to the complete file that can be independently downloaded, i.e., all the data of the file. Here, the file can be any type of file. For example, the file can be a video file. For example, some video files are so large that the video files will be split into a plurality of small files generally of tens of MB on a server. Each small file can be downloaded as an independent task unit. One small file is one resource, and one complete resource can be all data in one small file.

In this embodiment, whether the downloading task is complete can be determined in a plurality of ways. In one implementation, the method described above can include determining whether the downloading task is complete according to Range information in the downloading request.

In a practical application, the Range information can be acquired by parsing the downloading request. For example, when a user clicks to play a video in an application, a URL address of the video source and corresponding Range information are transmitted by a player to an accelerator, which is a downloading request received by the accelerator. Range information is parsed through a standard HTTP protocol. A Content-Range field can be acquired by parsing a header of a downloading request and Range information can be extracted from the Content-Range field.

At present, it can be determined that a resource is definitely incomplete in two cases.

The first case: Range information acquired by parsing a downloading request does not start from <NUM>, indicating that a resource to be downloaded does not start from the beginning and data acquired thereafter will definitely not form a complete resource. Correspondingly, the current downloading task is incomplete if Range information acquired by parsing a downloading request does not start from <NUM>. For example, Range information of a video played in sequence starts from <NUM>. In most cases, Range information does not start from <NUM>, definitely leading to an incomplete downloaded resource. For example, Range information does not start from <NUM> in the following three cases: A) Seek; B) skipping the credit titles; C) recording the last viewed position for the continuation of viewing, and so on.

The second case: in a practical application, a middle section of data is skipped when a user performs Seek operation, causing the entire file to be incomplete. A current resource to be downloaded is incomplete if intra-file Seek is identified according to a downloading request and, correspondingly, the current downloading task is incomplete if intra-file Seek is identified. Here, the intra-file Seek refers to Seek in an independent file.

In the first case described above, it can be determined whether a downloading task is complete when the downloading task is initiated. In the second case, a downloading task can be considered incomplete once Seek operation has been identified during a period from initiating the downloading task to the memory being full.

Based on the above two cases, in this embodiment, whether a downloading task is complete can be determined by the following two ways: <NUM>) determining whether Range information in the downloading request starts from <NUM>, and determining that the downloading task is complete if the Range information starts from <NUM>, and determining that the downloading task is incomplete if the Range information does not start from <NUM>; and <NUM>) identifying, according to Range information in the downloading request, whether the downloading request corresponds to Seek operation, and determining that the downloading task is incomplete if the downloading request corresponds to Seek operation. It is necessary to determine whether the downloading task is complete in combination with Range information if the downloading request does not correspond to Seek operation. In other words, a corresponding downloading task is definitely incomplete if the downloading request corresponds to Seek operation, and a corresponding downloading task is not necessarily complete if the downloading request does not correspond to Seek operation. In a practical application, a memory for a downloading task, with a size of a few MB, needs a few seconds to be full of data, and allows the identification of some quick Seek scenarios.

Specifically, the identifying, according to the Range information in the downloading request, whether the downloading request corresponds to Seek operation can include: determining, according to the Range information in the downloading request and Range information of a corresponding downloading task already existing in the memory, whether data corresponding to the downloading request is able be spliced into a complete resource with corresponding data already existing in the memory; and determining, if data corresponding to the downloading request is able to be spliced into a complete resource with the corresponding data already existing in the memory, that the downloading request does not correspond to Seek operation. Here, if data corresponding to the downloading request is not able be spliced into a complete resource with the corresponding data already existing in the memory, then it is determined that the downloading request corresponds to Seek operation. In addition, whether the current downloading request corresponds to Seek operation can also be identified by other means, which are not limited herein.

In this embodiment, the received data is first put into a memory and written to a magnetic disk with delay. Specifically, the writing the data in the memory to a magnetic disk can include: when the data in the memory reaches the preset upper limit of use and the downloading task is complete, creating a file in the magnetic disk and writing the data in the memory to the file, or directly opening a file corresponding to the downloading task and writing the data in the memory to the opened file. In other words, in this embodiment, when data in the memory is written to a magnetic disk, a file is created in conditions that the memory is full and the downloading task is complete. In this way, writes to a magnetic disk, such as file creation and file opening, are delayed and triggered when a corresponding memory is full, thereby effectively reducing the first-frame time.

In this embodiment, the process of writing data in a memory to a magnetic disk can include: determining whether a file corresponding to the current downloading task already exists (for example, determining whether a file corresponding to the downloading task already exists according to a resource ID of the downloading task and a resource ID of the file); if no file corresponding to the current downloading task exists, first creating a file in the magnetic disk, then opening the file and writing data in the memory to the file through an opened file handle, and closing the file after data in the memory has been completely written; and if a file corresponding to the current downloading task exists, directly opening the file and writing data in the memory to the file through an opened file handle, and then closing the file after data in the memory has been completely written.

In a practical application, a buffer path can be obtained from an initiating parameter when an accelerator has just been initiated. When the file creation operation is triggered, according to a resource ID of a downloading task, the buffer path is searched to find out whether a file named after the resource ID exists; and if so, the file is opened, and if not, a file named after the resource ID is created. For example, a resource ID is 53121400C244D5B00B87A39D804438FA5FC575A3, and the name of a file created can be 53121400C244D5B00B87A39D804438FA5FC575A step <NUM>.

In this embodiment, the writing the data in the memory to a magnetic disk can include: splicing the data in the memory into a continuous data block and writing the data block to the magnetic disk. Therefore, scattered and fragmented data from a plurality of P2P nodes uploading resources is stored in the memory first, and then written to a magnetic disk all at once after being spliced into a continuous and complete data block, thereby improving the writing efficiency, reducing the number of writes to a magnetic disk, and enhancing the IO performance of a magnetic disk.

In this embodiment, the method further includes: when the data in the memory reaches the preset upper limit of use and the downloading task is complete, analyzing the free space of the magnetic disk; and if the free space of the magnetic disk is not sufficient to store the data in the memory, performing an elimination operation on resources so as to write the data in the memory to the magnetic disk. In this manner, time-consuming steps for magnetic disk processing, such as analyzing the magnetic disk space and eliminating resources, can be delayed and triggered when a corresponding memory is full. The delay of such part of time consumption avoids the impacts of these steps on the first-frame data.

This embodiment also provides a device for downloading resources, applied to a P2P network. As shown in <FIG>, the device may include:.

In this embodiment, the device described above can further include:.

In one implementation, the determining module <NUM> can be specifically configured to determine whether the downloading task is complete according to Range information in the downloading request.

In one implementation, the determining module <NUM> can be specifically configured to determine whether the downloading task is complete by one or two of the following ways: <NUM>) determining whether the Range information in the downloading request starts from <NUM>, and determining that the downloading task is complete if the Range information starts from <NUM>; and <NUM>) identifying, according to the Range information in the downloading request, whether the downloading request corresponds to Seek operation, and determining that the downloading task is incomplete if the downloading request corresponds to Seek operation.

In one implementation, the magnetic-disk writing module <NUM> can be specifically configured to: when the data in the memory reaches the preset upper limit of use and the downloading task is complete, create a file in the magnetic disk and write the data in the memory to the file, or directly open a file corresponding to the downloading task and write the data in the memory to the opened file.

In one implementation, the magnetic-disk writing module <NUM> can be specifically configured to splice the data in the memory into a continuous data block and write the data block to the magnetic disk.

In one implementation, the memory module <NUM> can be configured to write the data of the downloading task to a memory, including: initially allocating one or a plurality of fixed-sized memory blocks to the downloading task, and writing the data of the downloading task to the memory through recycling of the memory block(s).

In one implementation, the memory module <NUM> can be configured to write the data of the downloading task to a memory, including: initially allocating one or a plurality of fixed-sized memory blocks to the downloading task; writing data currently received by the acquisition module to the memory block(s); when the memory block(s) is/are full, releasing part or all of the memory block(s) for use by subsequent data received by the acquisition module; and repeating such an operation until the downloading task is completed.

In a practical application, the above device of this embodiment can be disposed on or implemented as a P2P node.

It is noted that in the above device of this embodiment:.

A device for downloading resources, applied to a P2P network. As shown in <FIG>, the device may include:.

The device for downloading resources may also include: a memory <NUM>. The processor <NUM> is configured to read the computer program so as to implement the following operation: writing data of a downloading task to the memory <NUM>.

The device for downloading resources may also include: a magnetic disk <NUM>. The processor <NUM> is configured to read the computer program so as to implement the following operation: determining whether the downloading task is complete when data in the memory reaches a preset upper limit of use, where the downloading task being complete indicates that a complete resource is able to be acquired by the downloading task; and writing the data in the memory <NUM> to the magnetic disk <NUM> when it is determined that the downloading task is complete.

It is noted that the device for downloading resources shown in <FIG> may include other components in addition to the storage <NUM>, the processor <NUM>, the memory <NUM>, and the magnetic disk <NUM> described above. As an example, the device for downloading resources may further include a data storage for storing user data. As another example, the device for downloading resources may further include a communication circuit for communicating with an external device. As another example, the device for downloading resources may further include a bus for coupling parts of the device. As still another example, the device for downloading resources may further include an input component and an output component (e.g., a microphone, a speaker, a display, a keyboard, etc.). Additionally, the device described above may also include other components.

This embodiment also provides a computer-readable storage medium storing a computer program thereon, and the computer program, when executed by a processor, implement the steps of the method for downloading resources described above.

For other technical details of this embodiment, reference may be made to Embodiment <NUM>.

Exemplary implementations of each of the above embodiments are described in detail below. It is noted that the examples below can be combined with one another. Also, the processes, execution processes, and the like in the examples below may be adapted to the needs of a practical application. In addition, in a practical application, the above embodiments can also have other implementations.

In this example, an exemplary execution flow in a resource downloading process is described in detail.

As shown in <FIG>, the exemplary execution flow in a resource downloading process may include:.

In this example, a resource downloading process of P2P nodes of an entire P2P system is described in detail.

In the entire P2P system, a process of interaction among P2P nodes associated with resource downloading is as follows:.

Claim 1:
A method for downloading resources, applied to a peer-to-peer (P2P) network, the method being performed by a device for downloading resources, the method comprising:
initiating (<NUM>; <NUM>) a downloading task according to a downloading request from a resource requester;
acquiring (<NUM>; <NUM>) data of the downloading task and writing the data of the downloading task to a memory (<NUM>); and
reading (<NUM>) the data from the memory (<NUM>) and providing the data to the resource requester,
wherein the method further comprises:
determining (<NUM>, <NUM>), when data in the memory (<NUM>) reaches a preset upper limit of use, whether the downloading task is complete, wherein the downloading task being complete indicates that a complete resource is able to be acquired by the downloading task; and
writing (<NUM>) the data in the memory (<NUM>) to a magnetic disk (<NUM>) when it is determined that the downloading task is complete; and
characterized by
filtering out (<NUM>) the downloading task when the downloading task is incomplete so that the data in the memory will not be written to a magnetic disk,
wherein the method further comprises:
determining whether the downloading task is complete according to Range information in the downloading request; and
identifying, according to the Range information in the downloading request, whether the downloading request corresponds to Seek operation, and determining that the downloading task is incomplete if the downloading request corresponds to Seek operation;
wherein the identifying, according to the Range information in the downloading request, whether the downloading request corresponds to Seek operation comprises:
determining, according to the Range information in the downloading request and Range information of a corresponding downloading task already existing in the memory, whether data corresponding to the downloading request is able to be spliced into a complete resource with corresponding data already existing in the memory; and
determining, if the data corresponding to the downloading request is able to be spliced into a complete resource with the corresponding data already existing in the memory, that the downloading request does not correspond to Seek operation.