Flow control method and device, storage medium and computer equipment
By extracting and updating the stream pulling session information on the XDP interface, and managing traffic counting and error counting, the problem of lack of effective flow control during the client's stream pulling process is solved, and effective management of system traffic and security is achieved.
Patent Information
- Application Number
- CN202411758302.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-02
- Publication Date
- 2025-02-28
AI Technical Summary
In the prior art, clients lack effective flow control mechanisms during the flow pulling process, resulting in poor stability and security of the system, making it difficult to cope with the surge in server traffic and excessive system load caused by simultaneous or frequent requests by a large number of clients.
The data packet sent by the client is obtained through the preset XDP interface, extract the streaming session information, and update the streaming count container and the error counting container based on this information. When the number of repeated flow pulls or the number of wrong flow pulls exceeds the preset threshold, intercept, current limit or blocking operations are performed to achieve flow control and safety improvements.
Effectively distribute traffic and load, improve system stability and performance, prevent malicious requests from clients, and improve system security.
Smart Images

Figure CN119544613A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data communication technology, and in particular to a flow control method, device, storage medium and computer equipment. Background Art
[0002] Real-time Streaming Protocol (RTSP) is a network protocol specifically used for streaming audio and video data, providing users with streaming media control functions such as play, pause, fast forward, and rewind. In the RTSP service system, the RTSP server is responsible for receiving and responding to client requests and providing high-quality real-time streaming media data. Therefore, in order to cope with the growing user demand and improve the overall performance and stability of the system, in actual applications, multiple RTSP servers are often deployed to disperse traffic and load balance.
[0003] However, the existing multi-server architecture still has difficulty coping with the surge in server traffic and system overload caused by a large number of clients making simultaneous or frequent requests. In addition, it is difficult to identify and limit malicious requests from clients and is easily interfered with. It can be seen that the client lacks an effective flow control mechanism during the streaming process and has insufficient defense capabilities against clients, resulting in poor system stability and security. Summary of the invention
[0004] The purpose of this application is to solve at least one of the above-mentioned technical defects, especially the technical defects in the prior art that the client lacks an effective flow control mechanism during the streaming process and has insufficient prevention capabilities against the client, resulting in poor stability and security of the system.
[0005] The present application provides a flow control method, the method comprising:
[0006] Obtaining a data packet sent by a client through a preset XDP interface, and extracting streaming session information in the data packet; wherein the types of the data packet include request packets and response packets; the streaming session information includes a target IP address and a source IP address;
[0007] When the data packet is a request packet, the stream pull count container is updated based on the stream pull session information to obtain the total stream pull count of the target IP address and the number of repeated stream pulls corresponding to the request packet;
[0008] When it is detected that the number of repeated stream pulling exceeds the response threshold of the target IP address, the request packet is intercepted, and an intercept response packet containing the optimal IP address is returned to the client, so that the client redirects the optimal IP address to make a stream pulling session request;
[0009] When it is detected that the total number of pulled streams exceeds a preset control threshold, a flow limiting operation or a blocking operation is performed on the request packet;
[0010] When the data packet is a response packet, the error count container is updated based on the streaming session information to obtain the number of erroneous streaming of the source IP address, and when the number of erroneous streaming exceeds the error threshold of the source IP address, the response packet is blocked.
[0011] Optionally, extracting the streaming session information in the data packet includes:
[0012] Parsing the header of the data packet to obtain an IP header and a TCP header; wherein the IP header includes a target IP address and a source IP address;
[0013] Extracting the session request of the data packet and the session identifier and status code of the session request based on the TCP header;
[0014] Generate streaming session information according to the target IP address, the source IP address, the session identifier and the status code.
[0015] Optionally, updating the stream pull count container based on the stream pull session information to obtain the total stream pull count of the target IP address and the number of repeated stream pulls corresponding to the request packet includes:
[0016] Extracting the target IP address and session identifier from the streaming session information;
[0017] Retrieving the total number of stream pulls corresponding to the target IP address from the stream pull count container, and retrieving the number of repeated stream pulls corresponding to the session identifier from the total number of stream pulls;
[0018] The total number of pull flows and the number of repeated pull flows are counted by adding 1 respectively to update the pull flow counting container to obtain the latest total number of pull flows and the number of repeated pull flows.
[0019] Optionally, returning an intercept response packet including an optimal IP address to the client so that the client redirects the optimal IP address to perform a streaming session request includes:
[0020] Obtain the total number of streams received by each request server, and sort the total number of streams from low to high to obtain the sorting result;
[0021] Obtaining the IP address of the request server with the lowest total number of pull streams in the sorting results as the optimal IP address, and generating an intercept response packet according to the optimal IP address;
[0022] The intercept response packet is returned to the client so that the client redirects the request packet to the request server corresponding to the optimal IP address.
[0023] Optionally, the preset control threshold includes a first threshold and a second threshold; the first threshold is less than the second threshold;
[0024] When it is detected that the total number of pull flows exceeds a preset control threshold, a flow limiting operation or a blocking operation is performed on the request packet, including:
[0025] When it is detected that the total number of pulled streams exceeds the first threshold but does not exceed the second threshold, a flow limiting operation is performed on the request packet;
[0026] When it is detected that the total number of pulled streams exceeds the second threshold, a blocking operation is performed on the request packet.
[0027] Optionally, updating the error count of the error count container based on the stream pulling session information to obtain the number of error stream pulling of the source IP address includes:
[0028] Extracting the source IP address and status code from the streaming session information, and determining whether the status code is a data error;
[0029] If not, directly obtain the number of error stream pulling corresponding to the source IP address from the error counting container;
[0030] If so, the number of erroneous stream pulling corresponding to the source IP address is counted plus 1 in the error counting container, and the latest number of erroneous stream pulling is obtained.
[0031] Optionally, the method further comprises:
[0032] Acquire update data of the pull flow counting container or the error counting container, and synchronously update the storage data of the database according to the update data;
[0033] Regularly perform health assessment on the requesting server according to the stored data in the database, and dynamically adjust the configuration information of the XDP interface according to the assessment result.
[0034] The present application also provides a flow control device, comprising:
[0035] A data packet parsing module, used to obtain a data packet sent by a client through a preset XDP interface, and extract streaming session information in the data packet; wherein the types of the data packet include request packets and response packets; the streaming session information includes a target IP address and a source IP address;
[0036] A container update module, for updating the stream pull count container based on the stream pull session information when the packet type is a request packet, to obtain the total stream pull count of the target IP address and the number of repeated stream pulls corresponding to the request packet;
[0037] A first flow control module is used to intercept the request packet when it is detected that the number of repeated stream pulling exceeds the response threshold of the target IP address, and return an intercept response packet containing the optimal IP address to the client, so that the client redirects the optimal IP address to make a stream pulling session request;
[0038] A second flow control module is used to perform a flow limiting operation or a blocking operation on the request packet when it is detected that the total number of pull flows exceeds a preset control threshold;
[0039] The third flow control module is used to update the error count of the error count container based on the streaming session information when the packet type is a response packet, obtain the number of erroneous streaming of the source IP address, and block the response packet when the number of erroneous streaming exceeds the error threshold of the source IP address.
[0040] The present application also provides a storage medium, in which computer-readable instructions are stored. When the computer-readable instructions are executed by one or more processors, the one or more processors execute the steps of the flow control method described in any one of the above embodiments.
[0041] The present application also provides a computer device, comprising: one or more processors, and a memory;
[0042] The memory stores computer-readable instructions, and when the computer-readable instructions are executed by the one or more processors, the steps of the flow control method described in any one of the above embodiments are performed.
[0043] It can be seen from the above technical solutions that the embodiments of the present application have the following advantages:
[0044] The flow control method, device, storage medium and computer equipment provided by the present application, after the program deployment is started, the XDP interface can directly obtain the data packet sent by the client at the network interface, and extract the streaming session information in the data packet, including the target IP address and the source IP address. Therefore, through the custom configuration of the XDP interface, the present application does not need to modify the software code of the relevant server, thereby achieving the transparency and scalability of the system. In addition, in the flow control strategy configured by the XDP interface, when the data packet is a request packet, the streaming count container can be updated based on the streaming session information to obtain the total number of streaming of the target IP address and the number of repeated streaming corresponding to the request packet, and when it is detected that the number of repeated streaming exceeds the response threshold of the target IP address, the request packet is intercepted, and an intercept response packet containing the optimal IP address is returned to the client, so that the client redirects the optimal IP address to request the streaming session, and when it is detected that the total number of streaming exceeds the preset control threshold, the request packet can be limited or blocked, thereby effectively dispersing the traffic and load, and improving the stability and performance of the system. When the data packet is a response packet, the error count container is updated based on the streaming session information to obtain the number of erroneous streaming of the source IP address. When the number of erroneous streaming exceeds the error threshold of the source IP address, the response packet is blocked, thereby preventing the client from continuously retrying or sending malicious requests and improving the security of the system. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0046] Figure 1 A flow chart of a flow control method provided in an embodiment of the present application;
[0047] Figure 2 A flowchart of a redirection operation process provided in an embodiment of the present application;
[0048] Figure 3 A schematic diagram of a flow control mechanism provided in an embodiment of the present application;
[0049] Figure 4 A logical schematic diagram of a flow control mechanism provided in an embodiment of the present application;
[0050] Figure 5 A schematic diagram of the structure of a flow control device provided in an embodiment of the present application;
[0051] Figure 6 A schematic diagram of the internal structure of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0052] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0053] The existing multi-server architecture still has difficulty coping with the surge in server traffic and system overload caused by a large number of clients making simultaneous or frequent requests. In addition, it is difficult to identify and limit malicious requests from clients and is easily interfered with. It can be seen that the client lacks an effective flow control mechanism during the streaming process and has insufficient defense capabilities against clients, resulting in poor system stability and security.
[0054] Based on this, this application proposes the following technical solutions, see below for details:
[0055] In one embodiment, Figure 1 As shown, Figure 1 A flow chart of a flow control method provided in an embodiment of the present application; the present application provides a flow control method, which specifically includes the following:
[0056] S110: Obtain a data packet sent by the client through a preset XDP interface, and extract streaming session information in the data packet; wherein the types of the data packet include request packets and response packets; and the streaming session information includes a target IP address and a source IP address.
[0057] In this step, when the user initiates a streaming request to the request server at the client, such as sending an RTSP data packet to the RTSP server, the computer device can obtain the data packet sent by the client at the network interface through the XDP interface, and extract the streaming session information in the data packet. Through the custom configuration of the XDP interface, this application can directly process the data packet at the network interface without modifying the software code of the relevant server, thereby achieving transparency and scalability of the system.
[0058] RTSP (Real Time Streaming Protocol) is a protocol for transmitting audio and video data on the network. It uses TCP or UDP protocol for data transmission and provides control over streaming media, such as play, pause, fast forward and reverse functions. The RTSP server is the main device that provides RTSP services. It can receive and respond to RTSP requests from clients and provide real-time streaming media data.
[0059] In addition, the XDP interface used in this application is built based on XDP (Express Data Path). Here, XDP refers to an efficient data packet processing framework, so data packets can be processed directly at the entry of the network interface card driver, thereby reducing the processing time of data packets in the operating system kernel. Through XDP, this application can quickly filter and forward RTSP data packets, improving the processing efficiency of the system.
[0060] It should be noted that before implementing load balancing and flow control for multiple server racks, the computer device can receive the configuration file written by the user, then load the configuration file into the user space program and start it, and compile the configuration file in the kernel space to obtain the eBPF XDP program, and then build the XDP interface based on the eBPF XDP program, so that the XDP interface can directly intercept and process the data packet at the network interface, avoiding multiple switching of the data packet between the user state and the kernel state, thereby significantly improving the processing performance of the network data. Among them, the configuration file can be a YAML file written in Python, which is used to define parameter information such as thresholds, RTSP server addresses, Redis connection information, and speed limit values.
[0061] Specifically, the computer device can determine the type of intercepted data packets, including request packets and response packets, so that different control measures can be taken based on different types to control traffic and achieve load balancing. After obtaining the data packet sent by the client, the computer device can extract the streaming session information by parsing the protocol header information in the data packet; in the streaming session information, in addition to the basic protocol information of the data packet, such as the source port number and the destination port number, it can also cover more specific streaming metadata, such as the source IP address and the destination IP address, so that the flow direction and characteristics of the network traffic can be identified, providing direction for traffic control and optimization. Among them, the source IP address refers to the initiator of the data packet, that is, the IP address of the client, and the destination IP address refers to the destination of the data packet, that is, the IP address of the requesting server.
[0062] S120: When the data packet is a request packet, the stream pulling count container is updated based on the stream pulling session information to obtain the total stream pulling count of the target IP address and the repeated stream pulling count corresponding to the request packet.
[0063] In this step, after determining that the data packet is a request packet through step S110, the computer device can update the flow pull calculation on the flow pull count container based on the flow pull session information, and then obtain the total flow pull number of the target IP address and the repeated flow pull number corresponding to the request packet, so as to perform flow control based on the total flow pull number and the repeated flow pull number.
[0064] It is understood that in this application, the pull flow count container may refer to a data structure BPF MAP provided by the eBPF framework when using XDP for high-speed packet processing; the BPF MAP refers to a kernel-mode data storage structure that allows efficient storage and access of data in the XDP program, providing support for packet processing and state tracking. Through the counting management of BPF MAP, when a computer device detects a request packet, it can query and update the count in the MAP through session information such as the target IP address, without the need to frequently call the switch between kernel mode and user mode.
[0065] Specifically, whenever a request packet is received, the computer device can search in the pull-stream count container to see if there is already a record of the target IP address. If so, it means that the IP address already has an active pull-stream request, and the system will update the corresponding count value, that is, increment it based on the total pull-stream number, and at the same time calculate and update the number of repeated pull-streams corresponding to the current request packet. The repeated pull-stream number here is a repeated request count based on the same target IP address, which can be used to identify malicious requests or abnormally frequent pull-stream behaviors. Therefore, the computer device can use the total pull-stream number and the repeated pull-stream number as reference indicators to achieve flow control.
[0066] S130: When it is detected that the number of repeated stream pulling exceeds the response threshold of the target IP address, the request packet is intercepted, and an intercept response packet containing the optimal IP address is returned to the client, so that the client redirects the optimal IP address to make a stream pulling session request.
[0067] In this step, after obtaining the number of repeated stream pulling corresponding to the request packet through step S120, the computer device can perform a threshold detection on the number of repeated stream pulling, and when it is detected that the number of repeated stream pulling exceeds the response threshold of the target IP address, the request packet is intercepted, and an intercept response packet containing the optimal IP address is returned to the client, so that the client redirects the optimal IP address to make a stream pulling session request, thereby preventing the traffic and system load of a single request server from being too high, affecting the stability of the system and the stream pulling efficiency.
[0068] The response threshold refers to an upper limit set by the computer device when processing a streaming request, which is used to measure whether the number of repeated streaming requests for the same request packet in a specific target IP address is too high. If the number of repeated streaming requests for a request packet in its corresponding target IP address reaches or exceeds this threshold, it means that the request frequency of the request packet is too high, which will cause pressure or potential risks to server resources and system performance, so the computer device needs to divert it.
[0069] Specifically, when the computer device detects that the number of repeated stream pulls of the target IP address requested by the request packet exceeds the preset response threshold, the system will trigger an automatic interception mechanism to intercept the request packet to prevent potential traffic abuse and resource overload problems. When performing the interception operation, the computer device can also construct and return an interception response packet, which contains the optimal IP address calculated by the computer device. This optimal IP address is usually obtained based on real-time evaluation of the current network environment and load conditions. The IP address points to the IP address of the request server node with a lighter load for the client to re-initiate the stream pull request. By providing the client with a redirection suggestion for the optimal IP address, the computer device can effectively disperse the traffic load and reduce the request pressure on a single server.
[0070] S140: When it is detected that the total number of pull flows exceeds a preset control threshold, a flow limiting operation or a blocking operation is performed on the request packet.
[0071] In this step, after obtaining the total number of pull flows corresponding to the request packet through step S120, the computer device can perform a threshold detection on the total number of pull flows, and when it is detected that the total number of pull flows exceeds the preset control threshold, the request packet can be limited or blocked, thereby effectively dispersing the traffic and load and improving the stability and performance of the system.
[0072] For example, after receiving a request packet, the computer device can monitor the total number of pull streams from the target IP address requested by the request packet in real time, and compare it with the preset control threshold. When the computer device detects that the total number of pull streams from the target IP address exceeds this control threshold, it will trigger a flow limiting or blocking operation to protect system resources and prevent server overload.
[0073] Specifically, in the flow limiting operation, the computer device can dynamically reduce the response rate to the target IP address request, delay or batch process some requests, so as to gradually reduce the traffic peak without completely interrupting the service, and ensure that the request server load remains within a controllable range. In addition, in the case of abnormal and severe traffic, the computer device can also take blocking actions, that is, directly reject new pull requests to the target IP address, and return an error status or prompt message, so as to quickly reduce the pressure on the server and avoid the consumption of server resources by malicious requests or high-frequency requests.
[0074] S150: When the data packet is a response packet, the error count container is updated based on the streaming session information to obtain the number of erroneous streaming of the source IP address, and when the number of erroneous streaming exceeds the error threshold of the source IP address, the response packet is blocked.
[0075] In this step, after determining that the data packet is a response packet through step S110, the computer device can update the error count of the error count container based on the streaming session information to obtain the number of erroneous streaming of the source IP address, so that when the number of erroneous streaming exceeds the error threshold of the source IP address, the response packet can be blocked to prevent the client from continuously retrying or sending malicious requests, thereby improving the security of the system.
[0076] It should be noted that the data structure of the error count container in this application is consistent with that of the pull flow count container, which will not be described in detail here.
[0077] Specifically, after the computer device determines that the type of data packet received is a response packet, the computer device can further update the corresponding error count container based on the streaming session information to accurately track the number of erroneous streaming requests for each source IP address. The error count container stores the streaming request status information of each source IP address, including the number of failures. Once an error is detected in a response packet sent by a source IP address, the device will increment the error count of the source IP address to ensure real-time recording of each abnormal request, and when the number of erroneous streaming of the source IP address reaches or exceeds the error threshold, the blocking operation is triggered to intercept or reject the response packet from the source IP address, thereby preventing the client from wasting resources and security risks to the server due to excessive retries or potential malicious request behaviors.
[0078] It is understandable that this blocking mechanism can not only effectively reduce unnecessary network traffic, but also significantly improve the security and stability of the server. By limiting frequent erroneous requests, computer equipment can protect the core resources of the system from being maliciously occupied and reduce the risk of denial of service (DoS) attacks. In addition, the setting of error thresholds can be dynamically adjusted according to specific business needs, so as to flexibly respond to different network environments and load conditions, and avoid affecting the normal requests of legitimate users.
[0079] In the above embodiment, after the program deployment is started, the XDP interface can directly obtain the data packet sent by the client at the network interface, and extract the streaming session information in the data packet, including the target IP address and the source IP address. Therefore, through the custom configuration of the XDP interface, the present application does not need to modify the software code of the relevant server, thereby achieving the transparency and scalability of the system. In addition, in the flow control strategy configured by the XDP interface, when the data packet is a request packet, the streaming count container can be updated based on the streaming session information to obtain the total number of streaming of the target IP address and the number of repeated streaming corresponding to the request packet, and when it is detected that the number of repeated streaming exceeds the response threshold of the target IP address, the request packet is intercepted, and an intercept response packet containing the optimal IP address is returned to the client, so that the client redirects the optimal IP address to request the streaming session, and when it is detected that the total number of streaming exceeds the preset control threshold, the request packet can be limited or blocked, thereby effectively dispersing the traffic and load and improving the stability and performance of the system. When the data packet is a response packet, the error count container is updated based on the streaming session information to obtain the number of erroneous streaming of the source IP address. When the number of erroneous streaming exceeds the error threshold of the source IP address, the response packet is blocked, thereby preventing the client from continuously retrying or sending malicious requests and improving the security of the system.
[0080] In one embodiment, the process of extracting the streaming session information in the data packet in step S110 may include:
[0081] S111: Parse the header of the data packet to obtain an IP header and a TCP header; wherein the IP header includes a target IP address and a source IP address.
[0082] S112: Extracting a session request of the data packet and a session identifier and a status code of the session request based on the TCP header.
[0083] S113: Generate streaming session information according to the target IP address, source IP address, session identifier and status code.
[0084] In this embodiment, when extracting the streaming session information in the data packet, the computer device can first parse the header of the data packet to obtain the IP header and the TCP header, and then obtain the target IP address and the source IP address from the IP header, and extract the session request of the data packet based on the TCP header and the session identifier and status code of the session request, and then generate the streaming session information according to the target IP address, source IP address, session identifier and status code.
[0085] Specifically, the computer device can use the bpf_hdr_pointer macro to obtain a pointer to the data packet header from the data packet metadata, such as the XDP metadata, and then access the IP header and TCP header of the data packet through the pointer. The computer device can then parse the IP header and TCP header respectively to obtain the source IP address and destination IP address in the IP header, as well as the source port and destination port in the TCP header. Since RTSP usually uses TCP port 554 for communication, in this application, when the computer device detects that the destination port of the data packet is 554, it indicates that the data packet is an RTSP stream. At this time, the computer device can continue to scan and parse the TCP payload of the data packet to obtain a string starting with "rtsp: / / ", and then extract the complete RTSP URL for identifying specific session request information, such as session identification, status code, etc. Finally, the computer device can obtain the streaming session information of the data packet based on the parsed information combination.
[0086] In one embodiment, the process of updating the stream pull count container based on the stream pull session information in step S120 to obtain the total stream pull count of the target IP address and the number of repeated stream pulls corresponding to the request packet may include:
[0087] S121: Extract the target IP address and session identifier from the streaming session information.
[0088] S122: The total number of stream pulls corresponding to the target IP address is retrieved from the stream pull count container, and the number of repeated stream pulls corresponding to the session identifier is retrieved from the total number of stream pulls.
[0089] S123: adding 1 to the total number of stream pulls and the number of repeated stream pulls respectively to update the stream pull count container to obtain the latest total number of stream pulls and the number of repeated stream pulls.
[0090] In this embodiment, when the computer device updates the stream pull count of the stream pull count container, it can first extract the target IP address and session identifier in the stream pull session information, and then retrieve the total stream pull number corresponding to the target IP address from the stream pull count container, and retrieve the repeated stream pull number corresponding to the session identifier from the total stream pull number. Then, the computer device can respectively increase the total stream pull number and the repeated stream pull number by 1 to update the stream pull count container to obtain the latest total stream pull number and repeated stream pull number.
[0091] Specifically, the computer device can search in the pull stream count container according to the extracted target IP address to obtain the total pull stream number corresponding to the target IP address; the total pull stream number is used to record the number of all pull stream requests of the target IP address at the current moment, providing basic data for traffic management and resource allocation. After retrieving the total pull stream number, the computer device can also continue to search the repeated pull stream number corresponding to the session identifier; the repeated pull stream number is a count based on the session identifier, recording the number of repeated requests for the same session, and can be used to identify potential abnormal traffic, such as high-frequency requests for the same session or possible malicious behavior.
[0092] It is understandable that once the total number of pulls and the number of repeated pulls are successfully retrieved, the computer device can increment the two count values, that is, add 1, to reflect the new request of this request packet. The computer device can then store the updated counts back into the pull count container to ensure that the total number of pulls and the number of repeated pulls stored in the pull count container are the latest values, thereby accurately reflecting the current request load of the system. Therefore, the computer device can achieve real-time tracking and precise counting of different sessions, which is not only convenient for subsequent traffic control and anomaly detection, but also provides accurate data support for load balancing strategies, so as to balance the load, improve stability, and reduce potential abuse risks in high-concurrency environments.
[0093] In one embodiment, Figure 2 As shown, Figure 2 A flowchart of a redirection operation process provided in an embodiment of the present application; Figure 2 In step S130, the process of returning an intercept response packet including the optimal IP address to the client so that the client redirects the optimal IP address to perform a streaming session request may include:
[0094] S131: Obtain the total number of streams received by each requesting server, and sort the total number of streams in ascending order to obtain a sorting result.
[0095] S132: Obtain the IP address of the request server with the lowest total number of stream pulls in the sorting results as the optimal IP address, and generate an intercept response packet according to the optimal IP address.
[0096] S133: Return the intercept response packet to the client, so that the client redirects the request packet to the request server corresponding to the optimal IP address.
[0097] In this embodiment, when performing a request redirection operation, the computer device can first obtain the total number of stream pulls received by each request server, and sort the total stream pull numbers in order from low to high to obtain the sorting result, and then obtain the IP address of the request server with the lowest total stream pull number in the sorting result as the optimal IP address, and generate an intercept response packet based on the optimal IP address, so that the intercept response packet can be returned to the client, so that the client can redirect the request packet to the request server corresponding to the optimal IP address, which can effectively disperse the load, improve overall stability, and ensure that the client can successfully connect to the appropriate request server.
[0098] For example, after a client sends a request packet to an RTSP server, if the number of repeated stream pulls from the RTSP server exceeds the preset response threshold, the computer device will trigger the eBPF mechanism to intercept the stream pull request of the request packet and construct an RTSP REDIRECT response. This response packet contains a Location header, and the value of the header is the IP address of a new RTSP server. The IP address is obtained from the Redis database, and the Redis database stores the stream pull statistics of each RTSP server. Therefore, the computer device can select the IP address of the RTSP server with the least number of stream pulls to guide the client to redirect to the request server. After receiving the REDIRECT response, the client will automatically initiate a new request based on the IP address in the Location header and redirect to the RTSP server with a lighter load.
[0099] Furthermore, in order to prevent the redirection process from looping, the computer device can set the maximum number of redirections allowed for each client's source IP address (MAX_REDIRECTS) in the global configuration. When the number of redirections of the client reaches this threshold, the computer device will no longer send a REDIRECT response, but will directly accept the client's request, avoiding redirection dead loops or excessive redirection operations caused by the total number of streams pulled by multiple RTSP servers exceeding the threshold at the same time.
[0100] In one embodiment, the preset control threshold in step S140 may include a first threshold and a second threshold; the first threshold is less than the second threshold; wherein, when it is detected that the total number of pull flows exceeds the preset control threshold, the process of performing a flow limiting operation or a blocking operation on the request packet may include:
[0101] S141: When it is detected that the total number of pulled streams exceeds the first threshold but does not exceed the second threshold, a flow limiting operation is performed on the request packet.
[0102] S142: When it is detected that the total number of pulled streams exceeds a second threshold, a blocking operation is performed on the request packet.
[0103] In this embodiment, the preset control threshold of the present application may include a first threshold and a second threshold, and the first threshold is less than the second threshold. Based on this, when the computer device detects that the total number of pull flows exceeds the first threshold but does not exceed the second threshold, the request packet can be limited, and when the total number of pull flows is detected to exceed the second threshold, the request packet can be blocked, so as to improve the stability and performance of the system.
[0104] Specifically, when the total number of pull streams exceeds the first threshold but does not reach the second threshold, it means that the request load of the request server has begun to increase, but is still within an acceptable range. In this case, the computer device can perform a current limiting operation, that is, reduce the processing rate of new requests or delay the response, so as to effectively balance the traffic and avoid system overload. Among them, the current limiting method may include queuing processing requests, delaying responses, or limiting the number of concurrent requests for each source IP, etc., which are not limited here. In addition, when the total number of pull streams exceeds the second threshold, it means that the current traffic of the request server has exceeded the carrying range that it can handle, and there is an overload risk or abnormal situation. At this time, the computer device can use the XDP_DROP method to block the request packet and directly refuse to receive further pull stream requests, so as to quickly reduce the system burden and prevent the performance of a single node or the entire system from degrading.
[0105] It is understandable that through this hierarchical threshold control strategy, the computer device can flexibly respond to changes in the traffic of the request server and effectively disperse and control the traffic load. When the traffic in the request server is close to the upper limit, the computer device can balance the traffic through the current limiting operation, and when the traffic reaches a level that cannot be carried, the computer device can quickly cut off the high-load request through the blocking operation to ensure the stable operation of the server and improve the performance.
[0106] In one embodiment, step S150 updates the error count of the error count container based on the stream pulling session information to obtain the number of error stream pulling of the source IP address, including:
[0107] S151: extract the source IP address and status code in the streaming session information, and determine whether the status code is a data error.
[0108] S152: If not, directly obtain the number of error stream pulling corresponding to the source IP address from the error counting container.
[0109] S153: If yes, then the number of error stream pulling corresponding to the source IP address is counted by 1 in the error counting container, and the latest number of error stream pulling is obtained.
[0110] In this embodiment, when the computer device obtains the number of error stream pulling of the source IP address, it can first extract the source IP address and status code in the stream pulling session information, and then determine whether the status code is a data error. If the status code is not a data error, the computer device can directly obtain the number of error stream pulling corresponding to the source IP address from the error counting container; if the status code is a data error, the computer device can add 1 to the number of error stream pulling corresponding to the source IP address in the error counting container, and obtain the latest number of error stream pulling.
[0111] It can be understood that the status code of the present application can be used to identify the processing result of the current request. If the status code shows "RTSP / 1.0 401 Unauthorized", it means that the status code is a data error, indicating that there is an abnormality in the stream pull request corresponding to the response packet; otherwise, it means that the stream pull request of the response packet has been successfully processed, and the computer device does not need to perform additional error statistics for it.
[0112] Specifically, when the status code is a data error, the computer device can increment the error stream pulling number corresponding to the source IP address in the error counting container, that is, add 1, to immediately update the error counting container to ensure that the computer device records the latest error stream pulling data. When the status code is not a data error, the error stream pulling number remains unchanged, and the error counting container does not need to perform additional count updates, so the computer device can directly obtain the error stream pulling number corresponding to the source IP address from the error counting container.
[0113] In one embodiment, the method may further include:
[0114] S160: Acquire update data of the pull flow count container or the error count container, and synchronously update the storage data of the database according to the update data.
[0115] S170: regularly performing health assessment on the requesting server according to the stored data in the database, and dynamically adjusting the configuration information of the XDP interface according to the assessment result.
[0116] In this embodiment, when there is a count update in the pull flow count container or the error count container, the computer device can obtain the updated data of the pull flow count container or the error count container, and synchronously update the storage data of the database according to the updated data. Based on this, the computer device can periodically perform a health assessment on the request server according to the storage data in the database, and dynamically adjust the configuration information of the XDP interface according to the assessment result, so as to further improve the security and stability of the system.
[0117] Specifically, by keeping the database and the counting container updated synchronously, the computer device can access the stored data in the database regularly and perform a health assessment on the operation of each request server. This assessment process can include analyzing the total number of streams pulled, the number of repeated streams pulled, the number of error requests, and other key indicators of each server to determine the load status and operation health of the server. Then, based on the assessment results, the computer device can dynamically adjust the configuration information of the XDP interface to achieve more accurate flow control, prevent a single server from being overloaded or having performance bottlenecks, and effectively respond to abnormal requests and malicious traffic.
[0118] It can be understood that the present application forms an efficient feedback loop between the pull flow counting container, the error counting container, the database and the XDP interface, ensuring that the computer equipment can monitor the health of the server in real time and make rapid adjustments when necessary, which can not only improve the stability and security of the system, but also enhance the adaptability to high-concurrency environments, thereby maintaining efficient and stable operation under load fluctuations or potential threats.
[0119] In order to better explain the flow control method of the present application, the following will be Figure 3 and Figure 4 To further illustrate, schematically, Figure 3 and Figure 4 As shown, Figure 3 A schematic diagram of a flow control mechanism provided in an embodiment of the present application; Figure 4 A logical schematic diagram of a flow control mechanism provided in an embodiment of the present application.
[0120] Figure 3 In the , the traffic control mechanism is mainly composed of three parts: user space, kernel space and configuration file. Among them, the computer device can load the configuration file into the user space startup program, and then compile and load the eBPF XDP program through the user space program and configure the network interface to receive data packets through the interface obtained by the configuration and process the data packets through the kernel space processing logic, and then store the processing results in the eBPF maps (counting container). Furthermore, the user space can also read data from the eBPF maps and write it to the Redis database for storage, so that the data can be queried from the Redis database at regular intervals, and then the RTSP server can be checked for health, and the stored data in the Redis database can be monitored and decided whether to trigger the TC module command to limit the bandwidth of the client, so as to limit the flow of data packets sent by the client.
[0121] Furthermore, this application is Figure 4 To further explain the kernel space processing logic of the kernel space part of the traffic control mechanism. Figure 4 In the above, after receiving the data packet, the computer device can extract and parse the streaming session information such as Ethernet header, IP header and TCP header in the data packet. Then, when it is determined that the data packet is a request packet, the computer device can extract the source IP address and user name information of the RTSP streaming session, and the user name information can be used to characterize the session identifier of the request packet; therefore, based on the source IP address and user name information, the computer device can count the number of repeated streams of each RTSP server, and if the number of repeated streams exceeds the threshold A (response threshold), a response packet is constructed and returned, otherwise the request packet is allowed to pass; in addition, the computer device can also count the total number of streams pulled by each RTSP server, and if the total number of streams pulled exceeds the threshold B (first threshold), the current limit is triggered, and if it exceeds the threshold C, the IP is blocked, otherwise it is allowed to pass. In addition, when it is determined that the data packet is a response packet, the computer device can count the 401 Unauthorized error, that is, the response packet with an error status code, and obtain the source IP address of the response packet. If the error stream pull count corresponding to the source IP address exceeds the error threshold, the subsequent request of the source IP address is blocked, otherwise the response packet is allowed to pass.
[0122] The flow control device provided in the embodiment of the present application is described below. The flow control device described below and the flow control method described above can be referenced to each other.
[0123] In one embodiment, Figure 5 As shown, Figure 5 A schematic diagram of the structure of a flow control device provided in an embodiment of the present application; the present application also provides a flow control device, including a data packet parsing module 210, a container update module 220, a first flow control module 230, a second flow control module 240 and a third flow control module 250, specifically including the following:
[0124] The data packet parsing module 210 is used to obtain the data packet sent by the client through the preset XDP interface and extract the streaming session information in the data packet; wherein the types of data packets include request packets and response packets; the streaming session information includes the target IP address and the source IP address.
[0125] The container update module 220 is used to update the stream pull count container based on the stream pull session information when the packet type is a request packet, and obtain the total stream pull count of the target IP address and the repeated stream pull count corresponding to the request packet.
[0126] The first flow control module 230 is used to intercept the request packet when it is detected that the number of repeated stream pulling exceeds the response threshold of the target IP address, and return an intercept response packet containing the optimal IP address to the client, so that the client redirects the optimal IP address to make a stream pulling session request.
[0127] The second flow control module 240 is used to perform flow limiting or blocking operations on request packets when it is detected that the total number of pull flows exceeds a preset control threshold.
[0128] The third flow control module 250 is used to update the error count of the error count container based on the streaming session information when the packet type is a response packet, obtain the number of erroneous streaming of the source IP address, and block the response packet when the number of erroneous streaming exceeds the error threshold of the source IP address.
[0129] In the above embodiment, after the program deployment is started, the XDP interface can directly obtain the data packet sent by the client at the network interface, and extract the streaming session information in the data packet, including the target IP address and the source IP address. Therefore, through the custom configuration of the XDP interface, the present application does not need to modify the software code of the relevant server, thereby achieving the transparency and scalability of the system. In addition, in the flow control strategy configured by the XDP interface, when the data packet is a request packet, the streaming count container can be updated based on the streaming session information to obtain the total number of streaming of the target IP address and the number of repeated streaming corresponding to the request packet, and when it is detected that the number of repeated streaming exceeds the response threshold of the target IP address, the request packet is intercepted, and an intercept response packet containing the optimal IP address is returned to the client, so that the client redirects the optimal IP address to request the streaming session, and when it is detected that the total number of streaming exceeds the preset control threshold, the request packet can be limited or blocked, thereby effectively dispersing the traffic and load and improving the stability and performance of the system. When the data packet is a response packet, the error count container is updated based on the streaming session information to obtain the number of erroneous streaming of the source IP address. When the number of erroneous streaming exceeds the error threshold of the source IP address, the response packet is blocked, thereby preventing the client from continuously retrying or sending malicious requests and improving the security of the system.
[0130] In one embodiment, the data packet parsing module 210 may include:
[0131] The header parsing submodule is used to parse the header of the data packet to obtain the IP header and TCP header; wherein the IP header includes the target IP address and the source IP address.
[0132] The data extraction submodule is used to extract the session request of the data packet and the session identifier and status code of the session request based on the TCP header.
[0133] The information generation submodule is used to generate streaming session information based on the target IP address, source IP address, session identifier and status code.
[0134] In one embodiment, the container update module 220 may include:
[0135] The identifier extraction submodule is used to extract the target IP address and session identifier in the streaming session information.
[0136] The stream pulling number retrieval submodule is used to retrieve the total stream pulling number corresponding to the target IP address from the stream pulling count container, and retrieve the repeated stream pulling number corresponding to the session identifier from the total stream pulling number.
[0137] The pull flow counting submodule is used to count the total pull flow number and the repeated pull flow number by 1 respectively, so as to update the pull flow counting container and obtain the latest total pull flow number and repeated pull flow number.
[0138] In one embodiment, the first flow control module 230 may include:
[0139] The data sorting submodule is used to obtain the total number of streams received by each request server, and sort the total number of streams in descending order to obtain a sorting result.
[0140] The address selection submodule is used to obtain the IP address of the request server with the lowest total number of pull flows in the sorting results as the optimal IP address, and generate an intercept response packet based on the optimal IP address.
[0141] The redirection submodule is used to return the interception response packet to the client so that the client redirects the request packet to the request server corresponding to the optimal IP address.
[0142] In one embodiment, the preset control threshold in the second flow control module 240 may include a first threshold and a second threshold; the first threshold is less than the second threshold; wherein the second flow control module 240 may further include:
[0143] The current limiting submodule is used to perform a current limiting operation on the request packet when it is detected that the total number of pull flows exceeds a first threshold but does not exceed a second threshold.
[0144] The blocking submodule is used to block the request packet when it is detected that the total number of pull streams exceeds a second threshold.
[0145] In one embodiment, the three flow control modules 250 include:
[0146] The status code judgment submodule is used to extract the source IP address and status code in the streaming session information and determine whether the status code is a data error.
[0147] The first acquisition submodule is used to directly acquire the number of error stream pulling corresponding to the source IP address from the error counting container when the status code is not a data error.
[0148] The second acquisition submodule is used to count the number of error stream pulls corresponding to the source IP address in the error counting container by adding 1 when the status code is a data error, and to obtain the latest number of error stream pulls.
[0149] In one embodiment, the apparatus may further include:
[0150] The database update module is used to obtain the update data of the pull flow count container or the error count container, and synchronously update the storage data of the database according to the update data.
[0151] The configuration dynamic adjustment module is used to periodically perform health assessment on the request server according to the stored data in the database, and dynamically adjust the configuration information of the XDP interface according to the assessment results.
[0152] In one embodiment, the present application also provides a storage medium storing computer-readable instructions. When the computer-readable instructions are executed by one or more processors, the one or more processors execute the steps of the flow control method described in any of the above embodiments.
[0153] In one embodiment, the present application also provides a computer device having computer-readable instructions stored therein. When the computer-readable instructions are executed by one or more processors, the one or more processors execute the steps of the flow control method as described in any one of the above embodiments.
[0154] Indicatively, if Figure 6 As shown, Figure 6 This is a schematic diagram of the internal structure of a computer device provided in an embodiment of the present application. The computer device 300 may be provided as a server. Figure 6 The computer device 300 includes a processing component 302, which further includes one or more processors, and a memory resource represented by a memory 301 for storing instructions executable by the processing component 302, such as an application. The application stored in the memory 301 may include one or more modules, each corresponding to a set of instructions. In addition, the processing component 302 is configured to execute instructions to perform the flow control method of any of the above embodiments.
[0155] The computer device 300 may further include a power supply component 303 configured to perform power management of the computer device 300, a wired or wireless network interface 304 configured to connect the computer device 300 to a network, and an input / output (I / O) interface 305. The computer device 300 may operate based on an operating system stored in the memory 301, such as Windows Server TM, Mac OS X TM, Unix TM, Linux TM, Free BSD TM, or the like.
[0156] Those skilled in the art will understand that Figure 6 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0157] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0158] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The various embodiments can be combined as needed, and the same or similar parts can refer to each other.
[0159] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A flow control method, characterized in that: The method comprises: Obtaining a data packet sent by a client through a preset XDP interface, and extracting streaming session information in the data packet; wherein the types of the data packet include request packets and response packets; the streaming session information includes a target IP address and a source IP address; When the data packet is a request packet, the stream pull count container is updated based on the stream pull session information to obtain the total stream pull count of the target IP address and the number of repeated stream pulls corresponding to the request packet; When it is detected that the number of repeated stream pulling exceeds the response threshold of the target IP address, the request packet is intercepted, and an intercept response packet containing the optimal IP address is returned to the client, so that the client redirects the optimal IP address to make a stream pulling session request; When it is detected that the total number of pulled streams exceeds a preset control threshold, a flow limiting operation or a blocking operation is performed on the request packet; When the data packet is a response packet, the error count container is updated based on the streaming session information to obtain the number of erroneous streaming of the source IP address, and when the number of erroneous streaming exceeds the error threshold of the source IP address, the response packet is blocked.
2. The flow control method according to claim 1, characterized in that: The extracting the streaming session information in the data packet includes: Parsing the header of the data packet to obtain an IP header and a TCP header; wherein the IP header includes a target IP address and a source IP address; Extracting the session request of the data packet and the session identifier and status code of the session request based on the TCP header; Generate streaming session information according to the target IP address, the source IP address, the session identifier and the status code.
3. The flow control method according to claim 1, characterized in that: The updating of the stream pulling count of the stream pulling count container based on the stream pulling session information to obtain the total stream pulling count of the target IP address and the number of repeated stream pulling corresponding to the request packet includes: Extracting the target IP address and session identifier from the streaming session information; Retrieving the total number of stream pulls corresponding to the target IP address from the stream pull count container, and retrieving the number of repeated stream pulls corresponding to the session identifier from the total number of stream pulls; The total number of stream pulling and the number of repeated stream pulling are counted by adding 1 respectively to update the stream pulling counting container to obtain the latest total number of stream pulling and the number of repeated stream pulling.
4. The flow control method according to claim 1, characterized in that: The step of returning an intercept response packet including an optimal IP address to the client so that the client redirects the optimal IP address to perform a streaming session request includes: Obtain the total number of streams received by each request server, and sort the total number of streams from low to high to obtain the sorting result; Obtaining the IP address of the request server with the lowest total number of pull streams in the sorting results as the optimal IP address, and generating an intercept response packet according to the optimal IP address; The intercept response packet is returned to the client so that the client redirects the request packet to the request server corresponding to the optimal IP address.
5. The flow control method according to claim 1, characterized in that: The preset control threshold includes a first threshold and a second threshold; the first threshold is less than the second threshold; When it is detected that the total number of pull flows exceeds a preset control threshold, a flow limiting operation or a blocking operation is performed on the request packet, including: When it is detected that the total number of pulled streams exceeds the first threshold but does not exceed the second threshold, a flow limiting operation is performed on the request packet; When it is detected that the total number of pulled streams exceeds the second threshold, a blocking operation is performed on the request packet.
6. The flow control method according to claim 1, characterized in that: The updating of the error count of the error count container based on the stream pulling session information to obtain the number of error stream pulling of the source IP address includes: Extracting the source IP address and status code from the streaming session information, and determining whether the status code is a data error; If not, directly obtain the number of error stream pulling corresponding to the source IP address from the error counting container; If so, the number of erroneous stream pulling corresponding to the source IP address is counted plus 1 in the error counting container, and the latest number of erroneous stream pulling is obtained.
7. The flow control method according to claim 1, characterized in that: The method further comprises: Acquire update data of the pull flow counting container or the error counting container, and synchronously update the storage data of the database according to the update data; Regularly perform health assessment on the requesting server according to the stored data in the database, and dynamically adjust the configuration information of the XDP interface according to the assessment result.
8. A flow control device, characterized in that: include: A data packet parsing module, used to obtain a data packet sent by a client through a preset XDP interface, and extract streaming session information in the data packet; wherein the types of the data packet include request packets and response packets; the streaming session information includes a target IP address and a source IP address; A container update module, for updating the stream pull count container based on the stream pull session information when the packet type is a request packet, to obtain the total stream pull count of the target IP address and the number of repeated stream pulls corresponding to the request packet; A first flow control module is used to intercept the request packet when it is detected that the number of repeated stream pulling exceeds the response threshold of the target IP address, and return an intercept response packet containing the optimal IP address to the client, so that the client redirects the optimal IP address to make a stream pulling session request; A second flow control module is used to perform a flow limiting operation or a blocking operation on the request packet when it is detected that the total number of pull flows exceeds a preset control threshold; The third flow control module is used to update the error count of the error count container based on the streaming session information when the packet type is a response packet, obtain the number of erroneous streaming of the source IP address, and block the response packet when the number of erroneous streaming exceeds the error threshold of the source IP address.
9. A storage medium, characterized in that: The storage medium stores computer-readable instructions, and when the computer-readable instructions are executed by one or more processors, the one or more processors execute the steps of the flow control method according to any one of claims 1 to 7.
10. A computer device, characterized in that: include: one or more processors, and memory; The memory stores computer-readable instructions, and when the computer-readable instructions are executed by the one or more processors, the steps of the flow control method according to any one of claims 1 to 7 are performed.