A high-performance network long connection establishment method and device

By building a high-performance network long connection engine with connection pools, splitters and trackers, we solve the problems of service endpoint management and high concurrency in existing technologies, realize parallel processing of multiple long connection scenarios and protect against exceptions, ensuring improve the stability of the system.

CN113923249BActive Publication Date: 2024-08-27工银科技有限公司 +1
View PDF 17 Cites 0 Cited by

Patent Information

Application Number
CN202111186958.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-10-12
Publication Date
2024-08-27
Estimated Expiration
2041-10-12

AI Technical Summary

Technical Problem

Existing technology cannot uniformly manage service endpoints, has serious message delay and loss problems in high concurrency scenarios, cannot support the coexistence of multiple long-connection services, and lacks a protection mechanism for abnormal situations, leading to system crashes.

Method used

By building connection pools, splitters and trackers, we provide an open and universal high-performance network long-term connection engine to achieve unified management of service endpoints and high concurrency of message distribution, and can handle power outages, network outages, and client-side violent operations. Provide protection mechanism for abnormal situations.

Benefits of technology

It achieves unified management of service endpoints, high concurrency of message distribution and parallel processing of multiple long connection scenarios, provides a protection mechanism for abnormal situations, and ensures the stability of the system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113923249B
    Figure CN113923249B
Patent Text Reader

Abstract

The present application provides a high-performance network long connection establishment method and device, which relates to the communication field and can also be used in the financial field. The method includes: establishing a long connection with the client according to the long connection establishment request of the client; selecting a corresponding tracker from the pre-created trackers according to the type of the client, and using the selected tracker to monitor the status of the long connection; the status includes creation, disconnection and operation; using a pre-built splitter to send a message corresponding to the status to the client. The present application can provide an open and universal high-performance network long connection engine to quickly build a highly available long connection service.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of communications and can be used in the financial field. Specifically, it is a method and device for establishing a high-performance network long connection. Background Art

[0002] In the fields of instant messaging, data monitoring, etc., where the client needs to share server data in real time, scheduled polling and long connection are two commonly used technical solutions. Due to the shortcomings of scheduled polling such as high data sharing delay and high client resource consumption, the long connection technical solution is more popular with developers. The existing Java-based long connection technology is implemented using the Websocket protocol and provides a basic long connection service endpoint lifecycle management API. Developers can create, use and destroy long connection service endpoints by encapsulating the basic API. In conjunction with the client's encapsulation implementation, it can support conventional server-client data sharing needs. The existing technology has the following problems:

[0003] 1) Unable to uniformly manage service endpoints

[0004] Existing technologies only provide the ability to create, use, and recycle a single connection, but cannot directly achieve unified viewing and scheduling of all online connections.

[0005] 2) Message delay and loss are obvious in high-concurrency scenarios

[0006] The existing technology is based on a synchronization mechanism and has no message buffering mechanism, which can easily cause message delays, blockages, or even losses in high-concurrency scenarios.

[0007] 3) A single application cannot support multiple scenarios

[0008] Existing technologies can only implement one set of logic for important nodes such as connection creation and message processing, and cannot support the coexistence of multiple long connection services.

[0009] 4) Incompatible with multiple abnormal situations

[0010] The existing technology does not provide a protection mechanism for abnormal situations such as network disconnection, power outage, and client violent operation. Once the above situations occur, the server memory may run idle and cause the system to crash. Summary of the invention

[0011] In response to the problems in the prior art, the present application provides a high-performance network long connection establishment method and device, which can provide an open and universal high-performance network long connection engine to quickly build a highly available long connection service.

[0012] In order to solve the above technical problems, this application provides the following technical solutions:

[0013] In a first aspect, the present application provides a high-performance network long connection establishment method, comprising:

[0014] Establishing a persistent connection with the client according to the persistent connection establishment request of the client;

[0015] Selecting a corresponding tracker from pre-created trackers according to the type of the client, and using the selected tracker to monitor the status of the persistent connection; the status includes creation, disconnection, and operation;

[0016] A message corresponding to the state is sent to the client using a pre-built splitter.

[0017] Furthermore, the client includes a resource client, and the step of pre-building a resource client tracker includes:

[0018] Use the EnumWsType enumeration class to establish the long connection type of the resource client tracker;

[0019] Using the methods in the IWsProcessor interface to establish the standard interface of the resource client tracker;

[0020] The resource client tracker is established according to the long connection type of the resource client tracker and the standard interface of the resource client tracker.

[0021] Furthermore, the methods in the IWsProcessor interface include a whenAddedToPool method, a whenRemovedFromPool method, and a whenReceivedUpMsg method. The method in the IWsProcessor interface is used to establish a standard interface of the resource client tracker, including:

[0022] Use the whenAddedToPool method to establish the business logic standard interface after the persistent connection initialization corresponding to the resource client tracker;

[0023] Use the whenRemovedFromPool method to establish a standard business logic interface after the long connection corresponding to the resource client tracker is destroyed;

[0024] The whenReceivedUpMsg method is used to establish a business logic standard interface for uplink message processing in the long connection corresponding to the resource client tracker.

[0025] Furthermore, the client includes a business client, and the step of pre-building a business client tracker includes:

[0026] Use the EnumWsType enumeration class to establish the long connection type of the business client tracker;

[0027] Using the methods in the IWsProcessor interface to establish the standard interface of the business client tracker;

[0028] The service client tracker is established according to the long connection type of the service client tracker and the standard interface of the service client tracker.

[0029] Furthermore, the methods in the IWsProcessor interface include a whenAddedToPool method, a whenRemovedFromPool method, and a whenReceivedUpMsg method. The method in the IWsProcessor interface is used to establish a standard interface of the service client tracker, including:

[0030] Use the whenAddedToPool method to establish the business logic standard interface after the long connection initialization corresponding to the business client tracker;

[0031] Use the whenRemovedFromPool method to establish a standard business logic interface after the long connection corresponding to the business client tracker is destroyed;

[0032] The whenReceivedUpMsg method is used to establish a business logic standard interface for uplink message processing in the long connection corresponding to the business client tracker.

[0033] Further, establishing a persistent connection with the client according to the persistent connection establishment request of the client includes:

[0034] Use the void put method to establish a persistent connection with the client;

[0035] Bind the relationship between the unique identifier uuid of the persistent connection and the persistent connection object wsObj;

[0036] Bind a matching tracker according to the long link type of the long connection.

[0037] Further, the using a pre-built splitter to send a message corresponding to the state to the client includes:

[0038] Determine whether the message to be sent is congested, and if so, put the message to be sent into the ring buffer of the splitter;

[0039] The messages to be sent in the ring buffer are sent to the client by using the prepaid memory mechanism and the lock-free concurrency mechanism.

[0040] Furthermore, the high-performance network long connection establishment method further includes:

[0041] The heartbeat mechanism in the pre-built connection pool is used to monitor the full life cycle status of the long connection.

[0042] In a second aspect, the present application provides a high-performance network long connection establishment device, including:

[0043] A connection establishing unit, configured to establish a persistent connection with the client according to a persistent connection establishment request of the client;

[0044] A status monitoring unit, configured to select a corresponding tracker from pre-created trackers according to the type of the client, and monitor the status of the persistent connection using the selected tracker; the status includes creation, disconnection, and operation;

[0045] A message sending unit is used to send a message corresponding to the state to the client by using a pre-built splitter.

[0046] Further, the client includes a resource client, including:

[0047] A connection type determination unit, used to establish a long connection type of the resource client tracker using the EnumWsType enumeration class;

[0048] A standard interface determination unit, used to establish a standard interface of the resource client tracker using a method in an IWsProcessor interface;

[0049] The tracker establishing unit is used to establish the resource client tracker according to the long connection type of the resource client tracker and the standard interface of the resource client tracker.

[0050] Furthermore, the methods in the IWsProcessor interface include a whenAddedToPool method, a whenRemovedFromPool method, and a whenReceivedUpMsg method, and the standard interface determination unit includes:

[0051] A first standard interface determination module, used to establish a business logic standard interface after the long connection initialization corresponding to the resource client tracker by using the whenAddedToPool method;

[0052] A second standard interface determination module is used to establish a business logic standard interface after the long connection corresponding to the resource client tracker is destroyed by using the whenRemovedFromPool method;

[0053] The third standard interface determination module is used to establish a business logic standard interface for uplink message processing in the long connection corresponding to the resource client tracker by using the whenReceivedUpMsg method.

[0054] Furthermore, the client includes a business client, including:

[0055] A connection type determination unit, used to establish a long connection type of the service client tracker using the EnumWsType enumeration class;

[0056] A standard interface determination unit, used to establish a standard interface of the service client tracker using the method in the IWsProcessor interface;

[0057] The tracker establishing unit is used to establish the service client tracker according to the long connection type of the service client tracker and the standard interface of the service client tracker.

[0058] Furthermore, the methods in the IWsProcessor interface include a whenAddedToPool method, a whenRemovedFromPool method, and a whenReceivedUpMsg method, and the standard interface determination unit includes:

[0059] A first standard interface determination module, used to establish a business logic standard interface after the long connection initialization corresponding to the business client tracker by using the whenAddedToPool method;

[0060] A second standard interface determination module is used to establish a business logic standard interface after the long connection corresponding to the business client tracker is destroyed by using the whenRemovedFromPool method;

[0061] The third standard interface determination module is used to establish a business logic standard interface for uplink message processing in the long connection corresponding to the business client tracker by using the whenReceivedUpMsg method.

[0062] Furthermore, the high-performance network long connection establishment device, the connection establishment unit includes:

[0063] A connection establishment module, used to establish a persistent connection with the client using a void put method;

[0064] A relationship binding module, used to bind the relationship between the unique identifier uuid of the persistent connection and the persistent connection object wsObj;

[0065] The tracker matching module is used to bind the matching tracker according to the long link type of the long connection.

[0066] Furthermore, the message sending unit includes:

[0067] A message buffer module, used to determine whether congestion occurs in the message to be sent, and if so, put the message to be sent into the ring buffer of the splitter;

[0068] The message sending module is used to send the message to be sent in the ring buffer to the client by using the prepaid memory mechanism and the lock-free concurrency mechanism.

[0069] Furthermore, the high-performance network long connection establishment device further includes:

[0070] The heartbeat monitoring unit is used to monitor the full life cycle status of the long connection using the heartbeat mechanism in the pre-built connection pool.

[0071] In a third aspect, the present application provides an electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the method for establishing a high-performance network long connection when executing the program.

[0072] In a fourth aspect, the present application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the method for establishing a high-performance network long connection.

[0073] In response to the problems in the prior art, the high-performance network long connection establishment method and device provided by the present application can provide an open and universal high-performance network long connection engine by constructing a connection pool, a splitter and a tracker, thereby ensuring the unified management of service endpoints and the high concurrency of message distribution, thereby realizing parallel processing of multiple long connection scenarios, and can provide protection mechanisms for various abnormal situations such as power outages, network disconnections, and client violent operations, with simple access and stable service. BRIEF DESCRIPTION OF THE DRAWINGS

[0074] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0075] Figure 1 This is a flowchart of a method for establishing a high-performance network long connection in an embodiment of the present application;

[0076] Figure 2A flowchart of the steps for constructing a resource client tracker in an embodiment of the present application;

[0077] Figure 3 A flowchart of a standard interface for establishing a resource client tracker in an embodiment of the present application;

[0078] Figure 4 A flowchart of the steps for constructing a service client tracker in an embodiment of the present application;

[0079] Figure 5 A flowchart of a standard interface for establishing a business client tracker in an embodiment of the present application;

[0080] Figure 6 This is a flowchart of establishing a long connection in an embodiment of the present application;

[0081] Figure 7 This is a flowchart of sending a message to a client in an embodiment of the present application;

[0082] Figure 8 This is one of the structural diagrams of the high-performance network long connection establishment device in the embodiment of the present application;

[0083] Fig. 9 This is the second structural diagram of the high-performance network long connection establishment device in the embodiment of the present application;

[0084] Fig.10 This is one of the structural diagrams of the standard interface determination unit in the embodiment of the present application;

[0085] Fig.11 This is the third structural diagram of the high-performance network long connection establishment device in the embodiment of the present application;

[0086] Fig.12 This is the second structural diagram of the standard interface determination unit in the embodiment of the present application;

[0087] Fig.13 This is a structural diagram of a connection establishment unit in an embodiment of the present application;

[0088] Fig.14 This is a structural diagram of a message sending unit in an embodiment of the present application;

[0089] Fig.15 It is a schematic diagram of the structure of an electronic device in an embodiment of the present application;

[0090] Fig.16 This is one of the application scenario schematic diagrams of the embodiment of the present application;

[0091] Fig.17 This is the second schematic diagram of the application scenario of the embodiment of the present application. DETAILED DESCRIPTION

[0092] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0093] It should be noted that the high-performance network long connection establishment method and device provided in the present application can be used in the financial field, and can also be used in any field other than the financial field. The application field of the high-performance network long connection establishment method and device provided in the present application is not limited.

[0094] In areas such as instant messaging and data monitoring, the client may need to share data from the server in real time. To this end, the client can use two technical methods, timed polling or long connection. Due to the shortcomings of timed polling, such as high data sharing delay and high client resource consumption, the long connection technology solution is more popular with developers. The existing Java-based long connection technology is implemented using the Websocket protocol, which can provide a basic long connection service endpoint lifecycle management API. Developers can create, use and destroy long connection service endpoints by encapsulating the basic API, and cooperate with the client to implement encapsulation to support conventional server and client data sharing needs.

[0095] However, the existing technology currently only provides methods for creating, using and recycling a single connection, and cannot achieve unified viewing and scheduling of all online connections. Since the existing technology is based on a synchronization mechanism and does not establish a message buffering mechanism, it is easy to cause message delays, blockages, and even losses in high-concurrency scenarios. In addition, only a single connection logic can be implemented for important nodes such as connection creation and message processing. It cannot support the coexistence of multiple long-connection services, nor can it be compatible with multiple abnormal situations. There is no complete protection mechanism for abnormal situations such as network disconnection, power outages, and violent client operations. Once the above situation occurs, it may cause the server memory to idle and cause the system to crash.

[0096] Based on the problems existing in the prior art, this application provides a high-performance network long connection establishment method, see Figure 1 This method can provide an open and universal high-performance network persistent connection engine to quickly build a highly available persistent connection service, including:

[0097] S101: Establishing a persistent connection with the client according to the persistent connection establishment request of the client;

[0098] S102: Select a corresponding tracker from pre-created trackers according to the type of the client, and use the selected tracker to monitor the status of the long connection; the status includes creation, disconnection and operation;

[0099] S103: Use the pre-built splitter to send a message corresponding to the state to the client.

[0100] It is understandable that the method provided in this application can be applied to at least the following scenarios:

[0101] The first is that multiple business clients need to communicate with each other through the server. This scenario can exist in an e-commerce platform. The business client can be a customer handheld device 1 (such as a mobile phone) or a merchant desktop device 2 (such as a PC). The above two need to communicate with each other through the server 3. This communication is carried out in the form of a long connection, see Fig.16 .

[0102] The second scenario is that a resource client 5 provides resource services to a business client 4. This scenario often involves a large amount of computing and information exchange. For example, the business client 4 can be a financial institution that needs to complete a large amount of data computing, and the resource client 5 can be a data computing center with strong computing power. In this scenario, the financial institution can initiate a computing service request to the data computing center. In this process, the server 6 needs to help the two establish a long connection so that the data computing center can provide stable computing services to the financial institution, see Fig.17 .

[0103] It should be noted that the above scenarios are only for understanding the solutions described in this application, and the application scenarios of the solutions described in this application are not limited to these.

[0104] The executor of the method described in the present application may be a server. When the server receives a long connection establishment request sent by the client, it will establish a long connection with the client. This is specifically achieved through the connection pool provided by the method of the present application, as described below. Each client establishes a long connection with the server, which is equivalent to each client realizing a long connection with each other. The types of clients in the method described in the present application at least involve business clients and resource clients. Since different types of clients correspond to different types of trackers, it is necessary to select the corresponding tracker from the pre-created trackers according to the type of client, and use the selected tracker to monitor the status of the long connection; these states include at least creation, disconnection and operation.

[0105] It should be noted that a tracker is a program that tracks the life cycle of a service endpoint (creation, communication, and recycling). It can track based on the endpoint category. One tracker corresponds to one endpoint category. Developers can create different tracker implementation classes by implementing the tracker interface to achieve a single application supporting multiple long connection scenarios. The above service endpoint can be a client, but this application is not limited to this.

[0106] Finally, the method described in this application uses a pre-built splitter to send a message corresponding to the status to the client, so that the client can know the current persistent connection status in real time. In one embodiment, the client can also decide whether to continue the service process based on the current persistent connection status, and the server can also disconnect the persistent connection based on the subsequent disconnection request of the client to complete the billing.

[0107] From the above description, it can be seen that the high-performance network long connection establishment method and device provided by the present application can provide an open and universal high-performance network long connection engine by constructing a connection pool, a splitter and a tracker, thereby ensuring the unified management of service endpoints and the high concurrency of message distribution, thereby realizing parallel processing of multiple long connection scenarios, and can provide protection mechanisms for various abnormal situations such as power outages, network disconnections, and client violent operations, with simple access and stable service.

[0108] In one embodiment, see Figure 2 ,The client includes a resource client and the steps of pre-building a resource client tracker include:

[0109] S201: Use the EnumWsType enumeration class to establish the long connection type of the resource client tracker;

[0110] S202: Use the methods in the IWsProcessor interface to establish a standard interface for the resource client tracker;

[0111] S203: Establish a resource client tracker according to the long connection type of the resource client tracker and the standard interface of the resource client tracker.

[0112] It can be understood that the role of the resource client tracker is to track the connection status of the resource client, which includes but is not limited to establishing connection, disconnecting and maintaining connection.

[0113] In one embodiment, see Figure 3The methods in the IWsProcessor interface include the whenAddedToPool method, the whenRemovedFromPool method and the whenReceivedUpMsg method. The methods in the IWsProcessor interface are used to establish a standard interface for the resource client tracker, including: using the whenAddedToPool method to establish a standard business logic interface after the long connection corresponding to the resource client tracker is initialized (S301); using the whenRemovedFromPool method to establish a standard business logic interface after the long connection corresponding to the resource client tracker is destroyed (S302); using the whenReceivedUpMsg method to establish a standard business logic interface for uplink message processing in the long connection corresponding to the resource client tracker (S303).

[0114] Specifically, it can be established through the following steps:

[0115] ①Connection category enumeration

[0116] Use the EnumWsType enumeration class to extend the connection type, such as customer type, customer service type, etc.

[0117] ②Tracker standard interface

[0118] You can customize the tracker by implementing the IWsProcessor interface. The IWsProcessor interface provides three methods:

[0119] whenAddedToPool(WsockServer wsObj): triggered when the connection object is added to the connection pool. Developers can use this method to implement business logic after connection initialization.

[0120] whenRemovedFromPool(WsockServer wsObj): triggered when the connection object is destroyed. Developers can use this method to implement business logic after the connection is destroyed.

[0121] whenReceivedUpMsg(WsockServer wsObj,JSONObject upJson): triggered when the service receives an uplink message. Developers can use this method to implement the business logic of uplink message processing.

[0122] From the above description, it can be seen that the high-performance network long connection establishment method provided by this application can pre-build a resource client tracker.

[0123] In one embodiment, see Figure 4 The client includes a business client, and the steps of pre-building a business client tracker include:

[0124] S401: Use the EnumWsType enumeration class to establish the long connection type of the business client tracker;

[0125] S402: Use the method in the IWsProcessor interface to establish a standard interface for the business client tracker;

[0126] S403: Establish a service client tracker according to the long connection type of the service client tracker and the standard interface of the service client tracker.

[0127] It can be understood that the role of the resource client tracker is to track the connection status of the resource client, which includes but is not limited to establishing connection, disconnecting and maintaining connection.

[0128] In one embodiment, see Figure 5 The methods in the IWsProcessor interface include the whenAddedToPool method, the whenRemovedFromPool method and the whenReceivedUpMsg method. The methods in the IWsProcessor interface are used to establish a standard interface for the business client tracker, including: using the whenAddedToPool method to establish a standard business logic interface after the long connection corresponding to the business client tracker is initialized (S501); using the whenRemovedFromPool method to establish a standard business logic interface after the long connection corresponding to the business client tracker is destroyed (S502); using the whenReceivedUpMsg method to establish a standard business logic interface for uplink message processing in the long connection corresponding to the business client tracker (S503).

[0129] The specific steps for establishing a business client tracker are the same as those for establishing a resource client tracker, and are not described again here.

[0130] It can be seen from the above description that the high-performance network long connection establishment method provided by the present application can pre-build a business client tracker.

[0131] In one embodiment, see Figure 6 , establish a persistent connection with the client according to the persistent connection establishment request of the client, including:

[0132] S601: Use the void put method to establish a persistent connection with the client;

[0133] S602: Bind the relationship between the unique identifier uuid of the persistent connection and the persistent connection object wsObj;

[0134] S603: Bind the matching tracker according to the long link type of the long connection.

[0135] It is understandable that the high-performance network long connection establishment method provided by this application establishes a connection pool (WsockServerPool), and establishes a long connection with the client through the connection pool. The connection pool is responsible for the unified management of the life cycle of the long connection service endpoint, which can realize the elegant creation, use and recycling of the service endpoint in large-scale connection scenarios, and ensure the high utilization rate of the service endpoint in the pool through heartbeat, self-check and other mechanisms.

[0136] The connection pool is implemented based on the singleton mode, using a double-ended lock mechanism to ensure thread safety. All connection types and corresponding trackers are loaded during initialization. After initialization, the ready switch is turned on to provide external services. The functions of the connection pool include but are not limited to:

[0137] ①Create a connection

[0138] Use the void put(String uuid, WsockServer wsObj) method to create a connection, bind the connection's unique identifier uuid to the connection object wsObj, and bind the matching tracker according to the connection type.

[0139] ②Destroy the connection

[0140] Use the void remove(String uuid) method to destroy the connection, find the connection object wsObj according to the connection's unique identifier uuid, and clear it from memory.

[0141] ③ Broadcast message

[0142] Use the int broadcastMsgToAll(WsMsg msg) method to send a message to all online clients. This method returns the number of clients that have received the message.

[0143] ④ Targeted messages

[0144] Use int broadcastMsg(WsMsg msg,List <string>uuidList) method can be used to implement targeted messages for some online clients. This method returns the number of clients that have received the message.

[0145] ⑤Unicast message

[0146] Use the int broadcastMsg(WsMsg msg,String wsType,String wsOid) method to implement directed unicast messages, and uniquely identify a client through the connection type wsType and the connection identifier wsOid.

[0147] ⑥ Uplink message

[0148] Use void processUpMsg(WsockServer wsObj,JSONObject msgObj) to process the client's uplink message, and perform different processing for different connection objects wsObj and message contents msgObj.

[0149] It should be noted that the connection pool also provides a heartbeat mechanism to monitor the full life cycle status of the persistent connection. In one embodiment, the connection pool sends a heartbeat message to all clients every 5 seconds and requires the client to respond immediately. If the client does not respond to the heartbeat message for 30 consecutive seconds, it is considered that the client has gone offline, and the connection pool automatically recycles the service endpoint corresponding to the client.

[0150] From the above description, it can be seen that the high-performance network long connection establishment method provided in the present application can establish a long connection with the client according to the long connection establishment request of the client.

[0151] In one embodiment, see Figure 7 , using the pre-built splitter to send messages corresponding to the status to the client, including:

[0152] S701: Determine whether the message to be sent is congested, and if so, put the message to be sent into the ring buffer of the splitter;

[0153] S702: Using the prepaid memory mechanism and the lock-free concurrency mechanism, the message to be sent in the ring buffer is sent to the client.

[0154] It is understandable that the splitter can be used as a message distribution center for long-connection service endpoints. It is based on features such as ring buffer, prepaid memory, and lock-free concurrency, which can greatly reduce the probability of message delays, message loss, and other problems in high-concurrency scenarios.

[0155] The splitter in this application is used to send messages to the client by using its own characteristics, including but not limited to: having a ring buffer, a prepaid memory mechanism, and a lock-free concurrency mechanism. Using the above mechanism, when there are too many concurrent messages causing network congestion, messages can be sent to the client in an orderly manner without causing a lot of delays, as follows:

[0156] ① Ring buffer

[0157] This application implements a circular buffer based on an array. The circular buffer uses a number to identify its next available element. To put data in the buffer, you only need to use the number to find the available element position. The buffer elements that have been consumed will not be destroyed immediately. If the use result of an element fails, we can find the failed element segment in the buffer through the failed element position and the current available element position, and re-consume these elements. The consumed elements are kept until they are replaced by new elements. Developers can set a reasonable buffer size according to their own business characteristics.

[0158] ②Prepay memory

[0159] Since the ring buffer is implemented based on an array, we can pre-allocate memory to the buffer and keep the buffer elements permanently valid, which means that garbage collection is almost never triggered. There is no need to create an object for each addition of data like a linked list, and to destroy the object when it is deleted.

[0160] ③Lock-free concurrency

[0161] Assuming the length of the buffer is bufferSize, we set two pointers: head points to the next read position, and tail points to the next write position. Since this is a circular buffer, there is a problem here, how to judge whether the buffer is full or empty. The rule used here is that the last unit of the buffer does not store data. Therefore, if head == tail, then the buffer is empty. If head == tail + 1 (mod bufferSize), then the buffer is full.

[0162] How to read and write buffers in a thread-safe manner in a lock-free manner. The basic principle is this: when performing a read operation, we only modify the value of the head, and when performing a write operation, we only modify the value of the tail. When writing, we modify the value of the tail after writing the content to the buffer; when performing a read operation, we will read the value of the tail and assign it to copyTail, and the assignment operation is an atomic operation. Therefore, after reading copyTail, there must be data to read from head to copyTail, and there will be no situation where the read operation is performed without writing the data. Similarly, the value of the head will be modified after the read operation is completed; and before the write operation, the value of the head will be read to determine whether there is space to write data. Therefore, at this time, there must be space to write data between tail and head-1, and there will be no situation where the data at a position is overwritten by the write operation before it is read.

[0163] From the above description, it can be seen that the high-performance network long connection establishment method provided by the present application can use the pre-built splitter to send the message corresponding to the status to the client.

[0164] This case is an "artificial intelligence algorithm training platform" built by ICBC Technology. The platform provides algorithm developers with computing resources, software environment and other infrastructure required for algorithm training. Among them, computing resources are charged according to the length of use. The system needs to monitor the operating status of computing resources. When the developer selects computing resources and turns them on, the system will deduct fees every half an hour of normal operation. On the other hand, the system also needs to monitor the online status of the developer account. If the developer turns on the computing resources and does not turn them off, the developer account goes offline due to network disconnection, power outage or misoperation. At this time, the system needs to shut it down in time to avoid additional costs and waste of resources. In addition, if the developer's balance is insufficient during the training process, the system needs to notify the developer to recharge in time. Finally, if the training is over, the system needs to notify the developer of the completion of the training and automatically shut down the computing resources.

[0165] In order to better illustrate the feasibility of the technical solution described in this application, an example is now given to illustrate how to use the "open high-performance long connection engine" corresponding to the method described in this application to implement monitoring services.

[0166] After the developer goes online, the developer's WEB system establishes a persistent connection with the monitoring service; after the computing resources are turned on, the computing resources establish a persistent connection with the monitoring service.

[0167] ①Define tracker

[0168] This case involves two types of persistent connection clients: developer web system and computing resources. Two corresponding trackers need to be defined.

[0169] a. Developer WEB system tracker

[0170] Responsible for monitoring the developer's online, offline, and upstream messages. When the developer is online, put its long connection service endpoint into the connection pool; when the developer is offline, it is necessary to close the computing resources it is using and remove its service endpoint from the connection pool. When it is monitored that the developer's balance is insufficient, a downstream message will be sent to the WEB client to remind the developer to recharge; when the training is completed, a downstream message will be sent to the WEB client to inform the developer of the training results.

[0171] b. Computing Resource Tracker

[0172] Responsible for monitoring the online, offline, and uplink messages of computing resources. When the computing resources are turned on, their long-connection service endpoints are placed in the connection pool and billing begins; when the computing resources are turned off, their service endpoints are removed from the connection pool and billing stops; when the training is completed, the computing resources can send an uplink message to the monitoring service, which notifies the developer's WEB client of the completion of the training and shuts down the computing resources.

[0173] ②Connection pool management

[0174] The connection pool maintains a healthy connection with the developer's WEB system and computing resources through the heartbeat mechanism. If the developer's WEB system or computing resources do not respond to the heartbeat message in time within 30 seconds, the connection pool will consider it disconnected, remove its corresponding service endpoint from the connection pool and perform corresponding business operations.

[0175] In addition, the connection pool will establish a logical relationship between the service endpoint of the developer's WEB system and the computing resource service endpoint corresponding to the developer. When the developer goes offline, the monitoring service can find the computing resources opened by the developer in time and quickly close them to avoid resource waste. When billing a certain instance resource, if the developer's balance is insufficient, the corresponding service endpoint of the developer can be found in time and a unicast message can be sent to notify the developer to recharge. When the training of a computing resource is completed, the corresponding developer can be notified of the training result information in time.

[0176] ③Splitter ensures high performance

[0177] This case involves the following message interaction scenarios:

[0178] a. Broadcast heartbeat message

[0179] b. Unicast training result message

[0180] c. Unicast insufficient balance message

[0181] d. Unicast shutdown command message

[0182] When each service endpoint is established, a 1024-length ring buffer will be created for it. This buffer directly pre-occupies memory without resource recovery. When the above message needs to be sent, the monitoring service first puts the message into the ring buffer of the corresponding service endpoint and waits for the splitter to send the message. The splitter quickly and evenly obtains the waiting message from the ring buffer to perform the sending operation, and ensures the thread safety of the ring buffer through the zero concurrency mechanism. When there are a large number of messages that need to be sent in a short period of time, since the ring buffer has pre-occupied memory, a large number of memory allocation operations are reduced, ensuring fast and efficient program execution. In addition, the put operation of the ring buffer is implemented using an asynchronous mechanism, and there will be no service endpoint message blocking. The splitter implements message peak shaving and valley filling based on the ring buffer.

[0183] In summary, the beneficial effects of the technical solution described in this application include:

[0184] 1) Unified management of service endpoints

[0185] The connection pool provided in this application can uniformly manage long-connection service endpoints, and can realize broadcast messages to all service endpoints, targeted messages to some service endpoints, and unicast messages to a single service endpoint. It is powerful.

[0186] 2) Optimize concurrent message delay and message loss

[0187] This application uses a ring buffer to implement a splitter, and effectively reduces the probability of message delay and message loss in high concurrency scenarios through technologies such as pre-funded memory and lock-free concurrency.

[0188] 3) A single application can support multiple scenarios

[0189] The tracker provided in this application can be implemented according to the developer's needs. Multiple trackers can be implemented in one application. Each tracker can correspond to a connection type. The business logic of each type of connection's life cycle nodes such as creation, destruction, and receiving uplink messages can be implemented in its corresponding tracker.

[0190] 4) Compatible with various abnormal situations

[0191] The connection pool in this application provides a unified heartbeat mechanism, which can quickly identify abnormal connections caused by network disconnection, power outages, client violent operations, etc. If the connection is confirmed to be abnormal, it will be destroyed immediately to ensure high utilization of memory resources.

[0192] Based on the same inventive concept, the embodiments of the present application also provide a high-performance network long connection establishment device, which can be used to implement the method described in the above embodiments, as described in the following embodiments. Since the principle of solving the problem by the high-performance network long connection establishment device is similar to that of the high-performance network long connection establishment method, the implementation of the high-performance network long connection establishment device can refer to the implementation of the method based on software performance benchmark determination, and the repeated parts will not be repeated. As used below, the term "unit" or "module" can be a combination of software and / or hardware that implements predetermined functions. Although the system described in the following embodiments is preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceived.

[0193] In one embodiment, see Figure 8 In order to provide an open and universal high-performance network long connection engine to quickly build a highly available long connection service, the present application provides a high-performance network long connection establishment device, including: a connection establishment unit 801, a status monitoring unit 802 and a message sending unit 803.

[0194] A connection establishing unit 801 is used to establish a persistent connection with the client according to a persistent connection establishment request of the client;

[0195] A status monitoring unit 802 is used to select a corresponding tracker from pre-created trackers according to the type of the client, and use the selected tracker to monitor the status of the long connection; the status includes creation, disconnection and operation;

[0196] The message sending unit 803 is used to send the message corresponding to the state to the client by using the pre-built splitter.

[0197] In one embodiment, see Fig. 9 The client includes a resource client, including: a connection type determination unit 901, a standard interface determination unit 902 and a tracker establishment unit 903.

[0198] A connection type determination unit 901 is used to establish a long connection type of the resource client tracker using the EnumWsType enumeration class;

[0199] A standard interface determination unit 902, configured to establish a standard interface of the resource client tracker using a method in an IWsProcessor interface;

[0200] The tracker establishing unit 903 is used to establish the resource client tracker according to the long connection type of the resource client tracker and the standard interface of the resource client tracker.

[0201] In one embodiment, see Fig.10 The methods in the IWsProcessor interface include a whenAddedToPool method, a whenRemovedFromPool method, and a whenReceivedUpMsg method. The standard interface determination unit 902 includes:

[0202] The first standard interface determination module 1001 is used to establish the business logic standard interface after the long connection initialization corresponding to the resource client tracker by using the whenAddedToPool method;

[0203] The second standard interface determination module 1002 is used to establish the business logic standard interface after the long connection corresponding to the resource client tracker is destroyed by using the whenRemovedFromPool method;

[0204] The third standard interface determination module 1003 is used to establish a business logic standard interface for uplink message processing in the long connection corresponding to the resource client tracker by using the whenReceivedUpMsg method.

[0205] In one embodiment, see Fig.11 , the client includes a business client, including:

[0206] The connection type determination unit 1101 is used to establish the long connection type of the service client tracker by using the EnumWsType enumeration class;

[0207] A standard interface determining unit 1102, configured to establish a standard interface of the service client tracker using a method in an IWsProcessor interface;

[0208] The tracker establishing unit 1103 is configured to establish the service client tracker according to the long connection type of the service client tracker and the standard interface of the service client tracker.

[0209] In one embodiment, see Fig.12 The methods in the IWsProcessor interface include a whenAddedToPool method, a whenRemovedFromPool method, and a whenReceivedUpMsg method. The standard interface determination unit 902 includes:

[0210] The first standard interface determination module 1201 is used to establish the business logic standard interface after the long connection initialization corresponding to the business client tracker by using the whenAddedToPool method;

[0211] The second standard interface determination module 1202 is used to establish the business logic standard interface after the long connection corresponding to the business client tracker is destroyed by using the whenRemovedFromPool method;

[0212] The third standard interface determination module 1203 is used to establish a business logic standard interface for uplink message processing in the long connection corresponding to the business client tracker by using the whenReceivedUpMsg method.

[0213] In one embodiment, see Fig.13 , the high-performance network long connection establishment device, the connection establishment unit, includes: a connection establishment module 1301, a relationship binding module 1302 and a tracker matching module 1303.

[0214] The connection establishment module 1301 is used to establish a persistent connection with the client using a void put method;

[0215] A relationship binding module 1302 is used to bind the relationship between the unique identifier uuid of the persistent connection and the persistent connection object wsObj;

[0216] The tracker matching module 1303 is used to bind a matching tracker according to the long link type of the long connection.

[0217] In one embodiment, see Fig.14 , the message sending unit 803 includes:

[0218] The message buffer module 1401 is used to determine whether the message to be sent is congested, and if so, put the message to be sent into the ring buffer of the splitter;

[0219] The message sending module 1402 is used to send the message to be sent in the ring buffer to the client by using the prepaid memory mechanism and the lock-free concurrency mechanism.

[0220] In one embodiment, the high-performance network long connection establishment device further includes:

[0221] The heartbeat monitoring unit is used to monitor the full life cycle status of the long connection using the heartbeat mechanism in the pre-built connection pool.

[0222] From the hardware level, in order to provide an open and universal high-performance network persistent connection engine to quickly build a highly available persistent connection service, the present application provides an embodiment of an electronic device for implementing all or part of the content of the high-performance network persistent connection establishment method, and the electronic device specifically includes the following content:

[0223] Processor, memory, communication interface and bus; wherein the processor, memory and communication interface communicate with each other through the bus; the communication interface is used to realize information transmission between the high-performance network long connection establishment device and the core business system, user terminal and related databases and other related equipment; the logic controller can be a desktop computer, a tablet computer and a mobile terminal, etc., but this embodiment is not limited to this. In this embodiment, the logic controller can be implemented with reference to the embodiment of the high-performance network long connection establishment method and the embodiment of the high-performance network long connection establishment device in the embodiment, and the contents are incorporated herein, and the repeated parts are not repeated.

[0224] It is understandable that the user terminal may include a smart phone, a tablet electronic device, a network set-top box, a portable computer, a desktop computer, a personal digital assistant (PDA), a vehicle-mounted device, a smart wearable device, etc. Among them, the smart wearable device may include smart glasses, a smart watch, a smart bracelet, etc.

[0225] In practical applications, part of the high-performance network long connection establishment method can be executed on the electronic device side as described above, or all operations can be completed in the client device. The specific selection can be based on the processing capability of the client device and the limitations of the user's usage scenario. This application does not limit this. If all operations are completed in the client device, the client device may also include a processor.

[0226] The client device may have a communication module (i.e., a communication unit) that can communicate with a remote server to achieve data transmission with the server. The server may include a server on the task scheduling center side, and other implementation scenarios may also include a server on an intermediate platform, such as a server on a third-party server platform that has a communication link with the task scheduling center server. The server may include a single computer device, or a server cluster consisting of multiple servers, or a server structure of a distributed device.

[0227] Fig.15 FIG. 9 is a schematic block diagram of the system structure of the electronic device 9600 according to an embodiment of the present application. Fig.15 As shown, the electronic device 9600 may include a central processor 9100 and a memory 9140; the memory 9140 is coupled to the central processor 9100. It is worth noting that Fig.15 is exemplary; other types of structures may also be used to supplement or replace this structure to implement telecommunication functions or other functions.

[0228] In one embodiment, the function of the high-performance network long connection establishment method can be integrated into the central processor 9100. The central processor 9100 can be configured to perform the following control:

[0229] S101: Establishing a persistent connection with the client according to the persistent connection establishment request of the client;

[0230] S102: Select a corresponding tracker from pre-created trackers according to the type of the client, and use the selected tracker to monitor the status of the long connection; the status includes creation, disconnection and operation;

[0231] S103: Use the pre-built splitter to send a message corresponding to the state to the client.

[0232] From the above description, it can be seen that the high-performance network long connection establishment method and device provided by the present application can provide an open and universal high-performance network long connection engine by constructing a connection pool, a splitter and a tracker, thereby ensuring the unified management of service endpoints and the high concurrency of message distribution, thereby realizing parallel processing of multiple long connection scenarios, and can provide protection mechanisms for various abnormal situations such as power outages, network disconnections, and client violent operations, with simple access and stable service.

[0233] In another embodiment, the high-performance network long connection establishment device can be configured separately from the central processor 9100. For example, the data composite transmission device high-performance network long connection establishment device can be configured as a chip connected to the central processor 9100, and the function of the high-performance network long connection establishment method is realized through the control of the central processor.

[0234] like Fig.15 As shown, the electronic device 9600 may also include: a communication module 9110, an input unit 9120, an audio processor 9130, a display 9160, and a power supply 9170. It is worth noting that the electronic device 9600 does not necessarily have to include Fig.15 In addition, the electronic device 9600 may also include Fig.15 For components not shown, reference may be made to the prior art.

[0235] like Fig.15 As shown, the central processing unit 9100 is sometimes also referred to as a controller or an operation control, and may include a microprocessor or other processor device and / or logic device. The central processing unit 9100 receives input and controls the operation of various components of the electronic device 9600.

[0236] The memory 9140 may be, for example, one or more of a cache, a flash memory, a hard drive, a removable medium, a volatile memory, a non-volatile memory or other suitable devices. The above-mentioned information related to the failure may be stored, and a program for executing the relevant information may also be stored. The CPU 9100 may execute the program stored in the memory 9140 to implement information storage or processing, etc.

[0237] The input unit 9120 provides input to the central processing unit 9100. The input unit 9120 is, for example, a key or a touch input device. The power supply 9170 is used to provide power to the electronic device 9600. The display 9160 is used to display display objects such as images and texts. The display may be, for example, an LCD display, but is not limited thereto.

[0238] The memory 9140 may be a solid-state memory, such as a read-only memory (ROM), a random access memory (RAM), a SIM card, etc. It may also be a memory that saves information even when the power is off, can be selectively erased, and is provided with more data, examples of which are sometimes referred to as EPROMs, etc. The memory 9140 may also be some other type of device. The memory 9140 includes a buffer memory 9141 (sometimes referred to as a buffer). The memory 9140 may include an application / function storage unit 9142, which is used to store application programs and function programs or processes for executing the operation of the electronic device 9600 through the central processor 9100.

[0239] The memory 9140 may also include a data storage unit 9143 for storing data, such as contacts, digital data, pictures, sounds, and / or any other data used by the electronic device. The driver storage unit 9144 of the memory 9140 may include various drivers for communication functions of the electronic device and / or for executing other functions of the electronic device (such as messaging applications, address book applications, etc.).

[0240] The communication module 9110 is a transmitter / receiver 9110 that sends and receives signals via an antenna 9111. The communication module (transmitter / receiver) 9110 is coupled to the central processor 9100 to provide input signals and receive output signals, which may be the same as the case of a conventional mobile communication terminal.

[0241] Based on different communication technologies, multiple communication modules 9110 may be provided in the same electronic device, such as a cellular network module, a Bluetooth module and / or a wireless LAN module. The communication module (transmitter / receiver) 9110 is also coupled to a speaker 9131 and a microphone 9132 via an audio processor 9130 to provide an audio output via the speaker 9131 and receive an audio input from the microphone 9132, thereby realizing a common telecommunication function. The audio processor 9130 may include any suitable buffer, decoder, amplifier, etc. In addition, the audio processor 9130 is also coupled to the central processor 9100, so that recording can be performed on the local machine through the microphone 9132, and the sound stored on the local machine can be played through the speaker 9131.

[0242] The embodiments of the present application also provide a computer-readable storage medium capable of implementing all the steps of the method for establishing a high-performance network persistent connection in the above embodiment, where the execution subject is a server or a client. The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, all the steps of the method for establishing a high-performance network persistent connection in the above embodiment are implemented. For example, when the processor executes the computer program, the following steps are implemented:

[0243] S101: Establishing a persistent connection with the client according to the persistent connection establishment request of the client;

[0244] S102: Select a corresponding tracker from pre-created trackers according to the type of the client, and use the selected tracker to monitor the status of the long connection; the status includes creation, disconnection and operation;

[0245] S103: Use the pre-built splitter to send a message corresponding to the state to the client.

[0246] From the above description, it can be seen that the high-performance network long connection establishment method and device provided by the present application can provide an open and universal high-performance network long connection engine by constructing a connection pool, a splitter and a tracker, thereby ensuring the unified management of service endpoints and the high concurrency of message distribution, thereby realizing parallel processing of multiple long connection scenarios, and can provide protection mechanisms for various abnormal situations such as power outages, network disconnections, and client violent operations, with simple access and stable service.

[0247] It will be appreciated by those skilled in the art that embodiments of the present invention may be provided as methods, devices, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0248] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (apparatus), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0249] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0250] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0251] The present invention uses specific embodiments to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for those skilled in the art, according to the idea of ​​the present invention, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.< / string>

Claims

1. A high-performance network long connection establishment method, characterized in that: include: Establishing a persistent connection with the client according to the persistent connection establishment request of the client; Selecting a corresponding tracker from pre-created trackers according to the type of the client, and using the selected tracker to monitor the status of the persistent connection; the status includes creation, disconnection, and operation; Using a pre-built splitter, a message corresponding to the state is sent to the client; The client includes a resource client, and the step of pre-building a resource client tracker includes: using the EnumWsType enumeration class to establish a long connection type of the resource client tracker; using the method in the IWsProcessor interface to establish a standard interface of the resource client tracker; establishing the resource client tracker according to the long connection type of the resource client tracker and the standard interface of the resource client tracker; The client includes a business client, and the step of pre-building a business client tracker includes: using the EnumWsType enumeration class to establish a long connection type of the business client tracker; using the method in the IWsProcessor interface to establish a standard interface of the business client tracker; establishing the business client tracker according to the long connection type of the business client tracker and the standard interface of the business client tracker; The developer WEB system tracker is responsible for monitoring the developer's online, offline, and uplink messages. When the developer is online, its long-connection service endpoint is placed in the connection pool. When the developer is offline, the computing resources it is using are closed and its service endpoint is removed from the connection pool. When it is monitored that the developer's balance is insufficient, a downlink message will be sent to the WEB client to remind the developer to recharge. When the training is completed, a downlink message will be sent to the WEB client to inform the developer of the training results. Among them, the computing power resource tracker is responsible for monitoring the online, offline, and uplink messages of computing power resources; when the computing power resources are turned on, their long connection service endpoints are placed in the connection pool and billing begins; when the computing power resources are shut down, their service endpoints are removed from the connection pool and billing stops; when the training is completed, the computing power resources send an uplink message to the monitoring service, the monitoring service notifies the developer's WEB client of the completion of the training, and shuts down the computing power resources.

2. The method for establishing a high-performance network long connection according to claim 1, characterized in that: The methods in the IWsProcessor interface include the whenAddedToPool method, the whenRemovedFromPool method, and the whenReceivedUpMsg method. The method in the IWsProcessor interface is used to establish the standard interface of the resource client tracker, including: Use the whenAddedToPool method to establish the business logic standard interface after the persistent connection initialization corresponding to the resource client tracker; Use the whenRemovedFromPool method to establish a standard business logic interface after the long connection corresponding to the resource client tracker is destroyed; The whenReceivedUpMsg method is used to establish a business logic standard interface for uplink message processing in the long connection corresponding to the resource client tracker.

3. The method for establishing a high-performance network long connection according to claim 1, characterized in that: The methods in the IWsProcessor interface include the whenAddedToPool method, the whenRemovedFromPool method, and the whenReceivedUpMsg method. The method in the IWsProcessor interface is used to establish the standard interface of the service client tracker, including: Use the whenAddedToPool method to establish the business logic standard interface after the long connection initialization corresponding to the business client tracker; Use the whenRemovedFromPool method to establish a standard business logic interface after the long connection corresponding to the business client tracker is destroyed; The whenReceivedUpMsg method is used to establish a business logic standard interface for uplink message processing in the long connection corresponding to the business client tracker.

4. The method for establishing a high-performance network long connection according to claim 1, characterized in that: The establishing a persistent connection with the client according to the persistent connection establishment request of the client includes: Use the void put method to establish a persistent connection with the client; Bind the relationship between the unique identifier uuid of the persistent connection and the persistent connection object wsObj; Bind a matching tracker according to the long link type of the long connection.

5. The method for establishing a high-performance network long connection according to claim 1, characterized in that: The using a pre-built splitter to send a message corresponding to the state to the client includes: Determine whether congestion occurs in the message to be sent, and if so, put the message to be sent into the ring buffer of the splitter; The messages to be sent in the ring buffer are sent to the client by using the prepaid memory mechanism and the lock-free concurrency mechanism.

6. The method for establishing a high-performance network long connection according to claim 1, characterized in that: Also includes: The heartbeat mechanism in the pre-built connection pool is used to monitor the full life cycle status of the long connection.

7. A high-performance network long connection establishment device, characterized in that: include: A connection establishing unit, configured to establish a persistent connection with the client according to a persistent connection establishment request of the client; A status monitoring unit, configured to select a corresponding tracker from pre-created trackers according to the type of the client, and monitor the status of the persistent connection using the selected tracker; The states include creation, disconnection and operation; A message sending unit, configured to send a message corresponding to the state to the client using a pre-built splitter; Wherein, the client includes a resource client, including: A connection type determination unit of a resource client, used to establish a long connection type of the resource client tracker using an EnumWsType enumeration class; A standard interface determination unit of a resource client, used for establishing a standard interface of the resource client tracker by using a method in an IWsProcessor interface; A resource client tracker establishing unit, used to establish the resource client tracker according to the long connection type of the resource client tracker and the standard interface of the resource client tracker; The client includes a business client, including: A connection type determination unit of the business client, used to establish a long connection type of the business client tracker using the EnumWsType enumeration class; A standard interface determination unit of the service client, used to establish a standard interface of the service client tracker by using the method in the IWsProcessor interface; A service client tracker establishing unit, configured to establish the service client tracker according to a long connection type of the service client tracker and a standard interface of the service client tracker; The developer WEB system tracker is responsible for monitoring the developer's online, offline, and uplink messages. When the developer is online, its long-connection service endpoint is placed in the connection pool. When the developer is offline, the computing resources it is using are closed and its service endpoint is removed from the connection pool. When it is monitored that the developer's balance is insufficient, a downlink message will be sent to the WEB client to remind the developer to recharge. When the training is completed, a downlink message will be sent to the WEB client to inform the developer of the training results. Among them, the computing power resource tracker is responsible for monitoring the online, offline, and uplink messages of computing power resources; when the computing power resources are turned on, their long connection service endpoints are placed in the connection pool and billing begins; when the computing power resources are shut down, their service endpoints are removed from the connection pool and billing stops; when the training is completed, the computing power resources send an uplink message to the monitoring service, the monitoring service notifies the developer's WEB client of the completion of the training, and shuts down the computing power resources.

8. The high-performance network long connection establishment device according to claim 7, characterized in that: The methods in the IWsProcessor interface include a whenAddedToPool method, a whenRemovedFromPool method, and a whenReceivedUpMsg method. The standard interface determination unit includes: A first standard interface determination module, used to establish a business logic standard interface after the long connection initialization corresponding to the resource client tracker by using the whenAddedToPool method; A second standard interface determination module is used to establish a business logic standard interface after the long connection corresponding to the resource client tracker is destroyed by using the whenRemovedFromPool method; The third standard interface determination module is used to establish a business logic standard interface for uplink message processing in the long connection corresponding to the resource client tracker by using the whenReceivedUpMsg method.

9. The high-performance network long connection establishment device according to claim 7, characterized in that: The methods in the IWsProcessor interface include a whenAddedToPool method, a whenRemovedFromPool method, and a whenReceivedUpMsg method. The standard interface determination unit includes: A first standard interface determination module, used to establish a business logic standard interface after the long connection initialization corresponding to the business client tracker by using the whenAddedToPool method; A second standard interface determination module is used to establish a business logic standard interface after the long connection corresponding to the business client tracker is destroyed by using the whenRemovedFromPool method; The third standard interface determination module is used to establish a business logic standard interface for uplink message processing in the long connection corresponding to the business client tracker by using the whenReceivedUpMsg method.

10. The high-performance network long connection establishment device according to claim 7, characterized in that: The connection establishing unit comprises: A connection establishment module, used to establish a persistent connection with the client using a void put method; A relationship binding module, used to bind the relationship between the unique identifier uuid of the persistent connection and the persistent connection object wsObj; The tracker matching module is used to bind the matching tracker according to the long link type of the long connection.

11. The high-performance network long connection establishment device according to claim 7, characterized in that: The message sending unit comprises: A message buffer module, used to determine whether congestion occurs in the message to be sent, and if so, put the message to be sent into the ring buffer of the splitter; The message sending module is used to send the message to be sent in the ring buffer to the client by using the prepaid memory mechanism and the lock-free concurrency mechanism.

12. The high-performance network long connection establishment device according to claim 7, characterized in that: Also includes: The heartbeat monitoring unit is used to monitor the full life cycle status of the long connection using the heartbeat mechanism in the pre-built connection pool.

13. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the steps of the high-performance network long connection establishment method described in any one of claims 1 to 6 are implemented.

14. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method for establishing a high-performance network long connection described in any one of claims 1 to 6 are implemented.

Citation Information

Patent Citations

  • Method and server for communicating with client

    CN102932352A

  • TCP long connection communication system and method

    CN103618741A

  • Service realization method and device based on TCP long connection

    CN105763634A

  • Long connection maintenance method and device

    CN106972977A

  • Method and device for processing long connection establishment request

    CN107135279A