Connection management method, device, medium and equipment supporting multiple protocols
Patent Information
- Application Number
- CN202210202588.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-03
- Publication Date
- 2026-09-22
- Estimated Expiration
- 2042-03-03
AI Technical Summary
[0003]相关技术中,业务逻辑进程所能支持的连接协议较为单一,且在管理连接时易侵入和影响业务逻辑进程本身的功能与性能
[0021]本申请提供的方案将业务逻辑进程中的连接管理功能剥离、抽象成连接管理进程,来单独对接入的连接进行管理,可以避免对业务逻辑进程的功能侵入,以及保障业务逻辑进程的运行性能。在连接管理进程中,将对不同连接协议的连接的支持抽象、封装为对应的协议适配器,在启动连接管理进程时会遍历所有注册的协议适配器,以启动对多个网络端口的检测,每个网络端口对应于一种连接协议,每一种连接协议都对应有一个协议适配器;在检测到客户端发送给多个网络端口中目标网络端口的连接请求时,确定对应的目标连接协议,进而由目标连接协议对应的目标协议适配器中封装的连接建立方法,建立客户端与该目标网络端口之间的目标连接,该目标连接是适配目标连接协议的;当检测到该目标连接建立后,连接管理进程创建针对该目标连接的目标连接管理子进程,该目标连接管理子进程负责客户端与业务逻辑进程之间的通信转发以及对该目标连接的管理。本申请提供的技术方案将不同连接协议对应的连接创建过程与具体的连接协议剥离,并以适配器模式抽象封装,可以提供自定义连接协议的收缩与扩展,提高了连接管理进程的通用性和可用性,以便在业务逻辑进程运行时支持不同协议的连接接入;其次对于每条连接,创建对应的连接管理子进程来进行连接管理,连接管理子进程继承实现连接管理进程的管理功能,剥离了具体连接协议的连接管理细节,能够对多个连接进行既独立又统一的管理,提高了连接管理的高效性。
Smart Images

Figure CN116743834B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of network connection management, and specifically to a connection management method, apparatus, medium, and device that supports multiple protocols. Background Technology
[0002] During server program operation, its main functions are carried out by several services with different functions and their corresponding service process entities. Among these services, some require clients to establish and maintain connections for state synchronization and data transmission, such as the game's basic logic service and combat service in a game server. These game service processes are collectively referred to as business logic processes. Client connections enter the server through a gateway, and the server has a series of management functions for connections, such as connection authentication, device access control, connection quantity management, and single connection overload protection. In addition, different service models use different client-server connection protocols. For example, some games use the conventional TCP protocol for communication for their basic game logic, some web-based or platform mini-program games use the WebSocket protocol due to access method limitations, and some scenarios with high requirements for data real-time performance and throughput, such as combat services, use the reliable UDP protocol for communication.
[0003] In related technologies, the connection protocols supported by business logic processes are relatively limited, and the management of connections can easily intrude into and affect the functionality and performance of the business logic processes themselves. Summary of the Invention
[0004] To enable access to connections using different protocols and to manage these connections individually and uniformly during business operations, this application provides a connection management method, apparatus, medium, and device that support multiple protocols. The technical solution is as follows:
[0005] Firstly, this application provides a connection management method supporting multiple protocols, the method comprising:
[0006] Start the connection management process corresponding to the business logic process;
[0007] Based on the multiple protocol adapters in the connection management process, multiple network ports are detected separately; each protocol adapter and each network port corresponds to a connection protocol.
[0008] Upon detecting a connection request sent by a client to a target network port, the corresponding target connection protocol is determined; the target network port is included among the plurality of network ports.
[0009] Based on the target protocol adapter corresponding to the target connection protocol, establish a target connection between the client and the target network port that is compatible with the target connection protocol;
[0010] Once the establishment of the target connection is detected, a target connection management subprocess corresponding to the target connection is created; the target connection management subprocess is responsible for the communication forwarding between the client and the business logic process and the management of the target connection.
[0011] Secondly, this application provides a connection management device supporting multiple protocols, the device comprising:
[0012] The first process startup module is used to start the connection management process corresponding to the business logic process;
[0013] The port detection module is used to detect multiple network ports according to multiple protocol adapters in the connection management process; each protocol adapter and each network port corresponds to a connection protocol.
[0014] A connection protocol determination module is used to determine the corresponding target connection protocol when a connection request sent by a client to a target network port is detected; the target network port is included among the plurality of network ports.
[0015] The connection establishment module is used to establish a target connection between the client and the target network port that is adapted to the target connection protocol, based on the target protocol adapter corresponding to the target connection protocol.
[0016] The subprocess creation module is used to create a target connection management subprocess corresponding to the target connection after the target connection is detected to be established; the target connection management subprocess is responsible for the communication forwarding between the client and the business logic process and the management of the target connection.
[0017] Thirdly, this application provides a computer-readable storage medium storing at least one instruction or at least one program, which is loaded and executed by a processor to implement a multi-protocol connection management method as described in the first aspect.
[0018] Fourthly, this application provides a computer device including a processor and a memory, wherein the memory stores at least one instruction or at least one program, and the at least one instruction or at least one program is loaded and executed by the processor to implement a multi-protocol connection management method as described in the first aspect.
[0019] Fifthly, this application provides a computer program product, the computer program product including computer instructions, which, when executed by a processor, implement a multi-protocol connection management method as described in the first aspect.
[0020] The connection management method, apparatus, medium, and device supporting multiple protocols provided in this application have the following technical advantages:
[0021] The solution provided in this application separates and abstracts the connection management function from the business logic process into a connection management process, which manages the incoming connections independently. This avoids intrusion into the functionality of the business logic process and ensures its performance. Within the connection management process, support for different connection protocols is abstracted and encapsulated into corresponding protocol adapters. When the connection management process starts, it iterates through all registered protocol adapters to initiate the detection of multiple network ports. Each network port corresponds to a connection protocol, and each connection protocol has a corresponding protocol adapter. When a connection request is detected from a client to a target network port among the multiple network ports, the corresponding target connection protocol is determined. Then, the connection establishment method encapsulated in the target protocol adapter corresponding to the target connection protocol establishes a target connection between the client and the target network port. This target connection is compatible with the target connection protocol. After the target connection is established, the connection management process creates a target connection management subprocess for that target connection. This target connection management subprocess is responsible for communication forwarding between the client and the business logic process, as well as the management of the target connection. The technical solution provided in this application decouples the connection creation process corresponding to different connection protocols from the specific connection protocols and abstracts and encapsulates it using the adapter pattern. This allows for the contraction and expansion of custom connection protocols, improving the versatility and usability of the connection management process, so as to support connection access of different protocols during the business logic process. Secondly, for each connection, a corresponding connection management subprocess is created to manage the connection. The connection management subprocess inherits and implements the management functions of the connection management process, decoupling the connection management details of specific connection protocols. This enables independent yet unified management of multiple connections, improving the efficiency of connection management.
[0022] Additional aspects and advantages of this application will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of this application. Attached Figure Description
[0023] To more clearly illustrate the technical solutions and advantages in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0024] Figure 1 This is a schematic diagram of the architecture for implementing a connection management method supporting multiple protocols, provided in an embodiment of this application.
[0025] Figure 2 This is a flowchart illustrating a connection management method supporting multiple protocols provided in an embodiment of this application;
[0026] Figure 3 This is a schematic diagram illustrating the working principle of a full-duplex channel provided in an embodiment of this application;
[0027] Figure 4 This is a schematic diagram of the architecture of a connection management process that supports multi-protocol access, provided in an embodiment of this application.
[0028] Figure 5 This is a schematic diagram of the workflow of a connection management process provided in an embodiment of this application;
[0029] Figure 6 This is a schematic diagram of a connection management device supporting multiple protocols provided in an embodiment of this application;
[0030] Figure 7 This is a schematic diagram of the hardware structure of a device for implementing a connection management method that supports multiple protocols, provided in an embodiment of this application. Detailed Implementation
[0031] To enable access to connections using different protocols and to manage these connections individually and uniformly during business operations, embodiments of this application provide a connection management method, apparatus, medium, and device that support multiple protocols. The technical solutions in the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of them. All other embodiments obtained by those skilled in the art based on the embodiments of this application without creative effort are within the scope of protection of this application. Examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout.
[0032] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or server that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or devices.
[0033] To facilitate understanding of the technical solutions and their effects described in the embodiments of this application, the relevant technical terms are explained in the embodiments of this application:
[0034] Connection Management Process: A custom server process that runs independently after the gateway is connected. It communicates with the upper-layer business logic server and is responsible for managing client access, providing services such as rate limiting, re-login, and connection health status detection and alarms.
[0035] Business logic process: A process that provides specific business service capabilities. In game services, it can refer to a game process that includes a class of business functions such as basic game functions, room functions, and combat functions.
[0036] Gobus: A custom, full-duplex communication channel based on shared memory used to connect management processes and business logic processes.
[0037] CS protocol: A communication protocol between a client and a server, such as WebSocket, TCP, KCP, etc.
[0038] TCP: Transmission Control Protocol.
[0039] WebSocket: A full-duplex communication protocol based on TCP.
[0040] UDP: User Datagram Protocol.
[0041] KCP is a reliable UDP protocol.
[0042] Golang: A parallel programming language.
[0043] goroutine: Lightweight thread in the Golang language.
[0044] It is understood that in the specific embodiments of this application, data such as user information are involved. When the above embodiments of this application are applied to specific products or technologies, user permission or consent is required, and the collection, use and processing of related data must comply with the relevant laws, regulations and standards of the relevant countries and regions.
[0045] Please see Figure 1 This is a schematic diagram of the architecture of a server implementing a connection management method supporting multiple protocols, as provided in an embodiment of this application. Figure 1As shown, taking a game server as an example, this architecture can include at least two layers: the upper layer is the logic layer composed of business logic processes, and the lower layer is the connection layer, which is mainly composed of connection management processes (Connd).
[0046] The logic layer is primarily responsible for providing game service content, communication between business logic processes, and connection management with external services. Taking two business logic processes as an example, one is the game room service (Roomsvr), and the other is the battle service (Battlersvr). The business logic processes communicate with each other through Gobusd (a proxy node used to establish communication channels between game processes, and an independent process that can forward communication messages).
[0047] Each business logic process in the logic layer corresponds to an independent connection management process in the connection layer. The business logic process and its corresponding connection management process communicate via Gobus. The connection management process detects the network ports corresponding to different connection protocols, and the client establishes a connection with the corresponding connection management process through the server address mapped to that network port.
[0048] like Figure 1 As shown, the process of a client connecting to multiple business logic processes in the game can include: the client first selects a Roomsvr and its corresponding Connd. The Connd detects port p, and the client establishes a connection with this port using a certain connection protocol. Connection management can also include: the Connd determining whether the player UID (UserIdentity) corresponding to the connection exists. If it exists, it indicates either account hijacking or reconnection, and the account hijacking / reconnection logic is entered to determine the corresponding connection management subprocess iConn. If it does not exist, a new connection management subprocess iConn is created and added to the Connd's connection management center.
[0049] The client can also switch connection protocols to connect with different connection management processes. Specifically, the connection protocols for room services and battle services are different, such as... Figure 1As shown, when a battle needs to be formed after the room service is completed, the Roomsvr business layer selects a Battlesvr and informs the client of the network address of the port mapping detected by the corresponding Connd of the Battlesvr. The client establishes a connection with the Battlesvr Connd through the network address of the Battlesvr Connd to obtain the battle service. After the battle ends, the connection between the client and the Battlesvr Connd is closed. When the client exits the game, its connection with the Connd corresponding to the Roomsvr is closed. The client can connect to different Connds using different connection protocols, or it can choose different CS protocols to connect to the same Connd. The client can maintain multiple connections with different Connds on the server simultaneously, and the creation, maintenance, and closure of these connections are independent of each other.
[0050] This application embodiment can also be implemented using cloud technology. Cloud technology refers to a hosting technology that unifies hardware, software, and network resources within a wide area network (WAN) or local area network (LAN) to achieve data computation, storage, processing, and sharing. It can also be understood as a general term for network technologies, information technologies, integration technologies, management platform technologies, and application technologies based on cloud computing business models. Cloud technology requires cloud computing as its support. Cloud computing is a computing model that distributes computing tasks across a resource pool composed of a large number of computers, enabling various application systems to obtain computing power, storage space, and information services as needed. The network providing these resources is called the "cloud." Specifically, the game server and database are located in the cloud; the game server can be a physical machine or a virtualized machine.
[0051] The following describes a connection management method that supports multiple protocols, provided in this application. Figure 2 This is a flowchart illustrating a connection management method supporting multiple protocols provided in an embodiment of this application. This application provides the operational steps of the method described in the embodiment or flowchart, and may also include more or fewer operational steps. The order of steps listed in the embodiment is merely one possible execution order among many, and does not represent the only possible execution order. In actual system or server product execution, the method can be executed sequentially or in parallel (e.g., in a parallel processor or multi-threaded processing environment) as shown in the embodiment or the accompanying drawings. Please refer to... Figure 2 The connection management method supporting multiple protocols provided in this application embodiment may include the following steps:
[0052] S210: Start the connection management process corresponding to the business logic process.
[0053] In this embodiment, a business logic process refers to a process capable of providing specific business services. For example, in a game service, it could refer to a game process that includes basic game functions, room functions, combat functions, and other business functions. During the online operation and service provision of the server, numerous business logic processes require the client to establish connections (including short and long connections, primarily referring to long connections) and communicate with the server for state synchronization and data transmission. This leads to related connection management issues, such as network access management, authentication management, overload protection, and concurrent connection control.
[0054] In related technical solutions, connection management and business logic are intertwined in one process. If connection management is abnormal, it will lead to functional intrusion into the business logic and affect the running performance of the business logic. In severe cases, it will also lead to the dual impact of loss of business data or connection failure.
[0055] In this embodiment, the connection establishment and management functions are separated from the specific connection protocol and abstracted into an independent running process, namely the connection management process. For the gateway access layer, this can provide the connection access capability of the business. For the upper-layer business, it can shield the details of the connection management function, so that the connection management of the client and the server is separated from the upper-layer business logic, reducing the functional intrusion of the business logic.
[0056] In one embodiment of this application, starting the connection management process corresponding to the business logic process includes: starting a first thread in the connection management process, and the first thread maintaining communication with the business logic process through a full-duplex communication channel based on shared memory. The connection management process uses a full-duplex channel based on shared memory to communicate with the business logic process. If a failure occurs on one end, information can be temporarily stored in a message cache, and communication can continue after the other end recovers, effectively reducing service loss.
[0057] Figure 3 This is a schematic diagram illustrating the working principle of a full-duplex channel provided in this application embodiment. Server1 and Server2 are abstractions of the two communication ends. In this embodiment, Server1 is a connection management process (Connd), and Server2 is a business logic process (LogicSvr). Gobus is a full-duplex shared memory channel. Server1's read channel is Server2's write channel, and Server2's write channel is Server1's read channel. Each end starts a read / write thread (Goroutine) to poll for data changes on the shared memory channel. Sentinel is a sentinel packet placed at the end of each channel to perform boundary protection of the channel circular queue.
[0058] In addition to the data payload (raw data[] bytes), each data packet also includes a BusHead and a ChanHead header. In gaming applications, the BusHead contains a list of the corresponding player UIDs (User Identity) and some control flag fields. The BusHead is mainly used for logical processing at the sending and receiving ends, such as connection selection for Connect and session selection for business logic.
[0059] ChanHead contains length identifiers (HeadLen, BodyLen) and end identifiers (Src, Dst). ChanHead is mainly used for Gobus's internal logic related to packet unpacking, parsing, and verification.
[0060] In the above embodiments, Gobus communication is based on shared memory, which has advantages such as high speed, high reliability, and large transmission capacity. Furthermore, a custom packet splitting scheme can be used during communication, requiring only partial packet splitting to determine the transmission method (unicast, multicast, broadcast, etc.).
[0061] S220: Based on the multiple protocol adapters in the connection management process, multiple network ports are detected respectively; each protocol adapter and each network port corresponds to a connection protocol.
[0062] In this embodiment, access support for different connection protocols is abstracted and encapsulated into corresponding protocol adapters, which are then registered in the connection management process. The protocol adapter encapsulates the port detection process and connection creation process corresponding to the connection protocol and provides the corresponding adapter interface.
[0063] In one embodiment of this application, step S220 may specifically include:
[0064] When starting the connection management process, it iterates through the multiple protocol adapters registered in the connection management process to determine the network ports corresponding to the multiple connection protocols and the detection methods for each network port.
[0065] Based on the detection method for each network port, detection is performed on each network port.
[0066] Each network port corresponds to a different connection protocol, and these network ports need to be pre-deployed and maintained.
[0067] For example, the connection management process registers protocol adapters for the TCP protocol (TCP Adaptors) and the protocol adapters for the WebSocket protocol (WS Adaptors). TCP Adaptors detect port A, and WS Adaptors detect port B. The port detection methods are adapted to their respective connection protocols. Alternatively, an abstract port detection class can be encapsulated first, and then the protocol adapters can inherit from this class and implement port detection methods adapted to the connection protocols.
[0068] By registering protocol adapters for multiple connection protocols, it is possible to detect the network ports corresponding to different connection protocols, thereby providing support for connections of different connection protocols.
[0069] S230: When a connection request sent by a client to a target network port is detected, the corresponding target connection protocol is determined; the target network port is included among multiple network ports.
[0070] For example, after obtaining the network address (IP address and port number) of the connection management process, the client can initiate a connection request to the target network port corresponding to the connection management process.
[0071] S240: Based on the target protocol adapter corresponding to the target connection protocol, establish a target connection between the client and the target network port that is compatible with the target connection protocol.
[0072] In this embodiment, a target connection between the client and the target network port can be established according to the connection creation method adapted to the target connection protocol in the target protocol adapter corresponding to the target connection protocol.
[0073] Understandably, the protocol adapter also encapsulates the connection creation process, and the specific creation process is adapted to the connection protocol.
[0074] In this embodiment, by stripping the connection from the details of the specific connection protocol and abstracting and encapsulating them into protocol adapters corresponding to different connection protocols, connection requests based on different connection protocols can be supported simultaneously during the operation of the business logic process and the connection management process. At the same time, the adapter approach can provide the shrinking and expansion of custom connection protocols, thereby improving the versatility and usability of the connection management process.
[0075] S250: When a target connection is detected to be established, a target connection management subprocess corresponding to the target connection is created; the target connection management subprocess is responsible for the communication forwarding between the client and the business logic process and the management of the target connection.
[0076] In this embodiment, for each connection protocol, in addition to establishing a connection by registering the corresponding protocol adapter, a connection management subprocess corresponding to the connection is created to manage the connection, including data reading and writing, timeout handling, error handling, packet parsing, and overload protection. Specifically, the connection management process abstractly encapsulates connection management functions, which are stripped of specific protocol details. The connection management subprocess inherits the above connection management functions and implements specific connection management functions by calling interfaces, independent of protocol details. When the connection management process simultaneously accesses connections corresponding to multiple connection protocols, independent yet consistent management can be achieved through their respective connection management subprocesses, resulting in high efficiency and availability.
[0077] In one embodiment of this application, the method may specifically include:
[0078] Once the establishment of the target connection is detected, the target connection is checked, and the corresponding check results are obtained.
[0079] When the inspection results meet the preset inspection conditions, a target connection management subprocess corresponding to the target connection is created; the target connection, the target connection management subprocess, and the client's client identifier are in one-to-one correspondence.
[0080] Specifically, upon detecting a connection establishment, the protocol adapter reads the protocol packets from the connection, converts them into unified connection information, and calls the corresponding registration callback function to perform entry checks. Entry checks include blacklist / whitelist checks, maximum connection count checks, queuing checks, reconnection checks, and top-number checks, with different functional modules handling the corresponding check results. After the checks pass, a corresponding connection management subprocess is established and added to the connection management module within the connection management process.
[0081] Optionally, checking the target connection includes a list check, including:
[0082] Once the establishment of the target connection is detected, the client identifier corresponding to the target connection is determined.
[0083] If the client identifier is on the blacklist, the target connection will be disconnected.
[0084] If the destination identifier is on the blacklist, the target connection can be disconnected directly without creating a corresponding target connection management subprocess, thus reducing resource consumption.
[0085] Optionally, checking the target connection includes queuing checks, including:
[0086] Determine the current number of connections;
[0087] If the number of connections reaches a preset threshold, the target connection will be placed in a waiting queue.
[0088] To ensure the availability of the connection management process, it is necessary to check the maximum number of connections and the queuing check. If the number of connections of the current connection has not reached the preset maximum number of connections threshold, a corresponding connection management subprocess can be created for the target connection. If the number of connections of the current connection has reached the preset maximum number of connections threshold, the target connection can be placed in the waiting queue for queuing until a connection is cancelled and the target connection is woken up from the waiting queue, at which time the corresponding connection management subprocess is created.
[0089] In one embodiment of this application, the method further includes:
[0090] After creating the target connection management subprocess corresponding to the target connection, the corresponding read thread and write thread are started. The read thread and write thread are used for data communication between the client and the target connection management subprocess. For example, each connection will start two goroutines, one for reading and one for writing. By using concurrency, CPU (Central Processing Unit) utilization can be improved.
[0091] Figure 4 This is a schematic diagram of the architecture of a connection management process (HYBRID CONND, hereinafter referred to as Connd) that supports multi-protocol access, provided in an embodiment of this application. Figure 4 As shown, it can be divided into the following modules according to function:
[0092] Monitor: Data statistics and detection module. It primarily detects Connd's runtime metrics, including the number of connections, the number of packets sent and received, performance-related metrics, the number of reconnections, the number of anomalies, etc., and reports these metrics to the corresponding control platform.
[0093] ProtoAdaptors: Protocol adapters. Each connection protocol needs to implement the corresponding adapter's abstract interface, including how to initiate port detection, how to handle connection requests, and how to establish a connection. If there are protocols that need to be extended, abstract implementations and adapter registration are required.
[0094] ConnManager: The connection management module. Each connection is abstracted here as an iConn object (connection management subprocess or connection management unit), hiding the specific protocol implementation details. Each connection corresponds one-to-one with a player's UID. The connection management module also has a waiting queue (Waiting Q). If the number of connections exceeds a preset maximum, they are added to the waiting queue. When a connection is canceled, waiting connections are awakened from the waiting queue.
[0095] Chan Manager: The communication management module is mainly responsible for communication with the business logic process (LOGIC SVR). It is divided into read channel (Read Chan), write channel (Write Chan), and control channel (Control Chan). Each channel is a separate thread (goroutine), which improves CPU utilization through concurrency.
[0096] The connection layer primarily manages connections, while the business logic layer primarily manages sessions. Changes in connections (such as account number changes or network switching) do not affect the validity of sessions.
[0097] Based on the aforementioned connection management process architecture, Connd's connection management is primarily achieved through the control channel ( Figure 4 The Control Chant is implemented in [the relevant framework / platform]. Three command words are available as options:
[0098] LEAVE: After the client connection is lost, a LEAVE command is sent to the corresponding iConn, which closes the connection and reclaims resources.
[0099] OVERLAP: When a client reconnects / reconnects, it sends an OVERLAP command to the corresponding historical iConn, which closes the historical iConn, reclaims resources, and creates a new iConn to continue serving the corresponding client user.
[0100] SHUTDOWN: When Connd receives a specific data packet instructing the server to kick out the connection, it sends a SHUTDOWN command to the corresponding iConn. The corresponding iConn then informs the client to kick out the connection, closes the connection, and reclaims resources.
[0101] Generally, when a session in a business logic process is closed, Connd will be notified to close the connection. However, Connd's connection closure, reconnection, or reconnection all shield session details to prevent connection jitter and avoid affecting the operation of business-side services.
[0102] Figure 5 This is a schematic diagram of the workflow of a connection management process (Connd) provided in an embodiment of this application, as shown below. Figure 5 As shown, taking the establishment of a WebSocket connection as an example, after the Connd process starts, it starts a separate goroutine to maintain full-duplex communication with the business logic process via Gobus. Simultaneously, it detects the corresponding network port based on the registered protocol adapter.
[0103] The client obtains the network address of the connection (vip:port in the diagram) through other means (e.g., by requesting the login server) and then initiates connection (conn) creation. The connection creation function is handled by the specific protocol adapter. After the connection is established, the first protocol packet is read from the connection, and entry checks are performed, including reconnection / reset checks, queuing checks, and blacklist / whitelist checks. If the current number of connections exceeds the limit (e.g., ...), the client then checks the connection settings. Figure 4 The system checks the Maxconn Limiter; if the limit is exceeded, the connection enters a queue and waits to be woken up after the connection is closed. If it's a reconnection / reconnection to the previous connection, a control command is sent to close the existing connection. If it's a new connection, a corresponding connection management unit (iConn) is created and added to the connection management module (ConnMgr). Each connection starts two goroutines, one for reading and one for writing, using concurrency to improve CPU utilization.
[0104] After a connection is established, the client can communicate with the server. (Combined) Figures 3 to 5 The client sends a data packet. Upon receiving it, Connd packages it into a packet using the Write Channel in the communication management module, based on the user UID corresponding to the connection, and sends it to the Gobus channel. The peer LogicSvr reads the client data packet from the Gobus channel, establishes a session, and performs the corresponding logical function processing.
[0105] LogicSvr sends the corresponding data packet to the Gobus channel, and Connd reads the data packet through ReadChan in the communication management module. Connd then partially unpacks the packet to obtain the transmission mode (unicast or multicast), determines the user UID specified in the data packet, finds the corresponding connection management unit iConn in the connection management module, and sends it. The iConn in the connection management module sends data to the client through a write thread goroutine. When the client disconnects, the connection is broken. At this time, Connd reclaims the corresponding iConn and related resources and wakes up the connections in the waiting queue. If the business logic process actively initiates a disconnection, such as server maintenance or forced disconnection due to minor protection, a control command is sent to the corresponding iConn, and the iConn actively closes the connection conn.
[0106] The solution provided in this application separates and abstracts the connection management function from the business logic process into a connection management process, which manages the incoming connections independently. This avoids intrusion into the functionality of the business logic process and ensures its performance. Within the connection management process, support for different connection protocols is abstracted and encapsulated into corresponding protocol adapters. When the connection management process starts, it iterates through all registered protocol adapters to initiate the detection of multiple network ports. Each network port corresponds to a connection protocol, and each connection protocol has a corresponding protocol adapter. When a connection request is detected from a client to a target network port among the multiple network ports, the corresponding target connection protocol is determined. Then, the connection establishment method encapsulated in the target protocol adapter corresponding to the target connection protocol establishes a target connection between the client and the target network port. This target connection is compatible with the target connection protocol. After the target connection is established, the connection management process creates a target connection management subprocess for that target connection. This target connection management subprocess is responsible for communication forwarding between the client and the business logic process, as well as the management of the target connection. The technical solution provided in this application decouples the connection creation process corresponding to different connection protocols from the specific connection protocols and abstracts and encapsulates it using the adapter pattern. This allows for the contraction and expansion of custom connection protocols, improving the versatility and usability of the connection management process, so as to support connection access of different protocols during the business logic process. Secondly, for each connection, a corresponding connection management subprocess is created to manage the connection. The connection management subprocess inherits and implements the management functions of the connection management process, decoupling the connection management details of specific connection protocols. This enables independent yet unified management of multiple connections, improving the efficiency of connection management.
[0107] This application also provides a connection management device 600 that supports multiple protocols, such as... Figure 6 As shown, the device 600 may include:
[0108] The first process startup module 610 is used to start the connection management process corresponding to the business logic process;
[0109] The port detection module 620 is used to detect multiple network ports according to multiple protocol adapters in the connection management process; each protocol adapter and each network port corresponds to a connection protocol.
[0110] The connection protocol determination module 630 is used to determine the corresponding target connection protocol when a connection request sent by a client to a target network port is detected; the target network port is included among the plurality of network ports.
[0111] The connection establishment module 640 is used to establish a target connection between the client and the target network port that is adapted to the target connection protocol, according to the target protocol adapter corresponding to the target connection protocol;
[0112] The subprocess creation module 650 is used to create a target connection management subprocess corresponding to the target connection after the target connection is detected to be established; the target connection management subprocess is responsible for the communication forwarding between the client and the business logic process and the management of the target connection.
[0113] In one embodiment of this application, the first process startup module 610 may include:
[0114] The first thread startup unit is used to start the first thread in the connection management process. The first thread maintains communication with the business logic process through a full-duplex communication channel based on shared memory.
[0115] In one embodiment of this application, the port detection module 620 may include:
[0116] The adapter traversal unit is used to traverse multiple protocol adapters registered in the connection management process when the connection management process is started, and to determine the network ports corresponding to the multiple connection protocols and the detection methods for each network port.
[0117] The port detection unit is used to detect each of the network ports based on the detection method for each of the network ports.
[0118] In one embodiment of this application, the connection establishment module 640 includes:
[0119] The target connection establishment unit is used to establish the target connection between the client and the target network port according to the connection creation method adapted to the target connection protocol in the target protocol adapter corresponding to the target connection protocol.
[0120] In one embodiment of this application, the subprocess creation module 650 includes:
[0121] A connection checking unit is used to check the target connection after the establishment of the target connection is detected, and obtain the corresponding check result;
[0122] The subprocess creation unit is used to create a target connection management subprocess corresponding to the target connection when the check result meets the preset check conditions; the target connection, the target connection management subprocess, and the client identifier of the client are in one-to-one correspondence.
[0123] In one embodiment of this application, the connection checking unit includes:
[0124] The client identifier determination subunit is used to determine the client identifier corresponding to the target connection after the establishment of the target connection is detected;
[0125] The connection interruption subunit is used to disconnect the target connection if the client identifier is in a blacklist.
[0126] In one embodiment of this application, the connection checking unit further includes:
[0127] The connection number determination subunit is used to determine the number of connections currently being connected;
[0128] The waiting subunit is used to place the target connection into the waiting queue if the number of connections reaches a preset threshold.
[0129] In one embodiment of this application, the device 600 may further include:
[0130] The second thread startup unit is used to start the read thread and write thread corresponding to the target connection after creating the target connection management subprocess. The read thread and the write thread are used for data communication between the client and the target connection management subprocess.
[0131] It should be noted that the apparatus provided in the above embodiments is only illustrated by the division of the above functional modules when implementing its functions. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. In addition, the apparatus and method embodiments provided in the above embodiments belong to the same concept, and the specific implementation process can be found in the method embodiments, which will not be repeated here.
[0132] This application provides a computer device including a processor and a memory. The memory stores at least one instruction or at least one program, which is loaded and executed by the processor to implement a multi-protocol connection management method as provided in the above method embodiments.
[0133] Figure 7 A schematic diagram of the hardware structure of an apparatus for implementing a method provided in an embodiment of this application is shown. This apparatus may participate in or include the device or system provided in the embodiment of this application. Figure 7As shown, device 10 may include one or more processors 1002 (shown as 1002a, 1002b, ..., 1002n in the figure) 1002 (processor 1002 may include, but is not limited to, a microprocessor MCU or a programmable logic device FPGA, etc.), a memory 1004 for storing data, and a transmission device 1006 for communication functions. In addition, it may also include: a display, an input / output interface (I / O interface), a universal serial bus (USB) port (which may be included as one of the ports of the I / O interface), a network interface, a power supply, and / or a camera. Those skilled in the art will understand that... Figure 7 The structure shown is for illustrative purposes only and does not limit the structure of the electronic device described above. For example, device 10 may also include a... Figure 7 The more or fewer components shown, or having the same Figure 7 The different configurations shown.
[0134] It should be noted that the aforementioned one or more processors 1002 and / or other data processing circuits are generally referred to herein as "data processing circuits". These data processing circuits may be embodied, in whole or in part, in software, hardware, firmware, or any other combination thereof. Furthermore, the data processing circuits may be a single, independent processing module, or may be wholly or partially integrated into any other element within device 10 (or mobile device). As involved in the embodiments of this application, the data processing circuits serve as a processor control mechanism (e.g., selection of a variable resistor termination path connected to an interface).
[0135] The memory 1004 can be used to store software programs and modules of application software, such as the program instructions / data storage device corresponding to the method described in the embodiments of this application. The processor 1002 executes various functional applications and data processing by running the software programs and modules stored in the memory 1004, thereby realizing the above-mentioned multi-protocol connection management method. The memory 1004 may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 1004 may further include memory remotely located relative to the processor 1002, and these remote memories can be connected to the device 10 via a network. Examples of the above-mentioned networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.
[0136] The transmission device 1006 is used to receive or send data via a network. Specific examples of the network described above may include a wireless network provided by the communication provider of device 10. In one example, the transmission device 1006 includes a Network Interface Controller (NIC), which can connect to other network devices via a base station to communicate with the Internet. In another example, the transmission device 1006 may be a Radio Frequency (RF) module, used for wireless communication with the Internet.
[0137] The display may be, for example, a touchscreen liquid crystal display (LCD) that allows a user to interact with the user interface of device 10 (or a mobile device).
[0138] This application embodiment also provides a computer-readable storage medium, which can be disposed in a server to store at least one instruction or at least one program related to implementing a multi-protocol connection management method provided in the method embodiment. The at least one instruction or the at least one program is loaded and executed by the processor to implement the multi-protocol connection management method provided in the above method embodiment.
[0139] Optionally, in this embodiment, the storage medium may be located at at least one of the multiple network servers in a computer network. Optionally, in this embodiment, the storage medium may include, but is not limited to, various media capable of storing program code, such as USB flash drives, read-only memory (ROM), random access memory (RAM), portable hard drives, magnetic disks, or optical disks.
[0140] This invention also provides a computer program product or computer program, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform a multi-protocol connection management method provided in the various optional embodiments described above.
[0141] As can be seen from the embodiments of the connection management method, apparatus, medium, and device supporting multiple protocols provided in this application,
[0142] The solution provided in this application separates and abstracts the connection management function from the business logic process into a connection management process, which manages the incoming connections independently. This avoids intrusion into the functionality of the business logic process and ensures its performance. Within the connection management process, support for different connection protocols is abstracted and encapsulated into corresponding protocol adapters. When the connection management process starts, it iterates through all registered protocol adapters to initiate the detection of multiple network ports. Each network port corresponds to a connection protocol, and each connection protocol has a corresponding protocol adapter. When a connection request is detected from a client to a target network port among the multiple network ports, the corresponding target connection protocol is determined. Then, the connection establishment method encapsulated in the target protocol adapter corresponding to the target connection protocol establishes a target connection between the client and the target network port. This target connection is compatible with the target connection protocol. After the target connection is established, the connection management process creates a target connection management subprocess for that target connection. This target connection management subprocess is responsible for communication forwarding between the client and the business logic process, as well as the management of the target connection. The technical solution provided in this application decouples the connection creation process corresponding to different connection protocols from the specific connection protocols and abstracts and encapsulates it using the adapter pattern. This allows for the contraction and expansion of custom connection protocols, improving the versatility and usability of the connection management process, so as to support connection access of different protocols during the business logic process. Secondly, for each connection, a corresponding connection management subprocess is created to manage the connection. The connection management subprocess inherits and implements the management functions of the connection management process, decoupling the connection management details of specific connection protocols. This enables independent yet unified management of multiple connections, improving the efficiency of connection management.
[0143] It should be noted that the order of the embodiments described above is merely for descriptive purposes and does not represent the superiority or inferiority of the embodiments. Furthermore, the above description focuses on specific embodiments of this application. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps described in the claims can be performed in a different order than that shown in the embodiments and still achieve the desired results. Additionally, the processes depicted in the drawings do not necessarily require a specific or sequential order to achieve the desired results. In some implementations, multitasking and parallel processing are also possible or may be advantageous.
[0144] The various embodiments in this application are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the device, equipment, and storage medium embodiments are basically similar to the method embodiments, so the descriptions are relatively simple; relevant parts can be referred to the descriptions of the method embodiments.
[0145] Those skilled in the art will understand that all or part of the steps of the above embodiments can be implemented by hardware or by a program instructing related hardware. The program can be stored in a computer-readable storage medium, such as a read-only memory, a disk, or an optical disk.
[0146] The above description is only a preferred embodiment of this application and is not intended to limit this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.
Claims
1. A connection management method supporting multiple protocols, characterized in that, The method includes: Start the connection management process corresponding to the business logic process; Based on the multiple protocol adapters in the connection management process, multiple network ports are detected separately; each protocol adapter and each network port corresponds to a connection protocol. Upon detecting a connection request sent by a client to a target network port, the corresponding target connection protocol is determined; the target network port is included among the plurality of network ports. Based on the target protocol adapter corresponding to the target connection protocol, establish a target connection between the client and the target network port that is compatible with the target connection protocol; Once the target connection is detected to be established, a target connection management subprocess corresponding to the target connection is created; the target connection management subprocess is responsible for communication forwarding between the client and the business logic process, as well as the management of the target connection. There are multiple target connections between the client and the connection management process, and the target connection protocols corresponding to each target connection are different.
2. The method according to claim 1, characterized in that, The connection management process corresponding to the startup and business logic process includes: The first thread in the connection management process is started, and the first thread maintains communication with the business logic process through a full-duplex communication channel based on shared memory.
3. The method according to claim 1, characterized in that, The step of detecting multiple network ports based on multiple protocol adapters in the connection management process includes: When the connection management process is started, the multiple protocol adapters registered in the connection management process are traversed to determine the network ports corresponding to the multiple connection protocols and the detection methods for each network port. Based on the detection method for each of the network ports, detection is performed on each of the network ports.
4. The method according to claim 1, characterized in that, The step of establishing a target connection adapted to the target connection protocol between the client and the target network port according to the target protocol adapter corresponding to the target connection protocol includes: The target connection between the client and the target network port is established according to the connection creation method adapted to the target connection protocol in the target protocol adapter corresponding to the target connection protocol.
5. The method according to claim 1, characterized in that, The step of creating a target connection management subprocess corresponding to the target connection after detecting that the target connection has been established includes: Once the establishment of the target connection is detected, the target connection is checked to obtain the corresponding check results; When the inspection result meets the preset inspection conditions, a target connection management subprocess corresponding to the target connection is created; the target connection, the target connection management subprocess, and the client's client identifier are in one-to-one correspondence.
6. The method according to claim 5, characterized in that, The inspection of the target connection includes a list check, including: Once the establishment of the target connection is detected, the client identifier corresponding to the target connection is determined; If the client identifier is on a blacklist, the target connection is disconnected.
7. The method according to claim 5, characterized in that, The inspection of the target connection includes a queue inspection, comprising: Determine the current number of connections; If the number of connections reaches a preset threshold, the target connection is placed in a waiting queue.
8. The method according to claim 1, characterized in that, The method further includes: After creating the target connection management subprocess corresponding to the target connection, the read thread and write thread corresponding to the target connection are started. The read thread and write thread are used for data communication between the client and the target connection management subprocess.
9. A connection management device supporting multiple protocols, characterized in that, The device includes: The first process startup module is used to start the connection management process corresponding to the business logic process; The port detection module is used to detect multiple network ports according to multiple protocol adapters in the connection management process; each protocol adapter and each network port corresponds to a connection protocol. A connection protocol determination module is used to determine the corresponding target connection protocol when a connection request sent by a client to a target network port is detected; the target network port is included among the plurality of network ports. The connection establishment module is used to establish a target connection between the client and the target network port that is adapted to the target connection protocol, based on the target protocol adapter corresponding to the target connection protocol. The subprocess creation module is used to create a target connection management subprocess corresponding to the target connection after the target connection is detected to be established; the target connection management subprocess is responsible for the communication forwarding between the client and the business logic process and the management of the target connection; There are multiple target connections between the client and the connection management process, and the target connection protocols corresponding to each target connection are different.
10. The apparatus according to claim 9, characterized in that, The first process startup module includes: The first thread startup unit is used to start the first thread in the connection management process. The first thread maintains communication with the business logic process through a full-duplex communication channel based on shared memory.
11. The apparatus according to claim 9, characterized in that, The port detection module includes: The adapter traversal unit is used to traverse multiple protocol adapters registered in the connection management process when the connection management process is started, and to determine the network ports corresponding to the multiple connection protocols and the detection methods for each network port. The port detection unit is used to detect each of the network ports based on the detection method for each of the network ports.
12. The apparatus according to claim 9, characterized in that, The connection establishment module includes: The target connection establishment unit is used to establish the target connection between the client and the target network port according to the connection creation method adapted to the target connection protocol in the target protocol adapter corresponding to the target connection protocol.
13. The apparatus according to claim 9, characterized in that, The subprocess creation module includes: A connection checking unit is used to check the target connection after the establishment of the target connection is detected, and obtain the corresponding check result; The subprocess creation unit is used to create a target connection management subprocess corresponding to the target connection when the check result meets the preset check conditions; the target connection, the target connection management subprocess, and the client identifier of the client are in one-to-one correspondence.
14. The apparatus according to claim 13, characterized in that, The connection checking unit includes: The client identifier determination subunit is used to determine the client identifier corresponding to the target connection after the establishment of the target connection is detected; The connection interruption subunit is used to disconnect the target connection if the client identifier is in a blacklist.
15. The apparatus according to claim 13, characterized in that, The connection checking unit further includes: The connection number determination subunit is used to determine the number of connections currently being connected; The waiting subunit is used to place the target connection into the waiting queue if the number of connections reaches a preset threshold.
16. The apparatus according to claim 9, characterized in that, The device further includes: The second thread startup unit is used to start the read thread and write thread corresponding to the target connection after creating the target connection management subprocess. The read thread and the write thread are used for data communication between the client and the target connection management subprocess.
17. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores at least one instruction or at least one program, which is loaded and executed by a processor to implement a multi-protocol connection management method as described in any one of claims 1 to 8.
18. A computer device, characterized in that, The computer device includes a processor and a memory, the memory storing at least one instruction or at least one program, the at least one instruction or at least one program being loaded and executed by the processor to implement a multi-protocol connection management method as described in any one of claims 1 to 8.
19. A computer program product, comprising a computer program, characterized in that, When executed by a processor, the computer program implements a multi-protocol connection management method according to any one of claims 1 to 8.
Citation Information
Patent Citations
Memory, communication channel multiplexing implementation method, device and equipment
CN109889521A