Long connection establishment method, device, target device and storage medium

By receiving the authentication request from the client and determining the server list, the client establishes a long connection with the main server, solving the problem of large resource consumption of long-term connection load balancing resources in the existing technology, and achieving more efficient load balancing.

CN115665225BActive Publication Date: 2024-12-03VIVO MOBILE COMM CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202211351438.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-10-31
Publication Date
2024-12-03
Estimated Expiration
2042-10-31

AI Technical Summary

Technical Problem

The existing medium- and long-connect load balancing methods lead to large resource consumption, and establishing multiple long connections between the client and the server consumes resources, resulting in load imbalance problems.

Method used

By receiving the authentication request from the client, determining the address information of the main server and the backup server based on the client information, sending the server list to the client, so that it establishes a long connection with the main server, and reducing resource consumption.

Benefits of technology

It effectively reduces resource consumption, improves load balancing between clients and servers, and avoids resource waste caused by multiple long connections and load balancing algorithms.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115665225B_ABST
    Figure CN115665225B_ABST
Patent Text Reader

Abstract

The present application discloses a method, device, target device and storage medium for establishing a long connection, which belongs to the field of communication technology. The method includes: receiving an authentication request sent by a client, the authentication request is used by the client to request to connect to a server, and the authentication request includes information about the client; determining a server list based on the information about the client, the server list includes address information of the main server and address information of the backup server; sending a server list to the client, the server list is used by the client to establish a long connection with the main server.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application belongs to the field of communication technology, and specifically relates to a method, apparatus, target device and storage medium for establishing a long connection. Background Art

[0002] Currently, in the field of client-server communication, electronic devices usually use persistent connections to achieve communication in order to improve the communication performance of electronic devices. However, persistent connection communication will face the situation of unbalanced client load, so that the client server with high load may face risks such as slow service response and downtime.

[0003] To address the client load imbalance problem when using persistent connections for communication, the method used in the prior art is as follows: when the client starts, it requests the server's addressing service (NameServer) to obtain a list of currently online server addresses, so as to establish a persistent connection with each of the currently online servers. Then, before requesting to send data, the client selects a server from the server address list through a load balancing algorithm for communication.

[0004] However, using the above method, many long connections will be established between the client and the server, maintaining the connection will consume resources, and the load balancing algorithm before the client sends a request will also consume resources. As a result, the method of load balancing long connections in the prior art consumes a lot of resources. Summary of the invention

[0005] The purpose of the embodiments of the present application is to provide a method, apparatus, target device and storage medium for establishing a long connection, which can solve the problem of large resource consumption during load balancing of long connections in the prior art.

[0006] In a first aspect, an embodiment of the present application provides a method for establishing a long connection, the method comprising: receiving an authentication request sent by a client, the authentication request being used by the client to request connection to a server, the authentication request comprising information about the client; determining a server list based on the information about the client, the server list comprising address information of a primary server and address information of a backup server; and sending the server list to the client, the server list being used by the client to establish a long connection with the primary server.

[0007] In a second aspect, an embodiment of the present application provides a device for establishing a long connection, which includes: a receiving module, a determining module and a sending module. The receiving module is used to receive an authentication request sent by a client, where the authentication request is used by the client to request to connect to a server, and the authentication request includes information about the client. The determining module is used to determine a server list based on the information of the client, where the server list includes address information of a primary server and address information of a backup server. The sending module is used to send a server list to the client, where the server list is used by the client to establish a long connection with the primary server.

[0008] In a third aspect, an embodiment of the present application provides a target device, which includes a processor and a memory, wherein the memory stores programs or instructions that can be executed on the processor, and when the program or instructions are executed by the processor, the steps of the method described in the first aspect are implemented.

[0009] In a fourth aspect, an embodiment of the present application provides a readable storage medium, on which a program or instruction is stored, and when the program or instruction is executed by a processor, the steps of the method described in the first aspect are implemented.

[0010] In a fifth aspect, an embodiment of the present application provides a chip, comprising a processor and a communication interface, wherein the communication interface is coupled to the processor, and the processor is used to run a program or instruction to implement the method described in the first aspect.

[0011] In a sixth aspect, an embodiment of the present application provides a computer program product, which is stored in a storage medium and is executed by at least one processor to implement the method described in the first aspect.

[0012] In an embodiment of the present application, an authentication request sent by a client can be received, and the authentication request is used by the client to request to connect to a server, and the authentication request includes the client's information; thus, a server list including the address information of the main server and the address information of the backup server can be determined based on the client's information, and the server list is sent to the client, so that the client can establish a long connection with the main server based on the server list. In this solution, since the client can send an authentication request including the client's information to request to connect to the server, after receiving the authentication request, a server list including the address information of the main server and the address information of the backup server can be determined based on the client's information, and sent to the client, so that after receiving the server list, the client can establish a long connection with the main server based on the address information of the main server to communicate, thereby reducing resource consumption. BRIEF DESCRIPTION OF THE DRAWINGS

[0013] Figure 1is a schematic diagram of a method for establishing a long connection provided in an embodiment of the present application;

[0014] Figure 2 This is one of the flow charts of a method for establishing a long connection provided in an embodiment of the present application;

[0015] Figure 3 This is a second flow chart of a method for establishing a long connection provided in an embodiment of the present application;

[0016] Figure 4 It is a structural schematic diagram of a long connection establishment device provided in an embodiment of the present application;

[0017] Figure 5 is a schematic diagram of the hardware structure of a target device provided in an embodiment of the present application;

[0018] Figure 6 It is a schematic diagram of the hardware structure of a target device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0019] The following will be combined with the drawings in the embodiments of the present application to clearly describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, rather than all the embodiments. All other embodiments obtained by ordinary technicians in this field based on the embodiments in the present application belong to the scope of protection of this application.

[0020] The terms "first", "second", etc. in the specification and claims of the present application are used to distinguish similar objects, and are not used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable under appropriate circumstances, so that the embodiments of the present application can be implemented in an order other than those illustrated or described here, and the objects distinguished by "first", "second", etc. are generally of one type, and the number of objects is not limited. For example, the first object can be one or more. In addition, "and / or" in the specification and claims represents at least one of the connected objects, and the character " / " generally indicates that the objects associated with each other are in an "or" relationship.

[0021] The following describes in detail the method for establishing a long connection provided by the embodiment of the present application through specific embodiments and application scenarios in conjunction with the accompanying drawings.

[0022] The method for establishing a long connection in the embodiment of the present application can be applied to the scenario of establishing a long connection between the client and the server.

[0023] Currently, in the field of client-server communication, electronic devices usually use persistent connections to achieve communication in order to improve the communication performance of electronic devices. However, persistent connection communication will face the situation of unbalanced client load, so that the client server with high load may face risks such as slow service response and downtime.

[0024] In order to solve the problem of client load imbalance when using persistent connections for communication, the method used in the prior art is as follows: when the client starts, it requests the NameServer to obtain the address list of currently online servers, so as to establish a persistent connection with each of the currently online servers. Then, before requesting to send data, the client selects a server from the server address list through a load balancing algorithm for communication.

[0025] However, by using the above method, many long connections will be established between the client and the server, and maintaining the connection will consume resources (for example, CPU, memory, file handles, etc.). The more long connections there are, the more resources will be consumed; and the load balancing algorithm before the client sends a request will also consume CPU resources. Therefore, the resource consumption of the client load balancing method in the prior art is relatively large.

[0026] In the scheme provided in the embodiment of the present application, an authentication request sent by a client can be received, and the authentication request is used by the client to request to connect to a server, and the authentication request includes the client's information; thus, a server list including the address information of the main server and the address information of the backup server can be determined based on the client's information, and the server list is sent to the client, so that the client can establish a long connection with the main server according to the server list. In this scheme, since the client can send an authentication request including the client's information to request to connect to the server, after receiving the authentication request, a server list including the address information of the main server and the address information of the backup server can be determined based on the client's information, and sent to the client, so that after receiving the server list, the client can establish a long connection with the main server according to the address information of the main server to communicate, thereby reducing resource consumption.

[0027] The present application provides a method for establishing a long connection. Figure 1 A flowchart of a method for establishing a long connection provided by an embodiment of the present application is shown. Figure 1 As shown, the method for establishing a long connection provided in the embodiment of the present application may include the following steps 201 to 203.

[0028] Step 201: Receive an authentication request sent by a client.

[0029] In the embodiment of the present application, the above-mentioned authentication request is used by the client to request to connect to the server, and the authentication request includes the client's information.

[0030] Optionally, in an embodiment of the present application, when the client starts, it can send an authentication request to the target device. After receiving the authentication request, the target device can determine whether the client has the authority to connect to the server. When the authentication is passed, the address information of the server is returned to the client to allow it to connect to the server.

[0031] Optionally, in the embodiment of the present application, the above-mentioned target device may be a NameServer.

[0032] Optionally, in an embodiment of the present application, when the server is started, it can register with the NameSever in the form of an IP address and a port number.

[0033] Step 202: Determine the server list based on the client information.

[0034] In the embodiment of the present application, the above-mentioned server list includes the address information of the main server and the address information of the backup server.

[0035] In the embodiment of the present application, after acquiring the information of the client, the target device can determine a server list including the address information of the primary server and the address information of the backup server in combination with the information of the client.

[0036] Optionally, in an embodiment of the present application, the client information includes an application identifier corresponding to the client, address information of the client, and a computer room priority rule of the client; the above step 202 can be specifically implemented through the following steps 202a to 202d.

[0037] Step 202a: Determine at least one server according to the application program identifier corresponding to the client.

[0038] In the embodiment of the present application, at least one server is a server that serves an application, and the application is an application corresponding to the client.

[0039] It can be understood that one application corresponds to multiple servers.

[0040] Optionally, in the embodiment of the present application, the application identifier may be any one of the following: the name of the application, the account used to log into the application.

[0041] Step 202b: group at least one server according to the computer room priority rule of the client to obtain a first group and a second group.

[0042] In the embodiment of the present application, the first group includes address information of a server in the same computer room as that where the client is located, and the second group includes address information of a server in a different computer room from that where the client is located.

[0043] Optionally, in the embodiment of the present application, the room priority rule of the client is used to indicate the room the client is located in. It is understandable that grouping at least one server according to the room priority rule enables the client to connect to the server in the same room.

[0044] Optionally, in an embodiment of the present application, the target device can match the computer room where the client is located with the computer room where at least one of the above-mentioned servers is located, and store the address information of the server that is the same as the computer room where the client is located in the first group, and store the address information of the server that is different from the computer room where the client is located in the second group.

[0045] Step 202c: determine the address information of M servers from the first group by using a hash algorithm, and move the address information of the remaining servers in the first group to the second group to obtain a third group.

[0046] In the embodiment of the present application, the above-mentioned M servers are valid server terminals for the application programs corresponding to the service clients.

[0047] Specifically, the target device may select a server from the first group by using a consistent hashing algorithm. When M servers need to be selected, the target device may select them by using a linear detection method.

[0048] It should be noted that the hash algorithm can evenly distribute the clients to at least one server, so that the client load is balanced.

[0049] It can be understood that the number of clients connected to the M valid servers is relatively small compared to the number of clients connected to the remaining servers in the first group, so that when the client subsequently establishes a long connection with one of the M valid servers, the client can maintain load balancing.

[0050] It can be understood that at this time, the first group only stores address information of M servers.

[0051] Step 202d: determine the main server from the M servers according to the address information of the client, and determine the servers other than the main server and all servers in the third group as backup servers to obtain a server list.

[0052] Optionally, in an embodiment of the present application, when no abnormality occurs on the main server, the client maintains a long connection with the main server.

[0053] Optionally, in an embodiment of the present application, the backup server is used for backup. When an exception occurs in the main server and the client cannot establish a long connection with the main server, the client can establish a long connection with a backup server.

[0054] Optionally, in an embodiment of the present application, the above step 202d can be specifically implemented by the following steps 301 and 302, or steps 301 and 303.

[0055] Step 301: According to the address information of the client, find out from the preset allocation table whether the client has been allocated to the server.

[0056] In the embodiment of the present application, the above-mentioned preset allocation table includes at least one allocation relationship, and each allocation relationship is an allocation relationship between a client and a server.

[0057] Optionally, in an embodiment of the present application, each allocation relationship may be an allocation relationship between address information of a client and address information of a server.

[0058] Optionally, in an embodiment of the present application, the target device may create a preset allocation table in a database in advance for storing the allocation relationship between each client and the server. The preset allocation table may be a preset allocation table for an application corresponding to the client. It can be understood that each preset allocation table is a preset allocation table corresponding to an application, and at least one client included in each preset allocation table is a client corresponding to an application.

[0059] Step 302: When a server has been assigned to the client, determine whether the M servers include the server that has been assigned to the client, so as to determine a main server from the M servers.

[0060] It can be understood that when the target device finds the server that has been assigned to the client from the preset allocation table based on the client's address information, it can detect whether the server that has been assigned to the client is one of the M servers selected above to determine the main server from the M servers.

[0061] Optionally, in the embodiment of the present application, the above step 302 can be specifically implemented by the following step 302a or step 302b.

[0062] Step 302a: When the M servers include the server already assigned to the client, determine the server already assigned to the client as the main server.

[0063] It can be understood that when the server assigned to the client is one of the M valid servers selected above, the target device can determine the server assigned to the client as the main server.

[0064] Step 302b: When the M servers do not include the server already allocated to the client, determine whether the preset allocation table includes the M servers, so as to determine the main server from the M servers.

[0065] Optionally, in an embodiment of the present application, when the server to which the client has been allocated is not one of the M server ends selected above, it is proved that the allocation relationship has become invalid and the allocation record can be deleted.

[0066] It is understandable that since the server will expand or shrink its capacity, the storage allocation relationship may become invalid.

[0067] Optionally, in an embodiment of the present application, when the server allocated to the client is not one of the M selected servers, the target device can detect whether the M selected servers are located in a preset allocation table to determine the main server from the M valid servers through a minimum connection algorithm.

[0068] Optionally, in the embodiment of the present application, the above step 302b can be specifically implemented by the following step 302b1 or step 302b2.

[0069] Step 302b1: When the preset allocation table includes M servers, determine the server with the least number of connected clients among the M servers as the main server.

[0070] It can be understood that when the M selected servers are located in the preset allocation table, the target device can determine the main server from the M valid servers by using the minimum connection algorithm.

[0071] Specifically, the target device may obtain the number of clients connected to each of the M servers in the preset allocation table, and then determine the server with the least number of connected clients as the main server.

[0072] Step 302b2: When the preset allocation table does not include M servers, any one of the M servers is determined as the main server.

[0073] Optionally, in an embodiment of the present application, when the M server ends selected above are not located in the preset allocation table, it means that the M server ends are new server ends, and the number of clients connected to the M server ends respectively is 0, and the target device can determine any one of the M server ends as the main server end.

[0074] Optionally, in an embodiment of the present application, after the M servers do not include a server to which the client has been assigned and the target device determines the primary server, the correspondence between the client and the primary server may be added or updated to a preset allocation table.

[0075] Step 303: When no server is allocated to the client, determine whether the preset allocation table includes M servers, so as to determine a main server from the M servers.

[0076] Optionally, in an embodiment of the present application, when the client has not allocated a server, the target device may detect whether the M selected servers are located in a preset allocation table, so as to determine a main server from the M valid servers through a minimum connection algorithm.

[0077] Optionally, in an embodiment of the present application, after the client is not assigned a server and the target device determines the main server, the correspondence between the client and the main server may be added to a preset allocation table.

[0078] Optionally, in the embodiment of the present application, the above step 303 can be specifically implemented by the above step 302b1 or step 302b2.

[0079] It should be noted that, for the description of determining whether the preset allocation table includes M servers for the target device, so as to determine the main server from the M servers, reference may be made to the description in the above embodiment, which will not be repeated here.

[0080] Step 203: Send the server list to the client.

[0081] In the embodiment of the present application, the above-mentioned server list is used to establish a long connection between the client and the main server.

[0082] Optionally, in an embodiment of the present application, after the target device determines the main server, if the main server is not empty and is not being released, the target device places the address information of the main server at the first place in the server list.

[0083] Optionally, in an embodiment of the present application, after the target device determines the servers except the main server among the M servers and all the servers in the third group as backup servers, the address information of all the backup servers can be added to the server list.

[0084] Optionally, in an embodiment of the present application, the target device may shuffle the order of address information of all backup servers before sending the server list to the client.

[0085] Optionally, in the embodiment of the present application, after receiving the server list, the client can establish a persistent connection with the primary server according to the address information of the primary server. If an abnormality occurs in the primary server and the client cannot establish a persistent connection with the primary server, the client can establish a persistent connection with a backup server.

[0086] The embodiment of the present application provides a method for establishing a long connection, which can receive an authentication request sent by a client, and the authentication request is used by the client to request to connect to a server, and the authentication request includes the client's information; thus, a server list including the address information of the main server and the address information of the backup server can be determined based on the client's information, and the server list is sent to the client, so that the client can establish a long connection with the main server according to the server list. In this scheme, since the client can send an authentication request including the client's information to request to connect to the server, after receiving the authentication request, a server list including the address information of the main server and the address information of the backup server can be determined based on the client's information, and sent to the client, so that after receiving the server list, the client can establish a long connection with the main server according to the address information of the main server to communicate, thereby reducing resource consumption.

[0087] In the present application embodiment, Figure 2 As shown, the method for establishing a long connection provided in the embodiment of the present application may include the following steps S1 to S9.

[0088] Step S1: Receive an authentication request sent by a client.

[0089] Step S2: Determine at least one server according to the application program identifier corresponding to the client.

[0090] Step S3: group at least one server according to the computer room priority rule of the client to obtain a first group and a second group.

[0091] Step S4: determine the address information of M servers from the first group by using a hash algorithm, and move the address information of the remaining servers in the first group to the second group to obtain a third group.

[0092] Step S5: According to the address information of the client, find out from the preset allocation table whether the client has been allocated to the server.

[0093] Step S6: When the client has been assigned a server, determine whether the M servers include the server that has been assigned to the client.

[0094] Step S7: When the M servers include the server already assigned to the client, determine the server already assigned to the client as the main server.

[0095] Step S8: When the M servers do not include the server assigned to the client, determine the master server from the M valid servers using a minimum connection algorithm; or, when the client does not assign a server, determine the master server from the M valid servers using a minimum connection algorithm.

[0096] Step S9: Get the server list and send the server list to the client.

[0097] Optionally, in an embodiment of the present application, after the above step 203, the method for establishing a long connection provided in the embodiment of the present application further includes the following steps 401 to 404.

[0098] Step 401: Detect a preset allocation table according to the application program identifier corresponding to the client and the computer room priority rule of the client.

[0099] In the embodiment of the present application, the above-mentioned preset allocation table includes at least one allocation relationship, and each allocation relationship is an allocation relationship between a client and a server.

[0100] It is understandable that after the client establishes a persistent connection with the main server, there may still be an imbalance in the client load. The target device can adjust the balance through the background rebalancing task.

[0101] Specifically, the target device may detect the preset allocation table according to the application program identifier corresponding to the client and the computer room priority rule of the client.

[0102] Step 402: If there are invalid clients in the preset allocation table, remove the invalid clients from the preset allocation table.

[0103] It is understandable that due to the container environment, the client's address information always changes, or the client's shrinking operation will also generate some invalid address information. Therefore, when there is invalid client address information in the preset allocation table, the target device can clear the invalid client address information from the preset allocation table.

[0104] Step 403: Check whether the number of clients connected to each server in the preset allocation table is balanced.

[0105] In the embodiment of the present application, the target device can detect the number of clients connected to each server in the preset allocation table, and end the rebalancing task when the number of clients connected to each server is balanced.

[0106] Step 404: If there is a server with an unbalanced number of connected clients in the preset allocation table, adjust the preset allocation table by using an equalization algorithm.

[0107] It is understandable that the target device may detect the number of clients connected to each server in the preset allocation table, and when there is a server with an unbalanced number of clients connected, adjust the preset allocation table through an amortization algorithm.

[0108] In this way, the client load is guaranteed to be relatively balanced.

[0109] In the present application embodiment, Figure 3 As shown, the method for establishing a long connection provided in the embodiment of the present application may include the following steps S11 to S15.

[0110] Step S11: Detect the preset allocation table according to the application identifier corresponding to the client and the computer room priority rule of the client.

[0111] Step S12: If there are invalid clients in the preset allocation table, remove the invalid clients from the preset allocation table.

[0112] Step S13: Detect whether the number of clients connected to each server in the preset allocation table is balanced.

[0113] Step S14: When the number of clients connected to each server in the preset allocation table is balanced, the rebalancing task is terminated.

[0114] Step S15: If there is a server with an unbalanced number of connected clients in the preset allocation table, adjust the preset allocation table by using an equalization algorithm.

[0115] It should be noted that the execution subject of the long connection establishment method provided in the embodiment of the present application may be a long connection establishment device. In the embodiment of the present application, the long connection establishment method executed by the long connection establishment device is taken as an example to illustrate the long connection establishment device provided in the embodiment of the present application.

[0116] Figure 4 A possible structural diagram of a long connection establishment device involved in an embodiment of the present application is shown. Figure 4 As shown, the long connection establishing device 70 may include: a receiving module 71 , a determining module 72 and a sending module 73 .

[0117] The receiving module 71 is used to receive the authentication request sent by the client, which is used by the client to request to connect to the server, and the authentication request includes the client information. The determining module 72 is used to determine the server list according to the client information, and the server list includes the address information of the main server and the address information of the backup server. The sending module 73 is used to send the server list to the client, and the server list is used by the client to establish a long connection with the main server.

[0118] An embodiment of the present application provides a long connection establishment device. Since the client can send an authentication request including the client's information to the long connection establishment device to request to be connected to the server of the long connection establishment device, the long connection establishment device can determine a server list including the address information of the main server and the address information of the backup server based on the client's information after receiving the authentication request, and send it to the client, so that after receiving the server list, the client can establish a long connection with the main server based on the address information of the main server to communicate, thereby reducing resource consumption.

[0119] In a possible implementation, the client information includes an application identifier corresponding to the client, the address information of the client, and a computer room priority rule of the client; the above-mentioned determination module 72 is specifically used to determine at least one server according to the application identifier corresponding to the client, at least one server is a server that serves an application, and the one application is an application corresponding to the client; and according to the computer room priority rule of the client, at least one server is grouped to obtain a first group and a second group, the first group includes the address information of the server in the same computer room as the client, and the second group includes the address information of the server in a different computer room from the client; and determine the address information of M servers from the first group through a hash algorithm, and move the address information of the remaining servers in the first group to the second group to obtain a third group, the M servers are valid servers that serve the application corresponding to the client; and according to the address information of the client, determine the main server from the M servers, and determine the servers other than the main server among the M servers and all servers in the third group as backup servers to obtain a server list.

[0120] In one possible implementation, the above-mentioned determination module 72 is specifically used to search from a preset allocation table whether the client has been assigned a server according to the address information of the client, and the preset allocation table includes at least one allocation relationship, each allocation relationship is an allocation relationship between a client and a server; in the case that the client has been assigned a server, determine whether the M servers include the server to which the client has been assigned, so as to determine the main server from the M servers; or, in the case that the client has not been assigned a server, determine whether the preset allocation table includes M servers, so as to determine the main server from the M servers.

[0121] In one possible implementation, the above-mentioned determination module 72 is specifically used to determine the server end assigned to the client as the main server end when the M server ends include the server end assigned to the client; or, when the M server ends do not include the server end assigned to the client, determine whether the preset allocation table includes M server ends, so as to determine the main server end from the M server ends.

[0122] In one possible implementation, the above-mentioned determination module 72 is specifically used to determine the server with the least number of connected clients among the M server ends as the main server end when the preset allocation table contains M server ends; or, when the preset allocation table does not contain M server ends, determine any one of the M server ends as the main server end.

[0123] In a possible implementation, the long connection establishment device 70 provided in the embodiment of the present application also includes: a detection module, a processing module and an adjustment module. The detection module is used to detect the preset allocation table according to the application identifier corresponding to the client and the client's computer room priority rule after the above-mentioned sending module 73 sends the server list to the client. The preset allocation table includes at least one allocation relationship, and each allocation relationship is an allocation relationship between a client and a server. The processing module is used to remove invalid clients from the preset allocation table when there are invalid clients in the preset allocation table. The detection module is also used to detect whether the number of clients connected to each server in the preset allocation table is balanced. The adjustment module is used to adjust the preset allocation table through an averaging algorithm when there is a server with an uneven number of connected clients in the preset allocation table.

[0124] The long connection establishment device in the embodiment of the present application can be a target device, or a component in the target device, such as an integrated circuit or a chip. The target device can be a terminal, or it can be other devices other than a terminal. Exemplarily, the target device can be a mobile phone, a tablet computer, a laptop computer, a PDA, a vehicle-mounted electronic device, a mobile Internet device (Mobile Internet Device, MID), an augmented reality (augmented reality, AR) / virtual reality (virtual reality, VR) device, a robot, a wearable device, an ultra-mobile personal computer (ultra-mobile personal computer, UMPC), a netbook or a personal digital assistant (personal digital assistant, PDA), etc. It can also be a server, a network attached storage (Network Attached Storage, NAS), a personal computer (personal computer, PC), a television (television, TV), a teller machine or a self-service machine, etc., which is not specifically limited in the embodiment of the present application.

[0125] The long connection establishment device in the embodiment of the present application may be a device having an operating system. The operating system may be an Android operating system, an iOS operating system, or other possible operating systems, which are not specifically limited in the embodiment of the present application.

[0126] The long connection establishment device provided in the embodiment of the present application can implement each process implemented in the above method embodiment. To avoid repetition, it will not be repeated here.

[0127] Alternatively, if Figure 5 As shown, an embodiment of the present application also provides a target device 900, including a processor 901 and a memory 902, and the memory 902 stores a program or instruction that can be executed on the processor 901. When the program or instruction is executed by the processor 901, the various steps of the above-mentioned method embodiment are implemented, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.

[0128] It should be noted that the target device in the embodiment of the present application includes the mobile target device and the non-mobile target device mentioned above.

[0129] Figure 6 A schematic diagram of the hardware structure of a target device for implementing an embodiment of the present application.

[0130] The target device 100 includes but is not limited to: a radio frequency unit 101, a network module 102, an audio output unit 103, an input unit 104, a sensor 105, a display unit 106, a user input unit 107, an interface unit 108, a memory 109, and a processor 110.

[0131] Those skilled in the art will appreciate that the target device 100 may also include a power source (such as a battery) for supplying power to various components, and the power source may be logically connected to the processor 110 through a power management system, thereby implementing functions such as managing charging, discharging, and power consumption management through the power management system. Figure 6 The target device structure shown in the figure does not constitute a limitation on the target device. The target device may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently, which will not be described in detail here.

[0132] The radio frequency unit 101 is used to receive an authentication request sent by a client, where the authentication request is used by the client to request to connect to a server, and the authentication request includes information about the client.

[0133] The processor 110 is used to determine a server list according to the information of the client, where the server list includes address information of a primary server and address information of a backup server.

[0134] The radio frequency unit 101 is further used to send a server list to the client, where the server list is used for the client to establish a long connection with the main server.

[0135] An embodiment of the present application provides a target device. Since the client can send an authentication request including the client's information to the target device to request to connect to the server of the target device, the target device can determine a server list including the address information of the main server and the address information of the backup server based on the client's information after receiving the authentication request, and send the server list to the client, so that after receiving the server list, the client can establish a long connection with the main server based on the address information of the main server for communication, thereby reducing resource consumption.

[0136] Optionally, the client information includes an application identifier corresponding to the client, the address information of the client and a computer room priority rule of the client; the processor 110 is specifically used to determine at least one server according to the application identifier corresponding to the client, at least one server is a server that serves an application, and the one application is an application corresponding to the client; and according to the computer room priority rule of the client, at least one server is grouped to obtain a first group and a second group, the first group includes the address information of the server in the same computer room as the client, and the second group includes the address information of the server in a different computer room from the client; and determine the address information of M servers from the first group through a hash algorithm, and move the address information of the remaining servers in the first group to the second group to obtain a third group, the M servers are valid servers that serve the application corresponding to the client; and according to the address information of the client, determine the main server from the M servers, and determine the servers other than the main server and all servers in the third group as backup servers to obtain a server list.

[0137] Optionally, the processor 110 is specifically used to search from a preset allocation table whether the client has been assigned a server according to the address information of the client, the preset allocation table including at least one allocation relationship, each allocation relationship being an allocation relationship between a client and a server; in the case where the client has been assigned a server, determine whether the M servers include the server to which the client has been assigned, so as to determine the main server from the M servers; or, in the case where the client has not been assigned a server, determine whether the preset allocation table includes M servers, so as to determine the main server from the M servers.

[0138] Optionally, the processor 110 is specifically used to determine the server end assigned to the client as the main server end when the M server ends include the server end assigned to the client; or, when the M server ends do not include the server end assigned to the client, determine whether the preset allocation table includes M server ends, so as to determine the main server end from the M server ends.

[0139] Optionally, the processor 110 is specifically used to determine a server with the least number of connected clients among the M server ends as a main server end when the preset allocation table includes M server ends; or to determine any one of the M server ends as a main server end when the preset allocation table does not include M server ends.

[0140] Optionally, the processor 110 is further used to detect a preset allocation table according to an application identifier corresponding to the client and a computer room priority rule of the client after the radio frequency unit 101 sends a server list to the client, the preset allocation table including at least one allocation relationship, each allocation relationship being an allocation relationship between a client and a server; and in the case where there are invalid clients in the preset allocation table, clear the invalid clients from the preset allocation table; and detect whether the number of clients connected to each server in the preset allocation table is balanced; and in the case where there are servers with an uneven number of connected clients in the preset allocation table, adjust the preset allocation table through an averaging algorithm.

[0141] The target device provided in the embodiment of the present application can implement each process implemented in the above method embodiment and can achieve the same technical effect. To avoid repetition, it will not be described here.

[0142] The beneficial effects of various implementations in this embodiment can be specifically referred to the beneficial effects of the corresponding implementations in the above method embodiment. To avoid repetition, they will not be described again here.

[0143] It should be understood that in the embodiment of the present application, the input unit 104 may include a graphics processor (Graphics Processing Unit, GPU) 1041 and a microphone 1042, and the graphics processor 1041 processes the image data of a static picture or video obtained by an image capture device (such as a camera) in a video capture mode or an image capture mode. The display unit 106 may include a display panel 1061, and the display panel 1061 may be configured in the form of a liquid crystal display, an organic light emitting diode, etc. The user input unit 107 includes a touch panel 1071 and at least one of other input devices 1072. The touch panel 1071 is also called a touch screen. The touch panel 1071 may include two parts: a touch detection device and a touch controller. Other input devices 1072 may include, but are not limited to, a physical keyboard, function keys (such as volume control keys, switch keys, etc.), a trackball, a mouse, and a joystick, which will not be repeated here.

[0144] The memory 109 can be used to store software programs and various data. The memory 109 may mainly include a first storage area for storing programs or instructions and a second storage area for storing data, wherein the first storage area may store an operating system, an application program or instructions required for at least one function (such as a sound playback function, an image playback function, etc.), etc. In addition, the memory 109 may include a volatile memory or a non-volatile memory, or the memory 109 may include both volatile and non-volatile memories. Among them, the non-volatile memory may be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory may be a random access memory (RAM), a static random access memory (SRAM), a dynamic random access memory (DRAM), a synchronous dynamic random access memory (SDRAM), a double data rate synchronous dynamic random access memory (DDRSDRAM), an enhanced synchronous dynamic random access memory (ESDRAM), a synchronous link dynamic random access memory (SLDRAM) and a direct memory bus random access memory (DRRAM). The memory 109 in the embodiment of the present application includes but is not limited to these and any other suitable types of memory.

[0145] The processor 110 may include one or more processing units; optionally, the processor 110 integrates an application processor and a modem processor, wherein the application processor mainly processes operations related to an operating system, a user interface, and application programs, and the modem processor mainly processes wireless communication signals, such as a baseband processor. It is understandable that the modem processor may not be integrated into the processor 110.

[0146] An embodiment of the present application also provides a readable storage medium, on which a program or instruction is stored. When the program or instruction is executed by a processor, the various processes of the above-mentioned method embodiment are implemented and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.

[0147] The processor is the processor in the target device described in the above embodiment. The readable storage medium includes a computer readable storage medium, such as a computer read-only memory ROM, a random access memory RAM, a magnetic disk or an optical disk.

[0148] An embodiment of the present application further provides a chip, which includes a processor and a communication interface, wherein the communication interface is coupled to the processor, and the processor is used to run programs or instructions to implement the various processes of the above-mentioned method embodiment, and can achieve the same technical effect. To avoid repetition, it will not be repeated here.

[0149] It should be understood that the chip mentioned in the embodiments of the present application can also be called a system-level chip, a system chip, a chip system or a system-on-chip chip, etc.

[0150] An embodiment of the present application provides a computer program product, which is stored in a storage medium. The program product is executed by at least one processor to implement the various processes of the above-mentioned method embodiment and can achieve the same technical effect. To avoid repetition, it will not be repeated here.

[0151] It should be noted that, in this article, the terms "comprise", "include" or any other variant thereof are intended to cover non-exclusive inclusion, so that the process, method, article or device including a series of elements includes not only those elements, but also includes other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise one..." do not exclude the presence of other identical elements in the process, method, article or device including the element. In addition, it should be pointed out that the scope of the methods and devices in the embodiments of the present application is not limited to performing functions in the order shown or discussed, and may also include performing functions in a substantially simultaneous manner or in reverse order according to the functions involved, for example, the described method may be performed in an order different from that described, and various steps may also be added, omitted, or combined. In addition, the features described with reference to certain examples may be combined in other examples.

[0152] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a computer software product, which is stored in a storage medium (such as ROM / RAM, a disk, or an optical disk), and includes a number of instructions for a terminal (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present application.

[0153] The embodiments of the present application are described above in conjunction with the accompanying drawings, but the present application is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the guidance of the present application, ordinary technicians in this field can also make many forms without departing from the purpose of the present application and the scope of protection of the claims, all of which are within the protection of the present application.

Claims

1. A method for establishing a long connection, It is characterized in that The method comprises: Receiving an authentication request sent by a client, wherein the authentication request is used by the client to request to connect to a server, and the authentication request includes information of the client; Determine a server list according to the information of the client, wherein the server list includes address information of a primary server and address information of a backup server; Sending the server list to the client, where the server list is used for the client to establish a long connection with the main server; The client information includes an application identifier corresponding to the client, address information of the client, and a computer room priority rule of the client; Determining the server list according to the information of the client includes: Determine at least one server according to the application identifier corresponding to the client, wherein the at least one server is a server serving an application, and the application is an application corresponding to the client; According to the computer room priority rule of the client, the at least one server is grouped to obtain a first group and a second group, wherein the first group includes address information of servers in the same computer room as the client, and the second group includes address information of servers in a different computer room from the client; Determine address information of M servers from the first group by a hash algorithm, and move address information of remaining servers in the first group to the second group to obtain a third group, wherein the M servers are valid servers serving the application corresponding to the client; The main server is determined from the M servers according to the address information of the client, and the servers other than the main server among the M servers and all the servers in the third group are determined as the backup servers to obtain the server list.

2. The method according to claim 1, It is characterized in that Determining the main server from the M servers according to the address information of the client includes: According to the address information of the client, searching from a preset allocation table whether the client has been allocated a server, the preset allocation table including at least one allocation relationship, each allocation relationship being an allocation relationship between a client and a server; In the case where the client has been assigned a server, determining whether the M servers include the server that has been assigned to the client, so as to determine the main server from the M servers; or, In the case that the client has not been assigned a server, it is determined whether the preset allocation table includes the M servers, so as to determine the main server from the M servers.

3. The method according to claim 2, It is characterized in that The determining whether the M servers include a server that has been allocated to the client, so as to determine the main server from the M servers, includes: In the case where the M servers include a server already assigned to the client, determining the server already assigned to the client as the primary server; or, In the case that the M servers do not include the server already allocated to the client, it is determined whether the preset allocation table includes the M servers, so as to determine the main server from the M servers.

4. The method according to claim 2 or 3, It is characterized in that The determining whether the preset allocation table includes the M server ends, so as to determine the main server end from the M server ends, comprises: In the case where the preset allocation table includes the M servers, the server with the least number of connected clients among the M servers is determined as the main server; or When the preset allocation table does not include the M server ends, any one of the M server ends is determined as the main server end.

5. The method according to claim 1, It is characterized in that After sending the server list to the client, the method further includes: According to the application identifier corresponding to the client and the computer room priority rule of the client, a preset allocation table is detected, wherein the preset allocation table includes at least one allocation relationship, and each allocation relationship is an allocation relationship between a client and a server; In the case where there is an invalid client in the preset allocation table, clearing the invalid client from the preset allocation table; Detect whether the number of clients connected to each server in the preset allocation table is balanced; In the case where there is a server with an unbalanced number of connected clients in the preset allocation table, the preset allocation table is adjusted by an amortization algorithm.

6. A long connection establishment device, It is characterized in that The long connection establishment device comprises: a receiving module, a determining module and a sending module; The receiving module is used to receive an authentication request sent by a client, wherein the authentication request is used by the client to request to connect to a server, and the authentication request includes information about the client; The determining module is used to determine a server list according to the information of the client, wherein the server list includes address information of a primary server and address information of a backup server; The sending module is used to send the server list to the client, and the server list is used for the client to establish a long connection with the main server; The client information includes an application identifier corresponding to the client, address information of the client, and a computer room priority rule of the client; The determination module is specifically used to determine at least one server end according to the application identifier corresponding to the client, the at least one server end is a server end serving an application, and the one application is an application corresponding to the client; and according to the computer room priority rule of the client, the at least one server end is grouped to obtain a first group and a second group, the first group includes address information of servers in the same computer room as the client, and the second group includes address information of servers in a different computer room from the client; and determine the address information of M servers from the first group through a hash algorithm, and move the address information of the remaining servers in the first group to the second group to obtain a third group, the M servers are valid servers serving the application corresponding to the client; and according to the address information of the client, determine the main server end from the M servers, and determine the servers other than the main server end among the M servers and all servers in the third group as the backup servers to obtain the server list.

7. A target device, It is characterized in that It includes a processor and a memory, the memory stores a program or instruction that can be run on the processor, and when the program or instruction is executed by the processor, the steps of the long connection establishment method as described in any one of claims 1 to 5 are implemented.

8. A readable storage medium, It is characterized in that The readable storage medium stores a program or instruction, and when the program or instruction is executed by the processor, the steps of the method for establishing a long connection according to any one of claims 1 to 5 are implemented.