Communication load balancing method, equipment and medium
By listening to client requests, identity authentication and load balancing algorithms, the problem of unbalanced load on the server nodes is solved, and efficient data interaction and user experience improvement are achieved.
Patent Information
- Application Number
- CN202411382044.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Priority Date
- 2023-12-29
- Filing Date
- 2024-09-30
- Publication Date
- 2025-07-08
AI Technical Summary
In the prior art, the interaction between the client and the server can easily lead to excessive load on some ports on the server and unbalanced load, which may cause the server to crash or the ports to be unavailable, affecting the user experience.
By listening to the client's link request message, identity authentication and information entry are carried out, available server nodes and ports are determined, the load is balanced using the sorting algorithm, long link communication is established, and each client is assigned a unique identification code and password to provide data security.
It realizes load balancing between server nodes, improves client response speed and data interaction success rate, reduces the possibility of server unavailability, and improves user experience.
Smart Images

Figure CN120281774A_ABST
Abstract
Description
[0001] This application claims priority based on the invention patent application filed with the China National Patent Office on December 29, 2023, with the application number 202311867897.3 and the invention title "A Load Balancing Method, Device, and Medium Based on Netty Communication". The entire text of the above-mentioned Chinese patent application is incorporated herein by reference. Technical Field
[0002] The present invention relates to the field of Internet of Things communication technology, and in particular to a communication load balancing method, device, and medium. Background Art
[0003] With the development of Internet technology, people can handle various services through the Internet, which brings great convenience to people's lives. When handling services, users interact with the servers that handle the services through the client. For example, when a user searches for services or makes payments through the client, an HTTP connection can be established with the service server, and search requests or payment requests can be sent to the server through the HTTP short polling method, and requests are sent to the server at regular intervals within a certain period of time, so that after the server processes the service and obtains the request processing result, the request result is returned based on the requests regularly sent by the client.
[0004] Currently, in many Internet of Things application scenarios, with the increase in device terminals, the pressure on the server side is getting greater and the requirements for load balancing on the server side are also getting higher. In many current applications, the client directly sends messages to the server side. However, when a large number of clients send messages to the server side simultaneously, it is easy to cause excessive load on some ports of the server side. Once the server side crashes or the service ports become unavailable, the terminal will be unable to send messages to the server side, resulting in a situation where the function is unavailable within a short period of time, affecting the user experience of handling services. Summary of the Invention
[0005] Embodiments of the present invention provide a communication load balancing method, device, and medium, which are used to solve the following technical problems: The current interaction method between the client and the server side is likely to cause excessive load on some ports of the server side, uneven load between ports, and may cause the server side to crash or the ports to become unavailable.
[0006] Embodiments of the present invention adopt the following technical solutions:
[0007] On the one hand, an embodiment of the present invention provides a communication load balancing method, which includes: listening for link request messages sent by a client, and performing identity authentication and information entry on the client according to the link request message; determining available server nodes and available ports in each available server node according to the number of client links; sorting the available server nodes and the available ports; returning the tokens of each available server node and the sorted list of available server nodes to the client; establishing a long connection communication with the client according to the server node and port selected by the client.
[0008] The present invention provides an asynchronous and event-driven network application framework and tools through a communication framework to quickly develop high-performance and highly reliable server nodes and client programs, solving the problem of high development difficulty. Then, according to the number of client links that each server node currently needs to process, a load balancing algorithm is proposed, enabling the client to quickly obtain the port with the fastest response speed for connection and communication, thereby balancing the task volume of each port of the server node, maximizing the response speed of each client, and improving the customer experience.
[0009] In a feasible implementation, before listening for link request messages sent by a client, the method further includes: creating a number of server nodes based on a preset communication framework; in response to the operation of the user downloading the client, creating a client corresponding to each server node based on the preset communication framework; deploying the http address and identification code of the client; generating an account and password for the corresponding client through the server node and assigning them to the corresponding client.
[0010] This embodiment provides an identification credential for each client by deploying the address and unique identification code of each client, ensuring the data security between the client and the server node, as well as the consistency of link request and response data. And the server node assigns a default account and password to each client, facilitating the identity authentication of the client.
[0011] In a feasible implementation, listening for link request messages sent by a client, and performing identity authentication and information entry on the client according to the link request message specifically includes: parsing the data received in the server listening queue to obtain the link request information; extracting the http address, identification code, account, and password of the client from the link request information; performing identity authentication on the client according to the account and password; after the identity authentication passes, entering the identification code and http address of the client into the cache database redis in the form of a key-value pair, and pushing the link request information to the server message queue.
[0012] Based on the account and password assigned by the server node to the client, this embodiment authenticates the client. After determining that the client is a client associated with the server node, the identification code and HTTP address of the client are obtained and stored in an associated manner in the form of key-value pairs, facilitating the quick search for the client address to be returned when the server node responds to a request.
[0013] In a feasible implementation manner, according to the number of client connections, available server nodes and available ports in each available server node are determined, specifically including: obtaining in real time the number of client connections cached in the buffer of each server node; determining the server nodes with the number of client connections less than the first preset threshold as available server nodes and storing them in the available server node list; determining, according to the port numbers in the client connections, the number of client connections that each port of each available server node needs to process; and determining the ports with the number of client connections to be processed less than the second preset threshold as available ports and storing them in the available server node list.
[0014] This embodiment determines the relatively idle nodes among many server nodes as available nodes, and then determines the relatively idle ports in the available nodes as available ports, pre-screening the server nodes and ports with relatively fast corresponding speeds for the client, balancing the load among each server node and each port, accelerating the response speed of the client, and improving the user experience.
[0015] In a feasible implementation manner, sorting the available server nodes and the available ports specifically includes: obtaining the number of available ports corresponding to the current available server node and the total amount of corresponding client connections; calculating the ratio of the number of available ports to the total number of ports to obtain the first dynamic weight; calculating the difference between the first preset threshold and the total amount of client connections to obtain the second dynamic weight; according to performing weighted calculation on the number of available ports and the total amount of client connections to obtain the sorting weight P of the current available server node; where N1 is the number of available ports of the current available server node, ω1 is the first dynamic weight, N2 is the total amount of client connections corresponding to the current available server node, and ω2 is the second dynamic weight; sorting all available server nodes in descending order according to the sorting weight; and sorting the available ports corresponding to each available server node in ascending order according to the corresponding number of client connections.
[0016] This embodiment proposes a sorting algorithm for available server nodes, which can adjust the size of the dynamic weight in real time according to the number of available ports in each available server node and the change in the total number of corresponding client connections, comprehensively evaluate the idle degree of the available server nodes from two aspects, so as to perform a more reasonable sorting and make more accurate suggestions for the client to select server nodes.
[0017] In a feasible implementation, the tokens of each available server node and the sorted list of available server nodes are returned to the client, which specifically includes: packing the token generated by each available server node, the list of available server nodes, and the identification code of the client into a response data packet and storing it in the response message queue; extracting the client identification code in the response data packet and looking up the http address corresponding to the client in the cache database redis according to the client identification code; sending the response data packet to the http address corresponding to the client.
[0018] Based on the fact that the identification code and http address of the client have been stored in the cache database redis before, this embodiment directly looks up the corresponding http address in redis according to the client identification code, and can then transmit the response data to the corresponding client, avoiding the situation of incorrect feedback of response data.
[0019] In a feasible implementation, the method further includes: generating different tokens for each server node according to a preset time interval and a preset rule.
[0020] This embodiment reduces the risk of server nodes being attacked by generating different tokens for each server node irregularly.
[0021] In a feasible implementation, a long connection communication is established with the client according to the server node and port selected by the client, which specifically includes: obtaining the server node and port selected by the client; establishing a long connection communication between the port and the client through the selected server node; wherein, the rule for the client to select the server node and port is: select the first server node and the first port in the list of available server nodes; if the connection response time of the first port exceeds the preset time threshold, obtain the next port of the first server node until a responsive port is found; if the first server node fails, obtain the first port of the next server node in the list of available server nodes, and so on, until a responsive server node and a responsive port are found.
[0022] Based on the available server nodes sorted as described above, this embodiment preferentially obtains the first server node with the highest sorting weight as the communication node and connects to its most idle port, which can maximize the response speed of the client. At the same time, it reduces the processing burden on the port with a higher task volume, preventing new tasks from being added in a short period of time and balancing the load on each port. By sending the list of available server nodes to the client, it actually avoids the situation where the data interaction of the client is affected when a certain server fails. If the first server node in the list does not respond, the client can sequentially select the second, third server nodes for connection until a server node that can respond in a short time is found, ensuring the success rate of data interaction between the client and the server, reducing the possibility of service unavailability, and improving the user experience of handling business.
[0023] On the other hand, the embodiment of the present invention also provides a communication load balancing device, which includes: a request module for listening to the link request message sent by the client and performing identity authentication and information entry on the client according to the link request message; a port module for determining available server nodes and available ports in each available server node according to the number of client connections; a sorting module for sorting the available server nodes and the available ports; a return module for returning the tokens of each available server node and the sorted list of available server nodes to the client; and a link module for establishing a long link communication with the client according to the server node and port selected by the client.
[0024] The embodiment of the present invention also provides an electronic device, including a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the computer program, it implements the communication load balancing method described in any one of the above.
[0025] Finally, the embodiment of the present invention also provides a non-volatile computer storage medium storing computer executable instructions, and when the computer executable instructions are executed by a computer, they can implement the communication load balancing method described in any one of the above.
[0026] Compared with the prior art, a communication load balancing method, device, and medium provided by the embodiment of the present invention have the following beneficial effects:
[0027] The present invention provides an asynchronous, event-driven network application framework and tools through a communication framework to rapidly develop high-performance and highly reliable server nodes and client programs, solving the problem of high development difficulty. Then, according to the number of client connections that each server node currently needs to process, a sorting algorithm for available server nodes is proposed. The dynamic weight can be adjusted in real time according to the number of available ports in each available server node and the change in the total amount of corresponding client connections, comprehensively evaluating the idle degree of available server nodes from two aspects, so as to perform a more reasonable sorting and make more accurate suggestions for the client to select a server node. In addition, if the first server node in the list does not respond, the client can sequentially select the second and third server nodes for connection until a server node that can respond within a short time is found, ensuring the success rate of data interaction between the client and the server, reducing the possibility of service unavailability, and improving the user experience of handling services. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, the drawings in the following description are only some embodiments recorded in the present invention. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings. In the drawings:
[0029] Figure 1 It is a flowchart of a communication load balancing method provided by an embodiment of the present invention;
[0030] Figure 2 It is a schematic structural diagram of a communication load balancing device provided by an embodiment of the present invention;
[0031] Figure 3 It is a schematic structural diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0032] In order to enable those skilled in the art to better understand the technical solutions in the present invention, the following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of this specification, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present invention.
[0033] An embodiment of the present invention provides a communication load balancing method, as Figure 1 shown, the communication load balancing method specifically includes steps S101-S106:
[0034] S101. Monitor the link request message sent by the client, and based on the link request message, authenticate the client and enter information.
[0035] Specifically, first, based on a preset communication framework, create several server nodes. It is preferably to use the Netty communication framework. Netty is an excellent Java framework that provides an asynchronous, event-driven network application framework and tools for quickly developing high-performance and highly reliable network servers and client programs.
[0036] Furthermore, in response to the user's operation of downloading the client, based on the preset communication framework, create a client corresponding to each server node. And deploy the http address and identification code of the client. Finally, through the server node, generate the account and password of the client and assign them to the client.
[0037] By deploying the address and unique identification code of each client, an identification credential is provided for each client, ensuring the data security between the client and the server node, as well as the consistency of the link request and response data. And the server node assigns a default account and password to each client, facilitating the authentication of the client.
[0038] Furthermore, the server listening module continuously monitors the server listening queue. Once there is data in it, take it out for parsing, and then obtain the link request information. Then extract information such as the http address, identification code, account, and password of the client from the link request information.
[0039] Furthermore, authenticate the client based on the account and password. If the account or password is incorrect, directly reject the link request of the client.
[0040] Furthermore, after the authentication is passed, enter the identification code and http address of the client in the form of a key-value pair into the cache database redis, and push the link request information to the server message queue.
[0041] The present invention authenticates the client based on the account and password assigned by the server node to the client. After determining that the client is a client associated with the server node, then obtain the identification code and http address of the client. Associate and store the two in the form of a key-value pair, facilitating quickly finding the client address to be returned when the server node responds to the request.
[0042] S102. Determine the available server nodes and the available ports in each available server node according to the number of client links.
[0043] Specifically, the number of client connections cached in the buffer of each server node is obtained in real time. Then, the server nodes with the number of client connections less than the first preset threshold are determined as available server nodes and stored in the list of available server nodes.
[0044] Furthermore, according to the port numbers in the client connections, the number of client connections that each port of each available server node needs to process is determined. The ports with the number of client connections to be processed less than the second preset threshold are determined as available ports and stored in the list of available server nodes.
[0045] In one embodiment, let the first preset threshold be 50 and the second preset threshold be 20. The server nodes with the number of client connections less than 50 are determined as available nodes and stored in the list. Then, among all the ports corresponding to all the available nodes in the list, the ports with the number of client connections less than 20 are screened, and the remaining ports are deleted from the list to obtain the final list of available server nodes.
[0046] In this embodiment, relatively idle nodes are determined as available nodes among numerous server nodes, and the relatively idle ports among the available nodes are used as available ports, screening out relatively fast server nodes and ports for the client in advance, balancing the load among various server nodes and various ports, accelerating the response speed of the client, and improving the user experience.
[0047] S103. Sort the available server nodes and the available ports.
[0048] Specifically, first, obtain the number of available ports corresponding to the current available server node and the total amount of client connections corresponding thereto.
[0049] Furthermore, calculate the ratio of the number of available ports to the total number of ports to obtain the first dynamic weight. Calculate the difference between the first preset threshold and the total amount of client connections to obtain the second dynamic weight.
[0050] Furthermore, according to Perform a weighted calculation on the number of available ports and the total amount of client connections to obtain the sorting weight P of the current available server node; where N1 is the number of available ports of the current available server node, ω1 is the first dynamic weight, N2 is the total amount of client connections corresponding to the current available server node, and ω2 is the second dynamic weight.
[0051] Finally, sort all the available server nodes in descending order according to the sorting weight; sort the available ports corresponding to each available server node in ascending order according to the corresponding number of client connections.
[0052] In one embodiment, if the number of available ports N1 corresponding to the current available server node is 6, the total number of client connections N2 is 40, the first preset threshold is 50, and the total number of ports for each server node is 10. Then the first dynamic weight ω1 of the current available server node is 6 / 10 = 0.6, and the second dynamic weight ω2 is 50 - 40 = 10. Substituting the two weights into the formula, we get: P = 6 * 0.6 + 40 * 10 / 10 = 43.6. It can be seen that the sorting weight of the current available server node is 43.6.
[0053] If the number of available ports N1 corresponding to another available server node is 3 and the total number of client connections N2 is 40, then the first dynamic weight is 3 / 10 = 0.3, and the second dynamic weight is 50 - 40 = 10. Substituting into the formula, we get P = 3 * 0.3 + 40 * 10 / 10 = 40.9. It can be seen that if the total number of client connections is the same but the number of available ports is less, then the sorting weight of this available server node will decrease accordingly, so that the node with more available ports is ranked in the front. Similarly, according to the above formula, if the number of available ports is the same but the total number of client connections is less, then the calculated sorting weight will be larger, so that the node with less total number of client connections and more idle is ranked in the front.
[0054] In another embodiment, if the number of available ports N1 of a certain available server node is 3 and the total number of client connections N2 is 30, then the calculated sorting weight is P = 3 * 0.3 + 30 * (50 - 30) / 10 = 60.9, which is greater than the sorting weight of the current available server node. It can be seen that when the number of available ports and the total number of client connections each have their own advantages and disadvantages, according to this formula, the advantages and disadvantages of both can be comprehensively considered, a more reasonable sorting weight can be calculated, and a reasonable sorting can be performed on the server nodes.
[0055] This embodiment proposes a sorting algorithm for available server nodes, which can adjust the size of the dynamic weight in real time according to the change in the number of available ports in each available server node and the corresponding total number of client connections, comprehensively evaluate the idle degree of the available server nodes from two aspects, so as to perform a more reasonable sorting and make more accurate suggestions for the client to select server nodes.
[0056] S104. Return the tokens of each available server node and the sorted list of available server nodes to the client.
[0057] Specifically, the tokens generated by each available server node, the list of available server nodes, and the identification code of the client are packaged into a response data packet and stored in the response message queue. The client identification code in the response data packet is extracted, and based on the client identification code, the corresponding http address of the client is searched in the cache database redis. Finally, the response data packet is sent to the corresponding http address of the client. Since the identification code and http address of the client have been stored in the cache database redis as described above, in this embodiment, according to the client identification code, the corresponding http address can be directly searched in redis, and the response data can be transmitted to the corresponding client, avoiding the situation of incorrect feedback of response data.
[0058] As a feasible implementation manner, based on a preset time interval, different tokens are generated for each server node according to a preset rule, that is, the token of each server node is changed according to different rules at regular intervals, which can reduce the risk of the server node being attacked and the token being stolen.
[0059] S105. Establish a long connection communication with the client according to the server node and port selected by the client.
[0060] Specifically, in the client, the response data packet is parsed, and the first server node and the first port in the list of available server nodes are selected as the initial server node and the initial port. The server obtains the initial server node and the initial port selected by the client, and establishes a long connection communication with the client through the initial port of the initial server node.
[0061] In the client, the rule for selecting the server node and port is based on the previously sorted available server nodes. The first server node with the highest sorting weight is preferentially obtained as the communication node, and it is connected to its most idle port, which can maximize the response speed of the client, and at the same time reduce the processing burden on the port with a higher task volume, so that no new tasks are added in a short time, and the load of each port is balanced.
[0062] As a feasible implementation manner, if the connection response time of the best port exceeds the preset time threshold, the next port of the first server node in the list of available server nodes is obtained until a responsive port is found. If the first server node fails, the first port of the next server node in the list of available server nodes is obtained, and so on, until a responsive port is found.
[0063] By sending the list of available server nodes to the client, it actually avoids the situation where the data interaction of the client is affected when a certain server fails. If the first server node in the list does not respond, the client can sequentially select the second and third server nodes for connection until a server node that can respond within a short time is found, ensuring the success rate of data interaction between the client and the server, reducing the possibility of service unavailability, and improving the user experience of handling business.
[0064] In addition, the embodiment of the present invention also provides a communication load balancing device, as Figure 2 shown, the communication load balancing device 200 specifically includes:
[0065] A request module 210, configured to listen for the link request message sent by the client, and perform client authentication and information entry according to the link request message;
[0066] A port module 220, configured to determine available server nodes and available ports in each available server node according to the number of client connections;
[0067] A sorting module 230, configured to sort the available server nodes and available ports;
[0068] A return module 240, configured to return the tokens of each available server node and the sorted list of available server nodes to the client;
[0069] A link module 250, configured to establish a long link communication with the client according to the server node and port selected by the client.
[0070] The embodiment of the present invention also provides an electronic device, as Figure 3 shown, the electronic device includes a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the computer program, it implements the communication load balancing method in any of the above embodiments. The method may specifically include:
[0071] Listen for the link request message sent by the client, and perform client authentication and information entry according to the link request message;
[0072] Determine available server nodes and available ports in each available server node according to the number of client connections;
[0073] Sort the available server nodes and available ports;
[0074] Return the tokens of each available server node and the sorted list of available server nodes to the client;
[0075] Establish a long - term connection communication with the client according to the server node and port selected by the client.
[0076] Finally, the embodiment of the present invention also provides a non - volatile computer storage medium storing computer - executable instructions. When the computer - executable instructions are executed by a computer, they can implement the communication load balancing method in any of the above embodiments. The method specifically may include:
[0077] Listen for the link request message sent by the client, and authenticate the client and enter information according to the link request message.
[0078] Determine the available server nodes and the available ports in each available server node according to the number of client connections.
[0079] Sort the available server nodes and available ports.
[0080] Return the tokens of each available server node and the sorted list of available server nodes to the client.
[0081] Establish a long - term connection communication with the client according to the server node and port selected by the client.
[0082] The present invention provides an asynchronous and event - driven network application framework and tools through the Netty framework to quickly develop high - performance and highly reliable server nodes and client programs, solving the problem of high development difficulty. Then, according to the number of client connections that each server node currently needs to process, a sorting algorithm for available server nodes is proposed. It can adjust the size of the dynamic weight in real time according to the number of available ports in each available server node and the change of the corresponding total number of client connections, comprehensively evaluate the idle degree of available server nodes from two aspects, so as to perform a more reasonable sorting and give more accurate suggestions for the client to select server nodes. In addition, if the first server node in the list does not respond, the client can sequentially select the second and third server nodes for connection until a server node that can respond within a short time is found, ensuring the success rate of data interaction between the client and the server, reducing the possibility of service unavailability, and improving the user experience of handling business.
[0083] The systems, devices, modules or units illustrated in the above embodiments can be specifically implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer. Specifically, the computer can be, for example, a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or any combination of these devices.
[0084] For the convenience of description, when describing the above device, it is divided into various units according to functions and described separately. Of course, when implementing this specification, the functions of each unit can be realized in the same or multiple software and / or hardware.
[0085] It should also be noted that the term "comprising", "including" or any other variant thereof is intended to cover non-exclusive inclusion, so that a process, method, commodity or device comprising a series of elements not only includes those elements, but also includes other elements not expressly listed, or also includes elements inherent in such process, method, commodity or device. Without further limitation, an element defined by the statement "comprising an..." does not exclude the existence of additional identical elements in the process, method, commodity or device comprising the element.
[0086] This specification can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. This specification can also be practiced in a distributed computing environment, where tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media including storage devices.
[0087] Each embodiment in this specification is described in a progressive manner. The same or similar parts between each embodiment can be referred to each other, and the key point of each embodiment is to illustrate the differences from other embodiments. In particular, for the embodiments of the device, equipment, and non-volatile computer storage medium, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the description of the method embodiments.
[0088] The above describes specific embodiments of this specification. Other embodiments are within the scope of the present invention. In some cases, the actions or steps recorded in this specification can be executed in a different order from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In certain embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0089] The above is only one or more embodiments of this specification and is not used to limit this specification. For those skilled in the art, one or more embodiments of this specification can have various changes and modifications. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of one or more embodiments of this specification shall be included within the protection scope of this specification.
Claims
1. A communication load balancing method, characterized in that, The method includes: Listening for a link request message sent by the client, and based on the link request message, authenticating the client and entering information; Determining available server nodes and available ports in each available server node according to the number of client links; Sorting the available server nodes and the available ports; Returning the tokens of each available server node and the sorted list of available server nodes to the client; Establishing a long connection communication with the client according to the server node and port selected by the client.
2. The communication load balancing method according to claim 1, wherein Before listening for the link request message sent by the client, the method further includes: Creating a number of server nodes based on a preset communication framework; In response to the user's operation of downloading the client, creating a client corresponding to each server node based on the preset communication framework; Deploying the http address and identification code of the client; Generating an account and password for the corresponding client through the server node and assigning them to the corresponding client.
3. A communication load balancing method according to claim 1, characterized in that Listening for a link request message sent by the client, and based on the link request message, authenticating the client and entering information, specifically including: Parsing the data received in the server listening queue to obtain the link request information; Extracting the http address, identification code, account and password of the client from the link request information; Authenticating the client according to the account and password; After the authentication is passed, entering the identification code and http address of the client in the form of key-value pairs into the cache database redis, and pushing the link request information to the server message queue.
4. A communication load balancing method according to claim 1, characterized in that Determining available server nodes and available ports in each available server node according to the number of client links, specifically including: Obtaining the number of client links cached in the buffer of each server node in real time; Determining the server nodes with the number of client links less than the first preset threshold as available server nodes and storing them in the list of available server nodes; Determining the number of client links that each port of each available server node needs to process according to the port number in the client link; Determining the ports with the number of client links to be processed less than the second preset threshold as available ports and storing them in the list of available server nodes.
5. A communication load balancing method according to claim 1, characterized in that, Sorting the available server nodes and the available ports, specifically including: Obtaining the number of available ports corresponding to the current available server node and the total corresponding client link quantity; Calculating the ratio of the number of available ports to the total number of ports to obtain the first dynamic weight; Calculating the difference between the first preset threshold and the total client link quantity to obtain the second dynamic weight; According to Performing weighted calculation on the number of available ports and the total number of client connections to obtain the sorting weight P of the current available server node; where N1 is the number of available ports of the current available server node, ω1 is the first dynamic weight, N2 is the total number of client connections corresponding to the current available server node, and ω2 is the second dynamic weight; Sorting all available server nodes in descending order of sorting weight; Sorting the available ports corresponding to each available server node in ascending order of the corresponding number of client links.
6. A communication load balancing method according to claim 1, characterized in that, Returning the tokens of each available server node and the sorted list of available server nodes to the client, specifically including: Pack the token generated by each available server node, the list of available server nodes, and the identification code of the client into a response data packet, and store it in the response message queue; Extract the client identification code from the response data packet, and based on the client identification code, look up the corresponding http address of the client in the cache database redis; Send the response data packet to the http address corresponding to the client.
7. A communication load balancing method according to claim 1, wherein The method further includes: generating different tokens for each server node based on a preset time interval according to a preset rule.
8. A communication load balancing method according to claim 1, characterized in that Establish a long connection communication with the client according to the server node and port selected by the client, specifically including: Obtain the server node and port selected by the client; Establish a long connection communication between the port and the client through the selected server node; Among them, the rule for the client to select the server node and port is: select the first server node and the first port in the list of available server nodes; If the connection response time of the first port exceeds the preset time threshold, obtain the next port of the first server node until a responsive port is found; If the first server node fails, obtain the first port of the next server node in the list of available server nodes, and so on, until a responsive server node and a responsive port are found.
9. A communication load balancing device, characterized in that The device includes: A request module, configured to listen for a link request message sent by the client, and authenticate the client and enter information according to the link request message; A port module, configured to determine available server nodes and available ports in each available server node according to the number of client connections; A sorting module, configured to sort the available server nodes and the available ports; A return module, configured to return the tokens of each available server node and the sorted list of available server nodes to the client; A link module, configured to establish a long connection communication with the client according to the server node and port selected by the client.
10. An electronic device, comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, wherein When the processor executes the computer program, it implements the communication load balancing method according to any one of claims 1 to 8.
11. A non-volatile computer storage medium, characterized in that, Stores computer-executable instructions, and when the computer-executable instructions are executed by a computer, they can implement the communication load balancing method according to any one of claims 1 to 8.