Method and device for establishing connection

By filtering and updating the difference set between service consumers and service providers in the microservice architecture, and using the consistent hash algorithm to select service providers, the performance loss problem caused by the increase in the number of long connections is solved and achieved This saves resources and improves system stability.

CN118540362APending Publication Date: 2024-08-23HUAWEI CLOUD COMPUTING TECHNOLOGIES CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202310123075.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-02-15
Publication Date
2024-08-23

AI Technical Summary

Technical Problem

In a microservice architecture, as the number of service consumers and service providers increases, the number of long connections increases exponentially, resulting in increased performance loss and additional overhead. It is difficult to effectively manage and optimize existing technologies.

Method used

By using filtering processing and consistent hashing algorithms between service consumers and service providers, a part of service providers are selected to establish long connections, reducing the number of connections, and updating the connection set when the service provider changes to ensure that the difference set is minimized. This reduces resource usage and avoids the impact of connection re-establishment.

Benefits of technology

It effectively reduces the performance loss and additional overhead caused by too many connections in microservice scenarios, improves the stability and efficiency of the system, and avoids connection reconstruction problems caused by changes in the number of service providers.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118540362A
    Figure CN118540362A
Patent Text Reader

Abstract

The embodiment of the invention provides a method and device for establishing connection, relates to the technical field of computers, and can reduce performance loss and extra overhead caused by too many connections in a micro-service scene. The method is applied to a micro-service scene, and comprises the following steps: a service consumer obtains a first service provider set comprising a plurality of service providers from a service registration device, and when the number of the service providers in the first service provider set is greater than a first number, the service provider registration device performs service registration on the first service provider set; service providers in the first service provider set are filtered, a first target service provider set is obtained, and the first target service provider set comprises a first number of service providers; and establishing a long connection between the service consumer and each service provider in the first target service provider set, wherein the long connection is used for the service consumer to call the service provider in the first target service provider set.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the field of computer technology, and in particular, to a method and device for establishing a connection. Background Art

[0002] In the microservice architecture, service consumers can call service providers to implement microservices that service providers can provide. Usually, there are multiple service consumers and service providers. After a service consumer can establish communication connections with multiple service providers, the service consumer can initiate service calls to the service provider.

[0003] With the evolution of microservice architecture, service consumers and service providers can establish long connections, which can avoid the need to establish a connection between service consumers and service providers every time a service call is initiated. However, when the number of service consumers and service providers in the microservice architecture is large, the number of long connections between service consumers and service providers will increase exponentially, which will lead to greater performance loss and additional overhead during the microservice call process. Summary of the invention

[0004] The embodiments of the present application provide a method and device for establishing a connection, which can reduce the performance loss and additional overhead caused by too many connections in a microservice scenario.

[0005] In order to achieve the above purpose, the embodiment of the present application adopts the following technical solution:

[0006] In a first aspect, an embodiment of the present application provides a method for establishing a connection, which is applied to a service consumer in a microservice scenario, the method comprising: obtaining a first service provider set from a service registration device; the first service provider set includes multiple service providers; and when the number of service providers in the first service provider set is greater than a first number, filtering the service providers in the first service provider set to obtain a first target service provider set; wherein the first target service provider set includes a first number of service providers; and establishing a long connection between the service consumer and each service provider in the first target service provider set; the long connection is used by the service consumer to call the service provider in the first target service provider set.

[0007] In the method for establishing a connection provided by the embodiment of the present application, the service consumer can filter multiple service providers to select a part of the service providers from the multiple service providers, and then the service consumer establishes a connection with the selected part of the service providers. It can be seen that the service consumer does not need to establish a connection with all service providers. In this way, in a large-scale microservice architecture, the number of connections can be reduced, thereby reducing the performance loss and additional overhead caused by too many connections in the microservice scenario.

[0008] In a possible implementation manner, the above first quantity can be determined according to the total number of service providers in the first service provider set and a preset ratio (the preset ratio is greater than 0 and less than 1). It can be understood that the ratio of the service providers required when establishing a connection is preconfigured in the service consumer. After the service consumer obtains the first service provider set, the total number of service providers in the first service provider set is multiplied by the above preset ratio to obtain the above first quantity.

[0009] In a possible implementation manner, the above first service provider set further includes the addresses of multiple service providers; filtering the service providers in the first service provider set to obtain the first target service provider set includes: based on the address of the service consumer and the addresses of multiple service providers, using a random algorithm to screen out the first quantity of service providers from the first service provider set to obtain the first target service provider set.

[0010] In a possible implementation manner, the above random algorithm is the consistent hashing algorithm.

[0011] In a possible implementation manner, the number of service providers in the first service provider set is N, the first quantity is M, N is an integer greater than or equal to 2, 0 < M ≤ N; and when the above random algorithm is the consistent hashing algorithm, the above method of using a random algorithm to screen out the first quantity of service providers from the first service provider set based on the address of the service consumer and the addresses of multiple service providers to obtain the first target service provider set includes: performing a hash calculation on the addresses of N service providers, mapping the N service providers to N nodes on the hash ring to obtain N mapping points of the N service providers; and performing a hash calculation on M random strings including the IP address of the service consumer, mapping the M random strings to the hash ring to obtain M mapping points of the M random strings; and for each of the M random strings, starting from the mapping point of the random string on the hash ring, in the clockwise direction, dividing the service provider corresponding to the first mapping point among the N mapping points into the first target service provider set.

[0012] In one possible implementation, when the service provider set is updated from the first service provider set to the second service provider set, the method for establishing a connection provided by the embodiment of the present application also includes: updating the first number to the second number; and when the number of service providers in the second service provider set is greater than the second number, based on the address of the service consumer and the addresses of multiple service providers in the second service provider set, using a random algorithm, screening out a second number of service providers from the second service provider set to obtain a second target service provider set; and determining the difference between the first target service provider set and the second target service provider set to obtain a third target service provider set; and then establishing a long connection between the service consumer and each service provider in the third target service provider set.

[0013] In an embodiment of the present application, when the service providers in the microservice architecture change, such as adding new service providers, deleting service providers, or replacing service providers, the above-mentioned first service provider set will also be updated accordingly and updated to the second service provider set.

[0014] Furthermore, since the service providers in the first target service provider set have all established long connections with the service consumers and the long connections have not been disconnected, when the service provider changes, the service providers in the second target service provider set that have already established connections with the consumers do not need to re-establish connections. The service consumer only needs to establish a connection with each service provider in the third target service provider set (i.e., the difference between the first target service provider set and the second target service provider set). Furthermore, since the third target service provider set is the minimum difference set, it can greatly reduce resource usage and save overhead, and can also avoid the problem of a large number of connections needing to be re-established due to changes in the number of service providers, thus affecting service stability.

[0015] In a possible implementation, the ratio of the updated second number to the number of service providers in the second service provider set is equal to the ratio of the first number to the number of service providers in the first service provider set.

[0016] When the number of service providers in the service provider set changes, the first number is also updated accordingly according to the proportion of the change and updated to the second number. Then, according to the consistent hashing algorithm, it can be ensured that the difference between the service providers in the second target service provider set selected from the second service provider set and the service providers in the above-mentioned first target service provider set is minimized.

[0017] In one possible implementation, the method for establishing a connection provided by an embodiment of the present application also includes: executing a load balancing algorithm to screen out a target service provider from the service providers that have established a long connection with the service consumer, and using the target service provider as the service provider currently called by the service consumer, and then the service consumer initiates a call request to the target service provider set, executes the microservice call process, so that the server running the service provider is load balanced.

[0018] Optionally, the above-mentioned load balancing algorithm can be any one of polling method, weighted polling method, weighted random method, minimum connection number method, random method or source address hash method, which can be selected according to actual needs and is not limited in the embodiments of the present application.

[0019] In a second aspect, an embodiment of the present application provides a method for establishing a connection, which is applied to a load balancing device between a service consumer and a service provider in a microservice scenario, the method comprising: obtaining a first service provider set from a service registration device; the first service provider set includes multiple service providers; when the number of service providers in the first service provider set is greater than a first number, filtering the service providers in the first service provider set to obtain a first target service provider set including the first number of service providers; and then sending first indication information including the first target service provider set to the service consumer, the first indication information being used to indicate establishment of a long connection between the service consumer and each service provider in the first target service provider set.

[0020] Through the technical solution provided in the embodiments of the present application, the load balancing device can select a part of service providers from multiple service providers and provide these service providers to service consumers, so that the service consumers can establish connections with some service providers for subsequent service calls. In this way, the service consumers do not need to establish connections with all service providers. In this way, in a large-scale microservice architecture, the number of connections can be reduced, thereby reducing the performance loss and additional overhead caused by too many connections in the microservice scenario.

[0021] In one possible implementation, the first service provider set also includes addresses of multiple service providers; the service providers in the first service provider set are filtered to obtain a first target service provider set, including: based on the address of the service consumer and the addresses of the multiple service providers, a random algorithm is used to screen out a first number of service providers from the first service provider set to obtain the first target service provider set.

[0022] In one possible implementation, the random algorithm is a consistent hashing algorithm.

[0023] In a possible implementation, the number of service providers in the first service provider set is N, the first number is M, N is an integer greater than or equal to 2, and 0 < M ≤ N; and when the above random algorithm is a consistent hashing algorithm, based on the address of the service consumer and the addresses of multiple service providers, using a random algorithm, the first number of service providers is screened out from the first service provider set to obtain a first target service provider set, including: performing a hash calculation on the addresses of N service providers, mapping the N service providers to N nodes on the hash ring to obtain N mapping points of the N service providers; and performing a hash calculation on M random strings including the IP address of the service consumer, mapping the M random strings to the hash ring to obtain M mapping points of the M random strings; and for each of the M random strings, starting from the mapping point of the random string on the hash ring, in the clockwise direction, the service provider corresponding to the first mapping point among the N mapping points is divided into the first target service provider set.

[0024] In a possible implementation, when the service provider set is updated from the first service provider set to the second service provider set, the method for establishing a connection provided by the embodiments of the present application further includes: updating the first number to a second number; and in the case where the number of service providers in the second service provider set is greater than the second number, based on the address of the service consumer and the addresses of multiple service providers in the second service provider set, using a random algorithm, the second number of service providers is screened out from the second service provider set to obtain a second target service provider set; and determining the difference set between the first target service provider set and the second target service provider set to obtain a third target service provider set; and then establishing a long connection between the service consumer and each service provider in the third target service provider set.

[0025] In the embodiments of the present application, when the service providers in the microservice architecture change, for example, there are newly added service providers, or service providers are deleted, or service providers are replaced, the above first service provider set will also be updated accordingly to the second service provider set.

[0026] Furthermore, since the service providers in the first target service provider set have all established long connections with the service consumers and the long connections have not been disconnected, when the service provider changes, the service providers in the second target service provider set that have already established connections with the consumers do not need to re-establish connections. The service consumer only needs to establish a connection with each service provider in the third target service provider set (i.e., the difference between the first target service provider set and the second target service provider set). Furthermore, since the third target service provider set is the minimum difference set, it can greatly reduce resource usage and save overhead, and can also avoid the problem of a large number of connections needing to be re-established due to changes in the number of service providers, thus affecting service stability.

[0027] In a possible implementation, the ratio of the updated second number to the number of service providers in the second service provider set is equal to the ratio of the first number to the number of service providers in the first service provider set.

[0028] When the number of service providers in the service provider set changes, the above-mentioned first number is also updated accordingly according to the proportion of the change and updated to the second number. Then, according to the consistent hashing algorithm, it can be ensured that the difference between the service providers in the second target service provider set selected from the second service provider set and the service providers in the above-mentioned first target service provider set is minimized.

[0029] In one possible implementation, the method for establishing a connection provided by an embodiment of the present application also includes: executing a load balancing algorithm to screen out a target service provider from the service providers that have established a long connection with the service consumer, and using the target service provider as the service provider currently called by the service consumer, and then the service consumer initiates a call request to the target service provider set, executes the microservice call process, so that the server running the service provider is load balanced.

[0030] Optionally, the above-mentioned load balancing algorithm can be any one of polling method, weighted polling method, weighted random method, minimum connection number method, random method or source address hash method, which can be selected according to actual needs and is not limited in the embodiments of the present application.

[0031] In a third aspect, an embodiment of the present application provides a service consumer, which is applied to a microservice scenario. The service consumer includes an acquisition module, a processing module, and a communication module. Among them, the processing module is used to obtain a first set of service providers from a service registration device; the first set of service providers includes multiple service providers; the processing module is used to filter the service providers in the first set of service providers to obtain a first target set of service providers when the number of service providers in the first set of service providers is greater than a first number; wherein, the first target set of service providers includes the first number of service providers; the communication module is used to establish a long connection between the service consumer and each service provider in the first target set of service providers, and the long connection is used for the service consumer to call the service providers in the first target set of service providers.

[0032] In a possible implementation manner, the above-mentioned first set of service providers further includes the addresses of multiple service providers; specifically, the processing module is used to screen out the first number of service providers from the first set of service providers based on the address of the service consumer and the addresses of multiple service providers by using a random algorithm to obtain a first target set of service providers.

[0033] In a possible implementation manner, the number of service providers in the above-mentioned first set of service providers is N, the first number is M, N is an integer greater than or equal to 2, and 0 < M ≤ N; and the random algorithm is a consistent hashing algorithm; specifically, the processing module is used to perform hash calculation on the addresses of N service providers, map the N service providers to N nodes on the hash ring, and obtain N mapping points of the N service providers; and perform hash calculation on M random strings including the IP address of the service consumer, map the M random strings to the hash ring, and obtain M mapping points of the M random strings; and for each random string in the M random strings, starting from the mapping point of the random string on the hash ring, in the clockwise direction, divide the service provider corresponding to the first mapping point among the N mapping points into the first target set of service providers.

[0034] In a possible implementation, the service consumer provided by the embodiment of the present application also includes an update module; the update module is used to update the first number to a second number. The above-mentioned processing module is also used to, when the number of service providers in the second service provider set is greater than the updated second number, based on the address of the service consumer and the addresses of multiple service providers in the second service provider set, use a random algorithm to screen out a second number of service providers from the second service provider set to obtain a second target service provider set; and determine the difference between the first target service provider set and the second target service provider set to obtain a third target service provider set. The above-mentioned communication module is also used to establish a long connection between the service consumer and each service provider in the third target service provider set.

[0035] In a possible implementation, a ratio of the second number to the number of service providers in the second service provider set is equal to a ratio of the first number to the number of service providers in the first service provider set.

[0036] In one possible implementation, the service consumer provided by the embodiment of the present application also includes a load balancing module; the load balancing module is used to execute a load balancing algorithm to filter out a target service provider from the service providers that have established a long connection with the service consumer, and use the target service provider as the service provider currently called by the service consumer.

[0037] In a fourth aspect, an embodiment of the present application provides a load balancing device, which is applied to a microservice scenario, and the load balancing device includes: an acquisition module, a processing module, and a sending module. The processing module is used to obtain a first service provider set from a service registration device; the first service provider set includes multiple service providers; the processing module is used to filter the service providers in the first service provider set to obtain a first target service provider set when the number of service providers in the first service provider set is greater than the first number; the first target service provider set includes a first number of service providers; the sending module is used to send a first indication message to a service consumer, the first indication message includes the first target service provider set, and the first indication message is used to indicate the establishment of a long connection between the service consumer and each service provider in the first target service provider set.

[0038] In one possible implementation, the first service provider set also includes addresses of multiple service providers; the processing module is specifically used to screen out a first number of service providers from the first service provider set based on the address of the service consumer and the addresses of multiple service providers, using a random algorithm to obtain a first target service provider set.

[0039] In a possible implementation, the number of service providers in the above-mentioned first service provider set is N, the first number is M, N is an integer greater than or equal to 2, 0 < M ≤ N; and the random algorithm is a consistent hashing algorithm; the upper processing module is specifically configured to perform hash calculation on the addresses of N service providers, map the N service providers to N nodes on the hash ring, and obtain N mapping points of the N service providers; and perform hash calculation on M random strings including the IP address of the service consumer, map the M random strings to the hash ring, and obtain M mapping points of the M random strings; and for each random string in the M random strings, starting from the mapping point of the random string on the hash ring and in the clockwise direction, divide the service provider corresponding to the first mapping point among the N mapping points into the first target service provider set.

[0040] In a possible implementation, the load balancing device provided in the embodiment of the present application further includes an update module; the update module is used to update the first number to a second number. The above-mentioned processing module is further configured to, when the number of service providers in the second service provider set is greater than the updated second number, based on the address of the service consumer and the addresses of multiple service providers in the second service provider set, use a random algorithm to screen out the second number of service providers from the second service provider set to obtain a second target service provider set; and determine the difference set between the first target service provider set and the second target service provider set to obtain a third target service provider set. The above-mentioned sending module is further configured to send second indication information to the service consumer, where the second indication information includes the third target service provider set, and the second indication information is used to indicate to establish a long connection between the service consumer and each service provider in the third target service provider set.

[0041] In a possible implementation, the ratio of the second number to the number of service providers in the second service provider set is equal to the ratio of the first number to the number of service providers in the first service provider set.

[0042] In a possible implementation, the load balancing device provided in the embodiment of the present application further includes a load balancing module; the load balancing module is used to execute a load balancing algorithm to screen out a target service provider from the service providers that have established a long connection with the service consumer, and use the target service provider as the service provider currently called by the service consumer.

[0043] In a fifth aspect, an embodiment of the present application provides a device comprising a memory and at least one processor connected to the memory, the memory being used to store computer program code, the computer program code comprising computer instructions, and when the computer instructions are executed by at least one processor, the device executes the method described in the first aspect and any one of its possible implementation methods.

[0044] In a sixth aspect, an embodiment of the present application provides a computer-readable storage medium storing computer instructions, which, when executed on a computer, execute the method described in the first aspect and any one of its possible implementations.

[0045] In a seventh aspect, an embodiment of the present application provides a computer program product, which includes computer instructions. When the computer instructions are run on a computer, the method described in the first aspect and any one of its possible implementation methods is executed.

[0046] In an eighth aspect, an embodiment of the present application provides a chip, comprising a memory and a processor, the memory being used to store computer instructions, and the processor being used to call and run the computer instructions from the memory to execute the method described in the first aspect and any one of its possible implementation methods.

[0047] In the ninth aspect, an embodiment of the present application provides a device, comprising a memory and at least one processor connected to the memory, the memory being used to store computer program code, the computer program code comprising computer instructions, and when the computer instructions are executed by at least one processor, the device executes the method described in the second aspect and any one of its possible implementation methods.

[0048] In a tenth aspect, an embodiment of the present application provides a computer-readable storage medium storing computer instructions, which, when executed on a computer, execute the method described in the second aspect and any one of its possible implementations.

[0049] In an eleventh aspect, an embodiment of the present application provides a computer program product, which includes computer instructions. When the computer instructions are run on a computer, the method described in the second aspect and any one of its possible implementation methods is executed.

[0050] In the twelfth aspect, an embodiment of the present application provides a chip, including a memory and a processor, the memory being used to store computer instructions, and the processor being used to call and run the computer instructions from the memory to execute the method described in the second aspect and any one of its possible implementation methods.

[0051] It should be understood that the beneficial effects achieved by the technical solutions of the third to twelfth aspects of the present application and the corresponding possible implementation methods can be referred to the technical effects of the first aspect, the second aspect and their corresponding possible implementation methods, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0052] Figure 1 A schematic diagram of a microservice architecture provided for an embodiment of the present application;

[0053] Figure 2 A schematic diagram of the system architecture of a method for establishing a connection between an application provided in an embodiment of the present application;

[0054] Figure 3 A schematic diagram of the hardware structure of a server provided in an embodiment of the present application;

[0055] Figure 4 One of the schematic diagrams of a method for establishing a connection provided in an embodiment of the present application;

[0056] Figure 5 A second schematic diagram of a method for establishing a connection provided in an embodiment of the present application;

[0057] Figure 6 A schematic diagram of a hash ring provided in an embodiment of the present application;

[0058] Figure 7 A third schematic diagram of a method for establishing a connection provided in an embodiment of the present application;

[0059] Figure 8 A fourth schematic diagram of a method for establishing a connection provided in an embodiment of the present application;

[0060] Fig. 9 A fifth schematic diagram of a method for establishing a connection provided in an embodiment of the present application;

[0061] Fig.10 One of the structural diagrams of a service consumer provided in an embodiment of the present application;

[0062] Fig.11 A second structural diagram of a service consumer provided in an embodiment of the present application;

[0063] Fig.12 One of the structural schematic diagrams of a load balancing device provided in an embodiment of the present application;

[0064] Fig.13 The second structural diagram of a load balancing device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0065] The term "and / or" in this article is merely a description of the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone.

[0066] The terms "first" and "second" in the description and claims of the embodiments of the present application are used to distinguish different objects rather than to describe a specific order of the objects. For example, a first service provider set and a second service provider set are used to distinguish different service provider sets rather than to describe a specific order of the service provider sets.

[0067] In the embodiments of the present application, words such as "exemplary" or "for example" are used to indicate examples, illustrations or descriptions. Any embodiment or design described as "exemplary" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a specific way.

[0068] In the description of the embodiments of the present application, unless otherwise specified, the meaning of "multiple" refers to two or more than two. For example, multiple service providers refers to two or more service providers.

[0069] First, some concepts involved in a method and device for establishing a connection provided in an embodiment of the present application are explained.

[0070] 1. Microservices

[0071] Microservices are small services composed of a single application, with independent processes and lightweight processing mechanisms. Microservices can be designed based on business functions, that is, microservices are developed as a single small service with business functions. Microservices can be deployed on a single or multiple servers, and a microservice can communicate with other microservices.

[0072] Specifically, the microservice architecture is a distributed architecture, and each microservice makes service calls through the network. Therefore, the microservice architecture includes service providers (the callee) and service consumers (the caller). Service providers and service consumers are all microservices. It should be understood that the roles of service providers and service consumers are relative, and a service can be both a service provider and a service consumer.

[0073] 2. Connections in Microservice Architecture

[0074] The connection in the microservice architecture is the communication connection established between the service consumer and the service provider before the service consumer calls the service provider. In one case, first, the service consumer and the service provider establish a TCP connection based on the transmission control protocol (TCP), so that the service consumer and the service provider have the basis for data transmission. The TCP connection is a connection at the transport layer; secondly, the service consumer and the service provider establish a network connection between the service consumer and the service provider based on the hypertext transfer protocol (HTTP), that is, an HTTP connection, which is a connection at the application layer.

[0075] 3. Short connection and long connection

[0076] One of the two communicating parties (e.g., a service consumer and a service provider) (e.g., a service consumer) initiates a connection request to the other party (e.g., a service provider). The other party receives the connection request, and then the two parties interact to establish a connection and communicate based on the established connection. For example, the service consumer sends a message to the service provider, and the service provider sends a response.

[0077] Optionally, after the above communication ends, the service consumer or service provider can initiate a connection closing operation, and the communication connection closed after the above communication is a short connection. After the service consumer and the service provider complete a communication, the service consumer and the service provider do not initiate a connection closing operation, and the service consumer and the service provider continue to communicate based on the connection. Such a communication connection is a long connection.

[0078] It is understandable that short connections are easy to manage. All short connections are useful connections. Short connections take up fewer resources and do not require additional control. However, in scenarios where the two parties communicate frequently, connections need to be established frequently, which takes a lot of time. Long connections can avoid frequent establishment or closing of connections, which can save time. For scenarios with frequent communications, it is suitable to establish long connections. However, as the number of service consumers and / or service providers increases, the number of long connections also increases, which takes up more resources and causes greater performance loss and overhead for the server.

[0079] The embodiments of the present application involve a scenario in which a service consumer and a service provider in a microservice architecture establish a long connection. The method for establishing a connection provided by the embodiments of the present application can control the number of long connections between the service consumer and the service provider to ensure that the number of connections does not expand excessively, thereby causing large performance losses and additional overhead during the microservice call process.

[0080] It should be understood that the number of connections in this application is an abbreviation for the number of long connections between the service consumer and the service provider.

[0081] 4. Load Balancing

[0082] Usually, in a microservice architecture, there are multiple service providers that provide a certain service. In a single service call, a service consumer calls one of the multiple service providers. When the service consumer selects a service provider, a service provider can be selected from the multiple service providers based on the idea of ​​load balancing. Load balancing is to distribute the service consumer's call request to the appropriate service provider so that the load of the servers in the cluster running the service provider is balanced, that is, load balancing can avoid the situation where some servers are overloaded while other servers are relatively idle.

[0083] The following is a detailed description of the microservice architecture in combination with the above-mentioned microservice concepts. Figure 1 A schematic diagram of a microservice structure provided in an embodiment of the present application. Figure 1 The microservice architecture shown includes multiple service consumers 101 , multiple service providers 102 , and a service registration center (or service registration device) 103 .

[0084] The service provider 102 may register the information of the microservices that the service provider 102 can provide (the information of the microservices is the information that can indicate the microservices, such as the identifier of the microservices) and the address information of the service provider 103 in the service registration center 103. The service consumer 101 may perform service discovery by accessing the service registration center 103, that is, learn about the services that the service provider 102 can provide. Subsequently, the service consumer 101 may initiate a call request to the service provider 103 based on the needs of the service consumer 101.

[0085] In an embodiment of the present application, the service consumer 101 may be a client, and the service provider 102 may be a server. When the program of the service consumer 101 is started for the first time or when the service provider 102 changes (for example, the number of service providers 102 changes or the address of the service provider 102 changes), the service consumer 101 will obtain the address information of all service providers 102 from the service registration center 103, and then cache the address information of all service providers 102. Each time the service consumer 101 initiates a service call, based on the principle of load balancing, it selects a service provider 102 from multiple service providers for calling.

[0086] Combination Figure 1When the scale of microservices is large, for example, the number of service consumers is 10,000 and the number of service providers is 10,000, the total number of long connections can be as high as 10,000. 2 , so it can be seen that the performance of the server will be seriously affected.

[0087] Faced with the problem that a large number of long connections has a great impact on the performance of the server and the server has a large overhead, a technical solution for establishing a connection is currently proposed in the relevant technology. The technical solution is: set a time limit for the retention time of the long connection. When the retention time of the long connection exceeds the set time limit (that is, the long connection expires), the connection is closed (also called disconnection or destruction), which can prevent the number of long connections from continuing to increase. However, as the scale of microservices becomes larger and larger, the number of service providers increases. In some cases, when a service consumer initiates a new service call request, the call request is used to call a service provider, and the service provider has established a connection with the service consumer. However, when the service consumer initiates a new call request to the service provider, the long connection that has been established between the service consumer and the service provider expires. In this way, it is necessary to re-establish the connection between the service consumer and the service provider. Then the long connection is equivalent to a short connection, which will also bring additional overhead.

[0088] In response to the above problems, an embodiment of the present application provides a method and device for establishing a connection, which is applied to a service consumer in a microservice scenario. In the method, the service consumer obtains a first service provider set including multiple service providers from a service registration device, and when the number of service providers in the first service provider set is greater than the first number, the service providers in the first service provider set are filtered to obtain a first target service provider set including the first number of service providers, and then a long connection is established between the service consumer and each service provider in the first target service provider set, and the long connection is used for the service consumer to call the service providers in the first target service provider set. Through the technical solution provided by the embodiment of the present application, the service consumer can select a part of the service providers from multiple service providers for subsequent service calls without establishing a connection between the service consumer and all service providers. In this way, in a large-scale microservice architecture, the number of connections can be reduced, thereby reducing the performance loss and additional overhead caused by too many connections in the microservice scenario.

[0089] Further, in response to the above problems, the embodiment of the present application also provides a method and device for establishing a connection, which is applied to a load balancing device between a service consumer and a service provider in a microservice scenario. In the method, the load balancing device obtains a first service provider set from a service registration device, and the first service provider set includes multiple service providers; when the number of service providers in the first service provider set is greater than the first number, the service providers in the first service provider set are filtered to obtain a first target service provider set including the first number of service providers; and then the load balancing device sends a first indication information including the first target service provider set to the service consumer, and the first indication information is used to indicate the establishment of a long connection between the service consumer and each service provider in the first target service provider set. Through the technical solution provided by the embodiment of the present application, the load balancing device can select a part of the service providers from the multiple service providers and provide the part of the service providers to the service consumer, so that the service consumer establishes a connection with the part of the service providers for subsequent service calls, so that the service consumer does not need to establish a connection with all service providers. In this way, in a large-scale microservice architecture, the number of connections can be reduced, thereby reducing the performance loss and additional overhead caused by too many connections in the microservice scenario.

[0090] Optionally, refer to Figure 2 In the system architecture shown, the execution subject of the method for establishing a connection provided in the embodiment of the present application can be a service consumer (such as a load balancing module or other functional module in the service consumer) or a load balancing device located between the service consumer and the service provider. For example, in a scenario where load balancing is performed on the client side, the device that executes the method for establishing a connection can be the load balancing device of the service consumer; in a scenario where load balancing is performed on the server side, the device that executes the method for establishing a connection is a load balancing device located between the service consumer and the service provider.

[0091] The device for executing the method for establishing a connection provided in the embodiment of the present application (i.e., the above-mentioned service consumer or load balancing device) may be a server. Figure 3 A schematic diagram of the hardware structure of a server provided in an embodiment of the present application is provided. Figure 3 The various components shown in the EMBODIMENTS 2000 may be implemented in hardware, software, or a combination of hardware and software, including one or more signal processing and / or application specific integrated circuits.

[0092] like Figure 3 As shown, the server may include: a processor 301, a memory 302, and a communication interface 303. The processor 301, the memory 302, and the communication interface 303 may be connected to each other via a bus 304, or in other ways.

[0093] The processor 301 is the control center of the server. The processor 301 may be a general-purpose central processing unit (CPU) or other general-purpose processors. The general-purpose processor may be a microprocessor or any conventional processor.

[0094] The controller in the processor 301 is the nerve center and command center of the server. The controller can generate an operation control signal according to the instruction operation code and the timing signal to complete the control of fetching and executing instructions. Optionally, a memory can also be set in the processor 301 to store instructions and data.

[0095] Exemplarily, the processor 301 may include one or more CPUs, such as Figure 3 CPU 0 and CPU 1 are shown in .

[0096] The memory 302 includes, but is not limited to, a random access memory (RAM), a read only memory (ROM), an erasable programmable read-only memory (EPROM), a flash memory, or an optical memory, a disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store the desired program code in the form of an instruction or data structure and can be accessed by a computer. In the embodiment of the present application, the memory 302 can store computer instructions, which include instructions for executing the method for establishing a connection provided by the present application.

[0097] In a possible implementation, the memory 302 may exist independently of the processor 301. The memory 302 may be connected to the processor 301 via a bus 304 and is used to store data, instructions or program codes. The processor 301 calls and executes the instructions or program codes stored in the memory 302 to perform the above-mentioned method for establishing a connection.

[0098] In another possible implementation, the memory 302 may also be integrated with the processor 301 .

[0099] The communication interface 303 is used for the server to communicate with other devices or communication networks, such as Ethernet, RAN, wireless local area networks (WLAN), etc.

[0100] The bus 304 may be an industry standard architecture (ISA) bus, a peripheral component interconnect (PCI) bus, an extended industry standard architecture (EISA) bus, CXL, UB, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 3 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.

[0101] It should be noted that Figure 3 The server shown is only one example of a server, which may have more Figure 3 More or fewer components may be shown, two or more components may be combined, or there may be a different configuration of components.

[0102] Based on the microservice architecture described in the above embodiments, after the service provider completes the service registration in the service registration device (such as a registration center), the service consumer or the load balancing device executes the method for establishing a connection provided in the embodiments of the present application.

[0103] like Figure 4 As shown, when the method for establishing a connection provided in the embodiment of the present application is applied to a service consumer, the method may include the following steps:

[0104] S401: Acquire a first service provider set from a service registration device, where the first service provider set includes multiple service providers.

[0105] The service providers in the above-mentioned first service provider set are all service providers that have registered services in the service registration device. The first service provider set obtained by the service consumer from the service registration device also includes the addresses of multiple service providers. Optionally, the address of the service provider can be the IP address and port information of the service provider, or the address of the service provider can be the domain name and port information of the server where the service provider is located. The embodiment of the present application does not limit the address of the service provider.

[0106] S402: When the number of service providers in the first service provider set is greater than a first number, filter the service providers in the first service provider set to obtain a first target service provider set.

[0107] The first target service provider set includes the first number of service providers.

[0108] In the embodiments of the present application, the above-mentioned first quantity can be determined according to the total number of service providers in the first service provider set and a preset ratio (the preset ratio is greater than 0 and less than 1). It can be understood that the ratio of service providers required when establishing a connection is pre-configured in the service consumer. After the service consumer obtains the first service provider set, the total number of service providers in the first service provider set is multiplied by the above-mentioned preset ratio to obtain the above-mentioned first quantity.

[0109] Optionally, the above-mentioned preset ratio can be set according to actual needs, and the embodiments of the present application do not make any limitations.

[0110] Optionally, in combination with Figure 4 , such as Figure 5 shown, the first target service provider set is filtered from the first service provider set through the following S4021.

[0111] S4021. Based on the address of the service consumer and the addresses of multiple service providers, using a random algorithm, select the first quantity of service providers from the first service provider set to obtain the first target service provider set.

[0112] Optionally, the random algorithm can be any one of the following algorithms: consistent hashing algorithm, Knuth-Shuffle algorithm, Reservoir sampling random algorithm.

[0113] The process of determining the first target service provider set is introduced below by taking the consistent hashing algorithm as an example of the random algorithm. Assume that the number of service providers in the first service provider set is N, the above-mentioned first quantity is M, N is an integer greater than or equal to 2, and 0 < M ≤ N. Then the above-mentioned S4021 specifically includes S4021a - S4021c:

[0114] S4021a. Perform a hash calculation on the addresses of N service providers, map the N service providers to N nodes on the hash ring, and obtain N mapping points of the N service providers.

[0115] In the embodiments of the present application, taking the address as an IP address as an example, a string group including N strings is generated according to the IP addresses of the above-mentioned N service providers. This string group can be denoted as Provdier-IP[N], and a string in this string group is denoted as Provdier-IP_n, where IP_n represents the IP address of the nth service provider among the N service providers.

[0116] Perform hash calculation on each string in the above string group Provdier-IP[N] to obtain N hash values ​​corresponding to the N strings. The N hash values ​​can correspond to N nodes on the hash ring. In this way, the N service providers can be mapped to the hash ring. The N nodes on the hash ring are the mapping points of the N service providers. It should be noted that the detailed process of the consistent hashing algorithm can be referred to the existing technical information, and the embodiments of this application will not be described in detail.

[0117] S4021b. Perform hash calculation on the M random character strings containing the IP address of the service consumer, map the M random character strings to the hash ring, and obtain M mapping points of the M random character strings.

[0118] In an embodiment of the present application, for a service consumer, a string containing the IP address of the service consumer is generated, recorded as Consumer-IP, and then a string group containing M random strings is generated based on Consumer-IP, and the string group is recorded as Consumer-IP-randomKey[M]. A random string in the string group is recorded as Consumer-IP-randomKey_m, where randomKey_m represents the mth randomly generated random number, and the value of m is 1, 2, ..., M.

[0119] Similar to S4021a above, a hash calculation is performed on each string in the above string group Consumer-IP-randomKey[M] to obtain M hash values ​​of the M strings. The M hash values ​​can correspond to M nodes on the hash ring. In this way, the M random strings can be mapped to the hash ring to obtain M mapping points.

[0120] S4021c. For each of the M random strings, starting from the mapping point of the random string on the hash ring, divide the service providers corresponding to the first mapping point of the N mapping points into the first target service provider set in a clockwise direction.

[0121] In an embodiment of the present application, through S4021c, each of the above-mentioned M random strings can be matched to a mapping point from the N mapping points on the hash ring, thereby obtaining M target mapping points, and the set of service providers corresponding to the M target mapping points is the first target service provider set.

[0122] The above S4021c process is described by way of example. Figure 6 As shown in the figure, assuming that N is 10 and M is 4, the 10 service providers are mapped to the 10 mapping points on the hash ring, which can be recorded as N1, N2, ..., N 10, the M random strings are mapped to the 4 mapping points on the hash ring, which can be recorded as M1, M2, M3 and M4. For M1, starting from M1, the first mapping point among the N mapping points encountered in a clockwise direction is N7, then the service provider corresponding to N7 is divided into the first target service provider set; for M2, the first mapping point among the N mapping points encountered in a clockwise direction is N9, then the service provider corresponding to N9 is divided into the first target service provider set; for M3, the first mapping point among the N mapping points encountered in a clockwise direction is N1, then the service provider corresponding to N1 is divided into the first target service provider set; for M4, the first mapping point among the N mapping points encountered in a clockwise direction is N3, then the service provider corresponding to N3 is divided into the first target service provider set. In this way, the 4 service providers included in the first target service provider set are the service provider corresponding to N7, the service provider corresponding to N9, the service provider corresponding to N1 and the service provider corresponding to N3.

[0123] It should be noted that the values ​​of N and M are simple numerical values ​​taken to illustrate the consistent hashing algorithm, and do not represent the service provider and the value of the first quantity in actual applications, and the positions of the N mapping points and the M mapping points are only illustrative positions. 10 There are 10 service providers corresponding to each other, but N1, N2, ..., N 10 The order of the 10 service providers is irrelevant.

[0124] It should be noted that, when the number of service providers in the first service provider set is less than or equal to the first number, the service providers in the first service provider set are not filtered, and all service providers in the first service provider set are divided into the first target service provider set, that is, the first service provider set is taken as the first target service provider set.

[0125] S403: Establish a persistent connection between the service consumer and each service provider in the first target service provider set. The persistent connection is used by the service consumer to call the service providers in the first target service provider set.

[0126] In the embodiment of the present application, after the service consumer obtains the first target service provider set, the service consumer can initiate a request to establish a connection to each service provider in the first target service provider set to establish a communication connection with each service provider. Subsequently, the service consumer can call a service provider in the first target service provider set to complete the service call. The process of establishing a connection between the service consumer and the service provider can refer to existing technical information, and the embodiment of the present application will not be described in detail.

[0127] Optionally, combined Figure 5 ,like Figure 7 As shown, after the above S403, the method for establishing a connection provided in the embodiment of the present application may further include S404.

[0128] S404: Execute a load balancing algorithm to select a target service provider from the service providers that have established a long connection with the service consumer (ie, the first target service provider set), and use the target service provider as the service provider currently called by the service consumer.

[0129] In an embodiment of the present application, a load balancing algorithm is executed to select a service provider from the first target service provider set as the target service provider, and then the service consumer initiates a call request to the target service provider set and executes the microservice call process, so that the server running the service provider is load balanced.

[0130] It should be noted that in the scenario where load balancing is performed on the client side, the load balancing process is executed by the service consumer, that is, the above S404 is executed by the service consumer. In the scenario where load balancing is performed on the server side, the load balancing process is executed by the load balancing device located between the service consumer and the service provider, that is, the above S404 is executed by the load balancing device located between the service consumer and the service provider. In this scenario, when the service consumer initiates a request to establish a connection to the service provider, the request to establish a connection is initiated through the load balancing device. The load balancing device can obtain information about all service providers in the first target service provider set from the service consumer. Subsequently, when the service consumer calls the service provider, the load balancing device executes the load balancing algorithm to select the target service provider and returns it to the service consumer, so that the service consumer calls the target service provider.

[0131] Optionally, the above-mentioned load balancing algorithm can be any one of polling method, weighted polling method, weighted random method, minimum connection number method, random method or source address hash method, which can be selected according to actual needs and is not limited in the embodiments of the present application.

[0132] In the method for establishing a connection provided in an embodiment of the present application, a service consumer can filter multiple service providers to select a part of service providers from the multiple service providers, and then the service consumer establishes a connection with the selected part of service providers. It can be seen that the service consumer does not need to establish a connection with all service providers. In this way, in a large-scale microservice architecture, the number of connections can be reduced, thereby reducing the performance loss and additional overhead caused by too many connections in the microservice scenario.

[0133] In one implementation, when the service providers in the microservice architecture change, such as adding new service providers, deleting service providers, or replacing service providers, the first service provider set will also be updated to the second service provider set. Figure 8 As shown, the method for establishing a connection provided in the embodiment of the present application also includes S405-S408:

[0134] S405: Update the first quantity to the second quantity.

[0135] In an embodiment of the present application, a service consumer can detect changes in service providers. For example, a service consumer can periodically obtain a set of service providers from a service registration device. When a service provider set newly obtained by a service consumer (for example, the second service provider set described above) is different from a service provider set already obtained (for example, the first service provider set described above), (for example, adding new service providers, deleting service providers, or replacing service providers, etc.), the service consumer updates the first service provider set, that is, replaces the first service provider set with the second service provider set. Further, the service consumer determines a second number based on a preset proportion of the service consumer and the number of service providers in the second service provider set, thereby updating the first number to the second number.

[0136] Optionally, the ratio of the updated second number to the number of service providers in the second service provider set is equal to the ratio of the first number to the number of service providers in the first service provider set, that is, when the number of service providers in the service provider set changes, the number of service providers in the first target service provider set is also updated accordingly according to the proportion of the change.

[0137] Exemplarily, assuming that the first service provider set includes 100 service providers and the preset ratio is 0.05, the first number is 5. If the second service provider set obtained after the first service provider set is changed includes 120 service providers, the second number is 6.

[0138] S406. When the number of service providers in the second service provider set is greater than the second number, based on the address of the service consumer and the addresses of multiple service providers in the second service provider set, a random algorithm is used to screen out a second number of service providers from the second service provider set to obtain a second target service provider set.

[0139] The above-mentioned random algorithm may be a consistent hashing algorithm. The process of using the consistent hashing algorithm to screen out a second number of service providers from the second service provider set to obtain a second target service provider set is similar to the process of using the consistent hashing algorithm in the above-mentioned S4021 to screen out a first number of service providers from the first service provider set to obtain a first target service provider set. For the process of screening out the second number of service providers from the second service provider set, please refer to the relevant description of the above-mentioned embodiment, which will not be repeated here.

[0140] It should be noted that, in an embodiment of the present application, after the first service provider set is updated to the second service provider set and the first quantity is also updated to the second quantity, according to the consistent hashing algorithm, it can be ensured that the difference between the service providers in the second target service provider set screened from the second service provider set and the service providers in the above-mentioned first target service provider set is minimized.

[0141] For example, continue with Figure 6 Taking the example shown as an example, assuming that 10 new service providers are added to the first service provider set, that is, the second service provider set includes 20 service providers, the first number is updated from 4 to the second number is 8. Continuing to execute the consistent hashing algorithm, it can be seen that the 10 mapping points corresponding to the original 10 service providers in the second service provider set on the hash ring remain unchanged, and there are 4 strings among the 8 random strings generated by the service consumer that are the same as the 4 random strings before the update, so the mapping of these 4 random strings on the hash ring remains unchanged. In this way, the 4 service providers selected for the mapping points of these 4 strings remain unchanged. In other words, the second target service provider set includes the service provider corresponding to the node N7 in the above-mentioned hash ring, the service provider corresponding to N9, the service provider corresponding to N1, and the service provider corresponding to N3.

[0142] S407: Determine the difference between the first target service provider set and the second target service provider set to obtain a third target service provider set.

[0143] According to the above description, the service providers included in the third target service provider set are the minimum difference sets of the first target service provider set and the second target service provider set. For example, the third target service provider set includes: 4 new service providers filtered out from the 10 new service providers in the above example.

[0144] S408: Establish a long connection between the service consumer and each service provider in the third target service provider set.

[0145] In the embodiment of the present application, since the service providers in the first target service provider set have all established long connections with the service consumers, and the long connections have not been disconnected, when the service provider changes, the service providers in the second target service provider set that have established connections with the consumers do not need to re-establish connections, and the service consumers only need to establish connections with each service provider in the third target service provider set (i.e., the difference between the first target service provider set and the second target service provider set). Moreover, since the third target service provider set is the minimum difference set, it can greatly reduce resource usage and save overhead, and can also avoid the problem of a large number of connections needing to be re-established due to changes in the number of service providers, which affects service stability.

[0146] like Fig. 9 As shown, when the method for establishing a connection provided by the embodiment of the present application is applied to a load balancing device between a service consumer and a service provider, the method may include the following steps:

[0147] S901. Obtain a first service provider set from a service registration device, where the first service provider set includes multiple service providers.

[0148] The service providers in the above-mentioned first service provider set are all service providers that have registered services in the service registration device. The first service provider set obtained by the load balancing device from the service registration device also includes the addresses of multiple service providers. Optionally, the address of the service provider can be the IP address and port information of the service provider, or the address of the service provider can be the domain name and port information of the server where the service provider is located. The embodiment of the present application does not limit the address of the service provider.

[0149] S902: When the number of service providers in the first service provider set is greater than a first number, filter the service providers in the first service provider set to obtain a first target service provider set.

[0150] The first target service provider set includes the first number of service providers.

[0151] Similar to the above S402, the above first number can be determined according to the total number of service providers in the first service provider set and the preset proportion. It can be understood that the proportion of service providers required for establishing a connection is preconfigured in the load balancing device.

[0152] Optionally, the above preset proportions can be set according to actual needs, and are not limited in the embodiments of the present application.

[0153] In one implementation, the first target service provider set can be filtered from the first service provider set through the following S9021.

[0154] S9021: Based on the address of the service consumer and the addresses of multiple service providers, using a random algorithm, select the first quantity of service providers from the first service provider set to obtain the first target service provider set.

[0155] Optionally, the random algorithm can be any one of the following algorithms: consistent hashing algorithm, Knuth-Shuffle algorithm, Reservoir sampling random algorithm.

[0156] Taking the consistent hashing algorithm as an example of the random algorithm, the process of determining the first target service provider set is introduced below. Assume that the number of service providers in the first service provider set is N, the above first quantity is M, N is an integer greater than or equal to 2, 0 < M ≤ N. Similarly, similar to the above S4021, the above S9021 specifically includes S9021a - S9021c:

[0157] S9021a: Perform hash calculation on the addresses of N service providers, map the N service providers to N nodes on the hash ring, and obtain N mapping points of the N service providers.

[0158] S9021b: Perform hash calculation on M random strings including the IP address of the service consumer, map the M random strings to the hash ring, and obtain M mapping points of the M random strings.

[0159] S9021c: For each random string among the M random strings, starting from the mapping point of the random string on the hash ring, in the clockwise direction, divide the service provider corresponding to the first mapping point among the N mapping points into the first target service provider set.

[0160] It should be noted that in the case where the number of service providers in the first service provider set is less than or equal to the first quantity, no filtering process is performed on the service providers in the first service provider set, and all service providers in the first service provider set are divided into the first target service provider set, that is, the first service provider set is used as the first target service provider set.

[0161] It should be noted that the implementation process of the above S901-S902 is similar to that of S401-S402 in the above embodiment. The only difference is that S401-S402 is executed by the service consumer, and S901-S902 is executed by the load balancing device. Therefore, for more details of S901-S902, please refer to the above description of S401-S402, which will not be repeated here.

[0162] S903: Send first indication information to the service consumer, where the first indication information is used to instruct to establish a long connection between the service consumer and each service provider in the first target service provider set.

[0163] The above-mentioned first indication information includes a first target service provider set.

[0164] In an embodiment of the present application, after the load balancing device determines the first target service provider set, the load balancing device can send information containing the first target service provider set to the service consumer, so that the service consumer can initiate a request to establish a connection to each service provider in the first target service provider set to establish a communication connection with each service provider. Subsequently, the service consumer can call a service provider in the first target service provider set to complete the service call.

[0165] In some embodiments, after the load balancing device determines the first target service provider set, when the service consumer initiates a connection establishment request through the load balancing device, the service consumer sends the connection establishment request to the load balancing device, and the load balancing device forwards the connection establishment request to each service provider in the first target service provider set, and then the service consumer, the load balancing device and each service provider in the first target service provider set interact, and finally establishes a communication connection between the service consumer and each service provider in the first target service provider set.

[0166] Optionally, after the above S903, the method for establishing a connection provided in the embodiment of the present application may further include S904.

[0167] S904: Execute a load balancing algorithm to select a target service provider from the service providers that have established a long connection with the service consumer, and use the target service provider as the service provider currently called by the service consumer.

[0168] In the embodiment of the present application, a load balancing algorithm is executed to select a service provider from the first target service provider set as the target service provider, and then the service consumer initiates a call request to the target service provider set, executes the microservice call process, and makes the server running the service provider load balanced. Specifically, the service consumer initiates a call request through the load balancing device, and the load balancing device executes the load balancing algorithm to select the target service provider and returns it to the service consumer, so that the service consumer calls the target service provider.

[0169] In the method for establishing a connection provided in an embodiment of the present application, the load balancing device can select a part of service providers from multiple service providers and provide these part of service providers to the service consumer, so that the service consumer establishes a connection with the part of service providers for subsequent service calls. In this way, the service consumer does not need to establish a connection with all service providers. In this way, in a large-scale microservice architecture, the number of connections can be reduced, thereby reducing the performance loss and additional overhead caused by too many connections in the microservice scenario.

[0170] In one implementation, when the service providers in the microservice architecture change, such as adding new service providers, deleting service providers, or replacing service providers, the first service provider set will also be updated to the second service provider set. The method for establishing a connection provided in the embodiment of the present application also includes S905-S908:

[0171] S905: Update the first quantity to the second quantity.

[0172] In an embodiment of the present application, the load balancing device can detect changes in service providers. For example, the load balancing device can periodically obtain a set of service providers from a service registration device. When the set of service providers newly obtained by the load balancing device (for example, the second set of service providers mentioned above) is different from the set of service providers already obtained (for example, the first set of service providers mentioned above), (for example, adding new service providers, deleting service providers, or replacing service providers, etc.), the load balancing device updates the first set of service providers, that is, replaces the first set of service providers with the second set of service providers. Further, the load balancing device determines the second number based on the preset proportion of the service consumers and the number of service providers in the second set of service providers, thereby updating the first number to the second number.

[0173] Optionally, the ratio of the updated second number to the number of service providers in the second service provider set is equal to the ratio of the first number to the number of service providers in the first service provider set, that is, when the number of service providers in the service provider set changes, the number of service providers in the first target service provider set is also updated accordingly according to the proportion of the change.

[0174] S906. When the number of service providers in the second service provider set is greater than the second number, based on the address of the service consumer and the addresses of multiple service providers in the second service provider set, a random algorithm is used to screen out a second number of service providers from the second service provider set to obtain a second target service provider set.

[0175] The above-mentioned random algorithm may be a consistent hashing algorithm. The process of using the consistent hashing algorithm to screen out a second number of service providers from the second service provider set to obtain the second target service provider set is similar to the process of using the consistent hashing algorithm in the above-mentioned S9021 to screen out a first number of service providers from the first service provider set to obtain the first target service provider set. For the process of screening out the second number of service providers from the second service provider set, please refer to the relevant description of the above-mentioned embodiment, which will not be repeated here.

[0176] It should be noted that, in an embodiment of the present application, after the first service provider set is updated to the second service provider set and the first quantity is also updated to the second quantity, according to the consistent hashing algorithm, it can be ensured that the difference between the service providers in the second target service provider set screened from the second service provider set and the service providers in the above-mentioned first target service provider set is minimized.

[0177] S907: Determine the difference between the first target service provider set and the second target service provider set to obtain a third target service provider set.

[0178] According to the above description, the service providers included in the third target service provider set are the minimum difference set between the first target service provider set and the second target service provider set.

[0179] S908. Send second indication information to the service consumer, where the second indication information is used to instruct to establish a long connection between the service consumer and each service provider in the third target service provider set.

[0180] The second indication information includes a third target service provider set.

[0181] In the embodiment of the present application, since the service providers in the first target service provider set have all established a long connection with the service consumer, and the long connection has not been disconnected, when the service provider changes, the service providers in the second target service provider set that have established a connection with the consumer do not need to re-establish the connection. The load balancing device can instruct the service consumer through the second indication information that it only needs to establish a connection with each service provider in the third target service provider set (i.e., the difference set of the first target service provider set and the second target service provider set). Moreover, since the third target service provider set is the minimum difference set, it can greatly reduce resource usage and save overhead, and can also avoid the problem of a large number of connections needing to be re-established due to changes in the number of service providers, thereby affecting service stability.

[0182] Accordingly, an embodiment of the present application provides a service consumer. In the embodiment of the present application, the service consumer can be divided into functional modules according to the above method example. For example, each functional module can be divided corresponding to each function, or two or more functions can be integrated into one processing module. The above integrated module can be implemented in the form of hardware or in the form of software functional modules. It should be noted that the division of modules in the embodiment of the present application is schematic and is only a logical functional division. There may be other division methods in actual implementation.

[0183] In the case of dividing each functional module into corresponding functional modules, Fig.10 A possible structural diagram of the service consumer involved in the above embodiment is shown. Fig.10 As shown, the service consumer includes an acquisition module 1001, a processing module 1002 and a communication module 1003. Among them, the acquisition module 1001 is used to obtain a first service provider set from a service registration device; the first service provider set includes multiple service providers, for example, executing S401 in the above method embodiment. The processing module 1002 is used to filter the service providers in the first service provider set when the number of service providers in the first service provider set is greater than the first number, so as to obtain a first target service provider set, and the first target service provider set includes a first number of service providers, for example, executing S402 in the above method embodiment. The communication module 1003 is used to establish a long connection between the service consumer and each service provider in the first target service provider set, and the long connection is used by the service consumer to call the service provider in the first target service provider set, for example, executing S403 in the above method embodiment.

[0184] Optionally, the above processing module 1002 is specifically configured to screen out a first number of service providers from the first service provider set by using a random algorithm based on the address of the service consumer and the addresses of multiple service providers, so as to obtain a first target service provider set, for example, execute S4021 in the above method embodiment.

[0185] Optionally, the number of service providers in the above first service provider set is N, the first number is M, N is an integer greater than or equal to 2, 0 < M ≤ N, and the random algorithm is the consistent hashing algorithm; the above processing module 1002 is specifically configured to perform hash calculation on the addresses of N service providers, map the N service providers to N nodes on the hash ring, and obtain N mapping points of the N service providers; and perform hash calculation on M random strings including the IP address of the service consumer, map the M random strings to the hash ring, and obtain M mapping points of the M random strings; and for each random string in the M random strings, starting from the mapping point of the random string on the hash ring and in the clockwise direction, divide the service provider corresponding to the first mapping point among the N mapping points into the first target service provider set, for example, execute S4021a - S4021c in the above method embodiment.

[0186] Optionally, the service consumer provided in the embodiment of the present application further includes an update module 1004; the update module 1004 is configured to update the first number to a second number, for example, execute S405 in the above method embodiment. The above processing module 1002 is further configured to, when the number of service providers in the second service provider set is greater than the second number, screen out a second number of service providers from the second service provider set by using a random algorithm based on the address of the service consumer and the addresses of multiple service providers in the second service provider set, so as to obtain a second target service provider set; and determine the difference set between the first target service provider set and the second target service provider set to obtain a third target service provider set; for example, execute S406 - S407 in the above method embodiment. The above communication module 1003 is further configured to establish a long connection between the service consumer and each service provider in the third target service provider set, for example, execute S408 in the above method embodiment.

[0187] Optionally, the service consumer provided in the embodiment of the present application further includes a load balancing module 1005; the load balancing module 1005 is configured to execute a load balancing algorithm to screen out a target service provider from the service providers that have established a long connection with the service consumer, and use the target service provider as the service provider currently called by the service consumer, for example, execute S404 in the above method embodiment.

[0188] In the case of adopting an integrated unit, Fig.11 FIG. 2 shows another possible structural diagram of the service consumer involved in the above embodiment. Fig.11 As shown, the service consumer provided by the embodiment of the present application may include: a processing module 1101 and a communication module 1102. The processing module 1101 can be used to control and manage the actions of the service consumer. For example, the processing module 1101 can be used to support the service consumer in executing S401, S402 (including S4021, S4021a-S4021c), S404, S405-S407 in the above method embodiment, and / or other processes for the technology described herein. The communication module 1102 can be used to support the communication between the service consumer and other network entities, for example, to support the communication between the service consumer and the device. For example, the communication module 1102 can be used to support the service consumer in executing S403 and S408 in the above method embodiment. Optionally, as Fig.11 As shown, the service consumer may also include a storage module 1103 for storing computer instructions and data.

[0189] The processing module 1101 may be a processor or a controller (for example, the ... Figure 3 The processor 301 shown in the figure can also be a combination that realizes computing functions, such as a combination of one or more microprocessors, a combination of DSP and microprocessor, etc. The communication module 1102 can be a communication interface (for example, it can be the above-mentioned Figure 3 The storage module 1103 may be a memory (for example, the communication interface 303 as described above). Figure 3 When the processing module 1101 is a processor, the communication module 1102 is a communication interface, and the storage module 1103 is a memory, the processor, the transceiver, and the memory may be connected via a bus.

[0190] For more details on how the modules included in the above service consumers implement the above functions, please refer to the descriptions in the previous method embodiments, which will not be repeated here. Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments.

[0191] Accordingly, an embodiment of the present application provides a load balancing device. In the embodiment of the present application, the functional modules of the device can be divided according to the above method example. For example, each functional module can be divided corresponding to each function, or two or more functions can be integrated into one processing module. The above integrated module can be implemented in the form of hardware or in the form of software functional modules. It should be noted that the division of modules in the embodiment of the present application is schematic and is only a logical functional division. There may be other division methods in actual implementation.

[0192] In the case of dividing each functional module into corresponding functional modules, Fig.12 A possible structural diagram of the load balancing device involved in the above embodiment is shown. Fig.12 As shown, the load balancing device includes an acquisition module 1201, a processing module 1202 and a sending module 1203. Among them, the acquisition module 1201 is used to obtain a first service provider set from a service registration device; the first service provider set includes multiple service providers, for example, executing S901 in the above method embodiment. The processing module 1202 is used to filter the service providers in the first service provider set when the number of service providers in the first service provider set is greater than the first number, and obtain a first target service provider set. The first target service provider set includes a first number of service providers, for example, executing S902 in the above method embodiment. The sending module 1203 is used to send a first indication message to the service consumer, the first indication message includes the first target service provider set, and the first indication message is used to indicate the establishment of a long connection between the service consumer and each service provider in the first target service provider set, for example, executing S903 in the above method embodiment.

[0193] Optionally, the processing module 1202 is specifically used to select a first number of service providers from a first set of service providers based on the address of the service consumer and the addresses of multiple service providers by using a random algorithm to obtain a first target set of service providers, for example, executing S9021 in the method embodiment.

[0194] Optionally, the number of service providers in the above first service provider set is N, the first number is M, N is an integer greater than or equal to 2, 0 < M ≤ N, and the random algorithm is the consistent hashing algorithm; specifically, the processing module 1202 is configured to perform hash calculation on the addresses of N service providers, map the N service providers to N nodes on the hash ring, and obtain N mapping points of the N service providers; and perform hash calculation on M random strings including the IP address of the service consumer, map the M random strings to the hash ring, and obtain M mapping points of the M random strings; and for each random string in the M random strings, starting from the mapping point of the random string on the hash ring and in the clockwise direction, divide the service provider corresponding to the first mapping point among the N mapping points into the first target service provider set, for example, execute S9021a - S9021c in the above method embodiment.

[0195] Optionally, the load balancing device provided in the embodiment of the present application further includes an update module 1204; the update module 1204 is configured to update the above first number to a second number, for example, execute S905 in the above method embodiment. The processing module 1202 is further configured to, when the number of service providers in the second service provider set is greater than the second number, based on the address of the service consumer and the addresses of multiple service providers in the second service provider set, adopt a random algorithm to screen out the second number of service providers from the second service provider set to obtain a second target service provider set; and determine the difference set between the first target service provider set and the second target service provider set to obtain a third target service provider set; for example, execute S906 - S907 in the above method embodiment. The sending module 1203 is further configured to send second indication information to the service consumer, where the second indication information includes the third target service provider set, and the second indication information is used to indicate to establish long connections between the service consumer and each service provider in the third target service provider set, for example, execute S908 in the above method embodiment.

[0196] Optionally, the load balancing device provided in the embodiment of the present application further includes a load balancing module 1205; the load balancing module 1205 is configured to execute a load balancing algorithm to screen out a target service provider from the service providers that have established long connections with the service consumer, and use the target service provider as the service provider currently called by the service consumer, for example, execute S904 in the above method embodiment.

[0197] In the case of adopting an integrated unit, Fig.13 shows another possible structural schematic diagram of the load balancing device involved in the above embodiment. As Fig.13As shown, the load balancing device provided in the embodiment of the present application may include: a processing module 1301 and a communication module 1302. The processing module 1201 can be used to control and manage the actions of the load balancing device. For example, the processing module 1301 can be used to support the load balancing device to execute S901, S902 (including S9021, S9021a-S9021c), S904, S905-S907 in the above method embodiment, and / or other processes for the technology described herein. The communication module 1302 can be used to support the communication between the load balancing device and other network entities, for example, to support the communication between the load balancing device and the device. For example, the communication module 1302 can be used to support the load balancing device to execute S903 and S908 in the above method embodiment. Optionally, as Fig.13 As shown, the load balancing device may further include a storage module 1303 for storing computer instructions and data.

[0198] The processing module 1301 may be a processor or a controller (for example, the ... Figure 3 The processor 301 shown in the figure can also be a combination that realizes computing functions, such as a combination of one or more microprocessors, a combination of DSP and microprocessor, etc. The communication module 1302 can be a communication interface (for example, it can be the above-mentioned Figure 3 The storage module 1303 may be a memory (for example, the communication interface 303 as described above). Figure 3 When the processing module 1301 is a processor, the communication module 1302 is a communication interface, and the storage module 1303 is a memory, the processor, the transceiver, and the memory may be connected via a bus.

[0199] For more details on how the modules included in the load balancing device implement the above functions, please refer to the descriptions in the previous method embodiments, which will not be repeated here. Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other. Each embodiment focuses on the differences from other embodiments.

[0200] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using a software program, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer instruction is loaded and executed on a computer, the process or function in accordance with the embodiment of the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network or other programmable device. The computer instruction can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instruction can be transmitted from a website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (digital subscriber line, DSL)) mode or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, server or data center. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server, data center, etc. that includes one or more available media integrated. The available medium may be a magnetic medium (eg, a floppy disk, a magnetic disk, a magnetic tape), an optical medium (eg, a digital video disc (DVD)), or a semiconductor medium (eg, a solid state drive (SSD)).

[0201] Through the description of the above implementation methods, technicians in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above functional modules is used as an example. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. The specific working process of the system, device and unit described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.

[0202] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the modules or units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.

[0203] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0204] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0205] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application can be essentially or partly embodied in the form of a software product that contributes to the prior art, or all or part of the technical solution. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, server, or network device, etc.) or a processor to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: flash memory, mobile hard disk, read-only memory, random access memory, disk or optical disk, and other media that can store program codes.

[0206] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions within the technical scope disclosed in the present application should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

Claims

1. A method for establishing a connection, characterized in that: Applied to a service consumer in a microservice scenario, the method includes: Acquire a first service provider set from a service registration device; the first service provider set includes multiple service providers; In the case that the number of service providers in the first service provider set is greater than a first number, filtering the service providers in the first service provider set to obtain a first target service provider set; wherein the first target service provider set includes the first number of service providers; A persistent connection is established between the service consumer and each service provider in the first target service provider set; the persistent connection is used by the service consumer to call a service provider in the first target service provider set.

2. The method according to claim 1, characterized in that The first service provider set also includes addresses of the multiple service providers; The filtering of the service providers in the first service provider set to obtain a first target service provider set includes: Based on the address of the service consumer and the addresses of the multiple service providers, a random algorithm is used to screen out the first number of service providers from the first service provider set to obtain the first target service provider set.

3. The method according to claim 2, characterized in that The random algorithm is a consistent hashing algorithm.

4. The method according to any one of claims 1 to 3, characterized in that: When the service provider set is updated from the first service provider set to the second service provider set, the method further includes: updating the first quantity to a second quantity; In a case where the number of service providers in the second service provider set is greater than the second number, based on the address of the service consumer and the addresses of multiple service providers in the second service provider set, the random algorithm is used to screen out the second number of service providers from the second service provider set to obtain a second target service provider set; Determine a difference between the first target service provider set and the second target service provider set to obtain a third target service provider set; A long connection is established between the service consumer and each service provider in the third target service provider set.

5. The method according to claim 4, characterized in that A ratio of the second number to the number of service providers in the second set of service providers is equal to a ratio of the first number to the number of service providers in the first set of service providers.

6. The method according to any one of claims 1 to 5, characterized in that: The method further comprises: A load balancing algorithm is executed to select a target service provider from the service providers that have established a long connection with the service consumer, and the target service provider is used as the service provider currently called by the service consumer.

7. A method for establishing a connection, characterized in that: A load balancing device applied between a service consumer and a service provider in a microservice scenario, the method comprising: Acquire a first service provider set from a service registration device; the first service provider set includes multiple service providers; In the case that the number of service providers in the first service provider set is greater than a first number, filtering the service providers in the first service provider set to obtain a first target service provider set; wherein the first target service provider set includes the first number of service providers; Sending first indication information to the service consumer, wherein the first indication information includes the first target service provider set, and the first indication information is used to indicate establishment of a long connection between the service consumer and each service provider in the first target service provider set.

8. The method according to claim 7, characterized in that The first service provider set also includes addresses of the multiple service providers; The filtering of the service providers in the first service provider set to obtain a first target service provider set includes: Based on the address of the service consumer and the addresses of the multiple service providers, a random algorithm is used to screen out the first number of service providers from the first service provider set to obtain the first target service provider set.

9. The method according to claim 8, characterized in that The random algorithm is a consistent hashing algorithm.

10. The method according to any one of claims 7 to 9, characterized in that: When the service provider set is updated from the first service provider set to the second service provider set, the method further includes: updating the first quantity to a second quantity; In a case where the number of service providers in the second service provider set is greater than the second number, based on the address of the service consumer and the addresses of multiple service providers in the second service provider set, the random algorithm is used to screen out the second number of service providers from the second service provider set to obtain a second target service provider set; Determine a difference between the first target service provider set and the second target service provider set to obtain a third target service provider set; Sending second indication information to the service consumer, where the second indication information includes the third target service provider set, and the second indication information is used to instruct establishment of a long connection between the service consumer and each service provider in the third target service provider set.

11. The method according to claim 10, characterized in that A ratio of the second number to the number of service providers in the second set of service providers is equal to a ratio of the first number to the number of service providers in the first set of service providers.

12. The method according to any one of claims 7 to 11, characterized in that: The method further comprises: A load balancing algorithm is executed to select a target service provider from the service providers that have established a long connection with the service consumer, and the target service provider is used as the service provider currently called by the service consumer.

13. A service consumer, characterized in that: Applied to microservice scenarios, consumers of this service include: An acquisition module, configured to acquire a first service provider set from a service registration device; the first service provider set includes a plurality of service providers; a processing module, configured to filter the service providers in the first service provider set to obtain a first target service provider set when the number of service providers in the first service provider set is greater than a first number; wherein the first target service provider set includes the first number of service providers; A communication module is used to establish a persistent connection between the service consumer and each service provider in the first target service provider set; the persistent connection is used by the service consumer to call a service provider in the first target service provider set.

14. The service consumer according to claim 13, characterized in that: The first service provider set also includes addresses of the multiple service providers; The processing module is specifically configured to select the first number of service providers from the first set of service providers by using a random algorithm based on the address of the service consumer and the addresses of the multiple service providers, so as to obtain the first target service provider set.

15. The service consumer according to claim 14, characterized in that: The random algorithm is a consistent hashing algorithm.

16. The service consumer according to any one of claims 13 to 15, characterized in that: The service consumer further includes an update module; when the service provider set is updated from the first service provider set to the second service provider set, The updating module is configured to update the first quantity to a second quantity when the service provider set is updated from the first service provider set to a second service provider set; The processing module is further configured to, when the number of service providers in the second service provider set is greater than the second number, use the random algorithm to screen out the second number of service providers from the second service provider set based on the address of the service consumer and the addresses of the plurality of service providers in the second service provider set, so as to obtain a second target service provider set; The processing module is further configured to determine a difference between the first target service provider set and the second target service provider set to obtain a third target service provider set; The communication module is further used to establish a long connection between the service consumer and each service provider in the third target service provider set.

17. The service consumer according to claim 16, characterized in that: A ratio of the second number to the number of service providers in the second set of service providers is equal to a ratio of the first number to the number of service providers in the first set of service providers.

18. The service consumer according to any one of claims 13 to 17, characterized in that: The service consumer also includes a load balancing module; The load balancing module is used to execute a load balancing algorithm to filter out a target service provider from the service providers that have established a long connection with the service consumer, and use the target service provider as the service provider currently called by the service consumer.

19. A load balancing device, characterized in that: Applied to microservice scenarios, the load balancing device includes: An acquisition module, configured to acquire a first service provider set from a service registration device; the first service provider set includes a plurality of service providers; a processing module, configured to filter the service providers in the first service provider set to obtain a first target service provider set when the number of service providers in the first service provider set is greater than a first number; wherein the first target service provider set includes the first number of service providers; A sending module is used to send first indication information to the service consumer, wherein the first indication information includes the first target service provider set, and the first indication information is used to indicate the establishment of a long connection between the service consumer and each service provider in the first target service provider set.

20. The load balancing device according to claim 19, characterized in that: The first service provider set also includes addresses of the multiple service providers; The processing module is specifically configured to select the first number of service providers from the first set of service providers by using a random algorithm based on the address of the service consumer and the addresses of the multiple service providers, so as to obtain the first target service provider set.

21. The load balancing device according to claim 20, characterized in that: The random algorithm is a consistent hashing algorithm.

22. The load balancing device according to any one of claims 19 to 21, characterized in that: The load balancing device also includes an update module; The updating module is configured to update the first quantity to a second quantity when the service provider set is updated from the first service provider set to a second service provider set; The processing module is further configured to, when the number of service providers in the second service provider set is greater than the second number, use the random algorithm to screen out the second number of service providers from the second service provider set based on the address of the service consumer and the addresses of the plurality of service providers in the second service provider set, so as to obtain a second target service provider set; The processing module is further configured to determine a difference between the first target service provider set and the second target service provider set to obtain a third target service provider set; The sending module is further used to send second indication information to the service consumer, where the second indication information includes the third target service provider set, and the second indication information is used to indicate the establishment of a long connection between the service consumer and each service provider in the third target service provider set.

23. The load balancing device according to claim 22, characterized in that: A ratio of the second number to the number of service providers in the second set of service providers is equal to a ratio of the first number to the number of service providers in the first set of service providers.

24. The load balancing device according to any one of claims 19 to 23, characterized in that: The load balancing device also includes a load balancing module; The load balancing module is used to execute a load balancing algorithm to filter out a target service provider from the service providers that have established a long connection with the service consumer, and use the target service provider as the service provider currently called by the service consumer.

25. A device, characterized in that The device comprises a memory and at least one processor connected to the memory, wherein the memory is used to store computer program code, and the computer program code comprises computer instructions. When the computer instructions are executed by the at least one processor, the device executes the method according to any one of claims 1 to 6 or 7 to 12.

26. A computer-readable storage medium, characterized in that: Computer instructions are stored, and when the computer instructions are executed on a computer, the method according to any one of claims 1 to 6 or 7 to 12 is executed.

27. A computer program product, characterized in that The computer program product comprises computer instructions, and when the computer instructions are run on a computer, the method according to any one of claims 1 to 6 or 7 to 12 is executed.