[go: up one dir, main page]

WO2023221990A1 - Udp message distribution method, device and readable storage medium - Google Patents

Udp message distribution method, device and readable storage medium Download PDF

Info

Publication number
WO2023221990A1
WO2023221990A1 PCT/CN2023/094581 CN2023094581W WO2023221990A1 WO 2023221990 A1 WO2023221990 A1 WO 2023221990A1 CN 2023094581 W CN2023094581 W CN 2023094581W WO 2023221990 A1 WO2023221990 A1 WO 2023221990A1
Authority
WO
WIPO (PCT)
Prior art keywords
group
process group
groups
udp
ebpf
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Ceased
Application number
PCT/CN2023/094581
Other languages
French (fr)
Chinese (zh)
Inventor
陈祥祥
庄晓川
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Wangsu Science and Technology Co Ltd
Original Assignee
Wangsu Science and Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Wangsu Science and Technology Co Ltd filed Critical Wangsu Science and Technology Co Ltd
Priority to EP23800303.2A priority Critical patent/EP4529137A4/en
Priority to US18/506,048 priority patent/US12120203B2/en
Publication of WO2023221990A1 publication Critical patent/WO2023221990A1/en
Anticipated expiration legal-status Critical
Ceased legal-status Critical Current

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/16Implementation or adaptation of Internet protocol [IP], of transmission control protocol [TCP] or of user datagram protocol [UDP]
    • H04L69/164Adaptation or special uses of UDP protocol
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/60Software deployment
    • G06F8/65Updates
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5027Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals
    • G06F9/505Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals considering the load
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/16Implementation or adaptation of Internet protocol [IP], of transmission control protocol [TCP] or of user datagram protocol [UDP]
    • H04L69/167Adaptation for transition between two IP versions, e.g. between IPv4 and IPv6

Definitions

  • the embodiments of this application relate to the field of Internet technology, and in particular to a method, device and readable storage medium for distributing UDP messages.
  • UDP User Datagram Protocol
  • OSI Open System Interconnect
  • Streaming media protocols implemented based on UDP include: Secure Reliable Transport (SRT) protocol, Web Real-Time Communication (WEBRTC) protocol, Quick UDP Internet Connections (QUIC) protocol, etc.
  • SRT Secure Reliable Transport
  • WEBRTC Web Real-Time Communication
  • QUIC Quick UDP Internet Connections
  • TCP Transmission Control Protocol
  • UDP has no concept of connection, is fast and has low reliability.
  • Nginx server is a high-performance Hyper Text Transfer Protocol (Hyper Text Transfer Protocol, HTTP) and reverse generation server, which has the characteristics of high concurrency, good performance and small memory usage.
  • Nginx-based streaming media servers are widely used in streaming media technology. Multiple application services are deployed on the Nginx server, and multiple application services can run at the same time. Each application service corresponds to a group of processes, and a group of processes contains multiple processes. A group of processes uses the same UDP port to send and receive data.
  • This application provides a UDP message distribution method, equipment and readable storage medium.
  • ebpf resources are allocated to the new process group, so that each process group in multiple process groups has The independent ebpf resource ensures that UDP packet distribution will not be disrupted when multiple process groups coexist, achieving the purpose of improving service quality.
  • embodiments of the present application provide a method for distributing UDP messages, including:
  • the target process group is determined from multiple process groups in the port multiplexing group according to the four-tuple carried in the UDP message.
  • the multiple process groups are multiple process groups created in sequence for application services.
  • the multiple processes Each process group in the group has independent ebpf resources;
  • embodiments of the present application provide a device for distributing UDP messages, including:
  • Transceiver module used to receive UDP messages from terminal devices
  • a processing module configured to determine a target process group from multiple process groups in the port multiplexing group based on the four-tuple carried in the UDP message.
  • the multiple process groups are multiple process groups created sequentially for application services, Each process group in the plurality of process groups has independent ebpf resources;
  • a selection module used to select the target fd from the fd of each process in the target process group
  • a distribution module configured to distribute the UDP message using the target fd.
  • embodiments of the present application provide an electronic device, including: a processor, a memory, and a computer program stored on the memory and executable on the processor.
  • the processor executes the computer program
  • the The electronic device implements the method described in the above first aspect or various possible implementations of the first aspect.
  • embodiments of the present application provide a computer-readable storage medium.
  • Computer instructions are stored in the computer-readable storage medium. When executed by a processor, the computer instructions are used to implement the above first aspect or the first aspect. various possible implementations.
  • embodiments of the present application provide a computer program product including a computing program.
  • the computer program is executed by a processor, the method described in the above first aspect or various possible implementations of the first aspect is implemented.
  • each process group has an independent ebpf resource, and the ebpf resource is used to save the process group.
  • Information about the file handle fd of each process After the server receives the UDP message, it determines the target process group from multiple process groups in the port multiplexing group based on the four-tuple of the UDP message, selects the target fd from the fd of each process in the target process group, and uses The target fd sends and receives data.
  • Figure 1 is a schematic diagram of the implementation environment of the UDP message distribution method provided by the embodiment of the present application.
  • Figure 2 is a flow chart of a UDP message distribution method provided by an embodiment of the present application.
  • Figure 3A is a schematic diagram of the relationship between UDP messages and process groups in the UDP message classification method provided by the embodiment of the present application;
  • Figure 3B is another schematic diagram of the relationship between UDP messages and process groups in the UDP message dividing method provided by the embodiment of the present application;
  • Figure 4 is a schematic structural diagram of a new module inside the server in the UDP message distribution method provided by the embodiment of the present application;
  • FIG. 5 is a schematic diagram of a UDP message distribution device provided by an embodiment of the present application.
  • FIG. 6 is a schematic structural diagram of an electronic device provided by an embodiment of the present application.
  • UDP Transmission Control Protocol
  • UDP has high reliability but slow speed.
  • UDP has low latency, weak network resistance and other properties, so it is widely used in audio and video transmission, such as live broadcast scenarios.
  • UDP is different from TCP.
  • UDP has no concept of connection.
  • the Nginx server uses UDP, multiple processes of an application service on the Nginx server use the same UDP port to send and receive data.
  • an application service has a process group that contains multiple processes. Each process in this process group uses its own file handle. fd) There will be no problem in sending and receiving UDP messages.
  • UDP message should be sent to a process in the new process group, but is sent to a process in the old process group; another example, a UDP message should be sent to a process in the old process group, but is sent to a process in the new process group. Processes in the process group cause the entire application service to be unavailable, affecting service quality.
  • the push data should be sent to the processes in the old process group.
  • the push stream will be disconnected, causing the live broadcast to be interrupted.
  • the terminal device sends a UDP message to the Nginx server to request the stream.
  • the UDP message should be distributed to the processes in the new process group, but it is distributed to the process in the old process group, so the audience cannot watch. live streaming.
  • the UDP connect method is used to solve the above-mentioned problem of chaotic UDP packet distribution, it will cause the problem of single-core soft interrupt performance consumption. Moreover, the concurrency capability of the UDP connect solution is low, about 500.
  • embodiments of the present application provide a UDP message distribution method, device, and readable storage medium.
  • an Extended Berkeley packet filter Extended Berkeley Packet Filter
  • Packet Filter (ebpf) resource enables each process group in multiple process groups to have independent ebpf resources, ensuring that UDP packet distribution will not be disrupted when multiple process groups coexist, thereby achieving the purpose of improving service quality.
  • Figure 1 is a schematic diagram of the implementation environment of the UDP message distribution method provided by the embodiment of the present application.
  • the network architecture includes a terminal device 11 and a server 12 .
  • the terminal device 11 may be a terminal device on the host side or a terminal device on the viewing side, including but not limited to mobile phones and tablet computers installed with Android operating system, Microsoft operating system, Symbian operating system, Linux operating system or Apple iOS operating system. , personal computers, e-book readers, laptops, desktop computers, etc.
  • Server 12 may be hardware or software. When the server 12 is hardware, the server 12 is a single server or a distributed server cluster composed of multiple servers. When the server 12 is software, it may be multiple software modules or a single software module, etc., which is not limited by the embodiments of this application.
  • the server 12 is an Nginx-based server, including but not limited to edge nodes in a content delivery network (Content Delivery Network, CDN).
  • CDN Content Delivery Network
  • the server 12 can provide multiple application services, and these application services can run at the same time.
  • One application service corresponds to one UDP port, and one UDP port can have multiple process groups at the same time. Multiple process groups use the same UDP port to distribute UDP messages.
  • This UDP port is the port reuse (reuseport) group. Reuseport is a feature of socket that supports multiple different fds to use the same UDP port to distribute UDP messages.
  • the purpose of this case is to solve the following problem: when multiple process groups exist at the same time and multiple process groups use the same UDP port to distribute UDP messages, how to ensure that the distribution of UDP messages will not be disordered.
  • the reason why multiple process groups of an application service exist at the same time is to hot update or upgrade the application service.
  • a process in a process group becomes abnormal, based on this case, it can also be ensured that the distribution of UDP messages will not be disrupted.
  • the abnormal process is the process in the newly created process group among the multiple process groups; when the application service has only one process group, the abnormal process is the process in this process group.
  • Server 12 uses ebpf to manage UDP data streams.
  • the ebpf feature is supported on the new Linux kernel.
  • Each UDP port can be a reuseport group.
  • Each UDP port has independent ebpf resources and does not interfere with each other.
  • UDP ports include port 80 and port 443.
  • Port 80 has its own ebpf resource, and port 443 has its own ebpf resource.
  • Port 80 can have multiple process groups, and port 443 can also have multiple process groups.
  • terminal devices 11 and servers 12 in Figure 1 is only illustrative. In actual implementation, any number of terminal devices 11 and servers 12 can be deployed according to actual needs.
  • FIG. 2 is a flow chart of a UDP message distribution method provided by an embodiment of the present application. This embodiment is explained from the perspective of the server. This embodiment includes:
  • the server receives the UDP message from the terminal device.
  • the terminal device may be the anchor end or the audience's playback end, etc., which is not limited by the embodiments of this application.
  • the UDP packet carries push data.
  • the server finds the target fd and uses the target fd to pass the push data carried in the UDP packet to the upper-layer worker process.
  • the terminal device is the playback end, the UDP message is used to request live broadcast data.
  • the server determines the target fd based on the UDP message and uses the target fd to return the live broadcast data to the terminal device.
  • the server determines the target process group from multiple process groups in the port multiplexing group based on the four-tuple carried in the UDP message.
  • the multiple process groups are multiple process groups created in sequence for the application service.
  • the server can provide multiple application services, and these application services can run in parallel.
  • Application services inevitably require hot updates or upgrades.
  • hot update is also called reload, configuration update, hot reload, reload configuration, etc. It refers to dynamically loading configuration and updating parameters in the application service, but does not change the entire application service and does not upgrade the version of the application service.
  • Upgrading refers to upgrading the version of an application service, that is, replacing the pre-upgraded application service with the upgraded application service.
  • a master process is created for an application service, and a group of worker processes are created by the master process.
  • the Master process is responsible for managing the running status of the worker process.
  • This group of worker processes is one of the multiple process groups in step 202.
  • an application service is hot updated, a new process group is generated every time it is reloaded.
  • the old process will not exit immediately, but will exit when the exit time is reached.
  • the main process remains unchanged, and the main process creates a group of worker processes.
  • a first number is preset.
  • the first number is used to indicate the maximum number of process groups in the port multiplexing group, which can be 5, 32, etc., this application The examples are not limiting.
  • the first number is used to represent the maximum number of process groups in a port multiplexing group, and does not represent the maximum number of reloads. For example, if the first number is 5, it means that a port multiplexing group can have up to 5 process groups at the same time. When 5 process groups exist at the same time, it is possible to reload 4, 5 or more times. This is because once processes exist simultaneously When the number of groups reaches the first number, when reloading next, the server will clean up the earliest created process group and related records, and then reload.
  • a new process group will be created every time you upgrade. Different from reload, every time it is upgraded, the server creates a new master process, and the new master process creates a group of worker processes to obtain a new process group.
  • the server maintains a dynamic array, represented by reuseport array.
  • the elements in this dynamic array are the ebpf resources of each process group.
  • the number of elements is the same as the number of process groups that exist at the same time.
  • One element corresponds to one process group.
  • each process group has an independent ebpf resource, and the ebpf resource is used to maintain the fd of each process in the process group. For example, if there are two process groups at the same time, each process group contains 7 processes, then for any process group, 7 fds are stored in the ebpf resource of the process group, and different fds correspond to different processes.
  • the ebpf resource is used to save information about the file handle fd of each process in the process group, and the number of process groups in multiple process groups is greater than or equal to 2.
  • the ebpf resource of a process group stores the fd of each process in the process group and some other resources.
  • the server distinguishes clients (terminal devices that send UDP messages) based on four-tuple groups. Assume that before reload, UDP packets of a terminal device (terminal device 1) are distributed to processes in the old process group. Then, after reload, the UDP packets of this terminal device must be assigned to the old process group. After the new terminal device (Terminal Device 2) sends a UDP message, because the IP of Terminal Device 2 is different from the IP of Terminal Device 1, the UDP message of Terminal Device 2 is distributed to the new process group.
  • the server After the server receives the UDP message, it extracts four elements from the header of the UDP message, namely the source port number, source IP address, destination port number and destination IP address, and determines it from multiple process groups based on the four-tuple Target process group. Since each process group has independent ebpf resources, that is, different process groups have different fds, different process groups will not seize the same fd and will not cause confusion in UDP messages. That is to say, UDP packets originally distributed to the new process group will not be distributed to the old process group, and UDP packets originally distributed to the old process group will not be distributed to processes in the new process group.
  • process groups there are two process groups at the same time, which are process groups created before and after application service reload.
  • the one created first is called the old process group, and the one created later is called the new process group.
  • the fd of the new process is a newly generated fd, not an inherited fd of the old process.
  • the processes in the new process group inherit the fd of the processes in the old process group, resulting in a total of 14 processes in the new and old process groups, but only 7 fd, changes in hash mapping lead to data confusion.
  • there are a total of 14 processes in the new process group and the old process group but there are 14 FDs. Processes in different process groups will not preempt the same FD, so data confusion will not occur.
  • the server selects the target fd from the fds of each process in the target process group.
  • Figure 3A is a schematic diagram of the relationship between UDP messages and process groups in the UDP message classification method provided by the embodiment of the present application.
  • Figure 3B is another schematic diagram of the relationship between UDP messages and process groups in the UDP message classification method provided by the embodiment of the present application.
  • the UDP message is regarded as an old request
  • the target process group is the old process group
  • the old request is Distributed to the old process group
  • the server determines the target fd from the fd of each process in the old process group.
  • the UDP message is regarded as a new request
  • the target process group is the new process group
  • the new request is distributed to the new process group
  • the server determines the target fd from the fd of each process in the new process group.
  • the server selects the target fd from the fds of each process included in the target process group based on the load balancing principle. For example, the server determines the process with a smaller load from the multiple processes included in the target process group, and uses the fd of this process as the target fd.
  • the server uses the target fd to distribute UDP messages.
  • the server uses the target fd to send push data to the upper worker process.
  • the server obtains video data, etc. and responds to the viewer using the target fd.
  • each process group has an independent ebpf resource, and the ebpf resource is used to save the file handle fd of each process in the process group. information.
  • the server After the server receives the UDP message, it determines the target process group from multiple process groups in the port multiplexing group based on the four-tuple of the UDP message, selects the target fd from the fd of each process in the target process group, and uses The target fd sends and receives data.
  • each time a process group is created uses the main process to create a second process group.
  • the first process group and the second process group are two process groups created successively among multiple process groups.
  • the first process group corresponds to the first group of fd.
  • a second set of fds is generated for the second process group.
  • set the second group of fd to the standby resources in the resource collection to obtain the ebpf resource of the second process group.
  • the resource collection stores the pre-created standby resources.
  • the first number of the standby resources in the resource set is
  • the maximum number of process groups in the port multiplexing group is the same, and the second number of process groups in multiple process groups is less than or equal to the first number.
  • a resource collection is pre-created on the server, and pre-created resources to be used are stored in the resource collection.
  • the number of process groups that currently exist at the same time can be 2, 3, 4 or 5. Of course, if reload or upgrade does not occur, there will only be one process group in a port multiplexing group.
  • the server Each time the server creates a new process group, it saves the latest process group number. For example, when there is only one process group, the sequence number of the process group is sequence number 1. After reload is executed for the first time to create a new process group, the serial number of the new process group is serial number 2, and so on.
  • the process group is created by the application layer of the server, and the application layer is responsible for cleaning up the ebpf resources.
  • the number of processes in the new process group is the same as the number of processes in the old process group.
  • the embodiment of the present application is not limited. The number of processes in the old process group may be equal to, less than, or more than the number of processes in the new process group.
  • the process group that already existed before the process group was created is the first process group, and the process group created this time is the second process group.
  • the server uses the main process to create the second process group.
  • the first process group and the second process group are two process groups created successively among multiple process groups.
  • the first process group corresponds to The first set of fd.
  • the processes in the second process group do not inherit the fds of the processes in the first process group, but generate new fds for each process in the second process group, that is, the second group of fds.
  • the server After generating the second group of fd, the server takes out a standby resource from the resource collection and sets the second group of fd to the standby resource, thereby obtaining the ebpf resource of the second process group. Afterwards, the second grouped ebpf resource is stored as an element in the dynamic array (reuseport array).
  • the server each time a process group is created, the server generates a set of fds for the newly created process group and does not inherit the fds of the processes in the old process group, preventing multiple processes from seizing the same fd after the server receives a UDP message. , to ensure that UDP packets are sent without confusion.
  • the server When performing a hot update on an application service to create a second process group, before the server generates the second group of fds for the second process group, it filters out the fds in the listening structure of the first process group, the first process group and the second process. Groups are created by the first main process.
  • the second process group can obtain the listening structure of the first process group.
  • the fd of the process in the first process group will be closed, and the fd of each process in the first process group will be inherited by the corresponding process in the second process group.
  • the fd of the first process group and the fd of the second process group are the same, and these two sets of fd cannot be set to the dynamic array (reuseport array).
  • the fd of the listening structure is not inherited, but filtered out and not passed to the second process group. Moreover, the fd of the process in the first process group is not closed.
  • the first main process is used to pass environment variables to the second main process.
  • the first main process is the main process before the application service is upgraded, and the second main process is after the application service is upgraded. the main process.
  • the server closes the fd carrying the preset identification.
  • the preset identifier is used to indicate that the fd is the fd of ebpf.
  • the master process changes: it was the first master process before the upgrade, and it is the newly created second master process after the upgrade.
  • the entire process space has changed and been replaced by a new executable program, making the second process group unable to Get the listening structure of the first process group.
  • the newly created second process group is generated through the fork function and execv function.
  • the fd of each process in the first process group is not closed.
  • the server passes all fds of the old listening structure of the first process group to the new main process, that is, the second main process, through environment variables. After the second main process obtains these fds through environment variables, it sets them in the listening structure of the second process group and continues to use them.
  • the difference between this case and the traditional solution is that in this case, when using environment variables to transfer fd, it distinguishes between ordinary fd and ebpf fd.
  • a preset identification is added to the fd.
  • the preset identification is, for example, b, etc.
  • the fd passed by the environment variable includes 12, 13, b14 and 15.
  • b14 indicates that the fd is the fd of ebpf, and the value is 14.
  • the second main process parses out the fd carrying the preset identifier, it closes the fd so that the second process group no longer inherits the fd.
  • the server generates a new set of ebpf fd for the second process group and sets this set of fd to Obtain the ebpf resource of the second process group from a standby resource.
  • the fd is passed and distinguished through the environment variable, and the fd carrying the preset identifier is closed so that the second process group does not inherit the fd, but generates a fd for the second process group.
  • the server uses the first main process to create a third process group and closes the fd in the third process group's listening structure. Afterwards, the server generates a third group of fds for the third process group, and creates an ebpf resource corresponding to the third process group based on the third group of fds.
  • the old main process that is, the first main process
  • this group of worker processes is the third process group.
  • an application service has a first process group.
  • a new main process that is, the second main process
  • the first main process will create a third process Engineering group. If the existing solution is adopted, since the first main process does not modify the listening structure of the first process group, the fd of the third process group is the same as the fd of the first process group, and problems will occur.
  • the first process group will exit when the exit time is reached.
  • a group of fds that is, the third group of fds
  • the third group of fds will be set to a standby resource to obtain the ebpf resource of the third process group. That is to say, when the first main process creates the third process group, it obtains a new set of fds based on the third process group, that is, the third group of fds, and adds the third group of fds to the dynamic array (reuseport array) through the ebpf interface. . Subsequent new UDP messages are distributed to fd in the third process group, and then the third process group is started. The worker processes in the third process group use the new fd service.
  • the old master process restarts a process group, and generates fd for the new process group so that the new process group has independent ebpf resources to ensure that UDP message distribution will not be disordered when the upgrade fails. phenomenon to achieve the purpose of improving business quality.
  • the focus is on how to ensure that the distribution of UDP messages will not be disordered when at least two process groups exist at the same time during reload and upgrade.
  • the server After the server determines that an abnormal process exists in the newly created process group among multiple process groups, it creates a new worker process for the newly created process group.
  • the fd of the worker process is the fd of the abnormal process.
  • a process in the newly created process group may be abnormal due to the existence of bugs.
  • This process is an abnormal process or a hung process.
  • the newly created process group contains 7 processes. When one of the 7 processes becomes abnormal, there are 6 normal processes left. If the existing technology is used, the hash table maintained by the server will be disordered, and thus This leads to confusion in UDP packet distribution.
  • the main process in the reload scenario, the main process is the first main process, in the upgrade scenario, the main process is the second main process
  • restarts a worker process restarts a worker process, and the worker process Continue to use the fd of the abnormal process.
  • the main process associates fd according to the sequence number of each process in the newly created process group, so that the re-created worker process can receive UDP messages.
  • the old process group is a process group among multiple process groups except the latest created process group. For example, 5 process groups exist at the same time, the 5th process group is the latest created process group, and the other 4 process groups are old process groups.
  • the master process when an abnormal process occurs in the process group, the master process re-creates a worker process and uses the fd of the abnormal process to ensure that the distribution of UDP packets will not be disordered when an abnormal process occurs, thereby achieving the purpose of improving service quality.
  • the server maintains a dynamic array (reuseport array).
  • a dynamic array reuseport array
  • the server stores the ebpf resource of the process group created this time as an element in a dynamic array.
  • the server clears the elements of the first created process group in the order in which the process groups are created, and then adds the ebpf resources of the process group created this time. Stored in dynamic array.
  • the exit_master interface is an interface registered by the server to complete resource recycling.
  • the server pre-defines the first number, which is the maximum number of process groups that can exist at the same time.
  • the server stores the ebpf resource of the process group as an element in a dynamic array.
  • the number of elements in the dynamic array reaches the first number for the first time, it means that the resources to be used in the pre-created resource collection have been used up.
  • you create a process group again later you need to clear the ebpf resource corresponding to the first created process group from the dynamic array to release the ebpf resource. In this way, after creating a new process group, the new process group will have ebpf resources. Available.
  • This solution is used to recycle ebpf resources for reload scenarios to ensure that application services can be reloaded multiple times. By hot updating application services in a timely manner, the purpose of improving service quality is achieved.
  • the new master process calls the exit_master interface to clean up resources.
  • the exit_master interface to clean up resources.
  • each UDP port can be used as a port reuse group.
  • the server uses the UDP message distribution method described in the embodiment of this application to distribute UDP messages, so there will be no problem of data confusion.
  • streaming media protocols implemented based on UDP include SRT, QUIC, etc.
  • Multiple UDP ports can be configured for one protocol, and different protocols have different UDP ports.
  • Each UDP port corresponds to an ebpf resource. If there are multiple UDP ports, multiple copies of ebpf resources need to be loaded into the kernel. At the same time, the ebpf resources of each port are stored in different paths.
  • ports are distinguished by port multiplexing groups, and port multiplexing groups are based on IP + port. Therefore, when the same port can be bound to at least two IP protocols, the port multiplexing group simultaneously serves at least Two IP protocols.
  • the UDP port can be regarded as two multiplexed ports, one serving IPV4 and the other serving IPV6.
  • the UDP message distribution method provided by the embodiment of this application is universal and can be applied to streaming media protocols such as SRT, QUIC, WEBRTC, etc., and can solve the problem of data confusion caused by multiple process groups using the same UDP port to distribute UDP messages.
  • SRT streaming media protocols
  • QUIC QUIC
  • WEBRTC Wired Equivalent Privacy
  • the ebpf module (ngx_core_bpf_moudle) is added to the server to complete ebpf related processing.
  • the ebpf module registers two interfaces, one is the initialization interface (ngx_core_bpf_int_moudle), and the other is the resource recycling interface (ngx_core_bpf_exit_moudle_).
  • the initialization interface is used to complete the initialization and loading of ebpf resources
  • the resource recycling interface is used to complete resource recycling. Since this case is mainly to solve the problem of chaotic UDP packet distribution caused by multiple process groups using the same port multiplexing group, in master-worker mode, all ebpf operations must be completed by the master process.
  • a reuseport group will have a listening structure, and the listening structure has a socket address (sockaddr). If the sockaddr of the two listening structures is the same, then the two listening structures correspond to a reuseport group. If two If the sockaddr of the listening structures is different, the two listening structures correspond to different reuseport groups.
  • a UDP port may have one, two or more reuseport groups. The server adds a preset identifier in the listening structure of a reuseport group, indicating that the reuseport group uses the solution of the embodiment of this application to distribute UDP messages.
  • the main modifications include the following five points:
  • the server performs initialization operations in the initialization interface, and ebpf has requirements for the server's kernel version. If the server's kernel version is too low, the UDP message distribution method in this case is not supported. Therefore, the server needs to first determine the kernel version. For example, the uname system call method is used to determine whether the kernel supports it. If the kernel does not support it, the traditional UDP-based connect method is used. If the kernel supports it, the UDP message distribution method described in the embodiment of this application is used.
  • the server selects the target process group from multiple process groups through a quadruple.
  • An application service can have multiple process groups at the same time.
  • the fd of each process in a process group is a group of fd, which is regarded as an ebpf resource.
  • the quadruple of a UDP message is a new quadruple, the UDP message is a new request, and the new request obtains the target fd from the new process group;
  • the quadruple of a UDP message is the old quadruple group, the UDP message is an old request, and the target fd is obtained from the old process group.
  • Every time the server creates a new process group it needs to save the latest sequence number of the process group. Compare For example, if there is currently a process group, the sequence number is 1. Executing a reload will generate a new process group, and the sequence number of the new process group will be 2, and so on.
  • the new process group is created by the application layer, which is responsible for cleanup work.
  • the ebpf program works in the kernel. Set up ebpf related resources in the module initialization function, such as dynamic array (reuseport array), and then load the ebpf program into the kernel.
  • the saving method adopts file system association method, using bpf_obj_pin and bpf_pin_get methods.
  • the path that maps the handle of the ebpf program to the file system is: /sys/fs/bpf/udp_reuseport/udp_reuseport_prog.
  • the server is based on Nginx.
  • Nginx is an open source component and requires some modifications to the open source component.
  • UDP has no concept of connection
  • each process has an fd, and one process and one fd serves multiple clients.
  • an application service When reload or upgrade is performed, an application service will have multiple process groups at the same time.
  • the fd in the old process group continues to serve old requests, and new requests are served by the fd in the new process group.
  • the fd of each old process in the old process group will be closed.
  • the fd of each process in the old process group is not closed. For example, if the above default flag is 1, it means that the server's kernel version supports ebpf. At this time, every time a new process group is created, the fd of each process in the old process group will not be closed.
  • the fd of the listening structure of the old process group will be passed to the listening structure of the new process group through inheritance, resulting in the same fd of the two process groups. Cannot be set to a dynamic array (reuseport array). For this reason, in the embodiment of this application, when the kernel version supports ebpf and the server adopts the UDP message distribution method of this application, each time a new process group is created, the fd in the old process group will not be inherited, but the old one will be filtered out. fd in the listening structure of the process group.
  • the specific method is to pass the fd carrying the preset identifier in the old cycle (old cycle) without passing it to the new cycle (cycle).
  • the listening structure is used to store listening information and is created by the master process. Each worker process has a listening structure.
  • the listening information stored in the listening structure is, for example, fd, etc. In this case, every time a new process group is created, the processes in the new process group do not inherit the fd of the processes in the old process group.
  • the server passes all the fds of the old process group's listening structure to the new master process through environment variables. After the new master process obtains the fds through environment variables, it is used by the new process group.
  • the transfer and setting of fd are modified.
  • a preset identifier is added in front of the fd of ebpf.
  • the preset identifier is, for example, b, etc.
  • the passed fd includes 12, 13, b14 and 15, where b14 represents the fd of ebpf and the value is 14.
  • the new master process parses the fd of ebpf, it closes the fd.
  • the new process group does not inherit the fd.
  • the new master process generates a new set of fd for the new process group, and then adds the new fd of the group to the dynamic in the reuseport array.
  • the old master process starts a group of worker processes again, that is, the third process group.
  • the fd of the third process group is still the fd of the first process group.
  • the fds of these two process groups are the same, and the fd of the third process group cannot be changed.
  • fd is set to a dynamic array.
  • the fd in the listening structure of the third process group is closed, a group of fd is regenerated for the third process group, that is, the third group of fd, and the third group of fd is set to a dynamic array, and subsequent new The request obtains the target fd in the third group of fd, and then starts the worker process in the third process group.
  • These newly started worker processes can use the new fd service.
  • each process in each process group has its own fd to process UDP packets, so at the bottom level, the kernel uses ebpf to ensure that UDP packets reach the corresponding process. Then the UDP messages of each client are distinguished by four-tuple within the process. The process decides whether a UDP packet goes to the new process or the old process. After the UDP packet reaches the process, the application layer distinguishes different connections based on the maintained client information.
  • abnormal scenarios include: reload, upgrade and process exception.
  • the version of the application service will not change, but parameters, etc. will be updated.
  • the main process will not exit and the configuration will be reloaded. Every time a new process group is created, the main process creates a second process group based on the first process group, and generates a new set of fd for the second process group, so that the fd of the first process group and the second process group are different.
  • Each process group receives UDP messages through its own fd to ensure that the distribution of UDP messages will not be chaotic.
  • the application service is upgraded and the new version of the application replaces the old version of the application.
  • the new main process loads a new version of the executable program, and then the new main process creates a new set of fd and a new process group. Since traditional Nginx will set up fd inheritance, the fd of the old process group will be inherited to the new process group, which is no problem for TCP. However, for UDP, because ebpf is used, a set of fds needs to be set for each process group to ensure that these process groups serve at the same time. Otherwise, if the fds of two or more process groups are the same, UDP message distribution chaos will occur. .
  • the new process group does not inherit the fd of the old process group, but creates a new set of fd for the new process group, loads the newly created fd into the kernel, and then each process group passes Its own fd distributes UDP messages.
  • the fd of each worker process is uniformly allocated in the master process, and then loaded into and associated with ebpf through the kernel interface. At this time, the kernel maintains a group of fds. These fds internally listen to the same port through reuseport to ensure that the data will not be confused.
  • the master process will restart a new worker process, and the fd is still the hung process, that is, the fd of the abnormal process.
  • the main process will associate the previous fd according to the sequence number of each worker process, so the restarted process can still receive UDP messages.
  • one streaming media protocol can be configured with multiple ports, and different protocols are configured with different ports.
  • the protocols include SRT, QUIC, etc.
  • Different reuseport groups correspond to different ebpf resources, and different reuseports correspond to different UDP ports or the same UDP port.
  • port 123 is a port that supports SRT
  • port 123 is a reuseport group
  • port 111 is a port that supports QUIC
  • port 111 is a reuseport group.
  • port 10080 is bound to both IPv4 and IPv6, then port 10080 corresponds to two reuseport groups, and port 10080 serves both IPv4 and IPv6.
  • each reuseport group in the multiple reuseport groups has its own ebpf resource, and each reuseport group has multiple process groups, and each process group also has independent ebpf resources.
  • /sys/fs/bpf/udp_reuseport_10080/udp_reuseport_prog indicates port 10080;
  • /sys/fs/bpf/udp_reuseport_10081/udp_reuseport_prog indicates port 10081.
  • UDP ports are distinguished by reuseport groups, and reuseport groups are distinguished by IP+Port.
  • one UDP port can create two or more reuseport groups. For example, when the above port 10080 is bound to IPv4 and IPv6, two reuseport groups will be created, and each group will go through the ebpf process.
  • the server traverses the listening structure and determines the sockaddr in each listening structure. If the sockaddr is the same, the ports corresponding to the two listening structures are considered to be the same reuseport group and are loaded into ebpf together.
  • Each reuseport group has multiple process groups, each process group has multiple processes, and each process has its own fd.
  • the ebpf module has registered two interfaces, namely the initialization interface and the resource recycling interface.
  • the resource recycling interface is responsible for the cleaning operation of ebpf resources.
  • the main process will change.
  • the ebpf module calls the resource recycling interface to recycle resources.
  • each reload will generate a set of ebpf resources to save the fd information of each process in the new process group.
  • This group of fd will subsequently be set to standby resources to generate ebpf resources for the new process group.
  • the resource recycling interface will not be called for cleaning, causing resources to be leaked every time they are reloaded.
  • the traditional solution is to clean up after all worker processes have exited. If the worker process is cleared before it exits, the worker process will be unable to serve.
  • the elements in the dynamic array cannot exceed the first number.
  • the first number is, for example, 5. This is not limited by the embodiment of the present application. Once the number of elements exceeds the first number, it needs to be cleaned up to ensure that the number of elements that exist at the same time is less than or equal to the first number, that is, the number of process groups that exist at the same time is less than or equal to the first number.
  • the first number is 5, which means that up to 5 process groups can exist at the same time, and the sequence numbers are 0, 1, 2, 3, and 4 respectively.
  • position Before saving, determine whether the position is empty. If it is not empty, first clean up the elements originally held at the position, and then save the element created this time to this position. There are 5 positions in the dynamic array, namely position 0 to position 4. When elements are saved at positions 0 to 4, the elements created by reload will be placed at position 0. Since position 0 is not empty, the ebpf resource process corresponding to position 0 will be cleaned up, such as releasing memory and other operations, and will be closed. fd of ebpf resource. Then, store the newly created element at position 0.
  • FIG. 5 is a schematic diagram of a UDP message distribution device provided by an embodiment of the present application.
  • the UDP message distribution device 500 includes: a transceiver module 51 , a processing module 52 , a selection module 53 and a distribution module 54 .
  • Transceiver module 51 used to receive UDP messages from terminal devices
  • the processing module 52 is configured to determine a target process group from multiple process groups in the port multiplexing group according to the quadruple group carried in the UDP message.
  • the multiple process groups are multiple process groups created sequentially for the application service.
  • the multiple processes Each process group in the group has independent ebpf resources;
  • the selection module 53 is used to select the target fd from the fd of each process in the target process group;
  • Distribution module 54 is used to distribute UDP messages using the target fd.
  • the processing module 52 determines the target process group from multiple process groups in the port multiplexing group according to the quadruple carried in the UDP message, it is also used to use the main process each time a process group is created.
  • the first process group and the second process group are two process groups created successively among the plurality of process groups.
  • the first process group corresponds to the first group of fd; generate a second group for the second process group. fd; set the second group of fd to the resources to be used in the resource collection to get ebpf resource, the resource collection stores pre-created resources to be used.
  • the first number of the resources to be used in the resource collection is the same as the maximum number of process groups in the port multiplexing group.
  • the second number of process groups in multiple process groups The number is less than or equal to the first number.
  • the processing module 52 before the processing module 52 generates the second group of fd for the second process group, it is also used to filter out the listening structure of the first process group when performing a hot update on the application service to create the second process group.
  • the first process group and the second process group are both created by the first main process.
  • the processing module 52 is also used to store the ebpf resource of the process group created this time as an element in a dynamic array after each process group is created; when the number of elements in the dynamic array is greater than or equal to the first number, after cleaning the elements of the first created process group in the order in which the process groups among multiple process groups are created, the ebpf resources of the process group created this time are stored in a dynamic array.
  • the processing module 52 before the processing module 52 generates the second group of fd for the second process group, it is also used to use the first main process to the second main process when upgrading the application service to create the second process group. Pass the environment variable.
  • the first main process is the main process before the application service upgrade
  • the second main process is the main process after the application service upgrade.
  • the processing module 52 is also used to call the resource recovery interface to clean up the ebpf resources of the first process group each time the process group is created.
  • the processing module 52 is also used to use the first main process to create a third process group when the application service upgrade fails; close the fd in the listening structure of the third process group; target the third process The group generates the third group of fd; create the ebpf resource corresponding to the third process group based on the third group of fd.
  • the processing module 52 is also used to determine that there is an abnormal process in the latest created process group among multiple process groups; create a new worker process for the newly created process group, and the file handle of the worker process is abnormal. fd of the process.
  • the UDP port corresponding to the port multiplexing group is bound to at least two IP protocols
  • the UDP port serves at least two IP protocols at the same time.
  • the ebpf resource is used to save the information of the file handle fd of each process in the corresponding process group, and the number of process groups in multiple process groups is greater than or equal to 2.
  • the UDP message distribution device provided by the embodiment of the present application can perform the actions of the server in the above embodiment. Its implementation principles and technical effects are similar and will not be described again here.
  • FIG. 6 is a schematic structural diagram of an electronic device provided by an embodiment of the present application. As shown in Figure 6, the electronic device 600 is, for example, the above-mentioned control center or anti-attack node.
  • the electronic device 600 includes:
  • Memory 62 stores computer instructions
  • the processor 61 executes the computer instructions stored in the memory 62, so that the processor 61 executes the UDP message distribution method implemented by the server as above.
  • the electronic device 600 further includes a communication component 63 .
  • the processor 61, the memory 62 and the communication component 63 can be connected through the bus 64.
  • Embodiments of the present application also provide a computer-readable storage medium.
  • Computer instructions are stored in the computer-readable storage medium. When the computer instructions are executed by a processor, they are used to implement the UDP message distribution method implemented by the server as above.
  • Embodiments of the present application also provide a computer program product.
  • the computer program product includes a computer program.
  • the computer program is executed by a processor, the UDP message distribution method implemented by the server is implemented as above.

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Security & Cryptography (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computer And Data Communications (AREA)
  • Information Transfer Between Computers (AREA)
  • Stored Programmes (AREA)

Abstract

The present application discloses a UDP message distribution method, a device and a readable storage medium. When there are a plurality of process groups for one application service at the same time, each process group has an independent ebpf resource, the ebpf resources being used for storing information of a file handle (fd) of each process in the process groups. After receiving a UDP message, a server determines a target process group from amongst a plurality of process groups of a reuseport group on the basis of a four-tuple of the UDP message, selects a target fd from amongst fds of processes of the target process group, and transmits and receives data by means of the target fd. In the used solution, since each process group has the independent ebpf resource, processes in different process groups will not preempt the same fd, thereby avoiding distribution of UDP messages being in disorder when the plurality of process groups coexist, which achieves the purpose of ensuring service quality. Moreover, the problem of soft interrupt performance consumption caused by UDP connect can be further avoided, providing a high-concurrency capability.

Description

UDP报文的分发方法、设备及可读存储介质UDP message distribution method, equipment and readable storage medium

相关申请的交叉引用Cross-references to related applications

本申请基于申请号为“202210556806.3”、申请日为2022年5月20日的中国专利申请提出,并要求该中国专利申请的优先权,该中国专利申请的全部内容在此以引入方式并入本申请。This application is filed based on a Chinese patent application with application number "202210556806.3" and a filing date of May 20, 2022, and claims the priority of the Chinese patent application. The entire content of the Chinese patent application is hereby incorporated by reference. Apply.

技术领域Technical field

本申请实施例涉及互联网技术领域,特别涉及一种UDP报文的分发方法、设备及可读存储介质。The embodiments of this application relate to the field of Internet technology, and in particular to a method, device and readable storage medium for distributing UDP messages.

背景技术Background technique

用户数据报协议(User Datagram Protocol,UDP)是开放式系统互连(Open System Interconnect,OSI)参考模型中的一种无连接的传输层协议。随着技术的发展,越来越多的流媒体协议基于UDP实现。User Datagram Protocol (UDP) is a connectionless transport layer protocol in the Open System Interconnect (OSI) reference model. With the development of technology, more and more streaming media protocols are implemented based on UDP.

基于UDP实现的流媒体协议包括:安全可靠传输(Secure Reliable Transport,SRT)协议、网页即时通信(Web Real-Time Communication,WEBRTC)协议、快速UDP互联网连接(Quick UDP Internet Connections,QUIC)协议等。相较于传输控制协议(TransmissionControl Protocol,TCP),UDP没有连接的概念,速度快、可靠性较低。Streaming media protocols implemented based on UDP include: Secure Reliable Transport (SRT) protocol, Web Real-Time Communication (WEBRTC) protocol, Quick UDP Internet Connections (QUIC) protocol, etc. Compared with Transmission Control Protocol (TCP), UDP has no concept of connection, is fast and has low reliability.

Nginx服务器是一个高性能的超文本传输协议(Hyper Text Transfer Protocol,HTTP)和反向代服务器,有着高并发、性能好和占用内存少等特点。基于Nginx的流媒体服务器被广泛应用于流媒体技术中。Nginx服务器上部署多个应用服务,多个应用服务能够同时运行,每个应用服务对应一组进程,一组进程包含多个进程。一组进程使用同一个UDP端口收发数据。Nginx server is a high-performance Hyper Text Transfer Protocol (Hyper Text Transfer Protocol, HTTP) and reverse generation server, which has the characteristics of high concurrency, good performance and small memory usage. Nginx-based streaming media servers are widely used in streaming media technology. Multiple application services are deployed on the Nginx server, and multiple application services can run at the same time. Each application service corresponds to a group of processes, and a group of processes contains multiple processes. A group of processes uses the same UDP port to send and receive data.

然而,经验证发现:当应用服务升级或热更新时,会存在两组或多组进程。这时候,多组进程使用同一个UDP端口进行数据收发,会带来数据错乱的问题。例如,存在两组进程,分别为旧进程组和新进程组,则原本由新进程组中的进程分发的UDP报文被分发到旧进程组中的进程,或者,一个UDP报文原本应该分发给旧进程组中的进程,却分发给了新进程组中的进程。However, it has been verified that when an application service is upgraded or hot updated, there will be two or more groups of processes. At this time, multiple groups of processes use the same UDP port to send and receive data, which will cause data confusion. For example, if there are two groups of processes, namely the old process group and the new process group, then the UDP packet originally distributed by the process in the new process group is distributed to the process in the old process group, or a UDP packet was originally distributed to processes in the old process group, but distributed to processes in the new process group.

发明内容Contents of the invention

本申请提供一种UDP报文的分发方法、设备及可读存储介质,每次产生一个新的进程组,则为该新进程组分配ebpf资源,使得多个进程组中的每个进程组具有独立的ebpf资源,保证多个进程组共存时UDP报文的分发不会出现错乱,实现提高业务质量的目的。 This application provides a UDP message distribution method, equipment and readable storage medium. Each time a new process group is generated, ebpf resources are allocated to the new process group, so that each process group in multiple process groups has The independent ebpf resource ensures that UDP packet distribution will not be disrupted when multiple process groups coexist, achieving the purpose of improving service quality.

第一方面,本申请实施例提供一种UDP报文的分发方法,包括:In the first aspect, embodiments of the present application provide a method for distributing UDP messages, including:

接收来自终端设备的UDP报文;Receive UDP messages from terminal devices;

根据所述UDP报文携带的四元组从端口复用组的多个进程组中确定目标进程组,所述多个进程组是针对应用服务依次创建的多个进程组,所述多个进程组中的每个进程组具有独立的ebpf资源;The target process group is determined from multiple process groups in the port multiplexing group according to the four-tuple carried in the UDP message. The multiple process groups are multiple process groups created in sequence for application services. The multiple processes Each process group in the group has independent ebpf resources;

利用所述目标fd分发所述UDP报文。Use the target fd to distribute the UDP message.

第二方面,本申请实施例提供一种UDP报文的分发装置,包括:In the second aspect, embodiments of the present application provide a device for distributing UDP messages, including:

收发模块,用于接收来自终端设备的UDP报文;Transceiver module, used to receive UDP messages from terminal devices;

处理模块,用于根据所述UDP报文携带的四元组从端口复用组的多个进程组中确定目标进程组,所述多个进程组是针对应用服务依次创建的多个进程组,所述多个进程组中的每个进程组具有独立的ebpf资源;A processing module configured to determine a target process group from multiple process groups in the port multiplexing group based on the four-tuple carried in the UDP message. The multiple process groups are multiple process groups created sequentially for application services, Each process group in the plurality of process groups has independent ebpf resources;

选择模块,用于从所述目标进程组的各进程的fd中选择出目标fd;A selection module, used to select the target fd from the fd of each process in the target process group;

分发模块,用于利用所述目标fd分发所述UDP报文。A distribution module, configured to distribute the UDP message using the target fd.

第三方面,本申请实施例提供一种电子设备,包括:处理器、存储器及存储在所述存储器上并可在处理器上运行的计算机程序,所述处理器执行所述计算机程序时使得所述电子设备实现如上第一方面或第一方面各种可能的实现方式所述的方法。In a third aspect, embodiments of the present application provide an electronic device, including: a processor, a memory, and a computer program stored on the memory and executable on the processor. When the processor executes the computer program, the The electronic device implements the method described in the above first aspect or various possible implementations of the first aspect.

第四方面,本申请实施例提供一种计算机可读存储介质,所述计算机可读存储介质中存储有计算机指令,所述计算机指令在被处理器执行时用于实现如上第一方面或第一方面各种可能的实现方式所述的方法。In a fourth aspect, embodiments of the present application provide a computer-readable storage medium. Computer instructions are stored in the computer-readable storage medium. When executed by a processor, the computer instructions are used to implement the above first aspect or the first aspect. various possible implementations.

第五方面,本申请实施例提供一种包含计算程序的计算机程序产品,所述计算机程序被处理器执行时实现如上第一方面或第一方面各种可能的实现方式所述的方法。In a fifth aspect, embodiments of the present application provide a computer program product including a computing program. When the computer program is executed by a processor, the method described in the above first aspect or various possible implementations of the first aspect is implemented.

本申请实施例提供的UDP报文的分发方法、设备及可读存储介质,一个应用服务的多个进程组同时存在时,每个进程组具有独立的ebpf资源,ebpf资源用于保存进程组中每个进程的文件句柄fd的信息。服务器接收到UDP报文后,根据UDP报文的四元组从端口复用组的多个进程组中确定出目标进程组,从目标进程组的各进程的fd中选择出目标fd,并利用目标fd收发数据。采用该种方案,由于每个进程组具有独立的ebpf资源,不同进程组中的进程不会抢占同一个fd,确保多个进程组共存时UDP报文的分发不会出现错乱,实现保证业务质量的目的。而且,还能够避免UDP connect带来的软中断性能消耗问题,并发能力高。The UDP message distribution method, equipment and readable storage medium provided by the embodiment of this application, when multiple process groups of an application service exist at the same time, each process group has an independent ebpf resource, and the ebpf resource is used to save the process group. Information about the file handle fd of each process. After the server receives the UDP message, it determines the target process group from multiple process groups in the port multiplexing group based on the four-tuple of the UDP message, selects the target fd from the fd of each process in the target process group, and uses The target fd sends and receives data. Using this solution, since each process group has independent ebpf resources, processes in different process groups will not seize the same fd, ensuring that there will be no confusion in the distribution of UDP messages when multiple process groups coexist, ensuring service quality. the goal of. Moreover, it can also avoid the soft interrupt performance consumption problem caused by UDP connect, and has high concurrency.

附图说明 Description of the drawings

为了更清楚地说明本申请实施例中的技术方案,下面将对实施例描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed to be used in the description of the embodiments will be briefly introduced below. Obviously, the drawings in the following description are only some embodiments of the present application. For those of ordinary skill in the art, other drawings can also be obtained based on these drawings without exerting creative efforts.

图1是本申请实施例提供的UDP报文分发方法的实施环境示意图;Figure 1 is a schematic diagram of the implementation environment of the UDP message distribution method provided by the embodiment of the present application;

图2是本申请实施例提供的UDP报文的分发方法的流程图;Figure 2 is a flow chart of a UDP message distribution method provided by an embodiment of the present application;

图3A是本申请实施例提供的UDP报文分方法中UDP报文和进程组的关系一个示意图;Figure 3A is a schematic diagram of the relationship between UDP messages and process groups in the UDP message classification method provided by the embodiment of the present application;

图3B是本申请实施例提供的UDP报文分方法中UDP报文和进程组的关系另一个示意图;Figure 3B is another schematic diagram of the relationship between UDP messages and process groups in the UDP message dividing method provided by the embodiment of the present application;

图4是本申请实施例提供的UDP报文分发方法中服务器内部新增模块的结构示意图;Figure 4 is a schematic structural diagram of a new module inside the server in the UDP message distribution method provided by the embodiment of the present application;

图5为本申请实施例提供的一种UDP报文的分发装置的示意图;Figure 5 is a schematic diagram of a UDP message distribution device provided by an embodiment of the present application;

图6为本申请实施例提供的一种电子设备的结构示意图。FIG. 6 is a schematic structural diagram of an electronic device provided by an embodiment of the present application.

具体实施方式Detailed ways

为使本申请的目的、技术方案和优点更加清楚,下面将结合附图对本申请实施例作进一步地详细描述。In order to make the purpose, technical solutions and advantages of the present application clearer, the embodiments of the present application will be further described in detail below with reference to the accompanying drawings.

目前,传输控制协议(Transmission Control Protocol,TCP)可靠性高但是速度较慢。UDP具有低延迟、抗弱网等性能,因此被广泛应用于音视频传输中,如直播场景等。UDP和TCP不同,UDP没有连接的概念,当Nginx服务器使用UDP时,Nginx服务器上的一个应用服务的多个进程使用同一个UDP端口进行数据收发。正常情况下,应用服务未发生热更新或升级(upgrade)时,一个应用服务具有一个进程组,该进程组包含多个进程,这个进程组中的每个进程使用自己的文件句柄(file handle,fd)收发UDP报文不会出现问题。但是,当应用服务热更新或升级时,同时会存在2个甚至多个进程组,每个进程组都会抢占fd,导致UDP报文的收发错乱。例如,一个UDP报文本应该发送给新进程组中的进程,但是被发送给了旧进程组中的进程;再如,一个UDP报文本应该发送给旧进程组中的进程,但是被发送给新进程组中的进程,导致整个应用服务不可用,影响业务质量。Currently, Transmission Control Protocol (TCP) has high reliability but slow speed. UDP has low latency, weak network resistance and other properties, so it is widely used in audio and video transmission, such as live broadcast scenarios. UDP is different from TCP. UDP has no concept of connection. When the Nginx server uses UDP, multiple processes of an application service on the Nginx server use the same UDP port to send and receive data. Under normal circumstances, when an application service has not been hot updated or upgraded, an application service has a process group that contains multiple processes. Each process in this process group uses its own file handle. fd) There will be no problem in sending and receiving UDP messages. However, when application services are hot updated or upgraded, there will be two or more process groups at the same time, and each process group will preempt the fd, causing confusion in the sending and receiving of UDP packets. For example, a UDP message should be sent to a process in the new process group, but is sent to a process in the old process group; another example, a UDP message should be sent to a process in the old process group, but is sent to a process in the new process group. Processes in the process group cause the entire application service to be unavailable, affecting service quality.

直播场景中,假设主播端正在推流,推流数据本应该发送给旧进程组中的进程,出现上述错乱时,推流会被断开,导致直播中断。同理,观众拉流时,终端设备向Nginx服务器发送UDP报文请求拉流,该UDP报文本应该分发给新进程组中的进程,但是被分发给旧进程组中的进程,则观众无法观看直播。In the live broadcast scenario, assuming that the host is pushing the stream, the push data should be sent to the processes in the old process group. When the above confusion occurs, the push stream will be disconnected, causing the live broadcast to be interrupted. In the same way, when the viewer pulls the stream, the terminal device sends a UDP message to the Nginx server to request the stream. The UDP message should be distributed to the processes in the new process group, but it is distributed to the process in the old process group, so the audience cannot watch. live streaming.

若采用UDP connect方式解决上述的UDP报文分发错乱的问题,则会带来单核软中断性能消耗的问题。而且,UDP connect方案的并发能力较低,大概500左右。 If the UDP connect method is used to solve the above-mentioned problem of chaotic UDP packet distribution, it will cause the problem of single-core soft interrupt performance consumption. Moreover, the concurrency capability of the UDP connect solution is low, about 500.

基于此,本申请实施例提供一种UDP报文的分发方法、设备及可读存储介质,每次产生一个新的进程组,则为该新进程组分配扩展的伯克利数据包过滤器(Extended Berkeley Packet Filter,ebpf)资源,使得多个进程组中的每个进程组具有独立的ebpf资源,保证多个进程组共存时UDP报文的分发不会出现错乱,实现提高业务质量的目的。Based on this, embodiments of the present application provide a UDP message distribution method, device, and readable storage medium. Each time a new process group is generated, an Extended Berkeley packet filter (Extended Berkeley Packet Filter) is allocated to the new process group. Packet Filter (ebpf) resource enables each process group in multiple process groups to have independent ebpf resources, ensuring that UDP packet distribution will not be disrupted when multiple process groups coexist, thereby achieving the purpose of improving service quality.

图1是本申请实施例提供的UDP报文分发方法的实施环境示意图。请参照图1,该网络架构包括终端设备11和服务器12。Figure 1 is a schematic diagram of the implementation environment of the UDP message distribution method provided by the embodiment of the present application. Referring to FIG. 1 , the network architecture includes a terminal device 11 and a server 12 .

终端设备11可以是主播端的终端设备,也可以是观看端的终端设备,包括但不限于安装有安卓操作系统、微软操作系统、塞班操作系统、Linux操作系统或苹果iOS操作系统的手机、平板电脑、个人电脑、电子书阅读器、膝上型便携电脑、台式计算机等。The terminal device 11 may be a terminal device on the host side or a terminal device on the viewing side, including but not limited to mobile phones and tablet computers installed with Android operating system, Microsoft operating system, Symbian operating system, Linux operating system or Apple iOS operating system. , personal computers, e-book readers, laptops, desktop computers, etc.

服务器12可以是硬件也可以是软件。当服务器12为硬件时,该服务器12为单个服务器或多个服务器组成的分布式服务器集群。当服务器12为软件时,可以为多个软件模块或单个软件模块等,本申请实施例并不限制。服务器12为基于Nginx的服务器,包括但不限于内容分发网络(Content Delivery Network,CDN)中的边缘节点等。Server 12 may be hardware or software. When the server 12 is hardware, the server 12 is a single server or a distributed server cluster composed of multiple servers. When the server 12 is software, it may be multiple software modules or a single software module, etc., which is not limited by the embodiments of this application. The server 12 is an Nginx-based server, including but not limited to edge nodes in a content delivery network (Content Delivery Network, CDN).

服务器12能够提供多种应用服务,这些应用服务可同时运行,一个应用服务对应一个UDP端口,一个UDP端口可以同时存在多个进程组,多个进程组组使用同一个UDP端口分发UDP报文,这个UDP端口即为端口复用(reuseport)组。Reuseport是套接字(socket)的一个特性,支持多个不同的fd使用同一个UDP端口进行UDP报文的分发。The server 12 can provide multiple application services, and these application services can run at the same time. One application service corresponds to one UDP port, and one UDP port can have multiple process groups at the same time. Multiple process groups use the same UDP port to distribute UDP messages. This UDP port is the port reuse (reuseport) group. Reuseport is a feature of socket that supports multiple different fds to use the same UDP port to distribute UDP messages.

本案目的在于解决以下问题:多个进程组同时存在、多个进程组使用同一个UDP端口分发UDP报文时,如何确保UDP报文的分发不会错乱。一个应用服务的多个进程组同时存在的原因是:对应用服务热更新或升级。另外,当一个进程组中的某个进程异常时,基于本案,也能够确保UDP报文的分发不会出现错乱。当多个进程组同时存在时,异常进程是多个进程组中最新创建的进程组中的进程;当应用服务只有一个进程组时,异常进程是该进程组中的进程。The purpose of this case is to solve the following problem: when multiple process groups exist at the same time and multiple process groups use the same UDP port to distribute UDP messages, how to ensure that the distribution of UDP messages will not be disordered. The reason why multiple process groups of an application service exist at the same time is to hot update or upgrade the application service. In addition, when a process in a process group becomes abnormal, based on this case, it can also be ensured that the distribution of UDP messages will not be disrupted. When multiple process groups exist at the same time, the abnormal process is the process in the newly created process group among the multiple process groups; when the application service has only one process group, the abnormal process is the process in this process group.

服务器12利用ebpf进行UDP数据流的管理,ebpf特性在linux新内核上支持,通过在应用层编写一段业务逻辑代码植入内核运行,无需修改内核代码即可解决不同业务不同逻辑问题。真正做到可插拔,相较于修改内核代码,上述方式具有周期快、安全性高的特点。Server 12 uses ebpf to manage UDP data streams. The ebpf feature is supported on the new Linux kernel. By writing a business logic code in the application layer and implanting it into the kernel for operation, different business logic problems of different businesses can be solved without modifying the kernel code. It is truly pluggable. Compared with modifying the kernel code, the above method has the characteristics of fast cycle time and high security.

服务器12在模块初始化中初始化ebpf资源,并将ebpf资源加载入内核。同时考虑多端口的场景,即多个UDP端口,每个UDP端口都可以是reuseport组,每个UDP端口都有独立的ebpf资源,互不干扰。比如,UDP端口包括80端口和443端口,80端口有自己的ebpf资源,443端口有自己的ebpf资源。端口80可以有多个进程组,443端口也可以有多个进程组。 Server 12 initializes the ebpf resource in module initialization and loads the ebpf resource into the kernel. At the same time, consider the multi-port scenario, that is, multiple UDP ports. Each UDP port can be a reuseport group. Each UDP port has independent ebpf resources and does not interfere with each other. For example, UDP ports include port 80 and port 443. Port 80 has its own ebpf resource, and port 443 has its own ebpf resource. Port 80 can have multiple process groups, and port 443 can also have multiple process groups.

应当理解的是,图1中的终端设备11和服务器12的数量仅仅是示意性的。实际实现中,根据实际需求部署任意数量的终端设备11和服务器12。It should be understood that the number of terminal devices 11 and servers 12 in Figure 1 is only illustrative. In actual implementation, any number of terminal devices 11 and servers 12 can be deployed according to actual needs.

下面,基于图1所示架构,对本申请实施例所述的UDP报文的分发方法进行详细说明。示例性的,请参照图2。Next, based on the architecture shown in Figure 1, the UDP message distribution method described in the embodiment of the present application will be described in detail. For example, please refer to Figure 2.

图2是本申请实施例提供的UDP报文的分发方法的流程图。本实施例是从服务器的角度进行说明,本实施例包括:Figure 2 is a flow chart of a UDP message distribution method provided by an embodiment of the present application. This embodiment is explained from the perspective of the server. This embodiment includes:

201、服务器接收来自终端设备的UDP报文。201. The server receives the UDP message from the terminal device.

终端设备可以是主播端或观众的播放端等,本申请实施例并不限制。当终端设备为主播端时,UDP报文携带推流数据,服务器接收到UDP报文后,找到目标fd,利用目标fd将UDP报文携带的推流数据传递给上层的工作(worker)进程。当终端设备为播放端时,UDP报文用于请求直播数据,服务器接收到UDP报文后,根据UDP报文确定出目标fd,利用目标fd向终端设备返回直播数据。The terminal device may be the anchor end or the audience's playback end, etc., which is not limited by the embodiments of this application. When the terminal device is the host, the UDP packet carries push data. After receiving the UDP packet, the server finds the target fd and uses the target fd to pass the push data carried in the UDP packet to the upper-layer worker process. When the terminal device is the playback end, the UDP message is used to request live broadcast data. After receiving the UDP message, the server determines the target fd based on the UDP message and uses the target fd to return the live broadcast data to the terminal device.

202、服务器根据UDP报文携带的四元组从端口复用组的多个进程组中确定目标进程组,多个进程组是针对应用服务依次创建的多个进程组。202. The server determines the target process group from multiple process groups in the port multiplexing group based on the four-tuple carried in the UDP message. The multiple process groups are multiple process groups created in sequence for the application service.

本申请实施例中,服务器能够提供多种应用服务,这些应用服务可并行运行。应用服务不可避免地需要热更新或升级等。其中,热更新也称为reload、配置更新、热重载、重载配置等,指动态加载配置、更新应用服务中的参数,但是不改变整个应用服务,未对应用服务进行版本升级。升级是指对应用服务进行版本升级,即用升级后的应用服务替换升级前的应用服务。In this embodiment of the present application, the server can provide multiple application services, and these application services can run in parallel. Application services inevitably require hot updates or upgrades. Among them, hot update is also called reload, configuration update, hot reload, reload configuration, etc. It refers to dynamically loading configuration and updating parameters in the application service, but does not change the entire application service and does not upgrade the version of the application service. Upgrading refers to upgrading the version of an application service, that is, replacing the pre-upgraded application service with the upgraded application service.

服务器启动后,针对一个应用服务创建主(master)进程,由主进程创建一组工作(worker)进程。Master进程负责管理worker进程的运行情况。这组worker进程即为步骤202中多个进程组中的一个进程组。当对应用服务进行热更新时,每reload一次,则产生一个新的进程组。为了确保旧进程上的数据不会中断,旧进程不会立即退出,而是在退出时间到达时才退出,这就使得多次reload后,同时存在多个进程组。一般来说不会连续多次reload。但是有时候运维人员着急修改配置等,则会多次reload,使得多个进程组同时存在。每次reload时,主进程不变,主进程创建一组worker进程。After the server is started, a master process is created for an application service, and a group of worker processes are created by the master process. The Master process is responsible for managing the running status of the worker process. This group of worker processes is one of the multiple process groups in step 202. When an application service is hot updated, a new process group is generated every time it is reloaded. In order to ensure that the data on the old process will not be interrupted, the old process will not exit immediately, but will exit when the exit time is reached. This causes multiple process groups to exist at the same time after multiple reloads. Generally speaking, it will not reload multiple times in a row. However, sometimes operation and maintenance personnel are anxious to modify configurations, etc., and will reload multiple times, causing multiple process groups to exist at the same time. Each time it is reloaded, the main process remains unchanged, and the main process creates a group of worker processes.

为了避免同时存在多个进程组占用大量的资源,预先设置一个第一个数,该第一个数用于指示端口复用组的进程组的最大个数,可以是5、32等,本申请实施例并不限制。In order to avoid multiple process groups occupying a large amount of resources at the same time, a first number is preset. The first number is used to indicate the maximum number of process groups in the port multiplexing group, which can be 5, 32, etc., this application The examples are not limiting.

需要说明的是,第一个数用来表示一个端口复用组中进程组的最大个数,并不代表reload的最多次数。例如,第一个数为5,表示一个端口复用组最多同时存在5个进程组。当5个进程组同时存在时,有可能reload了4次、5次或更多次。这是因为一旦同时存在的进程 组的个数达到第一个数,则接下来reload时,服务器会清理掉最早创建的进程组以及相关记录,之后进行reload。It should be noted that the first number is used to represent the maximum number of process groups in a port multiplexing group, and does not represent the maximum number of reloads. For example, if the first number is 5, it means that a port multiplexing group can have up to 5 process groups at the same time. When 5 process groups exist at the same time, it is possible to reload 4, 5 or more times. This is because once processes exist simultaneously When the number of groups reaches the first number, when reloading next, the server will clean up the earliest created process group and related records, and then reload.

同理,每次升级时也会产生一个新的进程组。与reload不同的是,每次升级时,服务器创建新的master进程,由新的master进程创建一组worker进程从而得到一个新的进程组。In the same way, a new process group will be created every time you upgrade. Different from reload, every time it is upgraded, the server creates a new master process, and the new master process creates a group of worker processes to obtain a new process group.

本申请实施例中,服务器维护一个动态数组,用reuseport array来表示。这个动态数组中的元素是每个进程组的ebpf资源,元素的个数和同时存在的进程组的个数相同,一个元素对应一个进程组。由此可见:每个进程组具有独立的ebpf资源,ebpf资源用来保持进程组中每个进程的fd。例如,同时存在两个进程组,每个进程组包含7个进程,则对于任意一个进程组,该进程组的ebpf资源中保存7个fd,不同fd对应不同的进程。In the embodiment of this application, the server maintains a dynamic array, represented by reuseport array. The elements in this dynamic array are the ebpf resources of each process group. The number of elements is the same as the number of process groups that exist at the same time. One element corresponds to one process group. It can be seen that each process group has an independent ebpf resource, and the ebpf resource is used to maintain the fd of each process in the process group. For example, if there are two process groups at the same time, each process group contains 7 processes, then for any process group, 7 fds are stored in the ebpf resource of the process group, and different fds correspond to different processes.

可选的,在一些实施例中,ebpf资源用于保存对应进程组中每个进程的文件句柄fd的信息,多个进程组中进程组的个数大于或等于2。Optionally, in some embodiments, the ebpf resource is used to save information about the file handle fd of each process in the process group, and the number of process groups in multiple process groups is greater than or equal to 2.

示例性的,多次reload或upgrade之后,多个进程组共存,一个进程组的ebpf资源中存放该进程组中各进程的fd以及一些其他的资源等。For example, after multiple reloads or upgrades, multiple process groups coexist, and the ebpf resource of a process group stores the fd of each process in the process group and some other resources.

本申请实施例中,服务器根据四元组区分客户端(发送UDP报文的终端设备)。假设reload之前,一个终端设备(终端设备1)的UDP报文被分发到旧的进程组中的进程。那么,reload之后,这个终端设备的UDP报文一定得分给旧的进程组。新的终端设备(终端设备2)发送UDP报文后,由于终端设备2的IP和终端设备1的IP等不一样,终端设备2的UDP报文分发给新的进程组。In this embodiment of the present application, the server distinguishes clients (terminal devices that send UDP messages) based on four-tuple groups. Assume that before reload, UDP packets of a terminal device (terminal device 1) are distributed to processes in the old process group. Then, after reload, the UDP packets of this terminal device must be assigned to the old process group. After the new terminal device (Terminal Device 2) sends a UDP message, because the IP of Terminal Device 2 is different from the IP of Terminal Device 1, the UDP message of Terminal Device 2 is distributed to the new process group.

服务器接收到UDP报文后,从UDP报文的报文头中提取出四元素,即源端口号、源IP地址、目的端口号和目的IP地址,根据四元组从多个进程组中确定目标进程组。由于每个进程组有独立的ebpf资源,即不同进程组的fd不同,因此不同进程组不会抢占同一个fd,不会造成UDP报文的错乱。也就是说,不会将原本分发给新进程组的UDP报文分发给旧进程组,不会将原本分发给旧进程组的UDP报文分发给新进程组中的进程。After the server receives the UDP message, it extracts four elements from the header of the UDP message, namely the source port number, source IP address, destination port number and destination IP address, and determines it from multiple process groups based on the four-tuple Target process group. Since each process group has independent ebpf resources, that is, different process groups have different fds, different process groups will not seize the same fd and will not cause confusion in UDP messages. That is to say, UDP packets originally distributed to the new process group will not be distributed to the old process group, and UDP packets originally distributed to the old process group will not be distributed to processes in the new process group.

例如,同时存在2个进程组,分别为应用服务reload前后创建的进程组,先创建的称之为旧进程组,后创建的称之为新进程组。旧进程组里有7个进程,每个进程有自己的fd,新进程中有7个fd,每个进程也有自己的fd,新进程的fd是新产生的fd,不是继承旧进程的fd。倘若采用现有的技术,由于新进程组是通过对旧进程组复制产生,新进程组中的进程继承旧进程组中的进程的fd,使得新旧两个进程组共14个进程,但只有7个fd,哈希映射变化导致数据错乱。而本申请实施例中,新进程组和旧进程组共14个进程,但是有14个fd,不同进程组中的进程不会抢占同一个fd,因此不会发生数据错乱。For example, there are two process groups at the same time, which are process groups created before and after application service reload. The one created first is called the old process group, and the one created later is called the new process group. There are 7 processes in the old process group, and each process has its own fd. There are 7 fds in the new process, and each process also has its own fd. The fd of the new process is a newly generated fd, not an inherited fd of the old process. If the existing technology is used, since the new process group is generated by copying the old process group, the processes in the new process group inherit the fd of the processes in the old process group, resulting in a total of 14 processes in the new and old process groups, but only 7 fd, changes in hash mapping lead to data confusion. In the embodiment of this application, there are a total of 14 processes in the new process group and the old process group, but there are 14 FDs. Processes in different process groups will not preempt the same FD, so data confusion will not occur.

203、服务器从目标进程组的各进程的fd中选择出目标fd。 203. The server selects the target fd from the fds of each process in the target process group.

图3A是本申请实施例提供的UDP报文分方法中UDP报文和进程组的关系一个示意图。图3B是本申请实施例提供的UDP报文分方法中UDP报文和进程组的关系另一个示意图。Figure 3A is a schematic diagram of the relationship between UDP messages and process groups in the UDP message classification method provided by the embodiment of the present application. Figure 3B is another schematic diagram of the relationship between UDP messages and process groups in the UDP message classification method provided by the embodiment of the present application.

请参照图3A,当一个UDP报文的四元组和之前接收到的UDP报文的四元组相同时,则该UDP报文视为旧请求,目标进程组为旧进程组,旧请求被分发给旧的进程组,服务器从旧进程组的各进程的fd中确定目标fd。Please refer to Figure 3A. When the four-tuple of a UDP message is the same as the four-tuple of the previously received UDP message, the UDP message is regarded as an old request, the target process group is the old process group, and the old request is Distributed to the old process group, the server determines the target fd from the fd of each process in the old process group.

请参照图3B,当一个UDP报文的四元组和之前接收到的UDP报文的四元组不相同时,则该UDP报文视为新请求,目标进程组为新进程组,新请求被分发给新的进程组,服务器从新进程组的各进程的fd中确定目标fd。Please refer to Figure 3B. When the quadruple of a UDP message is different from the quadruple of the previously received UDP message, the UDP message is regarded as a new request, the target process group is the new process group, and the new request is distributed to the new process group, and the server determines the target fd from the fd of each process in the new process group.

服务器基于负载均衡原则等从目标进程组包含的各进程的fd中选择出目标fd。例如,服务器从目标进程组包含的多个进程中确定出负载较小的进程,将该进程的fd作为目标fd。The server selects the target fd from the fds of each process included in the target process group based on the load balancing principle. For example, the server determines the process with a smaller load from the multiple processes included in the target process group, and uses the fd of this process as the target fd.

204、服务器利用目标fd分发UDP报文。204. The server uses the target fd to distribute UDP messages.

当UDP报文是主播端的报文时,服务器利用目标fd向上层worker进程发送推流数据。当UDP报文为观众端的请求报文时,服务器获取视频数据等并利用目标fd响应给观众端。When the UDP message is from the anchor side, the server uses the target fd to send push data to the upper worker process. When the UDP message is a request message from the viewer, the server obtains video data, etc. and responds to the viewer using the target fd.

本申请实施例提供的UDP报文分发方法,一个应用服务的多个进程组同时存在时,每个进程组具有独立的ebpf资源,ebpf资源用于保存进程组中每个进程的文件句柄fd的信息。服务器接收到UDP报文后,根据UDP报文的四元组从端口复用组的多个进程组中确定出目标进程组,从目标进程组的各进程的fd中选择出目标fd,并利用目标fd收发数据。采用该种方案,由于每个进程组具有独立的ebpf资源,不同进程组中的进程不会抢占同一个fd,确保多个进程组共存时UDP报文的分发不会出现错乱,实现保证业务质量的目的。而且,还能够避免UDP connect带来的软中断性能消耗问题,并发能力高。In the UDP message distribution method provided by the embodiment of this application, when multiple process groups of an application service exist at the same time, each process group has an independent ebpf resource, and the ebpf resource is used to save the file handle fd of each process in the process group. information. After the server receives the UDP message, it determines the target process group from multiple process groups in the port multiplexing group based on the four-tuple of the UDP message, selects the target fd from the fd of each process in the target process group, and uses The target fd sends and receives data. Using this solution, since each process group has independent ebpf resources, processes in different process groups will not seize the same fd, ensuring that there will be no confusion in the distribution of UDP messages when multiple process groups coexist, ensuring service quality. the goal of. Moreover, it can also avoid the soft interrupt performance consumption problem caused by UDP connect, and has high concurrency.

可选的,在一些实施例中,每次创建进程组时,服务器利用主进程创建第二进程组,第一进程组和第二进程组是多个进程组中先后创建的两个进程组,第一进程组对应第一组fd。之后,针对第二进程组生成第二组fd。最后,将第二组fd设置到资源集合中的待用资源中以得到第二进程组的ebpf资源,资源集合中存储预先创建好的待用资源,资源集合中待用资源的第一个数与端口复用组的进程组的最大个数相同,多个进程组中进程组的第二个数小于或等于第一个数。Optionally, in some embodiments, each time a process group is created, the server uses the main process to create a second process group. The first process group and the second process group are two process groups created successively among multiple process groups. The first process group corresponds to the first group of fd. Afterwards, a second set of fds is generated for the second process group. Finally, set the second group of fd to the standby resources in the resource collection to obtain the ebpf resource of the second process group. The resource collection stores the pre-created standby resources. The first number of the standby resources in the resource set is The maximum number of process groups in the port multiplexing group is the same, and the second number of process groups in multiple process groups is less than or equal to the first number.

示例性的,在一些实施例中,服务器上预先创建一个资源集合,该资源集合中存储预先创建好的待用资源,待用资源的个数为第一个数,该第一个数即为上述的端口复用组的进程组的最大个数。例如,预先设置一个端口复用组最多同时存在5个进程组,则第一个数=5。 当前同时存在的进程组的个数可以是2、3、4或5。当然,倘若没有发生reload或升级,则一个端口复用组中仅存在一个进程组。For example, in some embodiments, a resource collection is pre-created on the server, and pre-created resources to be used are stored in the resource collection. The number of resources to be used is the first number, and the first number is The maximum number of process groups in the above port multiplexing group. For example, if a port multiplexing group is preset to have up to 5 process groups at the same time, then the first number = 5. The number of process groups that currently exist at the same time can be 2, 3, 4 or 5. Of course, if reload or upgrade does not occur, there will only be one process group in a port multiplexing group.

服务器每次创建一个新的进程组时,保存当前最新的进程组的序号。例如,只有一个进程组时,该进程组的序号为序号1。第一次执行reload创建一个新的进程组后,新的进程组的序号为序号2,以此类推。进程组由服务器的应用层创建,由应用层负责ebpf资源的清理工作。一般而言,新进程组中进程的个数和旧进程组中进程的个数相同。但是,本申请实施例并不限制,旧进程组中进程的个数可以等于、少于或多于新进程组中进程的个数。Each time the server creates a new process group, it saves the latest process group number. For example, when there is only one process group, the sequence number of the process group is sequence number 1. After reload is executed for the first time to create a new process group, the serial number of the new process group is serial number 2, and so on. The process group is created by the application layer of the server, and the application layer is responsible for cleaning up the ebpf resources. Generally speaking, the number of processes in the new process group is the same as the number of processes in the old process group. However, the embodiment of the present application is not limited. The number of processes in the old process group may be equal to, less than, or more than the number of processes in the new process group.

无论是reload还是upgrade,服务器每次创建一个新的进程组时,本次创建进程组之前,已经存在的进程组为第一进程组,本次创建的进程组为第二进程组。每次创建第二进程组时,服务器都是利用主进程创建出第二进程组,第一进程组和第二进程组是多个进程组中先后创建的两个进程组,第一进程组对应第一组fd。但是,第二进程组中的进程并不继承第一进程组中的进程的fd,而是针对第二进程组中的各个进程生成新的fd,即第二组fd。生成第二组fd后,服务器从资源集合中拿出一个待用资源,将第二组fd设置到该待用资源中,从而得到第二进程组的ebpf资源。之后,将第二进组的ebpf资源作为一个元素存储到动态数组(reuseport array)中。Whether it is reload or upgrade, every time the server creates a new process group, the process group that already existed before the process group was created is the first process group, and the process group created this time is the second process group. Each time a second process group is created, the server uses the main process to create the second process group. The first process group and the second process group are two process groups created successively among multiple process groups. The first process group corresponds to The first set of fd. However, the processes in the second process group do not inherit the fds of the processes in the first process group, but generate new fds for each process in the second process group, that is, the second group of fds. After generating the second group of fd, the server takes out a standby resource from the resource collection and sets the second group of fd to the standby resource, thereby obtaining the ebpf resource of the second process group. Afterwards, the second grouped ebpf resource is stored as an element in the dynamic array (reuseport array).

采用该种方案,每次创建进程组时,服务器针对新创建的进程组生成一组fd,不继承旧进程组中进程的fd,避免服务器接收到UDP报文后,多个进程抢占同一个fd,确保UDP报文发送不会出现错乱。Using this solution, each time a process group is created, the server generates a set of fds for the newly created process group and does not inherit the fds of the processes in the old process group, preventing multiple processes from seizing the same fd after the server receives a UDP message. , to ensure that UDP packets are sent without confusion.

下面,分别从reload和upgrade的角度,对每次创建新的进程组后,如何针对该新进程组生成一组新的fd进行详细描述。Below, from the perspectives of reload and upgrade, we will describe in detail how to generate a new set of FDs for the new process group each time it is created.

首先,reload场景。First, reload the scene.

当对应用服务执行热更新以创建第二进程组时,服务器针对第二进程组生成第二组fd之前,过滤掉第一进程组的监听结构体中的fd,第一进程组和第二进程组均由第一主进程创建。When performing a hot update on an application service to create a second process group, before the server generates the second group of fds for the second process group, it filters out the fds in the listening structure of the first process group, the first process group and the second process. Groups are created by the first main process.

这种场景中,master进程没有变,因此第二进程组可以得到第一进程组的监听结构体。传统的基于Nginx的服务器,当对应用服务进行热更新时,第一进程组中的进程的fd会被关闭,第一进程组中各进程的fd会被第二进程组中的对应进程继承,导致第一进程组的fd和第二进程组的fd相同,这两组fd就无法设置到动态数组(reuseport array)中。本案中,为了确保第一进程组的第一组fd和第二进程组的第二组fd不同,当第一进程组中的监听结构体(listening结构体)中的ebpf标志当前是ebpf方式的监听结构时,该监听结构体的fd不被继承,而是被过滤掉,不传递给第二进程组,而且,不关闭第一进程组中进程的fd。 In this scenario, the master process has not changed, so the second process group can obtain the listening structure of the first process group. For traditional Nginx-based servers, when an application service is hot updated, the fd of the process in the first process group will be closed, and the fd of each process in the first process group will be inherited by the corresponding process in the second process group. As a result, the fd of the first process group and the fd of the second process group are the same, and these two sets of fd cannot be set to the dynamic array (reuseport array). In this case, in order to ensure that the first group of fd of the first process group and the second group of fd of the second process group are different, when the ebpf flag in the listening structure (listening structure) of the first process group is currently ebpf mode When listening to the structure, the fd of the listening structure is not inherited, but filtered out and not passed to the second process group. Moreover, the fd of the process in the first process group is not closed.

采用该种方案,针对reload场景,过滤掉第一进程组的监听结构体中的fd,使得第二进程组中的进程不继承第一进程组的fd,而是针对第二进程组生成一组新的fd,即第二组fd,确保第一进程组的第一组fd和第二组fd不同,进而避免热更新时多个进程抢占同一个fd,确保热更新场景中UDP报文的分发不会错乱。Using this solution, for the reload scenario, filter out the fd in the listening structure of the first process group, so that the processes in the second process group do not inherit the fd of the first process group, but generate a group for the second process group. The new fd, that is, the second group of fd, ensures that the first group of fd and the second group of fd of the first process group are different, thereby preventing multiple processes from preempting the same fd during hot update and ensuring the distribution of UDP messages in the hot update scenario. There will be no confusion.

其次,升级场景。Secondly, upgrade the scene.

当对应用服务执行升级以创建第二进程组时,利用第一主进程向第二主进程传递环境变量,第一主进程是应用服务升级之前的主进程,第二主进程是应用服务升级之后的主进程。之后,当环境变量中存在携带预设标识的fd时,服务器关闭携带预设标识的fd。其中预设标识用于指示该fd是ebpf的fd。When an application service is upgraded to create a second process group, the first main process is used to pass environment variables to the second main process. The first main process is the main process before the application service is upgraded, and the second main process is after the application service is upgraded. the main process. Afterwards, when the fd carrying the preset identification exists in the environment variable, the server closes the fd carrying the preset identification. The preset identifier is used to indicate that the fd is the fd of ebpf.

这种场景中,master进程发生变化:升级之前为第一主进程,升级之后为新创建的第二主进程,整个进程空间都变了,替换为新的可执行程序,使得第二进程组无法得到第一进程组的监听结构体。新创建的第二进程组通过fork函数和execv函数产生。第一进程组中各进程的fd没有关闭。传统的基于Nginx的服务器,针对upgrade场景,服务器将第一进程组的旧的监听结构体的所有fd通过环境变量传递给新的主进程,即第二主进程。第二主进程通过环境变量得到这些fd后,设置到第二进程组的监听结构体中继续使用。In this scenario, the master process changes: it was the first master process before the upgrade, and it is the newly created second master process after the upgrade. The entire process space has changed and been replaced by a new executable program, making the second process group unable to Get the listening structure of the first process group. The newly created second process group is generated through the fork function and execv function. The fd of each process in the first process group is not closed. For traditional Nginx-based servers, for upgrade scenarios, the server passes all fds of the old listening structure of the first process group to the new main process, that is, the second main process, through environment variables. After the second main process obtains these fds through environment variables, it sets them in the listening structure of the second process group and continues to use them.

本案与传统方案的不同之处在于:本案中,利用环境变量传递fd时区分普通fd和ebpf的fd,对于ebpf的fd,对该fd添加预设标识,预设标识例如为b等,本申请实施例并不限制。例如,利用环境变量传递的fd包括12、13、b14和15,b14表示该fd是ebpf的fd,值为14。第二主进程解析出携带预设标识的fd后,关闭该fd,使得第二进程组不再继承该fd,服务器为第二进程组产生一组新的ebpf的fd,将这组fd设置到一个待用资源中得到第二进程组的ebpf资源。The difference between this case and the traditional solution is that in this case, when using environment variables to transfer fd, it distinguishes between ordinary fd and ebpf fd. For ebpf fd, a preset identification is added to the fd. The preset identification is, for example, b, etc. This application The examples are not limiting. For example, the fd passed by the environment variable includes 12, 13, b14 and 15. b14 indicates that the fd is the fd of ebpf, and the value is 14. After the second main process parses out the fd carrying the preset identifier, it closes the fd so that the second process group no longer inherits the fd. The server generates a new set of ebpf fd for the second process group and sets this set of fd to Obtain the ebpf resource of the second process group from a standby resource.

采用该种方案,针对upgrade的场景,由于主进程发生变化,通过环境变量传递并区分fd,关闭携带预设标识的fd使得第二进程组不继承该fd,而是针对第二进程组生成一组新的fd,即第二组fd,确保第一进程组的第一组fd和第二组fd不同,进而避免升级时多个进程抢占同一个fd,确保升级场景中UDP报文的分发不会错乱。Using this solution, for the upgrade scenario, due to the change of the main process, the fd is passed and distinguished through the environment variable, and the fd carrying the preset identifier is closed so that the second process group does not inherit the fd, but generates a fd for the second process group. Group a new fd, that is, the second group of fd, to ensure that the first group of fd and the second group of fd in the first process group are different, thereby preventing multiple processes from preempting the same fd during the upgrade, and ensuring that the distribution of UDP packets in the upgrade scenario is not will be confused.

升级时,很有可能存在升级失败的场景。这种情况下,服务器利用第一主进程创建第三进程组,关闭第三进程组的监听结构体中的fd。之后,服务器针对第三进程组生成第三组fd,并根据第三组fd创建第三进程组对应的ebpf资源。When upgrading, there may be a scenario where the upgrade fails. In this case, the server uses the first main process to create a third process group and closes the fd in the third process group's listening structure. Afterwards, the server generates a third group of fds for the third process group, and creates an ebpf resource corresponding to the third process group based on the third group of fds.

示例性的,如果升级失败,旧的主进程,即第一主进程再次启动一组worker进程,这组work进程即为第三进程组。例如,一个应用服务有一个第一进程组,如果升级成功,则新的主进程,即第二主进程创建第二进程组。但是,升级失败,第一主进程会创建一个第三进 程组。倘若采用现有的方案,由于第一主进程并未修改第一进程组的监听结构体,所以第三进程组的fd和第一进程组的fd相同,就会出现问题。而且,第一进程组在到达退出时间时会退出。本申请实施例中,会给第三进程组重新产生一组fd,即第三组fd,将该第三组fd设置到一个待用资源中从而得到第三进程组的ebpf资源。也就是说,第一主进程创建第三进程组时,根据第三进程组得到一组新的fd,即第三组fd,将第三组fd通过ebpf接口加入到动态数组(reuseport array)中。后续新的UDP报文就分发给第三进程组中的fd,接着启动第三进程组,第三进程组中的工作进程使用新的fd服务。For example, if the upgrade fails, the old main process, that is, the first main process, starts a group of worker processes again, and this group of worker processes is the third process group. For example, an application service has a first process group. If the upgrade is successful, a new main process, that is, the second main process, creates a second process group. However, if the upgrade fails, the first main process will create a third process Engineering group. If the existing solution is adopted, since the first main process does not modify the listening structure of the first process group, the fd of the third process group is the same as the fd of the first process group, and problems will occur. Moreover, the first process group will exit when the exit time is reached. In the embodiment of this application, a group of fds, that is, the third group of fds, will be regenerated for the third process group, and the third group of fds will be set to a standby resource to obtain the ebpf resource of the third process group. That is to say, when the first main process creates the third process group, it obtains a new set of fds based on the third process group, that is, the third group of fds, and adds the third group of fds to the dynamic array (reuseport array) through the ebpf interface. . Subsequent new UDP messages are distributed to fd in the third process group, and then the third process group is started. The worker processes in the third process group use the new fd service.

采用该种方案,升级失败时旧的master进程重启一个进程组,针对该新的进程组生成fd以使得该新的进程组具有独立的ebpf资源,确保升级失败时不会发生UDP报文分发错乱的现象,实现提高业务质量的目的。Using this solution, when the upgrade fails, the old master process restarts a process group, and generates fd for the new process group so that the new process group has independent ebpf resources to ensure that UDP message distribution will not be disordered when the upgrade fails. phenomenon to achieve the purpose of improving business quality.

上述实施例中,着重描述了reload和upgrade时,同时存在至少两个进程组时如何确保UDP报文的分发不会错乱。还有一种场景:多个进程组中最新创建的进程组中存在异常进程,这种场景同样会导致UDP报文的收发出现错乱。下面,对如何解决异常进程带来的数据错乱进行详细说明。In the above embodiment, the focus is on how to ensure that the distribution of UDP messages will not be disordered when at least two process groups exist at the same time during reload and upgrade. There is another scenario: there is an abnormal process in the newly created process group among multiple process groups. This scenario will also cause confusion in the sending and receiving of UDP messages. Below, we provide a detailed explanation of how to solve the data confusion caused by abnormal processes.

服务器确定出多个进程组中最新创建的进程组中存在异常进程后,针对该最新创建的进程组创建一个新的worker进程,该worker进程的fd即为异常进程的fd。After the server determines that an abnormal process exists in the newly created process group among multiple process groups, it creates a new worker process for the newly created process group. The fd of the worker process is the fd of the abnormal process.

示例性的,无论是reload还是upgrade的,最新创建的进程组中的某个进程可能会因为bug存在的原因出现异常,该进程即为异常进程或挂掉的进程。例如,最新创建的进程组中包含7个进程,当7个进程中的一个进程出现异常时,剩下6个正常进程,倘若采用现有技术,则服务器维护的哈希表将会错乱,进而导致UDP报文分发错乱。本案中,当最新创建的进程组中出现异常进程时,主进程(reload场景下,主进程为第一主进程,upgrade场景下,主进程为第二主进程)重启一个worker进程,并worker进程继续沿用异常进程的fd。这样一来,主进程根据最新创建的进程组中的每个进程的序号关联fd,使得重新创建的worker进程可以接收UDP报文。For example, whether it is reload or upgrade, a process in the newly created process group may be abnormal due to the existence of bugs. This process is an abnormal process or a hung process. For example, the newly created process group contains 7 processes. When one of the 7 processes becomes abnormal, there are 6 normal processes left. If the existing technology is used, the hash table maintained by the server will be disordered, and thus This leads to confusion in UDP packet distribution. In this case, when an abnormal process occurs in the newly created process group, the main process (in the reload scenario, the main process is the first main process, in the upgrade scenario, the main process is the second main process) restarts a worker process, and the worker process Continue to use the fd of the abnormal process. In this way, the main process associates fd according to the sequence number of each process in the newly created process group, so that the re-created worker process can receive UDP messages.

当旧进程组中出现异常进程时,由于已经创建新的进程组,旧进程组会在退出时间到达时退出。因此,服务器无需处理。旧进程组为多个进程组中除了最新创建的进程组外的其他进程组。例如,同时存在5个进程组,第5个进程组是最新创建的进程组,其他4个进程组是旧进程组。When an abnormal process occurs in the old process group, the old process group will exit when the exit time is reached because a new process group has been created. Therefore, no processing is required by the server. The old process group is a process group among multiple process groups except the latest created process group. For example, 5 process groups exist at the same time, the 5th process group is the latest created process group, and the other 4 process groups are old process groups.

另外,倘若未执行reload或upgrade,则只有一个进程组,同样存在出现异常进程的现象,处理方式同样,即master进程创建一个新的worker进程,该worker进程沿用异常进程的fd。 In addition, if reload or upgrade is not executed, there is only one process group, and there is also the phenomenon of abnormal processes. The processing method is the same, that is, the master process creates a new worker process, and the worker process inherits the fd of the abnormal process.

采用该种方案,当进程组中出现异常进程时,master进程重新创建一个worker进程并沿用异常进程的fd,确保出现异常进程时UDP报文的分发不会错乱,实现提高业务质量的目的。Using this solution, when an abnormal process occurs in the process group, the master process re-creates a worker process and uses the fd of the abnormal process to ensure that the distribution of UDP packets will not be disordered when an abnormal process occurs, thereby achieving the purpose of improving service quality.

可选的,在一些实施例中,服务器维护一个动态数组(reuseport array)。每次创建进程组后,服务器将本次创建的进程组的ebpf资源作为一个元素存储在动态数组中。当动态数组中元素的个数大于或等于第一个数时,服务器按照多个进程组中进程组的创建顺序清理最先创建的进程组的元素后,将本次创建的进程组的ebpf资源存储在动态数组中。Optionally, in some embodiments, the server maintains a dynamic array (reuseport array). Each time a process group is created, the server stores the ebpf resource of the process group created this time as an element in a dynamic array. When the number of elements in the dynamic array is greater than or equal to the first number, the server clears the elements of the first created process group in the order in which the process groups are created, and then adds the ebpf resources of the process group created this time. Stored in dynamic array.

示例性的,对于reload场景,每reload一次就会产生一个新的进程组,由于主进程并没有变,因此不会调用exit_master接口进行资源清理。其中,exit_master接口是服务器注册的一个用于完成资源回收工作的接口。For example, in the reload scenario, a new process group will be generated every time it is reloaded. Since the main process has not changed, the exit_master interface will not be called to clean up resources. Among them, the exit_master interface is an interface registered by the server to complete resource recycling.

服务器预先定义第一个数,即同时最多存在的进程组的个数。每次创建进程组后,服务器将该进程组的ebpf资源作为一个元素存储在动态数组中。当动态数组中元素的个数首次达到第一个数时,表示预先创建的资源集合中的待用资源已经使用完。后续再次创建进程组时需要将最先创建的进程组对应的ebpf资源从动态数组中清理掉从而释放该ebpf资源,这样一来,创建新的进程组后,该新的进程组就有ebpf资源可用。The server pre-defines the first number, which is the maximum number of process groups that can exist at the same time. Each time a process group is created, the server stores the ebpf resource of the process group as an element in a dynamic array. When the number of elements in the dynamic array reaches the first number for the first time, it means that the resources to be used in the pre-created resource collection have been used up. When you create a process group again later, you need to clear the ebpf resource corresponding to the first created process group from the dynamic array to release the ebpf resource. In this way, after creating a new process group, the new process group will have ebpf resources. Available.

采用该种方案,针对reload场景,循环利用ebpf资源,确保应用服务能够多次reload,通过及时对应用服务进行热更新,实现提高业务质量的目的。This solution is used to recycle ebpf resources for reload scenarios to ensure that application services can be reloaded multiple times. By hot updating application services in a timely manner, the purpose of improving service quality is achieved.

针对upgrade的场景,每次创建新的进程组后,master进程发生变化,新的master进程调用exit_master接口进行资源清理,通过及时清理资源,确保应用服务能多次upgrade,通过及时对应用服务进行升级,实现提高业务质量的目的。For the upgrade scenario, every time a new process group is created and the master process changes, the new master process calls the exit_master interface to clean up resources. By cleaning up resources in a timely manner, it ensures that the application service can be upgraded multiple times, and the application service is upgraded in a timely manner. , to achieve the purpose of improving service quality.

上述实施例中,均是对服务器上的一个端口复用组同时存在至少两个进程组时,如何确保UDP报文的分发不会错乱。然而,一个服务器上具有多个UDP端口,每个UDP端口都可以作为端口复用组。对于每个端口复用组,服务器都采用本申请实施例所述的UDP报文分发方法进行UDP报文的分发,因此不会出现数据错乱的问题。In the above embodiments, when there are at least two process groups in a port multiplexing group on the server, how to ensure that the distribution of UDP messages will not be disordered. However, if there are multiple UDP ports on a server, each UDP port can be used as a port reuse group. For each port multiplexing group, the server uses the UDP message distribution method described in the embodiment of this application to distribute UDP messages, so there will be no problem of data confusion.

另外,基于UDP实现的流媒体协议包括SRT、QUIC等,可以为一个协议配置多个UDP端口,不同协议具有不同的UDP端口。每个UDP端口对应一个ebpf资源,如果有多个UDP端口则需要加载多份ebpf资源到内核。同时,每个端口的ebpf资源存储在不同的路径。In addition, streaming media protocols implemented based on UDP include SRT, QUIC, etc. Multiple UDP ports can be configured for one protocol, and different protocols have different UDP ports. Each UDP port corresponds to an ebpf resource. If there are multiple UDP ports, multiple copies of ebpf resources need to be loaded into the kernel. At the same time, the ebpf resources of each port are stored in different paths.

而且,不同端口是通过端口复用组来区分的,而端口复用组是以IP+端口(port),因此,同一个端口可以绑定至少两种IP协议时,端口复用组同时服务于至少两种IP协议。Moreover, different ports are distinguished by port multiplexing groups, and port multiplexing groups are based on IP + port. Therefore, when the same port can be bound to at least two IP protocols, the port multiplexing group simultaneously serves at least Two IP protocols.

例如,UDP端口为10080端口,该UDP端口同时绑定IPv4和IPV6,则该UDP端口可以视为两个复用端口,一个服务于IPV4,一个服务于IPV6。 For example, if the UDP port is port 10080, and the UDP port is bound to both IPv4 and IPV6, the UDP port can be regarded as two multiplexed ports, one serving IPV4 and the other serving IPV6.

采用该种方案,通过支持多端口,基于一个UDP端口可以创建多个端口复用组,灵活度高。Using this solution, by supporting multiple ports, multiple port reuse groups can be created based on one UDP port, which is highly flexible.

本申请实施例提供的UDP报文分发方法具有通用性,可同时适用于SRT、QUIC、WEBRTC等流媒体协议,能够解决多个进程组使用同一个UDP端口分发UDP报文导致的数据错乱的问题。下面,以SRT为例,对本申请实施例所述的UDP报文发送方法进行详细说明。示例性的,请参照图4,图4是本申请实施例提供的UDP报文分发方法中服务器内部新增模块的结构示意图。The UDP message distribution method provided by the embodiment of this application is universal and can be applied to streaming media protocols such as SRT, QUIC, WEBRTC, etc., and can solve the problem of data confusion caused by multiple process groups using the same UDP port to distribute UDP messages. . Below, taking SRT as an example, the UDP message sending method described in the embodiment of this application will be described in detail. For example, please refer to Figure 4, which is a schematic structural diagram of a new module inside the server in the UDP message distribution method provided by the embodiment of the present application.

请参照图4,服务器用于SRT时,相较于传统的服务器,该服务器上除了SRT模块(ngx_srt_moudle)外,新增ebpf模块(ngx_core_bpf_moudle),用于完成ebpf相关处理。ebpf模块注册两个接口,一个是初始化接口(ngx_core_bpf_int_moudle),一个是资源回收接口(ngx_core_bpf_exit_moudle_)。初始化接口用于完成ebpf资源的初始化以及加载工作,资源回收接口用于完成资源回收工作。由于本案主要是解决多个进程组使用同一个端口复用组导致的UDP报文分发错乱的问题,在master-worker模式下,所有的ebpf操作必须由master进程完成。Please refer to Figure 4. When the server is used for SRT, compared with the traditional server, in addition to the SRT module (ngx_srt_moudle), the ebpf module (ngx_core_bpf_moudle) is added to the server to complete ebpf related processing. The ebpf module registers two interfaces, one is the initialization interface (ngx_core_bpf_int_moudle), and the other is the resource recycling interface (ngx_core_bpf_exit_moudle_). The initialization interface is used to complete the initialization and loading of ebpf resources, and the resource recycling interface is used to complete resource recycling. Since this case is mainly to solve the problem of chaotic UDP packet distribution caused by multiple process groups using the same port multiplexing group, in master-worker mode, all ebpf operations must be completed by the master process.

本案中,一个reuseport组会有一个监听结构体,监听结构体具有套接字地址(sockaddr),若两个监听结构体的sockaddr相同,则这两个监听结构体对应一个reuseport组,若两个监听结构体的sockaddr不相同,则这两个监听结构体对应不同的reuseport组。一个UDP端口可能会存在一个、两个或更多的reuseport组。服务器在一个reuseport组的监听结构体中新增预设标识,表示该reuseport组采用本申请实施例的方案进行UDP报文的分发。In this case, a reuseport group will have a listening structure, and the listening structure has a socket address (sockaddr). If the sockaddr of the two listening structures is the same, then the two listening structures correspond to a reuseport group. If two If the sockaddr of the listening structures is different, the two listening structures correspond to different reuseport groups. A UDP port may have one, two or more reuseport groups. The server adds a preset identifier in the listening structure of a reuseport group, indicating that the reuseport group uses the solution of the embodiment of this application to distribute UDP messages.

本申请实施例中,为了使得服务器实施上述的UDP报文分发方法,主要修改包括以下五点:In the embodiment of this application, in order to enable the server to implement the above-mentioned UDP message distribution method, the main modifications include the following five points:

一、模块初始化工作。1. Module initialization work.

服务器在初始化接口中做初始化操作,而ebpf对服务器的内核版本有要求,倘若服务器的内核版本太低,则不支持本案的UDP报文分发方法。因此,服务器需要先判断内核版本,例如采用uname系统调用方式判断内核是否支持,如果内核不支持,则采用传统的基于UDP connect方式。若内核支持,则采用本申请实施例所述的UDP报文分发方法。The server performs initialization operations in the initialization interface, and ebpf has requirements for the server's kernel version. If the server's kernel version is too low, the UDP message distribution method in this case is not supported. Therefore, the server needs to first determine the kernel version. For example, the uname system call method is used to determine whether the kernel supports it. If the kernel does not support it, the traditional UDP-based connect method is used. If the kernel supports it, the UDP message distribution method described in the embodiment of this application is used.

倘若内核版本支持,服务器通过四元组从多个进程组中选择目标进程组,一个应用服务可同时存在多个进程组,一个进程组的各进程的fd为一组fd,视为一份ebpf资源。当一个UDP报文的四元组为新的四元组时,该UDP报文为新请求,新请求从新的进程组里获取目标fd;当一个UDP报文的四元组为旧的四元组时,该UDP报文为旧请求,从旧的进程组里获取目标fd。服务器每次创建一个新的进程组后,需要保存当前最新的进程组的序号。比 如,当前有一个进程组,则序号为1,执行一次reload产生一个新的进程组,新的进程组的序号为2,以此类推。If the kernel version supports it, the server selects the target process group from multiple process groups through a quadruple. An application service can have multiple process groups at the same time. The fd of each process in a process group is a group of fd, which is regarded as an ebpf resource. When the quadruple of a UDP message is a new quadruple, the UDP message is a new request, and the new request obtains the target fd from the new process group; when the quadruple of a UDP message is the old quadruple group, the UDP message is an old request, and the target fd is obtained from the old process group. Every time the server creates a new process group, it needs to save the latest sequence number of the process group. Compare For example, if there is currently a process group, the sequence number is 1. Executing a reload will generate a new process group, and the sequence number of the new process group will be 2, and so on.

新的进程组由应用层创建,由应用层负责清理工作。ebpf程序在内核工作,在模块初始化函数中设置好ebpf相关资源,比如动态数组(reuseport array),然后将ebpf程序加载到内核。The new process group is created by the application layer, which is responsible for cleanup work. The ebpf program works in the kernel. Set up ebpf related resources in the module initialization function, such as dynamic array (reuseport array), and then load the ebpf program into the kernel.

Reload场景中,master进程没有变,还是当前的master进程,reload时无需再次加载ebpf程序。因此,需要将ebpf的fd保存起来,多次reload时只需要加载之前的fd即可。保存方式采用文件系统关联的方式,使用bpf_obj_pin和bpf_pin_get方式。例如,将ebpf程序的句柄映射到文件系统的路径为:/sys/fs/bpf/udp_reuseport/udp_reuseport_prog,不同reuseport组的保存路径不同。In the reload scenario, the master process has not changed and is still the current master process. There is no need to load the ebpf program again when reloading. Therefore, the fd of ebpf needs to be saved. When reloading multiple times, only the previous fd needs to be loaded. The saving method adopts file system association method, using bpf_obj_pin and bpf_pin_get methods. For example, the path that maps the handle of the ebpf program to the file system is: /sys/fs/bpf/udp_reuseport/udp_reuseport_prog. The saving paths for different reuseport groups are different.

二、核心代码修改。2. Core code modification.

本案中,服务器是基于Nginx的服务器,Nginx是一个开源组件,需要对开源组件进行一些修改。In this case, the server is based on Nginx. Nginx is an open source component and requires some modifications to the open source component.

因为UDP没有连接的概念,当多进程时,每个进程具有fd,一个进程一个fd服务多个客户端。当执行reload或upgrade时,一个应用服务会同时存在多个进程组,旧进程组的fd继续服务旧请求,新请求由新进程组里的fd服务。传统的基于Nginx的服务器,当对应用服务执行reload或upgrade时,旧进程组中各个旧进程的fd会被关闭。本案中,通过修改Nginx组件,使得当对应用服务执行reload或upgrade时,旧进程组中各进程的fd不关闭。例如,上述的预设标识为1,则表示服务器的内核版本支持ebpf,这时候,每次创建新的进程组后,不关闭旧进程组中各进程的fd。Because UDP has no concept of connection, when there are multiple processes, each process has an fd, and one process and one fd serves multiple clients. When reload or upgrade is performed, an application service will have multiple process groups at the same time. The fd in the old process group continues to serve old requests, and new requests are served by the fd in the new process group. For traditional Nginx-based servers, when reloading or upgrading an application service, the fd of each old process in the old process group will be closed. In this case, by modifying the Nginx component, when reloading or upgrading the application service, the fd of each process in the old process group is not closed. For example, if the above default flag is 1, it means that the server's kernel version supports ebpf. At this time, every time a new process group is created, the fd of each process in the old process group will not be closed.

传统的基于Nginx的服务器,当对应用服务执行reload或upgrade时,旧进程组的监听结构体的fd都会通过继承的方式传递给新进程组的监听结构体,导致两个进程组的fd相同,无法设置到动态数组(reuseport array)中。为此,本申请实施例中,当内核版本支持ebpf,服务器采用本申请的UDP报文分发方法时,每次创建新的进程组后,不继承旧进程组中的fd,而是过滤掉旧进程组的监听结构体中的fd。具体做法是在旧循环(old cycle)里面将携带预设标识的fd,不传递给新的循环(cycle)。监听结构体用来存放监听信息,由master进程创建,每个worker进程都有监听结构体,监听结构体里存放的监听信息例如为fd等。本案中,每次产生一个新的进程组,新进程组里的进程并不继承旧进程组里的进程的fd。For traditional Nginx-based servers, when an application service is reloaded or upgraded, the fd of the listening structure of the old process group will be passed to the listening structure of the new process group through inheritance, resulting in the same fd of the two process groups. Cannot be set to a dynamic array (reuseport array). For this reason, in the embodiment of this application, when the kernel version supports ebpf and the server adopts the UDP message distribution method of this application, each time a new process group is created, the fd in the old process group will not be inherited, but the old one will be filtered out. fd in the listening structure of the process group. The specific method is to pass the fd carrying the preset identifier in the old cycle (old cycle) without passing it to the new cycle (cycle). The listening structure is used to store listening information and is created by the master process. Each worker process has a listening structure. The listening information stored in the listening structure is, for example, fd, etc. In this case, every time a new process group is created, the processes in the new process group do not inherit the fd of the processes in the old process group.

执行升级(upgrade)时,不同于reload。因为reload时主进程并没有变,所以可以得到旧进程的监听结构体。但是,执行upgrade时,主进程变了,新的主进程通过fork+execv方式产生,新的主进程会继承旧的主进程的所有监听的fd。新的主进程创建新的进程组时,关闭 继承的fd,并针对新的进程组生成新的fd。传统方案中,服务器将旧进程组的监听结构体的所有fd通过环境变量传递给新的master进程,在新的master进程通过环境变量得到fd后,给新的进程组使用。这就使得两个进程组中的不同进程使用同一个fd。本案中,对fd的传递和设置进行修改。传递过程中,为了区分普通fd和ebpf的fd,在ebpf的fd前面加一个预设标识,预设标识例如为b等,本申请实施例并不限制。例如,传递的fd包括12、13、b14和15,其中,b14表示ebpf的fd,值为14。新的master进程解析到ebpf的fd后,关闭该fd,新的进程组不继承该fd,新的master进程针对新的进程组产生一组新的fd,之后将该组新的fd加入到动态数组(reuseport array)中。When performing an upgrade, it is different from reload. Because the main process has not changed during reload, you can get the listening structure of the old process. However, when performing an upgrade, the main process changes. The new main process is generated through fork+execv. The new main process will inherit all the monitored fds of the old main process. When the new main process creates a new process group, it is shut down Inherited fd, and generate a new fd for the new process group. In the traditional solution, the server passes all the fds of the old process group's listening structure to the new master process through environment variables. After the new master process obtains the fds through environment variables, it is used by the new process group. This allows different processes in the two process groups to use the same fd. In this case, the transfer and setting of fd are modified. During the transfer process, in order to distinguish the ordinary fd from the fd of ebpf, a preset identifier is added in front of the fd of ebpf. The preset identifier is, for example, b, etc. This application embodiment is not limited. For example, the passed fd includes 12, 13, b14 and 15, where b14 represents the fd of ebpf and the value is 14. After the new master process parses the fd of ebpf, it closes the fd. The new process group does not inherit the fd. The new master process generates a new set of fd for the new process group, and then adds the new fd of the group to the dynamic in the reuseport array.

倘若升级失败,旧的master进程再次启动一组worker进程,即第三进程组。这种场景下因为旧的master进程并没有修改第一进程组的fd,所以第三进程组的fd还是第一进程组的fd,这两个进程组的fd相同,无法将第三进程组的fd设置到动态数组中。为此,本案中,将第三进程组的监听结构体中的fd关闭,针对第三进程组重新生成一组fd,即第三组fd,将第三组fd设置到动态数组中,后续新的请求就在第三组fd中获取目标fd,接着启动第三进程组中的worker进程,这些新启动的worker进程就可以使用新的fd服务了。If the upgrade fails, the old master process starts a group of worker processes again, that is, the third process group. In this scenario, because the old master process did not modify the fd of the first process group, the fd of the third process group is still the fd of the first process group. The fds of these two process groups are the same, and the fd of the third process group cannot be changed. fd is set to a dynamic array. For this reason, in this case, the fd in the listening structure of the third process group is closed, a group of fd is regenerated for the third process group, that is, the third group of fd, and the third group of fd is set to a dynamic array, and subsequent new The request obtains the target fd in the third group of fd, and then starts the worker process in the third process group. These newly started worker processes can use the new fd service.

本案中,由于一个reuseport组存在多个进程组,每个进程组中的每个进程有自己的fd处理UDP报文,所以在底层由内核使用ebpf方式确保UDP报文到达对应的进程即可。然后在进程内部通过四元组区分每个客户端的UDP报文。由进程决定一个UDP报文是去新进程还是旧进程,UDP报文到达进程后,应用层根据维护的客户端的信息,区分不同的连接。In this case, since there are multiple process groups in a reuseport group, each process in each process group has its own fd to process UDP packets, so at the bottom level, the kernel uses ebpf to ensure that UDP packets reach the corresponding process. Then the UDP messages of each client are distinguished by four-tuple within the process. The process decides whether a UDP packet goes to the new process or the old process. After the UDP packet reaches the process, the application layer distinguishes different connections based on the maintained client information.

三、异常场景解决。3. Solve abnormal scenarios.

本申请实施例中,异常场景包括:reload、upgrade和进程异常。In the embodiment of this application, abnormal scenarios include: reload, upgrade and process exception.

针对reload场景,应用服务的版本不会变化,但是会更新参数等。主进程不会退出,会重新加载配置。每次创建新的进程组时,主进程根据第一进程组创建出第二进程组,针对第二进程组产生一组新的fd,使得第一进程组和第二进程组的fd不同,每个进程组通过自己的fd接收UDP报文,保证UDP报文的分发不会错乱。For reload scenarios, the version of the application service will not change, but parameters, etc. will be updated. The main process will not exit and the configuration will be reloaded. Every time a new process group is created, the main process creates a second process group based on the first process group, and generates a new set of fd for the second process group, so that the fd of the first process group and the second process group are different. Each process group receives UDP messages through its own fd to ensure that the distribution of UDP messages will not be chaotic.

针对upgrade场景,应用服务升级,新版本的应用程序替换旧版本的应用程序。新的主进程加载新版本的可执行程序,然后新的主进程创建新的一组fd以及新的进程组。由于传统的Nginx会设置fd的继承,使得旧的进程组的fd会被继承到新的进程组,这对于TCP是没有问题的。但是针对UDP,因为使用了ebpf,需要为每个进程组分别设置一组fd才能保证这些进程组同时服务,不然,若两个或多个进程组的fd相同,则会发生UDP报文分发错乱。因此,本申请实施例中,新的进程组不继承旧的进程组的fd,而是对新的进程组创建一组新的fd,将新创建的fd加载到内核,后续每个进程组通过自己的fd分发UDP报文。 For the upgrade scenario, the application service is upgraded and the new version of the application replaces the old version of the application. The new main process loads a new version of the executable program, and then the new main process creates a new set of fd and a new process group. Since traditional Nginx will set up fd inheritance, the fd of the old process group will be inherited to the new process group, which is no problem for TCP. However, for UDP, because ebpf is used, a set of fds needs to be set for each process group to ensure that these process groups serve at the same time. Otherwise, if the fds of two or more process groups are the same, UDP message distribution chaos will occur. . Therefore, in the embodiment of this application, the new process group does not inherit the fd of the old process group, but creates a new set of fd for the new process group, loads the newly created fd into the kernel, and then each process group passes Its own fd distributes UDP messages.

针对进程异常(coredump)场景,统一在master进程分配各个worker进程的fd,然后通过内核接口加载进入和ebpf关联。此时内核维护一组fd,这些fd内部通过reuseport监听同一个端口,确保数据不会错乱。当某个worker进程挂掉时,master进程会重新拉起一个新的worker进程,fd仍然是挂掉的进程,即异常进程的fd。主进程会根据每个worker进程的序号关联之前的fd,所以重新拉起的进程仍然可以接收UDP报文。For process exception (coredump) scenarios, the fd of each worker process is uniformly allocated in the master process, and then loaded into and associated with ebpf through the kernel interface. At this time, the kernel maintains a group of fds. These fds internally listen to the same port through reuseport to ensure that the data will not be confused. When a worker process dies, the master process will restart a new worker process, and the fd is still the hung process, that is, the fd of the abnormal process. The main process will associate the previous fd according to the sequence number of each worker process, so the restarted process can still receive UDP messages.

四、多端口问题。4. Multi-port problem.

本申请实施例中,一个流媒体协议可以配置多个端口,不同协议配置不同端口,协议包括SRT、QUIC等。这样一来,服务器上就会存在多个reuseport组,不同reuseport组对应不同的ebpf资源,不同的reuseport对应不同的UDP端口或者同一个UDP端口。例如,端口123为支持SRT的端口,端口123是一个reuseport组,端口111为支持QUIC的端口,端口111是一个reuseport组。再如,端口10080同时绑定IPv4和IPv6,则端口10080对应两个reuseport组,端口10080同时服务于IPv4和IPv6。当存在多个reuseport组时,多个reuseport组中每个reuseport组有自己的ebpf资源,而每个reuseport组具有多个进程组,每个进程组也有独立的ebpf资源。In the embodiment of this application, one streaming media protocol can be configured with multiple ports, and different protocols are configured with different ports. The protocols include SRT, QUIC, etc. In this way, there will be multiple reuseport groups on the server. Different reuseport groups correspond to different ebpf resources, and different reuseports correspond to different UDP ports or the same UDP port. For example, port 123 is a port that supports SRT, port 123 is a reuseport group, port 111 is a port that supports QUIC, and port 111 is a reuseport group. For another example, if port 10080 is bound to both IPv4 and IPv6, then port 10080 corresponds to two reuseport groups, and port 10080 serves both IPv4 and IPv6. When there are multiple reuseport groups, each reuseport group in the multiple reuseport groups has its own ebpf resource, and each reuseport group has multiple process groups, and each process group also has independent ebpf resources.

当存在多个reuseport组时,需要将每个reuseport组的ebpf资源加载到内核。同时,设置ebpf资源和文件系统关联时需要做区分,可通过命名方式区分:When there are multiple reuseport groups, the ebpf resources of each reuseport group need to be loaded into the kernel. At the same time, it is necessary to distinguish when setting the association between ebpf resources and file systems, which can be distinguished by naming:

/sys/fs/bpf/udp_reuseport_10080/udp_reuseport_prog表示10080端口;/sys/fs/bpf/udp_reuseport_10080/udp_reuseport_prog indicates port 10080;

/sys/fs/bpf/udp_reuseport_10081/udp_reuseport_prog表示10081端口。/sys/fs/bpf/udp_reuseport_10081/udp_reuseport_prog indicates port 10081.

本案中,不同的UDP端口通过reuseport组来区分,而reuseport组通过IP+Port区分。当一个UDP端口绑定两种或以上IP协议时,一个UDP端口可创建两个及以上的reuseport组。比如,上述的端口10080绑定IPv4和IPv6时,会创建两个reuseport组,每组都会走ebpf流程。In this case, different UDP ports are distinguished by reuseport groups, and reuseport groups are distinguished by IP+Port. When a UDP port is bound to two or more IP protocols, one UDP port can create two or more reuseport groups. For example, when the above port 10080 is bound to IPv4 and IPv6, two reuseport groups will be created, and each group will go through the ebpf process.

服务器遍历监听结构体,判断各监听结构体中的sockaddr,如果sockaddr相同,则认为该两个监听结构体对应的端口为同一个reuseport组,一起加载到ebpf中。每个reuseport组有多个进程组,每个进程组有多个进程,每个进程有自己的fd。The server traverses the listening structure and determines the sockaddr in each listening structure. If the sockaddr is the same, the ports corresponding to the two listening structures are considered to be the same reuseport group and are loaded into ebpf together. Each reuseport group has multiple process groups, each process group has multiple processes, and each process has its own fd.

五、资源回收问题。5. Resource recycling issues.

请参照图4,ebpf模块注册了两个接口,分别为初始化接口和资源回收接口,资源回收接口负载ebpf资源的清理操作。Upgrade场景中,主进程会发生变化,每次创建新的进程组后,ebpf模块调用资源回收接口进行资源回收。Please refer to Figure 4. The ebpf module has registered two interfaces, namely the initialization interface and the resource recycling interface. The resource recycling interface is responsible for the cleaning operation of ebpf resources. In the Upgrade scenario, the main process will change. Each time a new process group is created, the ebpf module calls the resource recycling interface to recycle resources.

Reload场景中,每reload一次就会产生一组ebpf资源,用于保存新进程组中各进程的fd的信息,这组fd后续会被设置到待用资源中从而产生新进程组的ebpf资源。但是,由于 主进程没有变,因此不会调用资源回收接口进行清理,导致每reload一次资源就会泄露一次。为了清理这组资源,传统方案是所有的worker进程退出后才可以清理,倘若在worker进程没有退出时就清理则会导致worker进程无法服务。但是现有方案中,没有机制得到一个进程组内所有worker进程退出的时机。因为服务器支持多次reload,每次reload的时候之前的旧的进程组可能并没结束,每个worker进程的退出时机不同,所以没法得知哪些worker进程是一组的。In the reload scenario, each reload will generate a set of ebpf resources to save the fd information of each process in the new process group. This group of fd will subsequently be set to standby resources to generate ebpf resources for the new process group. But due to The main process has not changed, so the resource recycling interface will not be called for cleaning, causing resources to be leaked every time they are reloaded. In order to clean up this set of resources, the traditional solution is to clean up after all worker processes have exited. If the worker process is cleared before it exits, the worker process will be unable to serve. However, in the existing solution, there is no mechanism to obtain the exit timing of all worker processes in a process group. Because the server supports multiple reloads, the old process group may not end during each reload. The exit timing of each worker process is different, so there is no way to know which worker processes belong to a group.

本案中,动态数组中的元素不能超过第一个数,第一个数例如是5个,本申请实施例并不限制。一旦元素的个数超过第一个数则需要清理,从而保证同时存在的元素的个数小于或等于第一个数,即同时存在的进程组的个数小于或等于第一个数。例如,第一个数为5,表示最多可以同时存在5个进程组,序号分别为0、1、2、3、4。每次针对新的进程组创建一组fd,得到一个ebpf资源后,将该ebpf资源作为一个元素存入动态数组的一个位置。存入之前判断该位置是否为空,如果不为空则先清理该位置原来保持的元素,然后将本次创建的元素保存到该位置。动态数组中有5个位置,分别为位置0~位置4。当位置0~位置4都保存了元素后,再次reload创建的元素会放到位置0,由于位置0不为空,则会对位置0对应的ebpf资源进程清理操作,比如释放内存等操作,关闭ebpf资源的fd。然后,将新创建的元素存入位置0。In this case, the elements in the dynamic array cannot exceed the first number. The first number is, for example, 5. This is not limited by the embodiment of the present application. Once the number of elements exceeds the first number, it needs to be cleaned up to ensure that the number of elements that exist at the same time is less than or equal to the first number, that is, the number of process groups that exist at the same time is less than or equal to the first number. For example, the first number is 5, which means that up to 5 process groups can exist at the same time, and the sequence numbers are 0, 1, 2, 3, and 4 respectively. Each time a group of fds is created for a new process group, and an ebpf resource is obtained, the ebpf resource is stored as an element in a position of the dynamic array. Before saving, determine whether the position is empty. If it is not empty, first clean up the elements originally held at the position, and then save the element created this time to this position. There are 5 positions in the dynamic array, namely position 0 to position 4. When elements are saved at positions 0 to 4, the elements created by reload will be placed at position 0. Since position 0 is not empty, the ebpf resource process corresponding to position 0 will be cleaned up, such as releasing memory and other operations, and will be closed. fd of ebpf resource. Then, store the newly created element at position 0.

下述为本申请装置实施例,可以用于执行本申请方法实施例。对于本申请装置实施例中未披露的细节,请参照本申请方法实施例。The following are device embodiments of the present application, which can be used to execute method embodiments of the present application. For details not disclosed in the device embodiments of this application, please refer to the method embodiments of this application.

图5为本申请实施例提供的一种UDP报文的分发装置的示意图。该UDP报文的分发装置500包括:收发模块51、处理模块52、选择模块53和分发模块54。Figure 5 is a schematic diagram of a UDP message distribution device provided by an embodiment of the present application. The UDP message distribution device 500 includes: a transceiver module 51 , a processing module 52 , a selection module 53 and a distribution module 54 .

收发模块51,用于接收来自终端设备的UDP报文;Transceiver module 51, used to receive UDP messages from terminal devices;

处理模块52,用于根据UDP报文携带的四元组从端口复用组的多个进程组中确定目标进程组,多个进程组是针对应用服务依次创建的多个进程组,多个进程组中的每个进程组具有独立的ebpf资源;The processing module 52 is configured to determine a target process group from multiple process groups in the port multiplexing group according to the quadruple group carried in the UDP message. The multiple process groups are multiple process groups created sequentially for the application service. The multiple processes Each process group in the group has independent ebpf resources;

选择模块53,用于从目标进程组的各进程的fd中选择出目标fd;The selection module 53 is used to select the target fd from the fd of each process in the target process group;

分发模块54,用于利用目标fd分发UDP报文。Distribution module 54 is used to distribute UDP messages using the target fd.

一种可行的实现方式中,处理模块52根据UDP报文携带的四元组从端口复用组的多个进程组中确定目标进程组之前,还用于每次创建进程组时,利用主进程创建第二进程组,第一进程组和第二进程组是所述多个进程组中先后创建的两个进程组,第一进程组对应第一组fd;针对第二进程组生成第二组fd;将第二组fd设置到资源集合中的待用资源中以得到 ebpf资源,资源集合中存储预先创建好的待用资源,资源集合中待用资源的第一个数与端口复用组的进程组的最大个数相同,多个进程组中进程组的第二个数小于或等于第一个数。In a feasible implementation, before the processing module 52 determines the target process group from multiple process groups in the port multiplexing group according to the quadruple carried in the UDP message, it is also used to use the main process each time a process group is created. Create a second process group. The first process group and the second process group are two process groups created successively among the plurality of process groups. The first process group corresponds to the first group of fd; generate a second group for the second process group. fd; set the second group of fd to the resources to be used in the resource collection to get ebpf resource, the resource collection stores pre-created resources to be used. The first number of the resources to be used in the resource collection is the same as the maximum number of process groups in the port multiplexing group. The second number of process groups in multiple process groups The number is less than or equal to the first number.

一种可行的实现方式中,处理模块52针对第二进程组生成第二组fd之前,还用于当对应用服务执行热更新以创建第二进程组时,过滤掉第一进程组的监听结构体中的fd,第一进程组和第二进程组均由第一主进程创建。In a feasible implementation, before the processing module 52 generates the second group of fd for the second process group, it is also used to filter out the listening structure of the first process group when performing a hot update on the application service to create the second process group. In the fd in the body, the first process group and the second process group are both created by the first main process.

一种可行的实现方式中,处理模块52,还用于每次创建进程组后,将本次创建的进程组的ebpf资源作为一个元素存储在动态数组中;当动态数组中元素的个数大于或等于第一个数时,按照多个进程组中进程组的创建顺序清理最先创建的进程组的元素后,将本次创建的进程组的ebpf资源存储在动态数组中。In a feasible implementation, the processing module 52 is also used to store the ebpf resource of the process group created this time as an element in a dynamic array after each process group is created; when the number of elements in the dynamic array is greater than or equal to the first number, after cleaning the elements of the first created process group in the order in which the process groups among multiple process groups are created, the ebpf resources of the process group created this time are stored in a dynamic array.

一种可行的实现方式中,处理模块52针对第二进程组生成第二组fd之前,还用于当对应用服务执行升级以创建第二进程组时,利用第一主进程向第二主进程传递环境变量,第一主进程是应用服务升级之前的主进程,第二主进程是应用服务升级之后的主进程;当环境变量中存在携带预设标识的fd时,关闭携带预设标识的fd。In a feasible implementation, before the processing module 52 generates the second group of fd for the second process group, it is also used to use the first main process to the second main process when upgrading the application service to create the second process group. Pass the environment variable. The first main process is the main process before the application service upgrade, and the second main process is the main process after the application service upgrade. When there is an fd carrying a preset identification in the environment variable, close the fd carrying the preset identification. .

一种可行的实现方式中,处理模块52,还用于每次创建进程组后,调用资源回收接口清理第一进程组的ebpf资源。In a feasible implementation manner, the processing module 52 is also used to call the resource recovery interface to clean up the ebpf resources of the first process group each time the process group is created.

一种可行的实现方式中,处理模块52,还用于当应用服务升级失败时,利用第一主进程创建第三进程组;关闭第三进程组的监听结构体中的fd;针对第三进程组生成第三组fd;根据第三组fd创建第三进程组对应的ebpf资源。In a feasible implementation, the processing module 52 is also used to use the first main process to create a third process group when the application service upgrade fails; close the fd in the listening structure of the third process group; target the third process The group generates the third group of fd; create the ebpf resource corresponding to the third process group based on the third group of fd.

一种可行的实现方式中,处理模块52,还用于确定多个进程组中最新创建的进程组中存在异常进程;针对最新创建的进程组创建新的worker进程,worker进程的文件句柄为异常进程的fd。In a feasible implementation, the processing module 52 is also used to determine that there is an abnormal process in the latest created process group among multiple process groups; create a new worker process for the newly created process group, and the file handle of the worker process is abnormal. fd of the process.

一种可行的实现方式中,当端口复用组对应的UDP端口绑定至少两种IP协议时,UDP端口同时服务于至少两种IP协议。In a feasible implementation manner, when the UDP port corresponding to the port multiplexing group is bound to at least two IP protocols, the UDP port serves at least two IP protocols at the same time.

[0145]一种可行的实现方式中,ebpf资源用于保存对应进程组中每个进程的文件句柄fd的信息,多个进程组中进程组的个数大于或等于2。[0145] In a feasible implementation manner, the ebpf resource is used to save the information of the file handle fd of each process in the corresponding process group, and the number of process groups in multiple process groups is greater than or equal to 2.

本申请实施例提供的UDP报文的分发装置,可以执行上述实施例中服务器的动作,其实现原理和技术效果类似,在此不再赘述。The UDP message distribution device provided by the embodiment of the present application can perform the actions of the server in the above embodiment. Its implementation principles and technical effects are similar and will not be described again here.

图6为本申请实施例提供的一种电子设备的结构示意图。如图6所示,该电子设备600例如为上述的调控中心或抗攻击节点,该电子设备600包括:FIG. 6 is a schematic structural diagram of an electronic device provided by an embodiment of the present application. As shown in Figure 6, the electronic device 600 is, for example, the above-mentioned control center or anti-attack node. The electronic device 600 includes:

处理器61和存储器62;Processor 61 and memory 62;

存储器62存储计算机指令; Memory 62 stores computer instructions;

处理器61执行存储器62存储的计算机指令,使得处理器61执行如上服务器实施的UDP报文的分发方法。The processor 61 executes the computer instructions stored in the memory 62, so that the processor 61 executes the UDP message distribution method implemented by the server as above.

处理器61的具体实现过程可参见上述方法实施例,其实现原理和技术效果类似,本实施例此处不再赘述。The specific implementation process of the processor 61 can be found in the above method embodiments. The implementation principles and technical effects are similar and will not be described again in this embodiment.

可选地,该电子设备600还包括通信部件63。其中,处理器61、存储器62以及通信部件63可以通过总线64连接。Optionally, the electronic device 600 further includes a communication component 63 . Among them, the processor 61, the memory 62 and the communication component 63 can be connected through the bus 64.

本申请实施例还提供一种计算机可读存储介质,计算机可读存储介质中存储有计算机指令,计算机指令被处理器执行时用于实现如上服务器实施的UDP报文的分发方法。Embodiments of the present application also provide a computer-readable storage medium. Computer instructions are stored in the computer-readable storage medium. When the computer instructions are executed by a processor, they are used to implement the UDP message distribution method implemented by the server as above.

本申请实施例还提供一种计算机程序产品,该计算机程序产品包含计算机程序,计算机程序被处理器执行时实现如上服务器实施的UDP报文的分发方法。Embodiments of the present application also provide a computer program product. The computer program product includes a computer program. When the computer program is executed by a processor, the UDP message distribution method implemented by the server is implemented as above.

本领域技术人员在考虑说明书及实践这里公开的申请后,将容易想到本申请的其它实施方案。本申请旨在涵盖本申请的任何变型、用途或者适应性变化,这些变型、用途或者适应性变化遵循本申请的一般性原理并包括本申请未公开的本技术领域中的公知常识或惯用技术手段。说明书和实施例仅被视为示例性的,本申请的真正范围和精神由下面的权利要求书指出。Other embodiments of the present application will be readily apparent to those skilled in the art from consideration of the specification and practice of the application disclosed herein. This application is intended to cover any variations, uses, or adaptations of this application that follow the general principles of this application and include common knowledge or customary technical means in the technical field that are not disclosed in this application. . It is intended that the specification and examples be considered as exemplary only, with a true scope and spirit of the application being indicated by the following claims.

应当理解的是,本申请并不局限于上面已经描述并在附图中示出的精确结构,并且可以在不脱离其范围进行各种修改和改变。本申请的范围仅由所附的权利要求书来限制。 It is to be understood that the present application is not limited to the precise structures described above and illustrated in the accompanying drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the application is limited only by the appended claims.

Claims (12)

一种UDP报文的分发方法,包括:A UDP message distribution method, including: 接收来自终端设备的UDP报文;Receive UDP messages from terminal devices; 根据所述UDP报文携带的四元组从端口复用组的多个进程组中确定目标进程组,所述多个进程组是针对应用服务依次创建的多个进程组,所述多个进程组中的每个进程组具有独立的ebpf资源;The target process group is determined from multiple process groups in the port multiplexing group according to the four-tuple carried in the UDP message. The multiple process groups are multiple process groups created in sequence for application services. The multiple processes Each process group in the group has independent ebpf resources; 从所述目标进程组的各进程的fd中选择出目标fd;Select the target fd from the fd of each process in the target process group; 利用所述目标fd分发所述UDP报文。Use the target fd to distribute the UDP message. 根据权利要求1所述的方法,其中,所述根据所述UDP报文携带的四元组从端口复用组的多个进程组中确定目标进程组之前,还包括:The method according to claim 1, wherein before determining the target process group from multiple process groups in the port multiplexing group according to the quadruple carried in the UDP message, it further includes: 每次创建进程组时,利用主进程创建第二进程组,第一进程组和所述第二进程组是所述多个进程组中先后创建的两个进程组,所述第一进程组对应第一组fd;Each time a process group is created, the main process is used to create a second process group. The first process group and the second process group are two process groups created successively among the plurality of process groups. The first process group corresponds to The first group fd; 针对所述第二进程组生成第二组fd;Generate a second group of fds for the second process group; 将所述第二组fd设置到资源集合中的待用资源中以得到所述ebpf资源,所述资源集合中存储预先创建好的待用资源,所述资源集合中待用资源的第一个数与所述端口复用组的进程组的最大个数相同,所述多个进程组中进程组的第二个数小于或等于所述第一个数。The second group of fd is set to the standby resources in the resource set to obtain the ebpf resource. The resource set stores pre-created standby resources. The first standby resource in the resource set is The number is the same as the maximum number of process groups in the port multiplexing group, and the second number of process groups in the plurality of process groups is less than or equal to the first number. 根据权利要求2所述的方法,其中,所述针对所述第二进程组生成第二组fd之前,还包括:The method according to claim 2, wherein before generating the second group of fd for the second process group, the method further includes: 当对所述应用服务执行热更新以创建所述第二进程组时,过滤掉所述第一进程组的监听结构体中的fd,所述第一进程组和所述第二进程组均由第一主进程创建。When hot updating is performed on the application service to create the second process group, the fd in the listening structure of the first process group is filtered out. The first process group and the second process group are both composed of The first main process is created. 根据权利要求2或3所述的方法,其中,还包括:The method according to claim 2 or 3, further comprising: 每次创建进程组后,将本次创建的进程组的所述ebpf资源作为一个元素存储在动态数组中;Each time a process group is created, the ebpf resource of the process group created this time is stored as an element in a dynamic array; 当动态数组中元素的个数大于或等于所述第一个数时,按照所述多个进程组中进程组的创建顺序清理最先创建的进程组的元素后,将本次创建的进程组的所述ebpf资源存储在所述动态数组中。When the number of elements in the dynamic array is greater than or equal to the first number, after cleaning the elements of the first created process group according to the creation order of the process groups among the multiple process groups, the process group created this time will be The ebpf resources are stored in the dynamic array. 根据权利要求2所述的方法,其中,所述针对所述第二进程组生成第二组fd之前,还包括:The method according to claim 2, wherein before generating the second group of fd for the second process group, the method further includes: 当对所述应用服务执行升级以创建所述第二进程组时,利用第一主进程向第二主进程传递环境变量,所述第一主进程是所述应用服务升级之前的主进程,所述第二主进程是所述应用服务升级之后的主进程; When the application service is upgraded to create the second process group, the first main process is used to transfer environment variables to the second main process. The first main process is the main process before the application service is upgraded, so The second main process is the main process after the application service is upgraded; 当所述环境变量中存在携带预设标识的fd时,关闭所述携带预设标识的fd。When the fd carrying the preset identification exists in the environment variable, the fd carrying the preset identification is closed. 根据权利要求5所述的方法,其中,还包括:The method of claim 5, further comprising: 每次创建进程组后,调用资源回收接口清理所述第一进程组的ebpf资源。Each time a process group is created, the resource recovery interface is called to clean up the ebpf resources of the first process group. 根据权利要求5或6所述的方法,其中,还包括:The method according to claim 5 or 6, further comprising: 当所述应用服务升级失败时,利用所述第一主进程创建第三进程组;When the application service upgrade fails, use the first main process to create a third process group; 关闭所述第三进程组的监听结构体中的fd;Close the fd in the listening structure of the third process group; 针对所述第三进程组生成第三组fd;Generate a third group of fds for the third process group; 根据所述第三组fd创建所述第三进程组对应的所述ebpf资源。Create the ebpf resource corresponding to the third process group according to the third group of fd. 根据权利要求1-7中任一项所述的方法,其中,还包括:The method according to any one of claims 1-7, further comprising: 确定所述多个进程组中最新创建的进程组中存在异常进程;Determine that there is an abnormal process in the latest created process group among the multiple process groups; 针对所述最新创建的进程组创建新的worker进程,所述worker进程的文件句柄fd为所述异常进程的fd。Create a new worker process for the newly created process group, and the file handle fd of the worker process is the fd of the abnormal process. 根据权利要求1-8中任一项所述的方法,其中,The method according to any one of claims 1-8, wherein, 当所述端口复用组对应的UDP端口绑定至少两种IP协议时,所述UDP端口同时服务于所述至少两种IP协议。When the UDP port corresponding to the port multiplexing group is bound to at least two IP protocols, the UDP port serves the at least two IP protocols at the same time. 根据权利要求1-9任一项所述的方法,其中,The method according to any one of claims 1-9, wherein, 所述ebpf资源用于保存对应进程组中每个进程的文件句柄fd的信息,所述多个进程组中进程组的个数大于或等于2。The ebpf resource is used to save information corresponding to the file handle fd of each process in the process group, and the number of process groups in the plurality of process groups is greater than or equal to 2. 一种电子设备,包括处理器、存储器及存储在所述存储器上并可在所述处理器上运行的计算机程序,所述处理器执行所述计算机程序时使得所述电子设备实现如权利要求1-9中任一所述的方法。An electronic device, including a processor, a memory, and a computer program stored on the memory and executable on the processor. When the processor executes the computer program, the electronic device implements the method of claim 1 Methods described in any one of -9. 一种计算机可读存储介质,其上存储有计算机程序,所述计算机程序被处理器执行时实现如权利要求1-9中任一所述的方法。 A computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the method according to any one of claims 1-9 is implemented.
PCT/CN2023/094581 2022-05-20 2023-05-16 Udp message distribution method, device and readable storage medium Ceased WO2023221990A1 (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
EP23800303.2A EP4529137A4 (en) 2022-05-20 2023-05-16 UDP message distribution method, apparatus and readable storage medium
US18/506,048 US12120203B2 (en) 2022-05-20 2023-11-09 UDP message distribution method, UDP message distribution apparatus, electronic device and computer readable storage medium

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202210556806.3A CN115118791B (en) 2022-05-20 2022-05-20 UDP message distribution method, device and readable storage medium
CN202210556806.3 2022-05-20

Related Child Applications (1)

Application Number Title Priority Date Filing Date
US18/506,048 Continuation US12120203B2 (en) 2022-05-20 2023-11-09 UDP message distribution method, UDP message distribution apparatus, electronic device and computer readable storage medium

Publications (1)

Publication Number Publication Date
WO2023221990A1 true WO2023221990A1 (en) 2023-11-23

Family

ID=83325501

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2023/094581 Ceased WO2023221990A1 (en) 2022-05-20 2023-05-16 Udp message distribution method, device and readable storage medium

Country Status (4)

Country Link
US (1) US12120203B2 (en)
EP (1) EP4529137A4 (en)
CN (1) CN115118791B (en)
WO (1) WO2023221990A1 (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115118791B (en) 2022-05-20 2023-09-22 网宿科技股份有限公司 UDP message distribution method, device and readable storage medium

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102508713A (en) * 2011-10-12 2012-06-20 杭州华三通信技术有限公司 Progress starting method, kernel and progress
CN113132356A (en) * 2021-03-23 2021-07-16 网宿科技股份有限公司 UDP (user Datagram protocol) message distribution method, equipment and storage medium
CN113630439A (en) * 2021-06-30 2021-11-09 网宿科技股份有限公司 Real-time communication RTC connection method, server and storage medium
CN113765867A (en) * 2020-08-12 2021-12-07 北京沃东天骏信息技术有限公司 Data transmission method, device, equipment and storage medium
CN115118791A (en) * 2022-05-20 2022-09-27 网宿科技股份有限公司 UDP message distribution method, device and readable storage medium

Family Cites Families (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2005092265A (en) * 2003-09-12 2005-04-07 Nec Corp Data distribution system, server system, receiving terminal, data distribution method used for same and its program
CN100361430C (en) * 2004-08-11 2008-01-09 华为技术有限公司 A method of data transmission
CN105930191B (en) * 2016-04-28 2019-01-04 网宿科技股份有限公司 The overloaded method and device of system service
CN108228366B (en) * 2017-12-29 2022-01-25 北京奇虎科技有限公司 Data stream processing method and device
US10742557B1 (en) * 2018-06-29 2020-08-11 Juniper Networks, Inc. Extending scalable policy management to supporting network devices
WO2020015838A1 (en) * 2018-07-20 2020-01-23 Nokia Solutions And Networks Oy Zero trust perimeterization for microservices
US11314614B2 (en) * 2020-01-02 2022-04-26 Sri International Security for container networks
WO2021252004A1 (en) * 2020-06-10 2021-12-16 Futurewei Technologies, Inc. Modular network services via distributed elastic middleboxes
CN113138836B (en) * 2021-04-14 2024-04-26 启明星辰信息技术集团股份有限公司 Escape prevention method using escape prevention system based on Docker container
CN113746930A (en) * 2021-09-09 2021-12-03 上海格尔安全科技有限公司 Network load balancing method and device, computer equipment and storage medium
CN114006839B (en) * 2021-09-27 2023-06-23 中盈优创资讯科技有限公司 Flow acquisition method and device based on eBPF
US11956221B2 (en) * 2021-12-16 2024-04-09 Cisco Technology, Inc. Encrypted data packet forwarding

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102508713A (en) * 2011-10-12 2012-06-20 杭州华三通信技术有限公司 Progress starting method, kernel and progress
CN113765867A (en) * 2020-08-12 2021-12-07 北京沃东天骏信息技术有限公司 Data transmission method, device, equipment and storage medium
CN113132356A (en) * 2021-03-23 2021-07-16 网宿科技股份有限公司 UDP (user Datagram protocol) message distribution method, equipment and storage medium
CN113630439A (en) * 2021-06-30 2021-11-09 网宿科技股份有限公司 Real-time communication RTC connection method, server and storage medium
CN115118791A (en) * 2022-05-20 2022-09-27 网宿科技股份有限公司 UDP message distribution method, device and readable storage medium

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
See also references of EP4529137A4 *

Also Published As

Publication number Publication date
CN115118791A (en) 2022-09-27
CN115118791B (en) 2023-09-22
EP4529137A1 (en) 2025-03-26
US20240089352A1 (en) 2024-03-14
US12120203B2 (en) 2024-10-15
EP4529137A4 (en) 2025-04-30

Similar Documents

Publication Publication Date Title
US11997143B2 (en) Managing communications among virtual machine nodes of a network service provider
US10341196B2 (en) Reliably updating a messaging system
CN112631788B (en) Data transmission method and data transmission server
US20170026306A1 (en) Systems and methods for autonomous resource discovery, management, and stitching
US10404837B2 (en) User datagram protocol (UDP) application handling during live kernel update
US11477102B2 (en) Upgrading user space networking stacks without disruptions to network traffic
US11943093B1 (en) Network connection recovery after virtual machine transition in an on-demand network code execution system
US7761609B1 (en) Socket level packet scheduling for connectionless protocols
CN115118791B (en) UDP message distribution method, device and readable storage medium
US7613825B2 (en) Hierarchical packet processing system and method, relay device and server
CN118138552A (en) Data transmission method and related equipment
CN119420825B (en) TCP socket local network communication optimization method and system
CN114500522B (en) Method for sharing image installation image stream, first computing node and storage medium
CN111756780A (en) Method for synchronizing connection information and load balancing system
US20200272504A1 (en) Hypervisor restart handling mechanism using random session numbers
CN120017617B (en) Multicast communication method and device, system, storage medium and program product
US20250291770A1 (en) Seamless NFS Server Pod Addition
US12348431B1 (en) Automated scaling of packet processing service resources
US12199940B1 (en) Address resolution protocol based deployment
CN116743845B (en) Edge service discovery method, device, node device and readable storage medium
CN114900485B (en) Method, electronic equipment and system for accessing network file storage
CN116016679A (en) Cloud primary service communication method, device, equipment and storage medium
CN117940901A (en) Stateful endpoint mobility in federated cloud computing systems

Legal Events

Date Code Title Description
WWE Wipo information: entry into national phase

Ref document number: 2023800303

Country of ref document: EP

NENP Non-entry into the national phase

Ref country code: DE

ENP Entry into the national phase

Ref document number: 2023800303

Country of ref document: EP

Effective date: 20241220