Connection method and system for websocket cluster and client
By obtaining the hardware indicators and buried point information of the nodes, dynamically adjusting the weights, and filtering out nodes with excellent hardware and service capabilities, solving the problem of node selection based on hardware capabilities in the existing technology, and improving the message processing and delivery of the websocket cluster Efficiency improves the stability of the system.
Patent Information
- Application Number
- CN202411179184.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-26
- Publication Date
- 2024-12-20
AI Technical Summary
When selecting nodes to connect to clients, existing websocket clusters only consider hardware capabilities and ignore the node's interaction capabilities, resulting in poor messaging and processing efficiency.
By obtaining the node's hardware indicators and buried point information, dynamically adjusting the weights, filtering out nodes with excellent hardware and service capabilities, ensuring efficient processing and message delivery of connection requests.
It improves the message processing and delivery efficiency of the websocket cluster, ensures that the selection of nodes meets the connection requirements, provides high-quality service capabilities, and improves the stability and response capabilities of the system.
Smart Images

Figure CN119172424A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data transmission, and in particular to a method and system for connecting a websocket cluster and a client. Background Art
[0002] WebSocket is a full-duplex communication protocol over a single TCP connection. WebSocket simplifies data exchange between clients and allows the server to actively push data to the receiver.
[0003] Traditional single-node WebSockets have limited connection and processing capabilities, making them incapable of handling a large number of connections and messages. A multi-node WebSocket cluster, however, distributes connections across multiple nodes, improving overall processing power and concurrency. When connecting to clients using a multi-node WebSocket cluster, it's important to consider the load on each node, providing clients with a more stable connection node for efficient message delivery and processing.
[0004] When connecting nodes and clients in a current WebSocket cluster, node selection primarily focuses on hardware capabilities such as bandwidth, CPU, and memory, without considering the node's interactive capabilities. This often results in poor connection and processing capabilities of the nodes connected to the client, affecting the efficiency of message transmission and processing. Summary of the Invention
[0005] In view of the shortcomings of the existing technology, the purpose of the present invention is to provide a method and system for connecting a websocket cluster and a client, aiming to solve the technical problem that in the existing technology, when selecting a node in a websocket cluster to connect to a client, only the hardware capabilities of the node are considered, and the consideration of the interactive capabilities of the node is lacking, resulting in poor efficiency of message transmission and message processing.
[0006] To achieve the above objectives, in a first aspect, an embodiment of the present application provides a method for connecting a websocket cluster to a client, which is applied to a websocket cluster, wherein the websocket cluster includes several nodes, each of which is used to connect to a client. The method for connecting the websocket cluster to the client includes the following steps:
[0007] When a connection request from the client is obtained, hardware indicators of the node are obtained, the hardware indicators including CPU usage, memory usage and connection rate, and a first initial weight parameter, a second initial weight parameter and a third initial weight parameter are configured for the CPU usage, the memory usage and the connection rate, respectively, to obtain the initial hardware capability of the node;
[0008] Based on a comparison result between the hardware indicator and the indicator threshold, updating the first initial weight, the second initial weight, and the third initial weight to obtain the real-time hardware capability of the node;
[0009] Acquire a plurality of candidate nodes from the plurality of nodes based on the real-time hardware capability;
[0010] Collecting tracking information of the candidate node in a specified time window, and obtaining the service capability of the candidate node through the tracking information;
[0011] An optimal node is determined from among the candidate nodes based on the service capability, and the client is connected to the optimal node.
[0012] Furthermore, the calculation formula of the initial hardware capability is:
[0013] P y =λ1*l1*l2+λ2*l2+λ3*l3,
[0014] Among them, P y represents the initial hardware capability, λ1 represents the first initial weight parameter, λ2 represents the second initial weight parameter, λ3 represents the third initial weight parameter, l1 represents the CPU usage rate, l2 represents the memory usage rate, l3 represents the connection rate, and l now Indicates the current number of connections of the node, l max Indicates the maximum number of connections for a node.
[0015] Furthermore, the step of updating the first initial weight, the second initial weight, and the third initial weight based on the comparison result between the hardware indicator and the indicator threshold includes:
[0016] Comparing the CPU usage rate with a first usage rate threshold, if the CPU usage rate is greater than the first usage rate threshold, obtaining a first duration, if the first duration is greater than the first time threshold, updating the first initial weight to a first sub-adjustment weight, if the CPU usage rate is less than the first usage rate threshold, obtaining a second duration, if the second duration is greater than the first time threshold, updating the first initial weight to a second sub-adjustment weight;
[0017] Comparing the memory usage with a second usage threshold, if the memory usage is greater than the second usage threshold, obtaining a third duration, if the third duration is greater than the second time threshold, updating the second initial weight to a third sub-adjustment weight, if the memory usage is less than the second usage threshold, obtaining a fourth duration, if the fourth duration is greater than the second time threshold, updating the second initial weight to a fourth sub-adjustment weight;
[0018] The connection rate is compared with a third usage rate threshold; if the connection rate is greater than the third usage rate threshold, a fifth duration is obtained; if the fifth duration is greater than the third time threshold, the third initial weight is updated to a fifth sub-adjustment weight; if the connection rate is less than the third usage rate threshold, a sixth duration is obtained; if the sixth duration is greater than the third time threshold, the third initial weight is updated to a sixth sub-adjustment weight.
[0019] Furthermore, the formula for obtaining the first sub-adjustment weight is:
[0020]
[0021] in, represents the first sub-adjustment weight, λ1 represents the first initial weight, and δ1 represents the adjustment factor;
[0022] The formula for obtaining the second sub-adjustment weight is:
[0023]
[0024] in, Represents the second sub-adjustment weight.
[0025] Furthermore, the tracking point information includes the connection establishment time, connection maintenance time, total connection times, connection failure times, successful reconnection times, reconnection times, message transmission times, message loss times, message error times, message repetition times, message transmission delay time, and message processing time.
[0026] Furthermore, the step of obtaining the service capability of the candidate node through the tracking point information includes:
[0027] Determine the connection stability index by the connection establishment time, the connection maintenance time, the total number of connections, the number of connection failures, the number of successful reconnections, and the number of reconnections;
[0028] Determine a message stability index by the number of message transmissions, the number of message losses, the number of message errors, and the number of message repetitions;
[0029] Determine the message speed index by the message transmission delay duration and the message processing duration;
[0030] The service capability of the candidate node is obtained based on the connection stability index, the message stability index, and the message speed index.
[0031] Furthermore, the calculation formula of the service capability is:
[0032] Service=α*CS-β*(1-MS)-γ*(1-MSpeed),
[0033] Among them, Service represents service capability, CS represents connection stability index, MS represents message stability index, MSpeed represents message speed index, and α, β, and γ represent weight values.
[0034] In a second aspect, an embodiment of the present application provides a system for connecting a websocket cluster to a client, which is applied to the method for connecting a websocket cluster to a client as described in the first aspect above, and the system includes:
[0035] an acquisition module, configured to, when receiving a connection request from the client, acquire hardware indicators of the node, the hardware indicators including CPU usage, memory usage, and connection rate, and configure a first initial weight parameter, a second initial weight parameter, and a third initial weight parameter for the CPU usage, the memory usage, and the connection rate, respectively, to acquire the initial hardware capability of the node;
[0036] An updating module, configured to update the first initial weight, the second initial weight, and the third initial weight based on a comparison result between the hardware indicator and the indicator threshold, so as to obtain the real-time hardware capability of the node;
[0037] A first selection module, configured to obtain a plurality of candidate nodes from the plurality of nodes based on the real-time hardware capability;
[0038] A collection module is used to collect tracking information of the candidate node in a specified time window and obtain the service capability of the candidate node through the tracking information;
[0039] The second selection module determines an optimal node from the candidate nodes based on the service capability, and connects the client to the optimal node.
[0040] In a third aspect, an embodiment of the present application provides a computer comprising a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the computer program, the method for connecting a websocket cluster and a client as described in the first aspect above is implemented.
[0041] In a fourth aspect, an embodiment of the present application provides a storage medium on which a computer program is stored. When the computer program is executed by a processor, the method for connecting a websocket cluster and a client as described in the first aspect above is implemented.
[0042] Compared with the existing technology, the beneficial effect of the present invention is that: when a connection request is obtained, several nodes are preferentially screened based on the real-time hardware capabilities to ensure that the alternative nodes have better hardware capabilities, and then among the alternative nodes, the service capabilities of the nodes are obtained based on the buried point information, and the optimal node is determined by comprehensively considering the hardware of the node and the interaction capabilities with the client, to ensure that the optimal node can provide high-quality message processing and message delivery services while being able to process connection requests; when obtaining the real-time hardware capabilities, a dynamic weight adjustment mechanism is introduced to continuously optimize the weight distribution according to the real-time performance of the node, to ensure that the importance of the hardware indicators in different scenarios is reasonably reflected, and then the alternative nodes that better meet the connection requirements are screened out. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] Figure 1 This is a flowchart of a method for connecting a websocket cluster to a client in the first embodiment of the present invention;
[0044] Figure 2 This is a structural block diagram of a system for connecting a websocket cluster and a client in a second embodiment of the present invention;
[0045] The following specific embodiments will further illustrate the present invention in conjunction with the above-mentioned drawings. DETAILED DESCRIPTION
[0046] To facilitate understanding of the present invention, the present invention will be described more fully below with reference to the accompanying drawings. The drawings illustrate several embodiments of the present invention. However, the present invention may be implemented in many different forms and is not limited to the embodiments described herein. Rather, these embodiments are provided to provide a more thorough and comprehensive understanding of the present invention.
[0047] It should be noted that when an element is referred to as being "fixed to" another element, it may be directly on the other element or there may be an intermediate element. When an element is referred to as being "connected to" another element, it may be directly connected to the other element or there may be an intermediate element. The terms "vertical," "horizontal," "left," "right," and similar expressions used herein are for illustrative purposes only.
[0048] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by those skilled in the art to which this invention pertains. The terms used in this specification of the present invention are for the purpose of describing specific embodiments only and are not intended to limit the present invention. The term "and / or" as used herein includes any and all combinations of one or more of the associated listed items.
[0049] See also Figure 1 The method for connecting a websocket cluster and a client provided in the first embodiment of the present invention is applied to a websocket cluster. The websocket cluster includes several nodes, and the nodes are used to connect to the client. In this embodiment, the websocket cluster is applied to teaching interactive software. The client includes a teacher end and a student end. The teacher end and the student end are connected to the nodes in the websocket cluster by initiating a connection request. After the connection is completed, the teacher end can send a test question message to the node connected to it and send the identification ID of the student end. The websocket cluster searches for the node connected to the student end based on the identification ID, and passes the test question message to the node connected to the student end. The node connected to the student end then transmits the test question to the student end.
[0050] The method for connecting the websocket cluster to the client includes the following steps:
[0051] S10: When a connection request from the client is obtained, hardware indicators of the node are obtained, where the hardware indicators include CPU usage, memory usage, and connection rate, and a first initial weight parameter, a second initial weight parameter, and a third initial weight parameter are configured for the CPU usage, the memory usage, and the connection rate, respectively, to obtain initial hardware capabilities of the node;
[0052] It should be noted that each of the different nodes has a corresponding upper server, and the hardware indicators of the node are the hardware indicators of the corresponding upper server.
[0053] The calculation formula for the initial hardware capability is:
[0054] P y=λ1*l1+λ2*l2+λ3*l3,
[0055] Among them, P y represents the initial hardware capability, λ1 represents the first initial weight parameter, and λ2 represents the second initial Maximum number of connections.
[0056] In this embodiment, the value of the first initial weight parameter is 0.4, the value of the second initial weight parameter is 0.3, and the value of the third initial weight parameter is 0.3.
[0057] S20: Based on the comparison result between the hardware indicator and the indicator threshold, update the first initial weight, the second initial weight, and the third initial weight to obtain the real-time hardware capability of the node;
[0058] Specifically, step S20 includes:
[0059] S210: Compare the CPU usage rate with a first usage rate threshold; if the CPU usage rate is greater than the first usage rate threshold, obtain a first duration; if the first duration is greater than the first time threshold, update the first initial weight to a first sub-adjustment weight; if the CPU usage rate is less than the first usage rate threshold, obtain a second duration; if the second duration is greater than the first time threshold, update the first initial weight to a second sub-adjustment weight;
[0060] The formula for obtaining the first sub-adjustment weight is:
[0061]
[0062] in, represents the first sub-adjustment weight, λ1 represents the first initial weight, and δ1 represents the adjustment factor;
[0063] The formula for obtaining the second sub-adjustment weight is:
[0064]
[0065] in, Represents the second sub-adjustment weight.
[0066] S220: Compare the memory usage rate with a second usage rate threshold; if the memory usage rate is greater than the second usage rate threshold, obtain a third duration; if the third duration is greater than the second time threshold, update the second initial weight to a third sub-adjustment weight; if the memory usage rate is less than the second usage rate threshold, obtain a fourth duration; if the fourth duration is greater than the second time threshold, update the second initial weight to a fourth sub-adjustment weight;
[0067] S230: Compare the connection rate with a third usage rate threshold; if the connection rate is greater than the third usage rate threshold, obtain a fifth duration; if the fifth duration is greater than the third time threshold, update the third initial weight to a fifth sub-adjustment weight; if the connection rate is less than the third usage rate threshold, obtain a sixth duration; if the sixth duration is greater than the third time threshold, update the third initial weight to a sixth sub-adjustment weight;
[0068] It can be understood that the acquisition method of the third sub-adjustment weight, the fourth sub-adjustment weight, the fifth sub-adjustment weight and the sixth sub-adjustment weight is the same as the acquisition method of the first sub-adjustment weight and the second sub-adjustment weight. Only the setting of the adjustment factor is different, which will not be repeated here.
[0069] When acquiring the real-time hardware capabilities, a dynamic weight adjustment mechanism is introduced to continuously optimize the weight distribution according to the real-time performance of the nodes, ensuring that the importance of the hardware indicators in different scenarios is reasonably reflected, and then screening out the alternative nodes that better meet the connection requirements.
[0070] S30: Acquire a plurality of candidate nodes from the plurality of nodes based on the real-time hardware capability;
[0071] The nodes are sorted from largest to smallest based on the real-time hardware capability, and the nodes with a hardware capability higher than a threshold are selected as the candidate nodes.
[0072] S40: Collecting tracking information of the candidate node in a specified time window, and obtaining the service capability of the candidate node through the tracking information;
[0073] Tracking points are added during key times such as the connection and message transmission between the websocket cluster and the client, and real-time data is collected and sent to the message queue kafaka. The streaming computing framework flink is used for processing and analysis to obtain tracking point information. It should be noted that the tracking point information in this embodiment is real-time data in a certain time window during the past event processing of the alternative node.
[0074] The buried point information includes the connection establishment time, connection maintenance time, total connection times, connection success times, connection failure times, reconnection success times, reconnection times, message transmission times, message loss times, message error times, message repetition times, message transmission delay time, and message processing time.
[0075] The connection establishment duration refers to the duration from the time the connection between the client and the node is initiated to the time the connection is completed. The connection maintenance duration refers to the duration from the time the client and the node complete the connection to the time the connection is disconnected. The message transmission delay duration refers to the time it takes for the node to receive a message after the client sends the message. The message processing duration refers to the time it takes for the node to forward the message to another client after receiving the message. It should be noted that the connection establishment duration, the connection maintenance duration, the message transmission delay duration and the message processing duration are all averages within the specified time window.
[0076] The step S40 includes:
[0077] S410: Determine a connection stability index based on the connection establishment duration, the connection maintenance duration, the total number of connections, the number of successful connections, the number of failed connections, the number of successful reconnections, and the number of reconnections;
[0078] The formula for obtaining the connection stability index is:
[0079]
[0080] Among them, CS represents the connection stability index, Connect loss Indicates the number of connection failures. z Indicates the total number of connections, Connect per Indicates the duration of the connection, Rconnect suc Indicates the number of successful reconnections, Rconnect z Indicates the number of reconnections, Connect t Indicates the duration of establishing a connection.
[0081] S420: Determine a message stability index based on the number of message transmissions, the number of message losses, the number of message errors, and the number of message repetitions;
[0082] The formula for obtaining the message stability index is:
[0083]
[0084] Among them, MS represents the message stability index, M z Indicates the number of message transmissions, M loss Indicates the number of message losses, Mwrong Indicates the number of message errors, M re Indicates the number of times the message is repeated.
[0085] S430: Determine a message speed index based on the message transmission delay duration and the message processing duration;
[0086] The formula for obtaining the message speed indicator is:
[0087]
[0088] Among them, MSpeed represents the message speed index, M SDE Indicates the message transmission delay, M SDIS Indicates the message processing time.
[0089] S440: Acquire the service capability of the candidate node based on the connection stability index, the message stability index, and the message speed index;
[0090] The calculation formula of the service capacity is:
[0091] Service=α*CS-β*(1-MS)-γ*(1-MSpeed),
[0092] Wherein, Service represents service capability, CS represents connection stability index, MS represents message stability index, MSpeed represents message speed index, and α, β, and γ represent weight values. In this embodiment, the value of α is 0.5, the value of β is 0.3, and the value of γ is 0.2.
[0093] S50: Determine an optimal node from the candidate nodes based on the service capability, and connect the client to the optimal node;
[0094] The candidate nodes are sorted from largest to smallest based on their service capabilities, the candidate node with the largest service capability is selected as the optimal node, and the connection with the client is established.
[0095] When a connection request is received, several nodes are screened based on the real-time hardware capabilities to ensure that the candidate nodes have better hardware capabilities. Then, among the candidate nodes, the service capabilities of the nodes are obtained based on the embedded point information. The optimal node is determined by comprehensively considering the hardware of the node and the interaction capabilities with the client to ensure that the optimal node can provide high-quality message processing and message delivery services while being able to process connection requests.
[0096] Preferably, the method further comprises:
[0097] S60: Selecting the node connected to the client as a node to be detected, continuously acquiring the service capability of the node to be detected, and determining whether to remove the node to be detected based on the service capability;
[0098] During the operation of the websocket cluster, there are several nodes that are already in operation, namely the nodes to be detected. Their service capabilities are determined as the service capabilities to be detected, and the service capabilities to be detected are compared with the capability threshold. If the service capabilities to be detected are less than the capability threshold, the seventh duration is obtained, and it is determined whether the seventh duration is greater than the fourth time threshold. If the seventh duration is greater than the fourth time threshold, it is determined that the node to be detected needs to be removed. After removing the node to be detected, the client connected to the node to be detected is allocated to a new node, and the allocation method is consistent with the steps S10-S50, which will not be repeated here. By continuously detecting the nodes, the efficiency of processing and transmitting messages between the clients can be continuously ensured during the operation of the websocket cluster, thereby improving the operational stability of the websocket cluster.
[0099] See also Figure 2 , the second embodiment of the present invention provides a system for connecting a websocket cluster to a client, which is applied to the method for connecting a websocket cluster to a client in the above embodiment, and will not be repeated here. As used below, the terms "module", "unit", "sub-unit", etc. can be a combination of software and / or hardware that implements a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, implementation in hardware, or a combination of software and hardware, is also possible and conceivable.
[0100] The system comprises:
[0101] an acquisition module 10, configured to acquire hardware indicators of the node upon receiving a connection request from the client, the hardware indicators including CPU usage, memory usage, and connection rate, and configure a first initial weight parameter, a second initial weight parameter, and a third initial weight parameter for the CPU usage, the memory usage, and the connection rate, respectively, to acquire the initial hardware capability of the node;
[0102] An updating module 20, configured to update the first initial weight, the second initial weight, and the third initial weight based on a comparison result between the hardware indicator and the indicator threshold, so as to obtain the real-time hardware capability of the node;
[0103] The update module 20 includes:
[0104] a first unit, configured to compare the CPU usage rate with a first usage rate threshold, obtain a first duration if the CPU usage rate is greater than the first usage rate threshold, update the first initial weight to a first sub-adjustment weight if the first duration is greater than the first time threshold, obtain a second duration if the CPU usage rate is less than the first usage rate threshold, and update the first initial weight to a second sub-adjustment weight if the second duration is greater than the first time threshold;
[0105] a second unit, configured to compare the memory usage with a second usage threshold, obtain a third duration if the memory usage is greater than the second usage threshold, update the second initial weight to a third sub-adjustment weight if the third duration is greater than the second time threshold, obtain a fourth duration if the memory usage is less than the second usage threshold, and update the second initial weight to a fourth sub-adjustment weight if the fourth duration is greater than the second time threshold;
[0106] a third unit, configured to compare the connection rate with a third usage rate threshold, obtain a fifth duration if the connection rate is greater than the third usage rate threshold, update the third initial weight to a fifth sub-adjustment weight if the fifth duration is greater than the third time threshold, obtain a sixth duration if the connection rate is less than the third usage rate threshold, and update the third initial weight to a sixth sub-adjustment weight if the sixth duration is greater than the third time threshold;
[0107] A first selection module 30 is configured to obtain a plurality of candidate nodes from the plurality of nodes based on the real-time hardware capability;
[0108] A collection module 40 is configured to collect tracking information of the candidate node in a specified time window and obtain the service capability of the candidate node through the tracking information;
[0109] The tracking information includes connection establishment time, connection maintenance time, total number of connections, number of connection failures, number of successful reconnections, number of reconnections, number of message transmissions, number of message losses, number of message errors, number of message duplications, message transmission delay time, and message processing time.
[0110] The acquisition module 40 includes:
[0111] A fourth unit is configured to determine a connection stability index based on the connection establishment duration, the connection maintenance duration, the total number of connections, the number of connection failures, the number of successful reconnections, and the number of reconnections;
[0112] A fifth unit is configured to determine a message stability index based on the number of message transmissions, the number of message losses, the number of message errors, and the number of message repetitions;
[0113] A sixth unit is configured to determine a message speed index according to the message transmission delay duration and the message processing duration;
[0114] A seventh unit is configured to obtain the service capability of the candidate node based on the connection stability index, the message stability index, and the message speed index;
[0115] A second selection module 50 determines an optimal node from the candidate nodes based on the service capability, and connects the client to the optimal node;
[0116] Preferably, the system further comprises:
[0117] The monitoring module 60 is configured to select the node connected to the client as a node to be detected, continuously obtain the service capability of the node to be detected, and determine whether to remove the node to be detected based on the service capability.
[0118] The present invention also provides a computer, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the method for connecting a websocket cluster with a client as described in the above technical solution is implemented.
[0119] The present invention also provides a storage medium on which a computer program is stored. When the computer program is executed by a processor, the method for connecting a websocket cluster and a client as described in the above technical solution is implemented.
[0120] Throughout this specification, reference to terms such as "one embodiment," "some embodiments," "examples," "specific examples," or "some examples" means that a specific feature, structure, material, or characteristic described in conjunction with that embodiment or example is included in at least one embodiment or example of the present invention. In this specification, schematic representations of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in any one or more embodiments or examples.
[0121] The above-described embodiments merely illustrate several implementations of the present invention, and while their descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the present invention. It should be noted that a person skilled in the art would be able to make numerous variations and improvements without departing from the spirit of the present invention, all of which fall within the scope of protection of the present invention. Therefore, the scope of protection of the present invention shall be determined by the appended claims.
Claims
1. A method for connecting a websocket cluster to a client, applied to a websocket cluster, wherein the websocket cluster includes a plurality of nodes, and the nodes are used to connect to the client, characterized in that: The method for connecting the websocket cluster to the client comprises the following steps: When a connection request from the client is obtained, hardware indicators of the node are obtained, the hardware indicators including CPU usage, memory usage and connection rate, and a first initial weight parameter, a second initial weight parameter and a third initial weight parameter are configured for the CPU usage, the memory usage and the connection rate, respectively, to obtain the initial hardware capability of the node; Based on the comparison result between the hardware indicator and the indicator threshold, updating the first initial weight, the second initial weight and the third initial weight to obtain the real-time hardware capability of the node; Acquire a plurality of candidate nodes from the plurality of nodes based on the real-time hardware capability; Collecting tracking information of the candidate node in a specified time window, and obtaining the service capability of the candidate node through the tracking information; An optimal node is determined from among the candidate nodes based on the service capability, and the client is connected to the optimal node.
2. The method for connecting a websocket cluster to a client according to claim 1, characterized in that: The calculation formula of the initial hardware capability is: P y =λ1*l1+λ2*l2+λ3*l3, Among them, P y represents the initial hardware capability, λ1 represents the first initial weight parameter, λ2 represents the second initial weight parameter, λ3 represents the third initial weight parameter, l1 represents the CPU usage rate, l2 represents the memory usage rate, l3 represents the connection rate, and l now Indicates the current number of connections of the node, l max Indicates the maximum number of connections for a node.
3. The method for connecting a websocket cluster to a client according to claim 1, characterized in that: The step of updating the first initial weight, the second initial weight, and the third initial weight based on the comparison result between the hardware indicator and the indicator threshold comprises: Compare the CPU usage rate with a first usage rate threshold, if the CPU usage rate is greater than the first usage rate threshold, obtain a first duration, if the first duration is greater than the first time threshold, update the first initial weight to a first sub-adjustment weight, if the CPU usage rate is less than the first usage rate threshold, obtain a second duration, if the second duration is greater than the first time threshold, update the first initial weight to a second sub-adjustment weight; Compare the memory usage rate with a second usage rate threshold, if the memory usage rate is greater than the second usage rate threshold, obtain a third duration, if the third duration is greater than the second time threshold, update the second initial weight to a third sub-adjustment weight, if the memory usage rate is less than the second usage rate threshold, obtain a fourth duration, if the fourth duration is greater than the second time threshold, update the second initial weight to a fourth sub-adjustment weight; The connection rate is compared with the third usage rate threshold. If the connection rate is greater than the third usage rate threshold, the fifth duration is obtained. If the fifth duration is greater than the third time threshold, the third initial weight is updated to the fifth sub-adjustment weight. If the connection rate is less than the third usage rate threshold, the sixth duration is obtained. If the sixth duration is greater than the third time threshold, the third initial weight is updated to the sixth sub-adjustment weight.
4. The method for connecting a websocket cluster to a client according to claim 3, characterized in that: The formula for obtaining the first sub-adjustment weight is: in, represents the first sub-adjustment weight, λ1 represents the first initial weight, and δ1 represents the adjustment factor; The formula for obtaining the second sub-adjustment weight is: in, Represents the second sub-adjustment weight.
5. The method for connecting a websocket cluster to a client according to claim 1, characterized in that: The buried point information includes connection establishment time, connection maintenance time, total connection times, connection failure times, reconnection success times, reconnection times, message transmission times, message loss times, message error times, message repetition times, message transmission delay time, and message processing time.
6. The method for connecting a websocket cluster to a client according to claim 5, characterized in that: The step of obtaining the service capability of the candidate node through the tracking point information includes: Determine a connection stability index by the connection establishment duration, the connection maintenance duration, the total number of connections, the number of connection failures, the number of successful reconnections, and the number of reconnections; Determine a message stability index by the number of message transmissions, the number of message losses, the number of message errors and the number of message repetitions; Determine the message speed index by the message transmission delay duration and the message processing duration; The service capability of the candidate node is obtained based on the connection stability index, the message stability index and the message speed index.
7. The method for connecting a websocket cluster to a client according to claim 6, characterized in that: The calculation formula of the service capacity is: Service=α*CS-β*(1-MS)-γ*(1-MSpeed), Among them, Service represents service capability, CS represents connection stability index, MS represents message stability index, MSpeed represents message speed index, and α, β, and γ represent weight values.
8. A system for connecting a websocket cluster to a client, applied to the method for connecting a websocket cluster to a client as claimed in any one of claims 1 to 7, characterized in that: The system comprises: an acquisition module, configured to acquire hardware indicators of the node when a connection request from the client is obtained, the hardware indicators including CPU usage, memory usage and connection rate, and configure a first initial weight parameter, a second initial weight parameter and a third initial weight parameter for the CPU usage, the memory usage and the connection rate respectively, so as to acquire the initial hardware capability of the node; An updating module, configured to update the first initial weight, the second initial weight, and the third initial weight based on a comparison result between the hardware indicator and the indicator threshold, so as to obtain the real-time hardware capability of the node; A first selection module, configured to obtain a plurality of candidate nodes from the plurality of nodes based on the real-time hardware capability; A collection module, used to collect the tracking information of the candidate node in a specified time window, and obtain the service capability of the candidate node through the tracking information; The second selection module determines an optimal node from among the candidate nodes based on the service capability, and connects the client to the optimal node.
9. A computer 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 computer program, the method for connecting a websocket cluster and a client is implemented as described in any one of claims 1 to 7.
10. A storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the method for connecting a websocket cluster and a client according to any one of claims 1 to 7 is implemented.
