Client load balancing method, device and equipment and storage medium

Obtaining the total number of connections of the service provider through the distributed cache and selecting the service provider with the smallest total number of connections for invocation solves the problem of inaccurate number of connections in the existing technology and improves service processing efficiency.

CN118827701AInactive Publication Date: 2024-10-22CHINA MOBILE M2M +1
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202311687905.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-12-08
Publication Date
2024-10-22
Estimated Expiration
Not applicable · inactive patent

Smart Images

  • Figure CN118827701A_ABST
    Figure CN118827701A_ABST
Patent Text Reader

Abstract

The invention discloses a client load balancing method, apparatus and device, and a storage medium. The method comprises the steps of obtaining a total connection number of all service providers through a distributed cache; the total number of connections of each service provider is the sum of the number of connections between the service provider and all connected service consumers; determining the service provider with the minimum total connection number; and calling the service provider with the minimum total connection number. By adopting the embodiment of the invention, the service provider with the minimum total connection number can be selected for calling, and the service processing efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of client load balancing, and in particular to a client load balancing method, device, equipment and storage medium. Background Art

[0002] In client-side load balancing, the load balancing decision is made by the consumer (client) of the service. When the client calls the microservice, the client-side load balancer selects the instance to send the request based on the configuration and strategy.

[0003] In the prior art, the service information of all services is stored independently, so the client load balancer can only obtain the number of connections between the service consumer initiating the call and each service provider, and select the service provider with the smallest number of connections to call. However, the service provider with the smallest number of connections does not mean that the total number of connections of the service provider is the smallest in the cluster, because the service provider will also be connected and called by other service consumers, and its total number of connections should be the sum of the number of connections between the service provider and all connected service consumers, so this will lead to slower service processing efficiency. Summary of the invention

[0004] The present invention provides a client load balancing method, device, equipment and storage medium, which determine the total number of connections of all service providers through distributed cache, can select the service provider with the smallest total number of connections for calling, and improve the processing efficiency of the service.

[0005] To achieve the above object, an embodiment of the present invention provides a client load balancing method, comprising:

[0006] Obtain the total number of connections of all service providers through distributed cache; the total number of connections of each service provider is the sum of the number of connections between the service provider and all connected service consumers;

[0007] Determining the service provider having the smallest total number of connections;

[0008] The service provider with the smallest total number of connections is called.

[0009] As an improvement of the above solution, after determining the service provider with the smallest total number of connections and before calling the service provider with the smallest total number of connections, the client load balancing method further includes:

[0010] Add 1 to the minimum total number of connections to obtain a first total number of connections, and write the first total number of connections into the distributed cache;

[0011] After calling the service provider with the smallest total number of connections, the client load balancing method further includes:

[0012] Subtract 1 from the minimum total number of connections to obtain a second total number of connections, and write the second total number of connections into the distributed cache.

[0013] As an improvement of the above solution, the adding 1 to the minimum total number of connections to obtain a first total number of connections, and writing the first total number of connections into the distributed cache includes:

[0014] Loading a preset first Lua script, adding 1 to the minimum total number of connections to obtain a first total number of connections, and writing the first total number of connections into the distributed cache;

[0015] The subtracting 1 from the minimum total number of connections to obtain a second total number of connections, and writing the second total number of connections into the distributed cache comprises:

[0016] A preset second Lua script is loaded, and an operation of subtracting 1 from the minimum total number of connections is performed to obtain a second total number of connections, and the second total number of connections is written into the distributed cache.

[0017] As an improvement to the above solution, the method of obtaining the total number of connections of all service providers through the distributed cache includes:

[0018] Get service information of all service providers;

[0019] The total number of connections corresponding to the service information is obtained respectively through the distributed cache.

[0020] As an improvement of the above solution, the service information includes: service name, IP and port.

[0021] To achieve the above object, an embodiment of the present invention further provides a client load balancing device, comprising:

[0022] A connection total acquisition module is used to acquire the total number of connections of all service providers through distributed cache; the total number of connections of each service provider is the sum of the number of connections between the service provider and all connected service consumers;

[0023] A determination module, used for determining the service provider with the smallest total number of connections;

[0024] The service calling module is used to call the service provider with the smallest total number of connections.

[0025] As an improvement of the above solution, the client load balancing device further includes:

[0026] an adding 1 module, configured to, after determining the service provider with the smallest total number of connections and before calling the service provider with the smallest total number of connections, add 1 to the smallest total number of connections to obtain a first total number of connections, and write the first total number of connections into the distributed cache;

[0027] A subtraction module is used to, after calling the service provider with the smallest total number of connections, subtract 1 from the smallest total number of connections to obtain a second total number of connections, and write the second total number of connections into the distributed cache.

[0028] As an improvement of the above solution, the total number of connections obtaining module is specifically used for:

[0029] Get service information of all service providers;

[0030] The total number of connections corresponding to the service information is obtained respectively through the distributed cache.

[0031] To achieve the above objectives, an embodiment of the present invention also provides a client load balancing device, including a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, and the processor implements the client load balancing method as described above when executing the computer program.

[0032] To achieve the above objectives, an embodiment of the present invention further provides a computer-readable storage medium, which includes a stored computer program; wherein, when the computer program is running, it controls the device where the computer-readable storage medium is located to execute the client load balancing method as described above.

[0033] Compared with the prior art, the client load balancing method, device, equipment and storage medium provided in the embodiment of the present invention obtain the total number of connections of all service providers through distributed cache; the total number of connections of each service provider is the sum of the number of connections between the service provider and all connected service consumers; the service provider with the smallest total number of connections is determined; and the service provider with the smallest total number of connections is called. It can be seen that the embodiment of the present invention determines and obtains the total number of connections of all service providers through distributed cache, and can select the service provider with the smallest total number of connections for calling, thereby improving the processing efficiency of the service. BRIEF DESCRIPTION OF THE DRAWINGS

[0034] Figure 1 is a flow chart of a client load balancing method provided by an embodiment of the present invention;

[0035] Figure 2 It is a structural block diagram of a client load balancing device provided by an embodiment of the present invention;

[0036] Figure 3 It is a structural block diagram of a client load balancing device provided by an embodiment of the present invention. DETAILED DESCRIPTION

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

[0038] See also Figure 1 , Figure 1 : is a flow chart of a client load balancing method provided by an embodiment of the present invention, wherein the client load balancing method comprises:

[0039] S1. Obtain the total number of connections of all service providers through distributed cache; the total number of connections of each service provider is the sum of the number of connections between the service provider and all connected service consumers;

[0040] S2. Determine the service provider with the smallest total number of connections;

[0041] S3. Call the service provider with the smallest total number of connections.

[0042] In an embodiment of the present invention, the total number of connections of all service providers is written into a distributed cache to achieve sharing among microservices, so that when load balancing is required, the total number of connections of all service providers is obtained through the distributed cache, and the total number of connections of each service provider is the sum of the number of connections between the service provider and all connected service consumers. For example, service provider A is connected to service consumer A and service consumer B respectively, then the total number of connections of service provider A is the number of connections between service provider A and service consumer A + the number of connections between service provider A and service consumer B, then the service provider with the smallest total number of connections is determined, and finally the service provider with the smallest total number of connections is called, thereby achieving optimal load balancing and improving service processing efficiency.

[0043] It can be understood that the number of connections is also the concurrency, and the total number of connections is also the total concurrency. By writing the total number of connections of all service providers into the distributed cache, the service provider with the smallest total number of connections can be determined through the distributed cache, and then the service provider can be called, and finally load balancing is achieved to the service provider with the smallest total number of connections in the cluster.

[0044] In an optional implementation, after determining the service provider with the smallest total number of connections and before calling the service provider with the smallest total number of connections, the client load balancing method further includes:

[0045] Add 1 to the minimum total number of connections to obtain a first total number of connections, and write the first total number of connections into the distributed cache;

[0046] After calling the service provider with the smallest total number of connections, the client load balancing method further includes:

[0047] Subtract 1 from the minimum total number of connections to obtain a second total number of connections, and write the second total number of connections into the distributed cache.

[0048] It can be understood that the service provider with the smallest total number of connections in the embodiment of the present invention performs an add / subtract operation on its total number of connections before / after the call, and writes the first / second total number of connections obtained after the add / subtract operation into the distributed cache, so that the smallest total number of connections in the distributed cache is updated to the first / second total number of connections, and the total number of connections of the service provider is maintained through the distributed cache. Among them, adding 1 before the call means that a new connection is to be added. After the call is completed, the actual total number of connections is also reduced by 1, so a subtraction operation is performed to count the total number of connections.

[0049] Further, the adding 1 to the minimum total number of connections to obtain a first total number of connections, and writing the first total number of connections into the distributed cache includes:

[0050] Loading a preset first Lua script, adding 1 to the minimum total number of connections to obtain a first total number of connections, and writing the first total number of connections into the distributed cache;

[0051] The subtracting 1 from the minimum total number of connections to obtain a second total number of connections, and writing the second total number of connections into the distributed cache comprises:

[0052] A preset second Lua script is loaded, and an operation of subtracting 1 from the minimum total number of connections is performed to obtain a second total number of connections, and the second total number of connections is written into the distributed cache.

[0053] It can be understood that the distributed cache is a redis-based distributed cache. In order to ensure the atomicity of the add 1 / subtract 1 operation, the Lua script is used to add 1 / subtract 1 to the minimum total number of connections to obtain the latest total number of connections, and the minimum total number of connections is written into the distributed cache.

[0054] Specifically, a preset first Lua script is loaded to implement an operation of adding 1 to the minimum total number of connections to obtain a first total number of connections, and the first total number of connections is written into the distributed cache.

[0055] A preset second Lua script is loaded to implement a subtraction operation on the minimum total number of connections to obtain a second total number of connections, and the second total number of connections is written into the distributed cache.

[0056] In an optional implementation manner, obtaining the total number of connections of all service providers through the distributed cache includes:

[0057] Get service information of all service providers;

[0058] The total number of connections corresponding to the service information is obtained respectively through the distributed cache.

[0059] It is understandable that the distributed cache stores service information of each service provider and its corresponding total number of connections. In order to obtain an accurate total number of connections, the service information of all service providers is first obtained, and then the total number of connections to the service information is found through the distributed cache.

[0060] In an optional implementation, the service information includes: service name, IP and port.

[0061] It is understandable that in order to obtain an accurate and unique total number of connections, the service names, IPs and ports of all service providers are first determined, and then the total number of connections to the service names, IPs and ports is found through the distributed cache.

[0062] It is understandable that the BestAvailableRule class and the RibbonLoadBalancerClient class can be customized so that when calling a service, the service provider with the smallest total number of connections can be selected for calling. Specifically, the choose method of the BestAvailableRule class can be set to obtain the total number of connections of all service providers through the distributed cache, and determine the service provider with the smallest total number of connections. The execute method of the RibbonLoadBalancerClient class can be set to add 1 to the smallest total number of connections to obtain the first total number of connections, write the first total number of connections to the distributed cache, and subtract 1 from the smallest total number of connections to obtain the second total number of connections, and write the second total number of connections to the distributed cache. Then inject the customized BestAvailableRule and RibbonLoadBalancerClient classes into the Spring container, and make them effective when calling the service, so that the service provider with the smallest total number of connections can be selected for calling.

[0063] A client load balancing method provided by an embodiment of the present invention obtains the total number of connections of all service providers through distributed cache; the total number of connections of each service provider is the sum of the number of connections between the service provider and all connected service consumers; the service provider with the smallest total number of connections is determined; and the service provider with the smallest total number of connections is called. It can be seen that the embodiment of the present invention determines and obtains the total number of connections of all service providers through distributed cache, and can select the service provider with the smallest total number of connections for calling, thereby improving the processing efficiency of the service.

[0064] See also Figure 2 , Figure 2 1 is a structural block diagram of a client load balancing device 10 provided in an embodiment of the present invention, wherein the client load balancing device comprises:

[0065] The total number of connections acquisition module 11 is used to acquire the total number of connections of all service providers through distributed cache; the total number of connections of each service provider is the sum of the number of connections between the service provider and all connected service consumers;

[0066] A determination module 12, configured to determine the service provider having the smallest total number of connections;

[0067] The service calling module 13 is used to call the service provider with the smallest total number of connections.

[0068] Optionally, the client load balancing device further includes:

[0069] an adding 1 module, configured to, after determining the service provider with the smallest total number of connections and before calling the service provider with the smallest total number of connections, add 1 to the smallest total number of connections to obtain a first total number of connections, and write the first total number of connections into the distributed cache;

[0070] A subtraction module is used to, after calling the service provider with the smallest total number of connections, subtract 1 from the smallest total number of connections to obtain a second total number of connections, and write the second total number of connections into the distributed cache.

[0071] Optionally, the adding 1 module is specifically used to: load a preset first Lua script, add 1 to the minimum total number of connections to obtain a first total number of connections, and write the first total number of connections into the distributed cache;

[0072] The subtraction module is specifically used to: load a preset second Lua script, subtract 1 from the minimum total number of connections to obtain a second total number of connections, and write the second total number of connections into the distributed cache.

[0073] Optionally, the total number of connections obtaining module is specifically used for:

[0074] Get service information of all service providers;

[0075] The total number of connections corresponding to the service information is obtained respectively through the distributed cache.

[0076] Optionally, the service information includes: service name, IP and port.

[0077] It is worth noting that the working process of each module in the client load balancing device 10 described in the embodiment of the present invention can refer to the working process of the client load balancing method described in the above embodiment, and will not be repeated here.

[0078] A client load balancing device 10 provided in an embodiment of the present invention obtains the total number of connections of all service providers through distributed cache; the total number of connections of each service provider is the sum of the number of connections between the service provider and all connected service consumers; the service provider with the smallest total number of connections is determined; and the service provider with the smallest total number of connections is called. It can be seen that the embodiment of the present invention determines and obtains the total number of connections of all service providers through distributed cache, and can select the service provider with the smallest total number of connections for calling, thereby improving the processing efficiency of the service.

[0079] In addition, an embodiment of the present invention further provides a computer-readable storage medium, which includes a stored computer program; wherein, when the computer program is running, it controls the device where the computer-readable storage medium is located to execute the client load balancing method as described in any of the above embodiments.

[0080] See also Figure 3 , Figure 3 : is a structural block diagram of a client load balancing device 20 provided in an embodiment of the present invention, and the client load balancing device 20 includes: a processor 21, a memory 22, and a computer program stored in the memory 22 and executable on the processor 21. When the processor 21 executes the computer program, the steps in the above-mentioned client load balancing method embodiment are implemented. Alternatively, when the processor 21 executes the computer program, the functions of each module / unit in the above-mentioned device embodiments are implemented.

[0081] Exemplarily, the computer program may be divided into one or more modules / units, which are stored in the memory 22 and executed by the processor 21 to implement the present invention. The one or more modules / units may be a series of computer program instruction segments capable of implementing specific functions, which are used to describe the execution process of the computer program in the client load balancing device 20.

[0082] The client load balancing device 20 may include, but is not limited to, a processor 21 and a memory 22. Those skilled in the art will appreciate that the schematic diagram is merely an example of the client load balancing device 20 and does not constitute a limitation on the client load balancing device 20. The client load balancing device 20 may include more or fewer components than shown in the diagram, or may combine certain components, or different components. For example, the client load balancing device 20 may also include input and output devices, network access devices, buses, and the like.

[0083] The processor 21 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc. The processor 21 is the control center of the client load balancing device 20, and uses various interfaces and lines to connect various parts of the entire client load balancing device 20.

[0084] The memory 22 can be used to store the computer program and / or module. The processor 21 implements various functions of the client load balancing device 20 by running or executing the computer program and / or module stored in the memory 22 and calling the data stored in the memory 22. The memory 22 can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.); the data storage area can store data created according to the use of the mobile phone (such as audio data, a phone book, etc.). In addition, the memory 22 can include a high-speed random access memory, and can also include a non-volatile memory, such as a hard disk, a memory, a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (SecureDigital, SD) card, a flash card (Flash Card), at least one disk storage device, a flash memory device, or other volatile solid-state storage devices.

[0085] Wherein, if the module / unit integrated in the client load balancing device 20 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 such an understanding, the present invention implements all or part of the processes in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium. When the computer program is executed by the processor 21, the steps of the above-mentioned method embodiments can be implemented. Wherein, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, U disk, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), electric carrier signal, telecommunication signal and software distribution medium, etc.

[0086] It should be noted that the device embodiments described above are merely schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. In addition, in the accompanying drawings of the device embodiments provided by the present invention, the connection relationship between the modules indicates that there is a communication connection between them, which may be specifically implemented as one or more communication buses or signal lines. A person of ordinary skill in the art may understand and implement it without paying any creative effort.

[0087] The above is a preferred embodiment of the present invention. It should be pointed out that a person skilled in the art can make several improvements and modifications without departing from the principle of the present invention. These improvements and modifications are also considered to be within the scope of protection of the present invention.

Claims

1. A client load balancing method, characterized in that: include: Get the total number of connections of all service providers through distributed cache; The total number of connections of each of the service providers is the sum of the number of connections between the service provider and all connected service consumers; Determining the service provider having the smallest total number of connections; The service provider with the smallest total number of connections is called.

2. The client load balancing method according to claim 1, characterized in that: After determining the service provider with the smallest total number of connections and before calling the service provider with the smallest total number of connections, the client load balancing method further includes: Add 1 to the minimum total number of connections to obtain a first total number of connections, and write the first total number of connections into the distributed cache; After calling the service provider with the smallest total number of connections, the client load balancing method further includes: Subtract 1 from the minimum total number of connections to obtain a second total number of connections, and write the second total number of connections into the distributed cache.

3. The client load balancing method according to claim 2, characterized in that: The adding 1 to the minimum total number of connections to obtain a first total number of connections, and writing the first total number of connections into the distributed cache includes: Loading a preset first Lua script, adding 1 to the minimum total number of connections to obtain a first total number of connections, and writing the first total number of connections into the distributed cache; The subtracting 1 from the minimum total number of connections to obtain a second total number of connections, and writing the second total number of connections into the distributed cache comprises: A preset second Lua script is loaded, and an operation of subtracting 1 from the minimum total number of connections is performed to obtain a second total number of connections, and the second total number of connections is written into the distributed cache.

4. The client load balancing method according to claim 1, wherein: The total number of connections of all service providers obtained through the distributed cache includes: Get service information of all service providers; The total number of connections corresponding to the service information is obtained respectively through the distributed cache.

5. The client load balancing method according to claim 4, characterized in that: The service information includes: service name, IP and port.

6. A client load balancing device, characterized in that: include: The total number of connections acquisition module is used to obtain the total number of connections of all service providers through distributed cache; The total number of connections of each of the service providers is the sum of the number of connections between the service provider and all connected service consumers; A determination module, used for determining the service provider with the smallest total number of connections; The service calling module is used to call the service provider with the smallest total number of connections.

7. The client load balancing device according to claim 6, characterized in that: The client load balancing device also includes: an adding 1 module, configured to, after determining the service provider with the smallest total number of connections and before calling the service provider with the smallest total number of connections, add 1 to the smallest total number of connections to obtain a first total number of connections, and write the first total number of connections into the distributed cache; A subtraction module is used to, after calling the service provider with the smallest total number of connections, subtract 1 from the smallest total number of connections to obtain a second total number of connections, and write the second total number of connections into the distributed cache.

8. The client load balancing device according to claim 6, characterized in that: The total number of connections acquisition module is specifically used for: Get service information of all service providers; The total number of connections corresponding to the service information is obtained respectively through the distributed cache.

9. A client load balancing device, characterized in that: The method comprises a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, wherein the processor implements the client load balancing method according to any one of claims 1 to 5 when executing the computer program.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a stored computer program; wherein, when the computer program is run, it controls the device where the computer-readable storage medium is located to execute the client load balancing method according to any one of claims 1 to 5.

Citation Information

Patent Citations

  • Load balancing method and device based on DNS (domain name system)

    CN105472025A

  • Method and device for counting connection numbers

    CN112291310A

  • Global load balancing method and device based on virtual service computing power

    CN114035895A

  • Distributed storage system load balancing scheduling method and device and storage medium

    CN114500578A

  • Load balancing method and apparatus, device, computer storage medium and program

    WO2023050901A1