Disclosure of Invention
According to the embodiment of the invention, a source-returning scheme of CDN nodes is provided.
In a first aspect of the present invention, a method for back-sourcing CDN nodes is provided. The method comprises the following steps:
any one cache server of a plurality of cache servers in a CDN node responds to a resource request, and a URI (uniform resource identifier) requested in the resource request and an IP (Internet protocol) list of the cache server in the CDN node are obtained;
the cache server calculates a target IP through a consistent hash algorithm according to the URI requested in the resource request and an IP list of the cache server in the CDN node, and forwards the resource request to the cache server corresponding to the target IP;
the cache server corresponding to the target IP judges whether the content requested in the resource request is cached, if so, the CDN node returns to a lower node of the CDN node until a client corresponding to the resource request is returned; otherwise, the CDN node sends a source request back to an upper node of the CDN node.
Further, the CDN node is an edge node or an aggregation node.
Further, the resource request is a user request sent by the client to a cache server in the edge node, a source return request sent by the cache server in the edge node to a cache server in the sink node, or a source return request sent by the cache server in the sink node to the source station layer.
Further, obtaining the IP list of the CDN node includes:
the cache server sends an HTTP request with the ID of the CDN node to a CDN dispatching center, receives IP list information returned by the CDN dispatching center, and updates an IP list of the cache server in the CDN node by the IP list information; the IP list information is the IP list information of all cache servers in CDN nodes where the cache servers are located.
Further, the method further comprises the following steps:
detecting a cache server, if the cache server is abnormal, disabling the cache server and deleting the IP information of the abnormal cache server from an IP list; and if the cache server in the disabled state is recovered to be normal, the cache server is disabled, and the IP information of the disabled cache server is added in the IP list of the cache server of the CDN node where the cache server is located.
Further, the detecting the cache server includes:
reporting a heartbeat message to a CDN dispatching center by a cache server to be detected at intervals of a first time, and if the heartbeat message of the cache server to be detected is not received by the CDN dispatching center within the first time, the cache server to be detected is abnormal; and/or
The CDN dispatching center sends a detection message to a to-be-detected cache server, and if a response message returned by the to-be-detected cache server is not received within a second time, the to-be-detected cache server is abnormal; and/or
The cache server receiving the resource request forwards the resource request to the cache server corresponding to the target IP, and if the client corresponding to the resource request does not receive the feedback information of the cache server corresponding to the target IP in a third time, the cache server corresponding to the target IP is abnormal; wherein the feedback information includes the content requested in the resource request, and the absence of the message requesting the content in the resource request.
Further, when the cache server executes the consistent hashing algorithm, if added and/or deleted IP information exists in the IP list, the cache server remaps the added and/or deleted IP information.
In a second aspect of the present invention, a source-back device for a CDN node is provided. The device comprises:
the acquisition module is arranged at any one cache server of a plurality of cache servers contained in the CDN node and is used for responding to the resource request and acquiring the URI requested in the resource request and the IP list of the cache server in the CDN node;
the calculation module is arranged in the cache server and used for calculating a target IP through a consistent hash algorithm according to the URI requested in the resource request and the IP list of the cache server in the CDN node and forwarding the resource request to the cache server corresponding to the target IP;
the judging module is arranged in the cache server corresponding to the target IP and is used for judging whether the content requested in the resource request is cached or not, if so, the CDN node returns to the lower node of the CDN node until the client corresponding to the resource request is returned; otherwise, the CDN node sends a source request back to an upper node of the CDN node.
In a third aspect of the invention, an electronic device is provided. The electronic device includes: a memory and a processor, the memory having stored thereon a computer program, the processor implementing the method as described above when executing the program.
In a fourth aspect of the invention, there is provided a computer readable storage medium having stored thereon a computer program which when executed by a processor implements a method as according to the first aspect of the invention.
It should be understood that the description in this summary is not intended to limit the critical or essential features of the embodiments of the invention, nor is it intended to limit the scope of the invention. Other features of the present invention will become apparent from the description that follows.
The invention can enable each CDN node to return to the source only once aiming at the user request of the same content, thereby reducing the source return rate, saving the upper bandwidth, improving the effective throughput, reducing the access pressure of the source site server and improving the user experience.
Detailed Description
For the purpose of making the objects, technical solutions and advantages of the embodiments of the present invention more apparent, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention, and it is apparent that the described embodiments are some embodiments of the present invention, but not all embodiments of the present invention. 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.
In addition, the term "and/or" herein is merely an association relationship describing an association object, and means that three relationships may exist, for example, a and/or B may mean: a exists alone, A and B exist together, and B exists alone. In addition, the character "/" herein generally indicates that the front and rear associated objects are an "or" relationship.
Fig. 1 is a schematic diagram of a source-back method of a CDN node according to an embodiment of the present invention.
The CDN architecture comprises two layers, namely an edge layer and a convergence layer; the convergence layer is arranged on the upper layer of the edge layer, and the edge layer is arranged on the lower layer of the convergence layer. The lower layer of the edge layer is a user layer; the user layer comprises a client, and the client is responsible for receiving a user instruction, generating a user request and sending the user request to the edge layer. The upper layer of the convergence layer is a source station layer, and the source station layer is responsible for receiving a source return request sent by the convergence layer and returning the content requested in the user request to a cache server of a node corresponding to the convergence layer according to the source return request. The source site layer includes a source site server.
The edge layer is in charge of receiving a user request sent by a client, randomly distributing any cache server in one edge node in the edge layer to perform cache inquiry, and sending a source request back to the convergence layer when the cache server does not inquire the content requested in the user request; the edge layer is also responsible for receiving the content file requested in the user request returned by the convergence layer and returning the content file to the client. The edge layer comprises a plurality of edge nodes, a plurality of cache servers are arranged in each edge layer node, and corresponding IP is distributed to each cache server; in each cache server, cache data is stored.
The aggregation layer is in charge of receiving the source return request of the edge layer, randomly distributing any cache server in one aggregation node in the aggregation layer to perform cache inquiry, and sending the source return request to the source station layer when the content requested in the source return request is not inquired in the cache server; and the convergence layer is also responsible for receiving the content file requested in the source returning request returned by the source station layer and returning the content file to the corresponding cache server of the corresponding edge node of the edge layer. The aggregation layer comprises a plurality of aggregation nodes, a plurality of cache servers are arranged in each aggregation node, and corresponding IP is distributed to each cache server; in each cache server, cache data is stored. The number of edge nodes in the edge layer is much greater than the number of sink nodes in the sink layer.
In the embodiment of the prior art, when a user requests to open a page or download a file through a client device, the user request randomly reaches any cache server in an edge node, and if the cache server caches the content file requested in the user request, the content file is directly returned to the client; if the cache server does not have the file requested in the user request, the source request is sent back to the upper layer, namely the convergence layer. The source-returning request also randomly reaches any cache server in the sink node of one sink layer, if the cache server caches the content file requested in the source-returning request, the content file is directly returned to the cache server of the corresponding edge node of the edge layer and returned to the client; if the cache server does not have the content file requested in the source return request, the source return request is sent to the upper layer, namely the source station layer; and the source station layer server returns the content file requested in the source return request to the client side step by step according to the source return path.
However, in this process, since there are several cache servers in each CDN node, and the user's request only accesses one of the cache servers, if the cache server has no request for content, even if there is content requested by the user in the other cache servers of the CDN node, the request of the same content (URI is the same) needs to be returned to the upper layer, so that the request of the same content (URI is the same) will be returned to the upper layer multiple times, so that the output bandwidth of the upper layer is increased, and the effective throughput is reduced.
According to the invention, each CDN node can only return to the source for the user request of the same content, so that the upper bandwidth is saved, the effective throughput is improved, and the source return speed and efficiency are improved.
Fig. 2 shows a flowchart of a method for backsourcing CDN nodes according to an embodiment of the present invention.
The method comprises the following steps:
s201, any cache server in a plurality of cache servers in a CDN node responds to a resource request, and a URI (uniform resource identifier) requested in the resource request and an IP (Internet protocol) list of the cache server in the CDN node are obtained;
the resource request is a user request sent by a client to a cache server in an edge node, a source returning request sent by the cache server in the edge node to a cache server in a sink node or a source returning request sent by the cache server in the sink node to a source station layer. The CDN node is an edge node or an aggregation node. The content router in the CDN network architecture is responsible for scheduling the user's requests to the appropriate devices (cache servers). Content routing is generally achieved through a load balancing system, load distribution of each content caching site is dynamically balanced, an optimal access site is selected for a user's request, and meanwhile usability of a website is improved.
When a CDN node receives a resource request sent by a lower layer, a cache server in the CDN node responds to the resource request, and randomly reaches a cache server in the current CDN node according to the resource request, cache processing software of the cache server obtains a uniform resource identifier URI (Uniform Resource Identifier) in the resource request, and then obtains IP lists of all cache servers of the current CDN node.
As an embodiment of the present invention, obtaining an IP list of CDN nodes includes:
the cache server sends an HTTP request with the ID of the CDN node to a CDN dispatching center, receives IP list information returned by the CDN dispatching center, and updates an IP list of the cache server in the CDN node by the IP list information; the IP list information is the IP list information of all cache servers in the CDN node where the cache server is located, as shown in table 1:
sequence number
|
Name of the name
|
IP information
|
1
|
Cache server 1
|
103.56.3.24
|
2
|
Cache server 2
|
103.56.3.26
|
3
|
Cache server 3
|
103.56.3.39
|
……
|
……
|
……
|
10
|
Cache server 10
|
103.56.3.89 |
TABLE 1
The CDN node ID can uniquely identify the CDN node.
When a user requests to open a page or download a file through a client device, the user request is sent to an edge layer, the user request reaches any cache server in an edge node in the edge layer, the URI requested in the user request is obtained through cache processing software in the cache server, and an IP list of all the cache servers in the edge node is obtained. The method comprises the steps that IP lists of all cache servers in an aggregation node are obtained, the cache servers send HTTP requests with the ID of the located edge node to a CDN dispatching center, IP list information returned by the CDN dispatching center is received, and the IP lists of the cache servers in the edge node are updated according to the IP list information.
When a cache server in an edge node in an edge layer sends a source return request to a convergence layer, the source return request reaches any cache server in a certain convergence node in the convergence layer, a URI (uniform resource identifier) requested in the source return request is obtained through cache processing software in the cache server, and an IP (Internet protocol) list of all the cache servers in the convergence node is obtained. The method comprises the steps that IP lists of all cache servers in an aggregation node are obtained, the cache servers send HTTP requests with the ID of the aggregation node to a CDN dispatching center, IP list information returned by the CDN dispatching center is received, and the IP lists of the cache servers in the aggregation node are updated through the IP list information.
S202, the cache server calculates a target IP through a consistent hash algorithm according to the URI requested in the resource request and the IP list of the cache server in the CDN node, and forwards the resource request to the cache server corresponding to the target IP.
Inserting an IP list formed by the IP of all cache servers in the current CDN node into a hash data structure through a consistent hash algorithm; the URI requested in the resource request is used as the input of a consistent hash algorithm, namely: ip=ip=con_hash (URI), and one fixed IP in the current CDN node is obtained, that is, the target IP. And forwarding the resource request to a cache server corresponding to the target IP.
Since the consistent hashing algorithm has consistency, the IP list in a node is fixed in most cases, so in most cases, a URI will fix a corresponding IP. The majority of cases are cases where no additions and/or deletions occur in the IP list. Because a fixed target IP can be calculated through the fixed URI and the IP list, a source returning request can be carried out to an upper layer based on a cache server corresponding to the target IP, and the content requested in the returned source returning request is cached to the cache of the cache server corresponding to the target IP.
As an embodiment of the present invention, when a process in the cache server executes the consistent hashing algorithm, if added and/or deleted IP information exists in the IP list, the cache server remaps the added and/or deleted IP information. The remapping is such that only the changed IP information is mapped and global remapping is not required. The mapping refers to associating the URI requested in the resource request with information in the IP list. After the IP list changes, the IP information corresponding to the URI requested in the resource request is also rebalanced. Because the consistent hash algorithm does not need global remapping, the method can also realize less source return under the condition that the equipment in the node is increased or decreased.
S203, the cache server corresponding to the target IP judges whether the content requested in the resource request is cached, if so, the CDN node returns to the lower node of the CDN node until the client corresponding to the resource request is returned; otherwise, the CDN node sends a source request back to an upper node of the CDN node.
When the CDN node sends a source return request to an upper node of the CDN node, the source return request is dispatched to appropriate equipment (cache server) in the upper node of the CDN node through a content router in a CDN network architecture. Content routing is generally achieved through a load balancing system, load distribution of each content caching site is dynamically balanced, an optimal access site is selected for a user's request, and meanwhile usability of a website is improved.
As an embodiment of the present invention, after sending a source request back to an upper node of the CDN node, the CDN node waits for receiving a content requested in the resource request returned by the upper node; after receiving the content requested in the resource request, caching the content requested in the resource request.
As an embodiment of the present invention, the method further includes detecting a cache server, if the cache server is abnormal, disabling the cache server and deleting the IP information of the abnormal cache server from the IP list; and if the cache server in the disabled state is recovered to be normal, the cache server is disabled, and the IP information of the disabled cache server is added in the IP list of the cache server of the CDN node where the cache server is located.
In an embodiment of the present invention, the detection of the cache server may be implemented in one or more of the following three ways:
mode one:
and reporting heartbeat messages to a CDN dispatching center every first time by the to-be-detected cache server, if the heartbeat messages of the to-be-detected cache server are not received by the CDN dispatching center within the first time, the to-be-detected cache server is abnormal, service on the IP is unavailable, each cache server configured in the node is issued, the abnormal cache server losing the heartbeat is forbidden, and the IP information of the forbidden cache server is deleted from an IP list.
And when the CDN dispatching center receives the heartbeat of the forbidden cache server again, the service is considered to be recovered, the forbidden cache server is forbidden, and the forbidden IP information of the forbidden cache server is added in the IP list of the cache server of the CDN node where the cache server is located. The first time is the time between two adjacent heartbeat messages and can be set manually.
Mode two:
the CDN dispatching center sends a detection message to a to-be-detected cache server, and if a response message returned by the to-be-detected cache server is not received within a second time, the to-be-detected cache server is abnormal; for example, the CDN dispatch center sends a probe HTTP request to each cache server in the node, and the cache server that receives the probe HTTP request normally responds to the HTTP200 status code, and the CDN dispatch center also receives the status code within a certain time, that is, indicates a successful response. If a response of a certain cache server is not received within a specified second time or the response is received within the specified second time but the response is not an HTTP200 status code, namely the response fails, the cache server is considered to be abnormal, an abnormal cache server losing the heartbeat is forbidden, and the IP information of the abnormal cache server is deleted from an IP list. The second time is the longest time from sending the detection message from the CDN scheduling center to receiving the status code, and may be manually specified.
And when the cache server responds to the HTTP detection request sent by the CDN dispatching center again and receives the HTTP200 state code, the service is considered to be recovered, the cache server is forbidden, and the forbidden IP information of the cache server is added in the IP list of the cache server of the CDN node where the cache server is located.
Mode three:
and the cache server receiving the resource request forwards the resource request to the cache server corresponding to the target IP, and if the client corresponding to the resource request does not receive the feedback information of the cache server corresponding to the target IP in a third time, the cache server corresponding to the target IP is abnormal.
The third time is the longest time from the sending of the user request to the receiving of the feedback content by the client, and can be set manually. The feedback information includes the content requested in the resource request, and the absence of a message requesting the content in the resource request. Whether the cache server in the CDN system searches the content requested in the user request or not, information is fed back to the client, and whether the corresponding cache server is abnormal or not can be judged by feeding back the information or not in a specified time.
The detection modes of the three modes are combined, so that the state of the cache server can be judged more comprehensively and accurately, and the judging efficiency and accuracy are improved.
The following describes the method of S201 to S203 by two specific examples.
Example 1:
in this embodiment 1, the resource request is a user request sent by the user through the client to open a page or download a file.
When a user requests to open a page or download a file through a client device, the user sends a user request to an edge layer through the client, the user request reaches any cache server in an edge node in the edge layer, the cache server obtains the URI requested in the user request through cache processing software in the cache server, and obtains IP lists of all the cache servers in the edge node.
And taking the URI requested in the user request and the IP list of all cache servers in the edge node as inputs, calculating a target IP by the cache servers according to a consistent hash algorithm, and forwarding the user request to the cache server corresponding to the target IP.
Judging whether a content file requested in the user request is cached in a cache server corresponding to the target IP, and if so, returning the content file to a client corresponding to the resource request; otherwise, the cache server of the edge node sends a source request back to the sink node of the sink layer.
Any cache server in the sink node of the sink layer obtains the URI requested in the retrieval source request through cache processing software in the cache server, and obtains the IP list of all the cache servers in the sink node. And taking the URI requested in the source return request and the IP list of all cache servers in the sink node as inputs, calculating by the cache servers according to a consistent hash algorithm to obtain a target IP, and forwarding the source return request to the cache server corresponding to the target IP. Judging whether the cache server corresponding to the target IP caches the content file requested in the back source request, if so, caching the content file to the cache server of the edge node sending the back source request, and returning the requested content file to the client corresponding to the back source request through the cache server. And if the cache server in the sink node is searched and the content file requested in the source returning request is not found, continuing to send the source returning request to the source station layer. After the source station server of the source station layer receives the source return request, the content file requested in the source return request is returned to the cache server of the sink node according to the source return path and is cached in the cache server, the content file requested in the source return request is continuously returned to the cache server of the edge node and is cached in the cache server, and the content file requested in the source return request is continuously returned to the client corresponding to the source return request.
It can be seen that, according to the above embodiment, through the source return process, the requested content is cached in the cache server corresponding to the target IP, and when the node of each layer in the CDN network architecture receives the content request that has been previously returned, the target IP can be found according to the fixed URI and the IP list, and the corresponding content is found from the cache server of the target IP, and is directly returned to the user, without returning to the upper layer again, thereby saving the upper layer bandwidth, improving the effective throughput, reducing the access pressure of the server of the source station, and reducing the source return rate.
It should be noted that, for simplicity of description, the foregoing method embodiments are all described as a series of acts, but it should be understood by those skilled in the art that the present invention is not limited by the order of acts described, as some steps may be performed in other orders or concurrently in accordance with the present invention. Further, those skilled in the art will also appreciate that the embodiments described in the specification are alternative embodiments, and that the acts and modules referred to are not necessarily required for the present invention.
The above description of the method embodiments further describes the solution of the present invention by means of device embodiments.
As shown in fig. 3, the apparatus 300 includes:
and the acquiring module 310 is configured to respond to the resource request, and acquire the URI requested in the resource request and the IP list of the cache server in the CDN node. The CDN node is an edge node or an aggregation node. The resource request is a user request sent by a client to a cache server in an edge node, a source returning request sent by the cache server in the edge node to a cache server in a sink node or a source returning request sent by the cache server in the sink node to a source station layer.
Further, the obtaining module 310 sends an HTTP request with an ID of the CDN node to a CDN dispatch center when obtaining the IP list of the CDN node, receives IP list information returned by the CDN dispatch center, and updates an IP list of a cache server in the CDN node with the IP list information; the IP list information is the IP list information of all cache servers in CDN nodes where the cache servers are located.
And the calculating module 320 is configured to calculate, according to the URI requested in the resource request and the IP list of the cache server in the CDN node, a target IP through a consistent hash algorithm, and forward the resource request to the cache server corresponding to the target IP.
A judging module 330, configured to judge whether a content requested in the resource request is cached, if yes, cache the content to the CDN node, and return the content from the CDN node to a lower node of the CDN node until a client corresponding to the resource request is returned; otherwise, the CDN node sends a source request back to an upper node of the CDN node.
As an embodiment of the present invention, as shown in fig. 4, the apparatus 300 further includes a mapping module 340;
the mapping module 340 is configured to, when the cache server executes the consistent hashing algorithm, remap the added and/or deleted IP information if the added and/or deleted IP information exists in the IP list.
As an embodiment of the present invention, as shown in fig. 4, the apparatus 300 further includes a detection module 350;
the detection module 350 further includes a first detection module 351, a second detection module 352, and a third detection module 353; wherein the method comprises the steps of
The first detection module 351 is configured to report a heartbeat message to a CDN scheduling center at intervals of a first time, and if the CDN scheduling center does not receive the heartbeat message of the cache server to be detected within the first time, the cache server to be detected is abnormal.
The second detection module 352 is configured to send a detection message to a cache server to be detected, and if a response message returned by the cache server to be detected is not received within a second time, the cache server to be detected is abnormal.
A third detection module 353, configured to forward the resource request to a cache server corresponding to the target IP, and if the client corresponding to the resource request does not receive feedback information of the cache server corresponding to the target IP within a third time, the cache server corresponding to the target IP is abnormal; wherein the feedback information includes the content requested in the resource request, and the absence of the message requesting the content in the resource request.
It will be clear to those skilled in the art that, for convenience and brevity of description, specific working procedures of the described modules may refer to corresponding procedures in the foregoing method embodiments, which are not described herein again.
As shown in fig. 5, the apparatus includes a Central Processing Unit (CPU) that can perform various suitable actions and processes according to computer program instructions stored in a Read Only Memory (ROM) or computer program instructions loaded from a storage unit into a Random Access Memory (RAM). In the RAM, various programs and data required for the operation of the device can also be stored. The CPU, ROM and RAM are connected to each other by a bus. An input/output (I/O) interface is also connected to the bus.
A plurality of components in a device are connected to an I/O interface, comprising: an input unit such as a keyboard, a mouse, etc.; an output unit such as various types of displays, speakers, and the like; a storage unit such as a magnetic disk, an optical disk, or the like; and communication units such as network cards, modems, wireless communication transceivers, and the like. The communication unit allows the device to exchange information/data with other devices via a computer network, such as the internet, and/or various telecommunication networks.
The processing unit performs the respective methods and processes described above, for example, the methods S201 to S203. For example, in some embodiments, methods S201-S203 may be implemented as a computer software program tangibly embodied on a machine-readable medium, such as a storage unit. In some embodiments, part or all of the computer program may be loaded and/or installed onto the device via the ROM and/or the communication unit. When the computer program is loaded into RAM and executed by the CPU, one or more steps of the methods S201 to S203 described above may be performed. Alternatively, in other embodiments, the CPU may be configured to perform methods S201-S203 by any other suitable means (e.g., by means of firmware).
The functions described above herein may be performed, at least in part, by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: a Field Programmable Gate Array (FPGA), an Application Specific Integrated Circuit (ASIC), an Application Specific Standard Product (ASSP), a system on a chip (SOC), a load programmable logic device (CPLD), etc.
Program code for carrying out methods of the present invention may be written in any combination of one or more programming languages. These program code may be provided to a processor or controller of a general purpose computer, special purpose computer, or other programmable data processing apparatus such that the program code, when executed by the processor or controller, causes the functions/operations specified in the flowchart and/or block diagram to be implemented. The program code may execute entirely on the machine, partly on the machine, as a stand-alone software package, partly on the machine and partly on a remote machine or entirely on the remote machine or server.
In the context of the present invention, a machine-readable medium may be a tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. The machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. The machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
Moreover, although operations are depicted in a particular order, this should be understood as requiring that such operations be performed in the particular order shown or in sequential order, or that all illustrated operations be performed, to achieve desirable results. In certain circumstances, multitasking and parallel processing may be advantageous. Likewise, while several specific implementation details are included in the above discussion, these should not be construed as limiting the scope of the invention. Certain features that are described in the context of separate embodiments can also be implemented in combination in a single implementation. Conversely, various features that are described in the context of a single implementation can also be implemented in multiple implementations separately or in any suitable subcombination.
Although the subject matter has been described in language specific to structural features and/or methodological acts, it is to be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or acts described above. Rather, the specific features and acts described above are example forms of implementing the claims.