Disclosure of Invention
An object of the embodiments of the present invention is to provide a method, an apparatus, and a server for limiting a network speed, which enable each application access to occupy bandwidth in a balanced manner, and optimize access quality.
In a first aspect, an embodiment of the present invention provides a network speed limiting method, where the method is applied to a server, the server is in communication connection with at least one other server, and the server is used as a portal server, and the method includes:
receiving a request message sent by a client;
acquiring communication path information of the request message, and a first speed limit threshold and a second speed limit threshold;
establishing connection with a next hop server according to the communication path information, and setting a speed limit threshold value for the portal server according to the first speed limit threshold value so that the data uploading speed passing through the portal server is smaller than the first speed limit threshold value;
and adding the second speed limit threshold into the request message, and sending the request message to a next hop server.
In a second aspect, an embodiment of the present invention further provides a network speed limiting method, where the speed limiting method is applied to a server, the server is in communication connection with at least one other server, and the server serves as an egress server, and the method includes:
receiving request messages sent by other servers;
analyzing the request message to obtain a second speed limit threshold;
and setting a speed limit threshold value for the exit server according to the second speed limit threshold value, so that the data downloading speed passing through the exit server is smaller than the second speed limit threshold value.
In a third aspect, an embodiment of the present invention further provides a network speed limiting device, where the device is applied to a server, the server is in communication connection with at least one other server, and the server is used as an entry server, where the device includes:
the first receiving module is used for receiving a request message sent by a client;
the acquisition module is used for acquiring the communication path information of the request message, and the first speed limit threshold value and the second speed limit threshold value;
the first setting module is used for establishing connection with a next hop server according to the communication path information and setting a speed limit threshold value for the entrance server according to the first speed limit threshold value so that the data uploading speed passing through the entrance server is smaller than the first speed limit threshold value;
and the sending module is used for adding the second speed limit threshold value into the request message and sending the request message to a next hop server.
In a fourth aspect, an embodiment of the present invention further provides a network speed limiting device, where the speed limiting device is applied to a server, the server is in communication connection with at least one other server, and the server is used as an egress server, where the device includes:
the second receiving module is used for receiving request messages sent by other servers;
the analysis module is used for analyzing the request message to obtain a second speed limit threshold value;
and the second setting module is used for setting a speed limit threshold value for the exit server according to the second speed limit threshold value so as to enable the data downloading speed passing through the exit server to be smaller than the second speed limit threshold value.
In a fifth aspect, an embodiment of the present invention further provides a server, including:
at least one processor; and the number of the first and second groups,
a memory communicatively coupled to the at least one processor; wherein,
the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the method described above.
According to the speed limiting method, the speed limiting device and the server provided by the embodiment of the invention, the speed limiting threshold is set for the entrance server according to the first speed limiting threshold by obtaining the first speed limiting threshold and the second speed limiting threshold so as to limit the uplink flow bandwidth. And sending the second speed limit threshold adding request message to the next hop server so that the exit server can obtain the second speed limit threshold by analyzing the request message, and setting the speed limit threshold for the exit server according to the second speed limit threshold to limit the downlink flow bandwidth. Therefore, each application access can occupy the bandwidth in a balanced manner, and the access quality is improved.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
The network speed limiting method and device provided by the invention are suitable for the application scenario shown in fig. 1, and comprise at least two servers 20, wherein the at least two servers 20 are in communication connection with each other, and any one server 20 in the at least two servers 20 is in communication connection with the controller 10. Of the at least two servers 20, the one communicatively coupled to the client is referred to as the ingress server and the one communicatively coupled to the origin server is referred to as the egress server. If there are more than three servers 20, the other servers 20 act as intermediate servers responsible for forwarding data packets between the ingress server and the egress server. Wherein each server 20 may serve any one of an ingress server, an intermediate server, and an egress server for different data transfer tasks.
The controller 10 is configured to manage transmission paths of data packets between the servers 20, and the controller 10 may obtain a communication path in advance and transmit the communication path to a corresponding portal server. And the entrance server sends the data request message to the source station server through the intermediate server and the exit server according to the communication path. The controller 10 is further configured to send a first speed limit threshold and a second speed limit threshold to the ingress server, and the ingress server sets a speed limit threshold for the ingress server according to the first speed limit threshold, so as to limit a data uploading rate (i.e., an uplink traffic bandwidth). And the entrance server also encapsulates the second speed limit threshold into the request message and sends the request message to the oral server through the intermediate server. The exit server analyzes the request message to obtain a second speed limit threshold, and sets a speed limit threshold for the exit server according to the second speed limit threshold to limit the data download rate (namely, the downlink traffic bandwidth). Therefore, each application access can occupy the bandwidth in a balanced manner, and the access quality is improved.
The network speed limiting method provided in the embodiment of the present invention may be executed by any server 20 shown in fig. 1, as shown in fig. 2, which is a flowchart of an embodiment of the speed limiting method, and when the server 20 is used as a portal server, the speed limiting method includes:
101: and receiving a request message sent by a client.
102: and acquiring the communication path information of the request message, and a first speed limit threshold and a second speed limit threshold.
In practical applications, the communication path information, the first speed limit threshold and the second speed limit threshold may be sent to the ingress server by the controller 10, and the controller 10 may obtain a preferred path from the ingress server to the source station server in advance through, for example, a routing algorithm, and then send the communication path information of the preferred path to the corresponding ingress server. From the communication path information, address information and port information of, for example, the next hop server, and address information and port information of the remaining hop servers, and the like can be obtained. Among them, address information such as an IP (Internet Protocol) address, and port information such as a port number.
103: and establishing connection with a next hop server according to the communication path information, and setting a speed limit threshold value for the portal server according to the first speed limit threshold value so as to enable the data uploading speed passing through the portal server to be smaller than the first speed limit threshold value.
In practical applications, a communication architecture shown in fig. 3 may be adopted between two servers (in the figure, an intermediate server is omitted between an ingress server and an egress server), where fe-sk represents a front-end socket and be-sk represents a back-end socket in fig. 3, where the front-end socket of the ingress server is responsible for communicating with a client, the back-end socket is responsible for communicating with a next-hop server, the front-end socket of the egress server is responsible for communicating with a previous-hop server, and the back-end socket is responsible for communicating with a source station server.
The connection between the entry server and the next hop server may be established, a backend socket may be created according to the address information and the port information of the next hop server, and the backend socket may be connected to the next hop server. Setting a speed limit threshold for the portal server may be achieved by setting a speed limit threshold for a backend socket, or a front-end socket and a backend socket of the portal server. Taking Linux system as an example, fair queues are opened for an entrance server, each intermediate server and an exit server, and after receiving a first speed limit threshold, the entrance server sets a speed limit threshold for a backend socket according to the first speed limit threshold. In practical application, a setsockopt () function may be called to set a speed limit threshold for a backend socket.
When the data uploading rate (uplink flow bandwidth) of the client reaches the set first speed limit threshold, the back-end socket of the entry server (i.e. the socket communicating with the next-hop server) performs sending rate shaping according to the set speed limit threshold, i.e. limits the data sending rate, thereby limiting the uploading rate of the network connection of the client.
104: and adding the second speed limit threshold into the request message, and sending the request message to a next hop server.
Before adding the second speed limit threshold to the request message, the second speed limit threshold may be encapsulated based on a Global Routing Protocol (GRP), and the GRP encapsulates the communication path information based on a binary stream, so that the length of the data segment can be effectively shortened, and the utilization rate of the network bandwidth can be improved.
Fig. 4 shows one form of a GRP format, which includes a header + Data portion, the header portion including an 8-byte Version number (Version), a 2-byte information type (MsgType), a 2-byte Data Stream length (Datalen), and the Data portion including a byte-variable Data Stream (Data Stream). Referring to fig. 5, the data portion includes an option unit and a plurality of address units, each address unit may be used to place address information of one server 20, and the second speed limit threshold may be placed in the option unit. Referring to fig. 6, a specific format of the option unit includes a 4-byte path ID, a 4-byte timestamp, a 4-byte session ID, and a 4-byte threshold. Wherein the value of the second speed limit threshold is placed in the 4-byte threshold segment.
According to the embodiment of the invention, the first speed limit threshold and the second speed limit threshold are obtained, and the speed limit threshold is set for the entrance server according to the first speed limit threshold so as to limit the uplink flow bandwidth. And sending the second speed limit threshold adding request message to the next hop server so that the exit server can obtain the second speed limit threshold by analyzing the request message, and setting the speed limit threshold for the exit server according to the second speed limit threshold to limit the downlink flow bandwidth. Therefore, each application access can occupy the bandwidth in a balanced manner, and the access quality is improved.
It should be noted that, the sequence numbers in the embodiments of the present invention are only for easy understanding, and do not limit the sequence of the steps.
An embodiment of the present invention further provides a network speed limiting method, which may be executed by any server 20 shown in fig. 1, as shown in fig. 7, which is a flowchart of an embodiment of the speed limiting method, where when the server is used as an egress server, the method includes:
201: and receiving the request message sent by other servers.
202: and analyzing the request message to obtain a second speed limit threshold value.
The intermediate server does not process the second speed limit threshold in the request message, and when the outlet server receives the request message sent by the inlet server or the intermediate server, the outlet server analyzes the request message to obtain the second speed limit threshold.
203: and setting a speed limit threshold value for the exit server according to the second speed limit threshold value, so that the data downloading speed passing through the exit server is smaller than the second speed limit threshold value.
Referring to fig. 3, the setting of the speed limit threshold for the egress server may be implemented by setting the speed limit threshold for a front-end socket of the egress server, or for a front-end socket and a back-end socket of the egress server. Taking the Linux system as an example, after receiving the second speed limit threshold, the egress server sets a speed limit threshold for the front-end socket according to the second speed limit threshold. In practical application, setsockopt () function may be called to set a speed limit threshold for the front-end socket.
When the data download rate (i.e. the downlink traffic bandwidth) of the client reaches the set second speed-limiting threshold, the front-end socket of the egress server (i.e. the socket communicating with the previous-hop server) performs sending rate shaping according to the set threshold, i.e. limits the rate of data sending, thereby limiting the download rate of the network connection of the client.
The embodiment of the invention receives the request messages sent by other servers, acquires the second speed limit threshold value from the request messages, and sets the speed limit threshold value for the exit server according to the second speed limit threshold value so as to limit the bandwidth of the downlink flow. After the upstream traffic bandwidth and the downstream traffic bandwidth are respectively limited by the inlet server and the outlet server, the multi-segment network connection bandwidth between the inlet server and the outlet server is limited in speed, and traffic burst is not caused, so that jitter and acceleration instability are avoided. It should be noted that the setting of the speed limit threshold may be performed once when creating the socket.
It should be noted that, the sequence numbers in the embodiments of the present invention are only for easy understanding, and do not limit the sequence of the steps.
Correspondingly, an embodiment of the present invention further provides a network speed limiting device, where the speed limiting device is used in any server 20 shown in fig. 1, and the server is used as a portal server, as shown in fig. 8, where the device 300 includes:
the first receiving module 301 is configured to receive a request packet sent by a client.
An obtaining module 302, configured to obtain the communication path information of the request packet, and the first speed limit threshold and the second speed limit threshold.
A first setting module 303, configured to establish a connection with a next hop server according to the communication path information, and set a speed limit threshold for the portal server according to the first speed limit threshold, so that the data upload rate passing through the portal server is smaller than the first speed limit threshold.
A sending module 304, configured to add the second speed limit threshold to the request packet, and send the request packet to a next hop server.
According to the embodiment of the invention, the first speed limit threshold and the second speed limit threshold are obtained, and the speed limit threshold is set for the entrance server according to the first speed limit threshold so as to limit the uplink flow bandwidth. And sending the second speed limit threshold adding request message to the next hop server so that the exit server can obtain the second speed limit threshold by analyzing the request message, and setting the speed limit threshold for the exit server according to the second speed limit threshold to limit the downlink flow bandwidth. Therefore, each application access can occupy the bandwidth in a balanced manner, and the access quality is improved.
Optionally, in another embodiment of the apparatus, referring to fig. 9, the apparatus 300 further includes:
a first opening module 305 for opening the fair queue.
The first setting module 303 is specifically configured to:
and establishing a back-end socket according to the address information and the port information of the next-hop server, establishing connection between the back-end socket and the next-hop server, and setting a speed-limiting threshold for the back-end socket according to the first speed-limiting threshold.
Optionally, in another embodiment of the apparatus, the second speed limit threshold is placed in the request message in a GRP format, the GRP format is based on a binary stream, the GRP format includes a header and a data portion, the data portion includes an option unit and an address unit, and the second speed limit threshold is placed in the option unit.
It should be noted that the speed limiting device can execute the speed limiting method provided by the embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method. For technical details that are not described in detail in the embodiments of the speed limiting device, reference may be made to the speed limiting method provided by the embodiments of the present invention.
Correspondingly, an embodiment of the present invention further provides a network speed limiting device, where the speed limiting device is used in any server 20 shown in fig. 1, and when the server is used in an egress server, as shown in fig. 10, the device 400 includes:
a second receiving module 401, configured to receive a request message sent by another server;
an analyzing module 402, configured to analyze the request packet to obtain a second speed limit threshold;
a second setting module 403, configured to set a speed limit threshold for the egress server according to the second speed limit threshold, so that the data download rate through the egress server is smaller than the second speed limit threshold.
The embodiment of the invention receives the request messages sent by other servers, acquires the second speed limit threshold value from the request messages, and sets the speed limit threshold value for the exit server according to the second speed limit threshold value so as to limit the bandwidth of the downlink flow. After the upstream traffic bandwidth and the downstream traffic bandwidth are respectively limited by the inlet server and the outlet server, the multi-segment network connection bandwidth between the inlet server and the outlet server is limited in speed, and traffic burst is not caused, so that jitter and acceleration instability are avoided.
Optionally, in another embodiment of the apparatus, referring to fig. 11, the apparatus 400 further includes:
a second starting module 404, configured to start a fair queue;
the second setting module 403 is specifically configured to:
and setting a speed limit threshold value for the front-end socket of the outlet server according to the second speed limit threshold value.
It should be noted that the speed limiting device can execute the speed limiting method provided by the embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method. For technical details that are not described in detail in the embodiments of the speed limiting device, reference may be made to the speed limiting method provided by the embodiments of the present invention.
Fig. 12 is a schematic diagram of a hardware structure of a server 20 according to an embodiment of the present invention, and as shown in fig. 12, the server 20 includes:
one or more processors 21 and a memory 22, with one processor 21 being an example in fig. 12.
The processor 21 and the memory 22 may be connected by a bus or other means, and fig. 12 illustrates the connection by a bus as an example.
The memory 22, which is a non-volatile computer-readable storage medium, may be used to store non-volatile software programs, non-volatile computer-executable programs, and modules, such as program instructions/modules corresponding to the speed limiting method in the embodiment of the present invention (for example, the second receiving module 401, the parsing module 402, and the second setting module 403 shown in fig. 10). The processor 21 executes various functional applications of the server and data processing by running the nonvolatile software programs, instructions and modules stored in the memory 22, that is, implements the speed limiting method of the above-described method embodiment.
The memory 22 may include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application program required for at least one function; the stored data area may store data created according to the use of the speed limit device, and the like. Further, the memory 22 may include high speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other non-volatile solid state storage device. In some embodiments, the memory 22 may optionally include memory located remotely from the processor 21, and these remote memories may be connected to the speed limiter device via a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
The one or more modules are stored in the memory 22, and when executed by the one or more processors 21, perform the speed limiting method in any of the above-described method embodiments, for example, the method steps 101 and 104 in fig. 2, and the method steps 201 to 203 in fig. 7, which are described above; the functions of the module 301 and 304 in fig. 8, the module 301 and 305 in fig. 9, the module 401 and 403 in fig. 10, and the module 401 and 404 in fig. 11 are realized.
The product can execute the method provided by the embodiment of the invention, and has corresponding functional modules and beneficial effects of the execution method. For technical details that are not described in detail in this embodiment, reference may be made to the method provided by the embodiment of the present invention.
Embodiments of the present invention provide a non-transitory computer-readable storage medium, which stores computer-executable instructions, which are executed by one or more processors, such as the processor 21 in fig. 12, to enable the one or more processors to execute the speed limiting method in any of the above-mentioned method embodiments, such as the method steps 101 and 104 in fig. 2 and the method steps 201 to 203 in fig. 7; the functions of the module 301 and 304 in fig. 8, the module 301 and 305 in fig. 9, the module 401 and 403 in fig. 10, and the module 401 and 404 in fig. 11 are realized.
The above-described embodiments of the apparatus are merely illustrative, and the units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment.
Through the above description of the embodiments, those skilled in the art will clearly understand that each embodiment can be implemented by software plus a general hardware platform, and certainly can also be implemented by hardware. It will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above can be implemented by hardware related to instructions of a computer program, which can be stored in a computer readable storage medium, and when executed, can include the processes of the embodiments of the methods described above. The storage medium may be a magnetic disk, an optical disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), or the like.
Finally, it should be noted that: the above examples are only intended to illustrate the technical solution of the present invention, but not to limit it; within the idea of the invention, also technical features in the above embodiments or in different embodiments may be combined, steps may be implemented in any order, and there are many other variations of the different aspects of the invention as described above, which are not provided in detail for the sake of brevity; although the present invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; and the modifications or the substitutions do not make the essence of the corresponding technical solutions depart from the scope of the technical solutions of the embodiments of the present invention.