Patent Description:
A content delivery network (CDN) system emerges as traffic volume, website visits, and data traffic in a network increase exponentially. In the CDN system, a user request may be directed to a CDN serving node closest to a user in a CDN server cluster by using a load balancing method such as network address transformation (NAT) or direct routing (DR), so that the user may obtain required content near the CDN server cluster, network congestion can be improved, and a response speed of the user to visit a website can be improved.

However, as CDN server clusters are further distributedly deployed, a plurality of CDN servers may be deployed in different network segments. As a result, conventional load balancing modes such as the NAT and the DR become unavailable. Therefore, how to perform effective load balancing in a distributed CDN scenario becomes an urgent problem to be resolved.

European patent application <CIT> provides an Hyper Text Transfer Protocol Live Streaming (HLS) based capability control method and service system and server load balancing (SLB) server. The HLS-based capability control service system includes an SLB server and one or more HLS video servers. The SLB server is configured to receive an HLS HTTP request from a terminal, redirect the HLS HTTP request to an HLS video server in an HTTP <NUM> manner, and return a service address of the specified HLS video server to the terminal; and the HLS video server is configured to receive an HTTP short connection request from the terminal, monitor a request status of each terminal in real time, and count online terminal users according to terminals that initiate requests.

Embodiments of this invention provide two load balancing methods by a terminal device and a load balancing device and corresponding apparatuses, and a load balancing system, to perform effective load balancing in a distributed CDN scenario.

Embodiments of this application provide a load balancing method and apparatus, applicable to a load balancing scenario. For example, the method and the apparatus are applied to a load balancing scenario of a distributed CDN. The load balancing scenario of the distributed CDN may be, for example, a scenario in which a CDN server cluster in a CDN system is deployed in a plurality of different network segments.

<FIG> is a schematic diagram of a communications architecture to which a load balancing method is applied according to an embodiment of this application. The communications architecture includes a terminal device, a load balancing device, and a CDN server. The load balancing device may be, for example, a load balancing (SLB) server or a network load balancing (NLB) server. The terminal device is configured to receive an operation of a user and initiate a content request (for example, request to download a video). The load balancing device is configured to: parse the content request, determine, according to a load balancing policy, a CDN server corresponding to the terminal device, and forward the content request to the CDN server. The CDN server is configured to parse the content request, and may directly transmit corresponding content and an IP address of the CDN server to the terminal device or may transmit corresponding content and an IP address of the CDN server to the terminal device by using the load balancing device. The terminal device determines, based on a content size and a service requirement, whether to establish a direct connection to the CDN server, to request, from the CDN server, transmission of subsequent content that is not transmitted.

In a possible design, as shown in <FIG>, the communications architecture of the load balancing method may further include a local domain name system (LDNS) server (LDNS for short), an authorized domain name system (DNS) server (such as an authorized DNS server of a service provider (SP)), and a global server load balance (GSLB) device (GSLB for short). The LDNS, the authorized DNS server, and the GSLB are mainly configured to provide an IP address of the load balancing device to the terminal device, so that the terminal device sends the content request to the load balancing device based on the IP address of the load balancing device.

In the descriptions of this application, "a plurality of' means at least two. In addition, to clearly describe the technical solutions in the embodiments of this application, terms such as "first" and "second" are used in the embodiments of this application to distinguish between same items or similar items that have basically the same functions or purposes. A person skilled in the art may understand that the terms such as "first" and "second" do not limit a quantity or an execution sequence, and the terms such as "first" and "second" do not mean being definitely different either.

An embodiment of this application provides a load balancing method. An example in which a load balancing device is an SLB server (which is referred to as an SLB for short below) is used for description.

The terminal device sends a first request message to the load balancing device, where the first request message is used to request to-be-transmitted data and an IP address of a CDN server.

It should be noted that before the terminal device sends the first request message to the SLB, the terminal device may obtain an IP address of the SLB by using the LDNS, the authorized DNS server, and the GSLB. For example, the user may first click a video file (for example, a uniform resource locator (URL) of the video file may be http://movie. mp4), so that the terminal device sends the first request message to the LDNS. The first request message is used to request the to-be-transmitted data and the IP address of the CDN server. The to-be-transmitted data is content of the video file, and the CDN server is a CDN server that may provide the content of the video file to the terminal device and that is closest to the terminal device. After receiving the first request message, the LDNS may request the authorized DNS server to parse the domain name of the video file (which is movie. The authorized DNS server determines cname of the domain name (for example, movie. cn) based on the domain name of the video file, and returns the cname to the LDNS and an IP address of the GSLB that is responsible for parsing the cname. After receiving the cname and the IP address of the GSLB that is responsible for parsing the cname, the LDNS requests the GSLB to parse the cname. The GSLB determines, based on the cname and an IP address of the LDNS, an SLB that is closest to the terminal device, and returns the IP address of the SLB to the LDNS. The LDNS returns the IP address of the SLB to the terminal device. Therefore, the terminal device may send the first request message to the SLB to request the SLB to provide a service.

In a possible design, fields included in the first request message corresponding to the video file are as follows:.

The "GET http://webpage. com HTTP/<NUM>" field is used to indicate a used transmission protocol.

The "Host: vali. net" field is used to indicate server information.

The "Proxy-Connection: keep-alive" field is used to indicate that a connected mode is to maintain connection.

The "User-Agent: Mozilla/<NUM> (Windows NT <NUM>; Win64; x64)" field is used to indicate a browser version.

The "X-Requested-With: ShockwaveFlash/<NUM>. <NUM>" field is used to indicate a player version.

The "Accept: */*" field is used to indicate a reserved field.

The "Real-Server: IP/32bits" field is used to indicate a <NUM>-bit IP address that is returned to the CDN server.

The "Accept-Encoding: gzip, deflate" field is used to indicate a compression type.

The "Accept-Language: zh-CN,zh;q=<NUM>,en;q=<NUM>" field is used to indicate a language type.

Step <NUM>: The load balancing device sends the first request message to the CDN server.

The SLB receives the first request message sent by the terminal device, and selects, for the terminal device according to a load balancing policy, a CDN server that may serve the terminal device and that is closer to the terminal device. Then, the SLB sends the first request message to the CDN server. The load balancing policy may include at least one of the following: a network status, a load status, content existence, or a network delay of a distributed CDN server.

In a possible design, the SLB may send the first request message to the CDN server by using an IP tunnel (tunnel). Specifically, after receiving the first request message from the terminal device, the SLB encapsulates, into the first request message, a source IP address (namely, the IP address of the SLB) that may be across network segments, and forwards, in a data packet form, the encapsulated first request message to the CDN server by using the IP tunnel. After receiving the first request message sent by the SLB, the CDN server returns a request result to the terminal device based on the IP address of the SLB. A destination IP address carried in a message header of the first request message is the IP address of the SLB, and therefore the request result should be returned to the terminal device by using the IP address of the SLB as the source address. The SLB no longer performs a task of forwarding, to the terminal device, an IP data packet returned from the CDN server, and this reduces load of the SLB.

The CDN server sends a first response message to the terminal device, where the first response message includes a length of the to-be-transmitted data and the IP address of the CDN server.

The CDN server receives the first request message sent by the SLB. Then, the CDN server may send the length of the to-be-transmitted data and the IP address of the CDN server to the terminal device by using an initial packet. In other words, the first response message may include a first data packet that is sent by the CDN server to the terminal device after the CDN server receives the first request message.

The terminal device receives the first response message sent by the CDN server.

It should be noted that a source IP address of the first response message is the IP address of the SLB. In other words, the CDN server sends the first response message in a name of the SLB (in other words, the IP address of the SLB is used as a sending address and an IP address of the terminal device is used as a destination address). Although the CDN server directly sends data to the terminal device by bypassing the SLB when the CDN server sends the data, the terminal device still considers that the data packet received by the terminal device is sent by the SLB, to send an acknowledgement (ACK) packet of the data packet to the SLB, and the SLB forwards the ACK packet to the CDN server again by using the IP tunnel. In other words, the ACK packet returned by the terminal device needs to pass through the SLB to reach the CDN server. In a high concurrent request, the SLB is prone to become a hotspot device (an Http connection to a large quantity of terminal devices needs to be maintained). For the foregoing reasons, the terminal device may continue to perform steps <NUM> to <NUM>, to avoid pressure and risk of high concurrent request access faced by the SLB.

If the terminal device determines that the length of the to-be-transmitted data is greater than or equal to a preset threshold, the terminal device establishes a connection to the CDN server based on the IP address of the CDN server.

It should be noted that before the terminal device establishes the connection to the CDN server based on the IP address of the CDN server, the terminal device may receive a second response message sent by the CDN server, where the second response message includes a part of the to-be-transmitted data. In a possible design, the CDN server directly sends the second response message to the terminal device, where a source IP address of the second response message is an IP address of the load balancing device. In another possible design, the CDN server sends the second response message to the terminal device by using the SLB. In this way, before the terminal device establishes the connection to the CDN server, the terminal device may receive the part of the to-be-transmitted data from the CDN server, so that data transmission can be quickly started, thereby improving data transmission efficiency.

According to an example in step <NUM>, if the terminal device determines that a size of the content of the video file is greater than or equal to the preset threshold, the terminal device sends a connection establishment request, such as an Http request, to the CDN server, to establish a new TCP connection, and receives subsequent content of the to-be-transmitted data by using the new TCP connection. The subsequent content of the to-be-transmitted data, namely, data that is in the to-be-transmitted data and that is not transmitted, refers to data in the to-be-transmitted data other than some data included in the second response message. The preset threshold may be determined based on an RTT between the terminal device and the CDN server or between the terminal device and the SLB. The preset threshold may be, for example, but is not limited to, <NUM>, <NUM>, <NUM>, <NUM>, <NUM>, or the like.

After the terminal device establishes the connection to the CDN server, the terminal device sends a second request message to the CDN server, where the second request message is used to request the data that is in the to-be-transmitted data and that is not transmitted.

In a possible design, the terminal device may obtain, by using a resumable data transfer technology, the data that is in the to-be-transmitted data and that is not transmitted. For example, the terminal device may send an HTTP obtaining request (the second request message) to the CDN server, where the HTTP obtaining request includes a start position of the data that is in the to-be-transmitted data and that is not transmitted. For example, it is assumed that the terminal device has received <NUM> bytes (bytes) of data by using the second response message, content of the Http get request may include: Range: <NUM>+, and Range: <NUM>+ is used to indicate the start position of the data that is in the to-be-transmitted data to be requested and that is not transmitted.

The CDN server sends a third response message to the terminal device.

After receiving the second request message, the CDN server may send the third response message to the terminal device. The terminal device receives the third response message sent by the CDN server, where the third response message includes the data that is in the to-be-transmitted data and that is not transmitted, and a source IP address of the third response message is the IP address of the CDN server. In a possible design, within a preset time interval after the terminal device sends the second request message to the CDN server, the terminal device may perform step <NUM> or step <NUM> to maintain stability of data transmission, thereby reducing jitter.

The terminal device receives, within the preset time interval, a fourth response message sent by the CDN server.

In a possible design, after the terminal device sends the second request message to the CDN server, the terminal device may receive, within the preset time interval, the fourth response message sent by the CDN server. The fourth response message includes the part of the to-be-transmitted data, and a source IP address of the fourth response message is the IP address of the load balancing device. In other words, terminal device receives, within the preset time interval, the fourth response message sent by the CDN server that functions as the SLB. The preset time interval is determined based on the RTT between the terminal device and the CDN server. For example, the preset time interval may be <NUM> RTT, <NUM> RTT, <NUM> RTT, or the like.

The terminal device receives, within the preset time interval, a fifth response message sent by the load balancing device.

In a possible design, after the terminal device sends the second request message to the CDN server, the terminal device receives, within the preset time interval, the fifth response message sent by the SLB, where the fifth response message includes the part of the to-be-transmitted data. The terminal device receives, within the preset time interval, the fifth response message sent by the CDN server by using the SLB. The preset time interval is determined based on the RTT between the terminal device and the load balancing device. For example, the preset time interval may be <NUM> RTT, <NUM> RTT, <NUM> RTT, or the like.

The terminal device sends a disconnection request to the load balancing device, where the disconnection request is used to instruct to disconnect the terminal device from the load balancing device.

The load balancing device receives the disconnection request sent by the terminal device, and the load balancing device sends a disconnection response to the terminal device, and disconnects a link between the load balancing device and the terminal device.

In other words, after the terminal device establishes the connection to the CDN server, the terminal device may disconnect from the SLB. In this way, a data channel between the terminal device and the SLB is switched to a new data transmission channel between the terminal device and the CDN server, to reduce resource consumption of the SLB, and decrease a quantity of long connections of the SLB (that is, the SLB does not need to maintain the Http connection to the large quantity of terminal devices), thereby reducing pressure and risk when the SLB faces high concurrent request access.

In addition, if the terminal device determines that the length of the to-be-transmitted data is less than the preset threshold, the terminal device performs step <NUM>.

If the terminal device determines that the length of the to-be-transmitted data is less than the preset threshold, the terminal device waits for the to-be-transmitted data to be transmitted by using the SLB or the CDN server.

When the terminal device requests a small file (a length of to-be-transmitted data corresponding to the small file is less than the preset threshold), because a delay of re-establishing a connection between the terminal device and the CDN server is relatively long, the terminal device does not need to establish a connection to the CDN server, and only needs to wait for the small file to be transmitted by using the SLB or the CDN server. The CDN server sends the small file to the terminal device in the name of the SLB or by using the SLB. In this way, in a small file transmission process, a download delay is not excessively long. In addition, because transmission duration of the small file is relatively short, the SLB does not need to maintain a connection to the terminal device for a long time. In other words, the SLB is not occupied for a long time, and the load of the SLB is not increased.

It should be noted that steps <NUM> to <NUM> can be executed in a different sequence, and a sequence of steps executed is not specifically limited in this embodiment.

In this embodiment of this application, the terminal device may establish a direct connection to CDN servers in different network segments based on the IP address of the CDN server. Compared with a conventional load balancing mode such as NAT and DR in which load balancing across network segments cannot be performed, in this embodiment of this application, effective load balancing can be performed in a distributed CDN scenario. In addition, based on the foregoing solution, the load balancing device may forward, to the CDN server, the first request message sent by the terminal device, so that data transmission between the terminal device and the CDN server can be quickly started. In addition, after establishing the connection to the CDN server, the terminal device may further receive, from the CDN server, the data that is in the to-be-transmitted data and that is not transmitted. In this way, a transmission delay when the terminal device receives the to-be-transmitted data can be reduced, and data transmission efficiency is improved.

The foregoing mainly describes the solutions provided in the embodiments of this application from a perspective of the terminal device, the CDN server, and the load balancing device. It may be understood that, to implement the foregoing functions, the terminal device, the CDN server, and the load balancing device include corresponding hardware structures and/or software modules for performing the functions. A person skilled in the art should easily be aware that, in combination with the algorithm steps described in the embodiments disclosed in this specification, this application may be implemented by hardware or a combination of hardware and computer software. Whether a function is performed by hardware or hardware driven by computer software depends on particular applications and design constraints of the technical solutions. A person skilled in the art may use different methods to implement the described functions for each particular application, but it should not be considered that the implementation falls beyond the scope of this application.

In the embodiments of this application, the terminal device, the CDN server, and the load balancing device may be divided into functional modules based on the foregoing method examples. For example, each functional module may be obtained through division based on each corresponding function, or two or more functions may be integrated into one processing module. The integrated module may be implemented in a form of hardware, or may be implemented in a form of a software functional module. It should be noted that, in this embodiment of this application, division into the modules is an example, is merely logical function division, and may be other division in an actual implementation.

When each functional module is obtained through division based on each corresponding function, <FIG> is a possible schematic structural diagram <NUM> of the terminal device <NUM> in the foregoing embodiment. The terminal device includes: a sending unit <NUM>, a receiving unit <NUM> and a processing unit <NUM>. In this embodiment of this application, the sending unit <NUM> may be configured to send a first request message to a load balancing device, where the first request message is used to request to-be-transmitted data and an IP address of a CDN server. The receiving unit <NUM> is configured to receive a first response message sent by the CDN server, where the first response message includes a length of the to-be-transmitted data and the IP address of the CDN server, and a source IP address of the first response message is an IP address of the load balancing device. The processing unit <NUM> is configured to: if the processing unit <NUM> determines that the length of the to-be-transmitted data is greater than or equal to a preset threshold, establish a connection to the CDN server based on the IP address of the CDN server. The sending unit <NUM> may be configured to support the terminal device in performing processes <NUM>, <NUM>, and <NUM> in <FIG>. The receiving unit <NUM> is configured to support the terminal device in performing at least one of the following processes in <FIG>: processes <NUM>, <NUM>, <NUM>, or <NUM>. The processing unit <NUM> is configured to support the terminal device in performing processes <NUM> and <NUM> in <FIG>.

In a possible design, the terminal device may be implemented by using a structure (an apparatus or a system) in <FIG>.

<FIG> is a schematic diagram of a structure according to an embodiment of this application. A structure <NUM> includes at least one processor <NUM>, a communications bus <NUM>, a memory <NUM>, and at least one communications interface <NUM>.

The processor <NUM> may be a central processing unit (CPU), a micro processing unit, a general-purpose processing unit, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA) or another programmable logic device, a transistor logic device, a hardware component, or any combination thereof.

The communications bus <NUM> may include a channel in which information is transmitted between the foregoing components.

The communications interface <NUM> is any apparatus such as a transceiver, and is configured to communicate with another device or communications network, such as Ethernet, a radio access network (RAN), or a wireless local area network (WLAN).

The memory <NUM> may be a read-only memory (ROM) or another type of static storage device that can store static information and an instruction, or a random access memory (RAM) or another type of dynamic storage device that can store information and an instruction, or may be an electrically erasable programmable read-only memory (EEPROM), a compact disc read-only memory (CD-ROM) or other compact disc storage, optical disc storage (including a compact disc, a laser disc, an optical disc, a digital versatile disc, a Blu-ray disc, or the like), a disk storage medium or another magnetic storage device, or any other medium that can be configured to carry or store expected program code having an instruction or data structure form and that can be accessed by a computer. However, this is not limited. The memory may exist independently and is connected to the processing unit by using a bus. The memory may be alternatively integrated with the processing unit.

The memory <NUM> is configured to store application program code that executes the solution in this application, and the processor <NUM> controls execution of the solution in this application. The processor <NUM> is configured to execute the application program code stored in the memory <NUM>, to implement the function of the method in this application.

In a specific implementation, in an embodiment, the structure <NUM> may include a plurality of processors, for example, the processor <NUM> and a processor <NUM> in <FIG>. Each of the processors may be a single-CPU (single-CPU) processor, or may be a multi-CPU (multi-CPU) processor. The processor herein may be one or more devices, circuits, and/or processing cores for processing data (for example, a computer program instruction).

In specific implementation, in an embodiment, the structure <NUM> may further include an output device <NUM> and an input device <NUM>. The output device <NUM> communicates with the processor <NUM>, and may display information in a plurality of manners. For example, the output device <NUM> may be a liquid crystal display (LCD), a light emitting diode (LED) display device, a cathode ray tube (CRT) display device, or a projector (projector). The input device <NUM> communicates with the processor <NUM>, and may receive a user input in a plurality of manners. For example, the input device <NUM> may be a mouse, a keyboard, a touchscreen device, or a sensing device.

In specific implementation, the structure <NUM> may be a desktop computer, a portable computer, a network server, a personal digital assistant (PDA), a mobile phone, a tablet computer, a wireless terminal device, a communications device, an embedded device, or a device with a structure similar to that in <FIG>. A type of the structure <NUM> is not limited in this embodiment of this application.

The transceiver may be configured to perform receiving and sending of information performed by the terminal device in the foregoing method embodiment.

The processor <NUM> may be configured to perform other processing except the receiving and sending of information performed by the terminal device in the foregoing method embodiment.

<FIG> is a possible schematic structural diagram <NUM> of the CDN server <NUM> used in the foregoing embodiment when each functional module is divided for each corresponding function. The CDN server includes a receiving unit <NUM> and a sending unit <NUM>. In this embodiment of this application, the receiving unit <NUM> is configured to receive a first request message sent by a load balancing device, where the first request message is used to request to-be-transmitted data and an IP address of a CDN server. The sending unit <NUM> is configured to send a first response message to a terminal device, where the first response message includes a length of the to-be-transmitted data and the IP address of the CDN server, so that the terminal device determines, based on the length of the to-be-transmitted data, whether to establish a connection to the CDN server. The sending unit <NUM> is configured to support the CDN server in performing processes <NUM> and <NUM> in <FIG>.

In a possible design, the CDN server may be implemented by using a structure (an apparatus or a system) in <FIG>.

The processor <NUM> may be a CPU, a micro processing unit, a general-purpose processing unit, a DSP, an ASIC, an FPGA or another programmable logic device, a transistor logic device, a hardware component, or any combination thereof.

The communications interface <NUM> is any apparatus such as a transceiver, and is configured to communicate with another device or communications network, such as Ethernet, a RAN, or a WLAN.

The memory <NUM> may be a ROM or another type of static storage device capable of storing static information and instructions, or a RAM or another type of dynamic storage device capable of storing information and instructions; or may be an EEPROM, a CD-ROM, or other compact disc storage or optical disc storage (including a compressed optical disc, a laser disc, an optical disc, a digital versatile disc, a Blu-ray disc, and the like), a magnetic disk storage medium or another magnetic storage device, or any other medium capable of carrying or storing expected program code in a form of instructions or data structures and capable of being accessed by a computer, but is not limited thereto. The memory may exist independently and is connected to the processing unit by using a bus. The memory may be alternatively integrated with the processing unit.

In a specific implementation, in an embodiment, the structure <NUM> may include a plurality of processors, for example, the processor <NUM> and a processor <NUM> in <FIG>. Each of these processors may be a single-core processor, or may be a multi-core processor. The processor herein may be one or more devices, circuits, and/or processing cores for processing data (for example, a computer program instruction).

The transceiver may be configured to perform receiving and sending of information performed by the CDN server in the foregoing method embodiment.

The processor <NUM> may be configured to perform other processing except the receiving and sending of information performed by the CDN server in the foregoing method embodiment.

When each functional module is obtained through division based on each corresponding function, <FIG> is a possible schematic structural diagram <NUM> of a load balancing device <NUM> used in the foregoing embodiment. The load balancing device includes a receiving unit <NUM>, a sending unit <NUM>, and a processing unit <NUM>. In this embodiment of this application, the receiving unit <NUM> may be configured to receive a first request message sent by a terminal device, where the first request message is used to request to-be-transmitted data and an IP address of a CDN server. The sending unit <NUM> is configured to send the first request message to the CDN server, so that the CDN server sends a first response message to the terminal device, where the first response message includes a length of the to-be-transmitted data and the IP address of the CDN server. The processing unit <NUM> is configured to disconnect a link between the load balancing device and the terminal device. The sending unit <NUM> is configured to support the load balancing device in performing process <NUM> in <FIG>.

In a possible design, the load balancing device may be implemented by using a structure (an apparatus or a system) in <FIG>.

The transceiver may be configured to perform receiving and sending of information performed by the load balancing device in the foregoing method embodiment.

The processor <NUM> may be configured to perform other processing except the receiving and sending of information performed by the load balancing device in the foregoing method embodiment.

An embodiment of this application further provides a computer-readable storage medium, including an instruction. When the instruction runs on a computer, the computer is enabled to perform the method according to any one of the foregoing embodiments.

An embodiment of this application further provides a computer program product including an instruction. When the computer program product runs on the computer, the computer is enabled to perform the method according to any one of the foregoing embodiments.

An embodiment of this application further provides an apparatus. The apparatus exists in a product form of a chip. The apparatus includes a processor, a memory, and a transceiver component. The transceiver component includes an input/output circuit. The memory is configured to store a computer executable instruction. The processor implements the method according to any one of the foregoing embodiments by performing the computer executable instruction stored in the memory. In this case, the method provided in this embodiment of this application may be executed by a chip.

An embodiment of this application further provides a communications system, including at least a first device, a second device, and a third device. The first device may be any terminal device provided in the foregoing embodiment, the second device may be any load balancing device provided in the foregoing embodiment, and the third device may be any CDN server provided in the foregoing embodiment.

A person skilled in the art should be aware that in the foregoing one or more examples, functions described in this application may be implemented by hardware, software, firmware, or any combination thereof. When the present invention is implemented by software, the foregoing functions may be stored in a computer-readable medium or transmitted as one or more instructions or code in the computer-readable medium. The computer-readable medium includes a computer storage medium and a communications medium, where the communications medium includes any medium that enables a computer program to be transmitted from one place to another. The storage medium may be any available medium accessible to a general-purpose or dedicated computer.

The objectives, technical solutions, and benefits of this application are further described in detail in the foregoing specific embodiments. It should be understood that the foregoing descriptions are merely specific embodiments of this application, but are not intended to limit the protection scope of this application. Any modification, equivalent replacement or improvement made based on technical solutions of this application shall fall within the protection scope of this application.

Therefore, the embodiments of this application may use a form of hardware only embodiments, software only embodiments, or embodiments with a combination of software and hardware. Moreover, the embodiments of this application may use a form of a computer program product that is implemented on one or more computer-usable storage media (including but not limited to a disk memory, a CD-ROM, an optical memory, and the like) that include computer-usable program code.

The embodiments of this application are described with reference to the flowcharts and/or block diagrams of the method, the device (system), and the computer program product according to the embodiments of this application. It should be understood that computer program instructions may be used to implement each process and/or each block in the flowcharts and/or the block diagrams and a combination of a process and/or a block in the flowcharts and/or the block diagrams. These computer program instructions may be provided for a general-purpose computer, a dedicated computer, an embedded processor, or a processing unit of any other programmable data processing device to generate a machine, so that the instructions executed by a computer or a processing unit of any other programmable data processing device generate an apparatus for implementing a specific function in one or more processes in the flowcharts and/or in one or more blocks in the block diagrams.

Claim 1:
A load balancing method, comprising:
sending (<NUM>), by a terminal device, a first request message to a load balancing device, wherein the first request message is used to request to-be-transmitted data and an internet protocol, IP, address of a content delivery network, CDN, server that may provide the to-be-transmitted data;
selecting, by the load balancing device, for the terminal device based on a load balancing policy, a CDN that may serve the terminal;
sending, by the load balancing device, the first request message to the selected CDN server by using an IP tunnel;
receiving (<NUM>), by the terminal device, a first response message sent by the CDN server, wherein the first response message comprises a length of the to-be-transmitted data and the IP address of the CDN server, and a source IP address of the first response message is an IP address of the load balancing device; and
sending, by the terminal device, an acknowledgement, ACK, packet of the first response message to the load balancing device, wherein the IP destination address of the ACK packet is the IP address of the load balancing device,
forwarding, by the load balancing device, the ACK packet to the selected CDN server by using the IP tunnel;
when the terminal device determines that the length of the to-be-transmitted data is greater than or equal to a preset threshold, establishing (<NUM>), by the terminal device, a connection to the CDN server based on the IP address of the CDN server,
receiving, by the terminal device, subsequent content of the to-be-transmitted data by using the connection with the CDN server.