A load balancing method, device, electronic device and computer storage medium

By introducing an instance change notification mechanism in the microservice system, the problems of customized indicator management and load balancing of microservice instances are solved, load balancing and overload protection are realized, and operation and maintenance costs are reduced.

CN113010313BActive Publication Date: 2025-03-18SHENZHEN TENCENT NETWORK INFORMATION TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202110281054.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-03-16
Publication Date
2025-03-18
Estimated Expiration
2041-03-18

AI Technical Summary

Technical Problem

The prior art is difficult to effectively manage and synchronize custom metrics of microservice instances in microservice systems, resulting in difficulties in load balancing and traffic management scenarios.

Method used

By implementing the instance change notification mechanism between the service provider and the name service server, the instance change notification includes instance information and custom metric information, and the notification is forwarded to the name service server in the cluster. The service initiator updates the local routing table based on this information, and then determines the target instance for processing the access request.

Benefits of technology

It realizes balancing the load of the service provider instance, provides overload protection, and reduces the number of scheduling services at the service layer, and reduces the development, machine and operation and maintenance costs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113010313B_ABST
    Figure CN113010313B_ABST
Patent Text Reader

Abstract

The present application relates to a load balancing method, device, electronic device and storage medium, the method comprising: a service provider sends an instance change notification to a name service server in response to an instance change request; the name service server forwards the instance change notification to the remaining name service servers in the cluster; each of the name service servers respectively forwards the instance change notification to the service initiator connected thereto; each of the service initiators updates a local routing table based on the instance information and custom indicator information in the instance change notification; when any of the service initiators receives an access request from a client, the service initiator determines the target instance for processing the access request based on the updated local routing table, and forwards the access request to the target instance. The present application can balance the load of the instance of the service provider, perform overload protection on the service provider, and complete the desired business logic.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a load balancing method, device, electronic device and computer storage medium. Background Art

[0002] The microservice framework is an emerging software architecture that decomposes a large and complex application into multiple microservices. Each microservice can be deployed independently and is loosely coupled. Each microservice only focuses on completing a task and completing it well.

[0003] During the operation of the framework, it may be necessary to manage the custom indicators of each instance in the microservice. In the existing technical solution, Zookeeper (a distributed, open source distributed application coordination service) can only attach data to the service persistent node, while the instance node as a temporary node cannot attach data, so it cannot be used to synchronize the custom indicators of the instance.

[0004] In large-scale microservice system management tool products such as Polaris and Istio, instances can have metadata information and can implement traffic management solutions based on instance metadata. However, in scenarios such as when a copy activity is started and you want to send requests to the service provider with the most online players and no overload, or when logging in normally and you want to send requests to the service provider with fewer players, it is difficult to use metadata to represent business custom indicator information such as the number of players and current load. Therefore, the above existing solutions are difficult to meet these special usage scenarios.

[0005] Under this condition, if Figure 1 As shown in the figure, businesses generally use a separate scheduling / status management service to manage the indicators of all processes in the cluster. At this time, the business needs to access a name service and deploy a scheduling service based on the business scenario. Especially if some resources are global management resources, an additional scheduling center is required to manage the resources, which is very unfriendly to businesses based on name programming. In addition, it is also necessary to consider the high availability and disaster recovery solutions of the scheduling service, which have high machine costs and operation and maintenance costs. Summary of the invention

[0006] The technical problem to be solved by the present application is to provide a load balancing method, device, electronic device and computer storage medium, which can solve the above-mentioned problems existing in the related technologies.

[0007] In order to solve the above technical problems, on the one hand, the present application provides a load balancing method, which includes: a service provider sends an instance change notification to a name service server in response to an instance change request, wherein the instance change notification includes changed instance information and custom indicator information; the name service server forwards the instance change notification to the remaining name service servers in the cluster; each of the name service servers forwards the instance change notification to the service initiator connected thereto; each of the service initiators updates a local routing table based on the instance information and the custom indicator information in the instance change notification; when any of the service initiators receives an access request from a client, the service initiator determines a target instance for processing the access request based on the updated local routing table, and forwards the access request to the target instance.

[0008] On the other hand, the present application provides a load balancing method, which includes: receiving an instance change notification sent by a corresponding name service server in a cluster, the instance change notification including changed instance information and custom indicator information, the instance change notification being sent by a service provider to a corresponding name service server in response to an instance change request, and forwarded by the corresponding name service server to the remaining name service servers in the cluster, each of the name service servers being able to forward the instance change notification to a service initiator connected thereto; updating a local routing table based on the instance information and the custom indicator information in the instance change notification; and upon receiving an access request from a client, determining a target instance for processing the access request based on the updated local routing table, and forwarding the access request to the target instance.

[0009] On the other hand, the present application provides a load balancing device, which includes: a notification receiving module, which is used to receive an instance change notification sent by a corresponding name service server in a cluster, the instance change notification including changed instance information and custom indicator information, the instance change notification is sent by the service provider to the corresponding name service server in response to an instance change request, and is forwarded by the corresponding name service server to the remaining name service servers in the cluster, and each of the name service servers can forward the instance change notification to the service initiator connected thereto; a local routing table updating module, which is used to update the local routing table based on the instance information and the custom indicator information in the instance change notification; an access request processing module, which is used to determine the target instance for processing the access request based on the updated local routing table after any of the service initiators receives an access request from a client, and forward the access request to the target instance.

[0010] On the other hand, the present application provides an electronic device, comprising a processor and a memory, wherein the memory stores at least one instruction, at least one program, a code set or an instruction set, and the at least one instruction, the at least one program, the code set or the instruction set is loaded by the processor and executed as described above.

[0011] On the other hand, the present application provides a computer storage medium, wherein the storage medium stores at least one instruction, at least one program, code set or instruction set, and the at least one instruction, at least one program, code set or instruction set is loaded by a processor and executed as described above.

[0012] In an embodiment of the present application, a service initiator receives an instance change notification sent by a corresponding name service server in a cluster, wherein the instance change notification includes changed instance information and custom indicator information. The instance change notification is sent by the service provider to the corresponding name service server in response to an instance change request, and is forwarded by the corresponding name service server to the remaining name service servers in the cluster, and a local routing table is updated based on the instance information and the custom indicator information in the instance change notification. After receiving an access request from a client, a target instance for processing the access request is determined based on the updated local routing table, and the access request is forwarded to the target instance. In this way, the load of the service provider instances can be balanced, the service provider can be protected from overload, and the desired business logic can be completed. For example, when a copy activity is started, the request will be sent to the service provider with the largest number of online players and is not overloaded, while during normal login, the request will be sent to the service provider with the largest number of online players and is not overloaded. In addition, for businesses that originally access and implement business scheduling services, the functions of the scheduling services in the business modules can be integrated into the basic components to reduce the number of services at the business layer. At the same time, there is no need to consider the high availability and disaster recovery solutions of the scheduling services, which can reduce development, machine and operation and maintenance costs. BRIEF DESCRIPTION OF THE DRAWINGS

[0013] In order to more clearly illustrate the technical solutions and advantages in the embodiments of the present application or the prior art, the drawings required for use in the embodiments or the prior art descriptions are briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0014] Figure 1 is a schematic diagram of access scheduling service in the prior art;

[0015] Figure 2 It is a schematic diagram of the hardware environment provided by the embodiment of the present application;

[0016] Figure 3 is a flow chart of a load balancing method provided in an embodiment of the present application;

[0017] Figure 4 This is an application scenario diagram of a load balancing method provided in an embodiment of the present application;

[0018] Figure 5 is a flow chart of another load balancing method provided in an embodiment of the present application;

[0019] Figure 6 It is a flow chart of a method for forwarding an access request to a target instance in a load balancing method provided in an embodiment of the present application;

[0020] Figure 7 is another flow chart of a method for forwarding an access request to a target instance in a load balancing method provided in an embodiment of the present application;

[0021] Figure 8 It is a flow chart of a method for determining the weight of an instance in a target instance group in a load balancing method provided in an embodiment of the present application;

[0022] Fig. 9 It is a flow chart of a method for adjusting local indicators of a selected target instance in a load balancing method provided in an embodiment of the present application;

[0023] Fig.10 It is a structural diagram of a load balancing device provided in an embodiment of the present application;

[0024] Fig.11 It is a structural diagram of a load balancing device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0025] To make the purpose, technical solutions and advantages of the present application clearer, the present application will be further described in detail below in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of the present application.

[0026] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or server that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0027] This application involves the following key terms, and the following are the meanings of each key term.

[0028] Service: A functional unit or combination of functional units of an application, which has a unique specified name and can contain several instances.

[0029] Instance: An instance of a Service, a process implementation that provides service capabilities. The relationship between a Service and an Instance is similar to the relationship between a Class and its Object in object-oriented programming, that is, an Instance is an instantiated Service.

[0030] RecvServer / Service Provider: As the destination and service provider, it is called by SendServer in the cluster.

[0031] SendServer / Service Initiator: As the sender and call initiator, it calls RecvServer in the cluster.

[0032] TbusppNS / name service server: has reverse notification capability and can pass Service / Instance changes to other Instances.

[0033] TbusppAgent: Tbuspp's self-developed L4 agent and communication bus designed for service-oriented architecture in game development scenarios.

[0034] The present application embodiment provides a load balancing method. Optionally, in the present application embodiment, the above load balancing method can be applied to Figure 2In the hardware environment shown, the service provider 101, the name service server 102, the service initiator 103 and the user terminal 104 are formed. When the custom indicator information of the instance of the service provider 101 changes, it can be synchronized to the service initiator 103 through the name service server, and then when the user terminal 104 sends an access request to the service initiator 103 through the installed client, the service initiator 103 can forward the access request to the service provider 101 based on the local routing table.

[0035] Among them, the service provider 101, the name service server 102 and the service initiator 103 can be independent physical servers, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms. The terminal can be a smart phone, a tablet computer, a laptop computer, a desktop computer, a smart speaker, a smart watch, etc., but is not limited to this. The terminal and the server can be directly or indirectly connected via wired or wireless communication, and this application does not limit this.

[0036] like Figure 2 As shown, the service provider 101, the name service server 102, the service initiator 103 and the user terminal 104 are connected via a network, and the network includes but is not limited to: a wide area network, a metropolitan area network or a local area network.

[0037] As a possible implementation, the service provider 101, the name service server 102, the service initiator 103 and the user terminal 104 can all be node devices in the blockchain system, and can share the acquired and generated information with other node devices in the blockchain system, so as to realize information sharing among multiple node devices. Multiple node devices in the blockchain system can be configured with the same blockchain, which is composed of multiple blocks, and the adjacent blocks have an association relationship, so that when the data in any block is tampered, it can be detected by the next block, so that the data in the blockchain can be prevented from being tampered, and the security and reliability of the data in the blockchain can be ensured.

[0038] The following is a description of a load balancing method provided in an embodiment of the present application. Figure 3 As shown, the method includes:

[0039] Step S301: the service provider sends an instance change notification to the name service server in response to the instance change request, wherein the instance change notification includes the changed instance information and the custom indicator information;

[0040] In an embodiment of the present application, the instance change request includes at least one of an instance online request, an instance offline request, and an indicator synchronization request initiated during instance operation, wherein the instance online request refers to a request for the instance to register itself with the name service server so that it can be discovered by other instances in the cluster, and the instance offline request refers to a request for the instance to deregister itself from the name service server so that it cannot be discovered by other instances in the cluster. The instance online request is generally a necessary process for process initialization, and the process from process initialization to service provision is: process starts execution → sends instance online request → online success → normal service...

[0041] The triggering of the indicator synchronization request initiated during the instance operation is determined by the business layer. It can be sent periodically or when the change reaches a certain amount. The former is usually used.

[0042] The custom indicator information can be non-text content and cannot be expressed through metadata. Assuming that the business custom indicators are the current number of online users and CPU status, with values ​​of 10000 and 90 respectively, when serialized into bytes, it may be serialized as {"online_users":10000,"cpu":90}, or it may be serialized as "\020\'\000\000Z\000\000\000", and the serialization here is related to the specific implementation of the program.

[0043] In practical applications, such as Figure 4 As shown in step 1 in , the service provider can call the interface corresponding to the instance change request (when the instance change request is an instance online request, call the corresponding startup interface; when the instance change request is an indicator synchronization request, call the corresponding synchronization indicator interface), and send the instance online request to the local TbusppAgent; Figure 4 As shown in step 2 in , after receiving the instance change request sent by the service provider, TbusppAgent forwards it to the name service server.

[0044] Step S303: the name service server forwards the instance change notification to other name service servers in the cluster;

[0045] In actual application, the name service server will generate an instance change notification after receiving the instance change request, such as Figure 4 As shown in step 3 in , after receiving the instance change notification, the name service server sends it to all other name service servers in the cluster, and at the same time writes the instance information and custom indicator information in the instance change notification into the database.

[0046] Step S305: Each of the name service servers forwards the instance change notification to the service initiator connected thereto;

[0047] In practical applications, such as Figure 4 As shown in step 4, all the name service servers send instance change notifications to the TbusppAgents that are connected to them; Figure 4 As shown in step 5, TbusppAgent then forwards the instance change notification to the service initiator and service provider it manages. Figure 4 As shown in step 6, upon receiving the instance change notification sent by the name service server, TbusppAgent will reply to the name service server that it has received the notification or that the TbusppAgent response has timed out; Figure 4 As shown in step 7 of , the name service server in the cluster replies the result of the notification to the name service server that initiated the instance change notification; Figure 4 As shown in step 8, the name service server that initiated the instance change notification forwards the result of the notification to the TbusppAgent that initiated the instance change notification; Figure 4 As shown in step 9, the TbusppAgent that initiates the instance change notification forwards the result of this notification to the service provider that initiates the instance change notification.

[0048] If the instance change request is an instance online request, and the result of the notification is a response timeout, then the instance initialization will fail, and the business party should try again; if the instance change request is an indicator synchronization request, and the result of the notification is a response timeout, then this request can be ignored and re-reported in the next cycle. In principle, errors and failures related to the name service cannot affect the running instance, so the design allows the failure of indicator synchronization requests.

[0049] Step S307: each of the service initiators updates a local routing table based on the instance information and the custom indicator information in the instance change notification;

[0050] In an embodiment of the present application, the local routing table includes existing instance information and custom indicator information. When each service initiator receives the instance change notification, the instance information and custom indicator information in the instance change notification are used to update the existing instance information and custom indicator information in the local routing table.

[0051] In practical applications, such as Figure 4 As shown, after step 5, all of the service initiators and service providers may update the instance information and custom indicator information in the local routing table.

[0052] Step S309: When any of the service initiators receives an access request from the client, the service initiator determines a target instance for processing the access request based on the updated local routing table, and forwards the access request to the target instance.

[0053] In the embodiment of the present application, the target instance can be determined by a random or round-robin routing algorithm, or by weighted random or round-robin based on the custom indicator information of each instance. The weight of each instance can also be calculated based on the custom indicator information of each instance, and the instance with the largest weight can be directly selected as the target instance. That is, the business party can select the routing algorithm it needs to determine the target instance according to its business logic, and the embodiment of the present application does not limit this.

[0054] In an embodiment of the present application, a service initiator receives an instance change notification sent by a corresponding name service server in a cluster, wherein the instance change notification includes changed instance information and custom indicator information. The instance change notification is sent by the service provider to the corresponding name service server in response to an instance change request, and is forwarded by the corresponding name service server to the remaining name service servers in the cluster, and a local routing table is updated based on the instance information and the custom indicator information in the instance change notification. After receiving an access request from a client, a target instance for processing the access request is determined based on the updated local routing table, and the access request is forwarded to the target instance. In this way, the load of the service provider instances can be balanced, the service provider can be protected from overload, and the desired business logic can be completed. For example, when a copy activity is started, the request will be sent to the service provider with the largest number of online players and is not overloaded, while during normal login, the request will be sent to the service provider with the largest number of online players and is not overloaded. In addition, for businesses that originally access and implement business scheduling services, the functions of the scheduling services in the business modules can be integrated into the basic components to reduce the number of services at the business layer. At the same time, there is no need to consider the high availability and disaster recovery solutions of the scheduling services, which can reduce development, machine and operation and maintenance costs.

[0055] Moreover, for the service implementation business that originally broadcasts customized indicator information from the service provider to the service initiator, it can provide the function of including the initial indicator when the service initiator is discovered, while reducing the performance loss caused by the service provider broadcast. In addition, it can also provide a more general framework for the business.

[0056] The embodiments of the present application can be used in the following application scenarios:

[0057] a) The server hardware of each instance of the service provider is quite different and cannot be clearly classified. The routing weight cannot be set in a general way such as metadata;

[0058] b) When the service provider has insufficient capacity, it needs to expand capacity. Since the actual load of the instance before and after the expansion is quite different, the business hopes to send new business requests to the newly started instance of the service provider;

[0059] c) In the business logic, each instance in the service provider needs to report its own operating status (including business data) in a timely manner so that the service initiator can select a suitable target instance to send business data each time.

[0060] In particular, the embodiments of the present application can be used in at least the following game scenarios:

[0061] a) Load balancing of battle service nodes to avoid abnormal operation caused by excessive load on some battle service nodes;

[0062] b) When a dungeon activity is started, players will be assigned to the node with the most online players and without overload;

[0063] c) During normal login, players are assigned to nodes with fewer players to avoid high load on the service provider affecting the player experience;

[0064] d) Related business requests are aggregated to the same node, and when the load reaches the upper limit, they are distributed to other nodes under the same service;

[0065] e) Distribute messages based on the number of in-game business resources (props, etc.).

[0066] The present application also provides a load balancing method, wherein any service initiator is used as an execution subject, such as Figure 5 As shown, the method may include:

[0067] Step S501: receiving an instance change notification sent by a corresponding name service server in a cluster, wherein the instance change notification includes changed instance information and custom indicator information, and the instance change notification is sent by a service provider to a corresponding name service server in response to an instance change request, and forwarded by the corresponding name service server to other name service servers in the cluster, and each of the name service servers can forward the instance change notification to a service initiator connected thereto;

[0068] Step S503: updating the local routing table based on the instance information and the custom indicator information in the instance change notification;

[0069] Step S505: after receiving an access request from the client, determine a target instance for processing the access request based on the updated local routing table, and forward the access request to the target instance.

[0070] For technical details in the embodiments of this application, please refer to the method provided in the previous embodiment of this application.

[0071] In some embodiments, Figure 6 and Figure 7 As shown, after receiving an access request from a client, determining a target instance for processing the access request based on an updated local routing table, and forwarding the access request to the target instance may include:

[0072] Step S601: upon receiving an access request from a client, determining a target instance group corresponding to the access request in the local routing table;

[0073] In an embodiment of the present application, the access request is a service request from a client, for example, a normal game login request or a copy activity start request from a client. The local routing table may include multiple instance groups, each of which may correspond to an access request of a specific service type. For example, the local routing table includes instance group A and instance group B, wherein instance group A corresponds to a normal game login request, and instance group B corresponds to a copy activity start request. When the access request is a normal game login request, instance group A is determined as the target instance group, and when the access request is a copy activity start request, instance group B is determined as the target instance group.

[0074] The instances in each instance group may be instances selected by the service initiator based on the service type or name and metadata information described in the routing rule. For example, the service initiator selects each instance based on the copy activity start request and the metadata information described in the corresponding routing rule (such as the current load needs to be less than or equal to the preset load, and the number of players needs to be greater than or equal to the preset number of players), and adds the qualified instances to the instance group corresponding to the copy activity addition request.

[0075] The service initiator can filter the instances in the instance group when updating the local routing table, so that after receiving an access request from the client, it can determine the target instance group corresponding to the access request in the local routing table.

[0076] Step S603: determining whether the target instance group needs to be updated;

[0077] In an embodiment of the present application, judging whether the target instance group needs to be updated is to judge whether the instance information in the target instance group or the custom indicator information corresponding to the instance is updated, for example, whether a new instance is added to the target instance group or whether the custom indicator of a certain instance is updated.

[0078] Step S605: when the target instance group needs to be updated, traverse the instances in the target instance group, and calculate the position or weight of each instance in the target instance group based on the custom indicator information of each instance in the target instance group;

[0079] In an embodiment of the present application, the position or weight in the target instance group is used to characterize the probability that an instance in the target instance group is determined as a target instance. The closer the position of an instance in the target instance group is, the greater the probability that the instance is determined as a target instance. Alternatively, the greater the weight of an instance in the target instance group, the greater the probability that the instance is determined as a target instance.

[0080] For example, for a request to start a copy activity, the position or weight of each instance in the target instance group can be calculated based on custom indicator information of each instance in the target instance group, such as current load information and the number of players. The position or weight of each instance in the target instance group is inversely proportional to the current load information and directly proportional to the number of players.

[0081] The embodiment of the present application does not limit the specific calculation formula, as long as it can reflect the above positive and negative proportional relationship. It should be noted that for instances in the same target instance group, their positions or weights in the target instance group need to be calculated based on the same calculation formula.

[0082] Step S607: Determine a target instance for processing the access request based on the position or weight of each instance in the target instance group, and forward the access request to the target instance.

[0083] In the embodiment of the present application, the instance with the highest position or the highest weight in the target instance group is determined as the target instance for processing the access request, and the access request is forwarded to the target instance.

[0084] In the embodiment of the present application, by grouping the instances in the local routing table, the corresponding target instance group can be quickly determined when an access request is received; and by determining whether the target instance group is updated, and updating the position or weight of each instance in the target instance group when the target instance group needs to be updated, and determining the target instance based on the updated position or weight, the reliability of the determined target instance can be increased. That is, through the embodiment of the present application, the response speed of the service can be improved, and the reliability of overload protection for the service provider can be guaranteed.

[0085] In some embodiments, Figure 6 and Figure 7 As shown, the method may also include:

[0086] Step S604: when the target instance group does not need to be updated, obtaining a self-balancing binary search tree from a cache corresponding to the target instance group, the self-balancing binary search tree being a data structure constructed according to the position or weight of each instance in the target instance group that was most recently updated and stored in the cache;

[0087] Step S606: Determine a target instance for processing the access request according to the self-balancing binary search tree, and forward the access request to the target instance.

[0088] In the embodiment of the present application, the self-balancing binary search tree is a data structure constructed according to the position or weight of each instance in the target instance group that was most recently updated and stored in a cache corresponding to the target instance group.

[0089] For example, in the last access request before the current access request, if the target instance group needs to be updated, then after the position or weight of each instance in the target instance group is updated, it is necessary to construct a self-balancing binary search tree based on the updated position or weight of each instance in the target instance group, and save the constructed self-balancing binary search tree in the cache corresponding to the target instance group. Accordingly, when the current access request is received and the target instance group does not need to be updated, the target instance for processing the current access request can be determined directly based on the balanced binary search tree in the cache.

[0090] The self-balancing binary search tree can be a red-black tree. When constructing the red-black tree, each instance in the target instance group can be inserted in sequence. The red-black tree is self-balanced according to the position or weight of each instance. After the red-black tree is constructed, the leftmost node of the red-black tree is the node with the most forward position or the smallest weight, and the rightmost node of the red-black tree is the node with the most backward position or the largest weight. After the red-black tree is constructed, the red-black tree is saved in a cache corresponding to the target instance group. Accordingly, when an access request is received and the target instance group does not need to be updated, the rightmost node of the red-black tree can be directly determined as the target instance to forward the request to the node with the largest weight; or the leftmost node of the red-black tree can be directly determined as the target instance to forward the request to the node with the most forward position.

[0091] In an embodiment of the present application, by directly obtaining a self-balancing binary search tree from the cache when the target instance group does not need to be updated, and determining the target instance based on the self-balancing binary search tree, the time for searching the target instance from the target instance group can be reduced, thereby improving the response speed of the service.

[0092] In some embodiments, Figure 8As shown, when the target instance group needs to be updated, traversing the instances in the target instance group and calculating the position or weight of each instance in the target instance group based on the custom indicator information of each instance in the target instance group may include:

[0093] Step S801: when the target instance group has an instance group update tag, determining that the target instance group needs to be updated, the instance group update tag is set when any instance in the target instance group is changed;

[0094] Step S803: traversing the instances in the target instance group, and determining the instances in the target instance group that have instance update tags as instances to be adjusted, wherein the instance update tags are used to indicate that the instances with the tags have been changed;

[0095] Step S805: updating the weight of each of the to-be-adjusted instances in the target instance group based on the custom indicator information of each of the to-be-adjusted instances in the target instance group.

[0096] In an embodiment of the present application, when the service initiator updates the instance information and custom indicator information in the local routing table, an instance update tag is set for the changed instance to quickly check which instances in the instance group need to be updated, and an instance group update tag is set for the instance group to which the changed instance belongs to to quickly check whether a certain instance group needs to be updated.

[0097] For example, instance group A initially includes instance a, instance b, and custom indicator information corresponding to each instance. When the custom indicator information of instance a changes, an instance update label is set for instance a to indicate that the custom indicator of the instance has changed, and an instance group update label is set for instance group A. In this way, when an access request is received from a client and instance group A is the target instance group corresponding to the access request, it can be quickly determined based on the label of instance group A that instance group A needs to be updated. When traversing the instances in instance group A, it can be determined based on the label of the instance that the position or weight of instance a in instance group A needs to be updated.

[0098] When instance b goes offline, an instance update tag is set for instance b to indicate that instance b has been deleted, and an instance group update tag is set for instance group A. In this way, when an access request is received from a client and instance group A is the target instance group corresponding to the access request, it can be quickly determined based on the tag of instance group A that instance group A needs to be updated, and when traversing the instances in instance group A, it can be determined based on the instance tags that instance b has been removed from instance group A.

[0099] When instance c goes online, instance group A will include instance a, instance b, and instance c. An instance update tag is set for instance c to indicate that instance c is a newly launched instance, and an instance group update tag is set for instance group A. In this way, when an access request is received from a client and instance group A is the target instance group corresponding to the access request, it can be quickly determined based on the tag of instance group A that instance group A needs to be updated. When traversing the instances in instance group A, it can be determined based on the instance tags that the position or weight of instance c in instance group A needs to be updated.

[0100] In an embodiment of the present application, by setting an instance group update label for the target instance group, it is possible to quickly determine whether the target instance group needs to be updated based on the instance group update label, and when setting an instance update label for an instance in the target instance group, it is only necessary to recalculate the weight of the instance based on the custom indicator information of the instance, without having to perform weight calculations on all instances in the target instance group. This can reduce the time required to determine the target instance, that is, it is possible to determine the target instance more efficiently, thereby improving the response speed of the service.

[0101] In some embodiments, Fig. 9 As shown, after the step of determining a target instance for processing the access request based on the updated local routing table after receiving the access request from the client, and forwarding the access request to the target instance, the method may further include:

[0102] Step S901: temporarily adjusting the custom indicator information of the target instance in the local routing table;

[0103] Step S903: upon receiving the next access request from the client, determining a target instance for processing the next access request based on the temporarily adjusted local routing table;

[0104] Step S905: When the target service provider where the target instance is located sends an instance change notification, the temporarily adjusted local routing table is overwritten with the changed instance information and custom indicator information included in the instance change notification.

[0105] In an embodiment of the present application, after the service initiator receives an access request and forwards the access request to the target instance, the service initiator temporarily adjusts the custom indicator information of the target instance in the local routing table, so that when the service initiator receives an access request again, it can determine the target instance for processing the next access request based on the temporarily adjusted local routing table. When the target service provider where the target instance is located re-reports the instance change notification, the changed instance information and custom indicator information included in the instance change notification are used to overwrite the temporarily adjusted local routing table.

[0106] For example, if the service needs to select a route based on the minimum load, and the target instance group includes instance a (load = 10), instance b (load = 20), and instance c (load = 30), instance a will be given priority when distributing service requests. However, continuous selection of instance a will cause a sharp increase in the load of instance a. Therefore, before instance a re-reports its custom indicator information, the load of instance a can be temporarily adjusted each time the service initiator selects instance a. When the load adjustment of instance a reaches 20, when a service request is received subsequently, the instance with a smaller load between instance a and instance b (before the load reaches 30) will be selected, and the load of the selected instance will be temporarily adjusted, thereby avoiding a sharp increase in the load of instance a caused by continuous selection of instance a.

[0107] It should be noted that the adjustment made by the service initiator to the service provider is only effective locally. As long as the service provider actively initiates the change, all nodes will use the latest indicator of the service provider synchronized this time as the standard. In other words, the adjustment principle is: each node can only actively synchronize its own custom indicator information, and each node's adjustment of other nodes' indicator information is a temporary adjustment based on the local.

[0108] In the embodiment of the present application, a sudden increase in load caused by a certain instance being continuously selected is avoided, so that the load of the instances of the service provider can be balanced and the service provider can be protected from overload.

[0109] For technical details not described in detail in the above embodiments, please refer to the methods provided in any embodiment of the present application.

[0110] The present application also provides a load balancing device 1000, see Fig.10 , the apparatus 1000 may include:

[0111] The notification receiving module 1010 is used to receive an instance change notification sent by a corresponding name service server in the cluster, wherein the instance change notification includes changed instance information and custom indicator information, and the instance change notification is sent by the service provider to the corresponding name service server in response to an instance change request, and is forwarded by the corresponding name service server to the remaining name service servers in the cluster, and each of the name service servers can forward the instance change notification to the service initiator connected thereto;

[0112] A local routing table updating module 1020, configured to update a local routing table based on the instance information and the custom indicator information in the instance change notification;

[0113] The access request processing module 1030 is used to determine a target instance for processing the access request based on the updated local routing table after any of the service initiators receives an access request from a client, and forward the access request to the target instance.

[0114] In some embodiments, the access request processing module may include:

[0115] A target instance group determination submodule, configured to determine a target instance group corresponding to the access request in the local routing table after receiving an access request from a client;

[0116] An instance group update judgment submodule, used to judge whether the target instance group needs to be updated;

[0117] A calculation submodule, used for traversing the instances in the target instance group when the target instance group needs to be updated, and calculating the position or weight of each instance in the target instance group based on the custom indicator information of each instance in the target instance group;

[0118] The access request processing submodule is used to determine the target instance for processing the access request based on the position or weight of each instance in the target instance group, and forward the access request to the target instance.

[0119] In some embodiments, the access request processing module may further include:

[0120] A self-balancing binary search tree acquisition submodule, used to acquire a self-balancing binary search tree from a cache corresponding to the target instance group when the target instance group does not need to be updated, the self-balancing binary search tree being a data structure constructed according to the position or weight of each instance in the target instance group that was most recently updated and stored in the cache;

[0121] The access request processing submodule is further configured to determine a target instance for processing the access request according to the self-balancing binary search tree, and forward the access request to the target instance.

[0122] In some embodiments, the computing submodule includes:

[0123] a first update determination unit, configured to determine that the target instance group needs to be updated when the target instance group has an instance group update tag, the instance group update tag being set when an instance in the target instance group changes;

[0124] an instance-to-be-adjusted determining unit, configured to traverse the instances in the target instance group, and determine the instances in the target instance group having instance update tags as the instances to be adjusted, wherein the instance update tags are set when the instances are newly added to the target instance group or when the custom indicator information of the instances is changed;

[0125] A weight updating unit is used to update the weight of each of the to-be-adjusted instances in the target instance group based on the custom indicator information of each of the to-be-adjusted instances in the target instance group.

[0126] In some embodiments, the apparatus may further include:

[0127] A custom indicator information temporary adjustment module, used to temporarily adjust the custom indicator information of the target instance in the local routing table;

[0128] The access request processing module is further configured to determine, when receiving a next access request from a client, a target instance for processing the next access request based on the temporarily adjusted local routing table;

[0129] The custom indicator information overwriting module is used to overwrite the temporarily adjusted local routing table with the changed instance information and custom indicator information included in the instance change notification when the target service provider where the target instance is located sends an instance change notification.

[0130] An embodiment of the present application also provides a computer-readable storage medium, in which at least one instruction, at least one program, code set or instruction set is stored, and the at least one instruction, at least one program, code set or instruction set is loaded by a processor and executed by any of the above methods of the present embodiment.

[0131] The present application also provides an electronic device, the structure diagram of which can be seen in Fig.11The device 1100 may have relatively large differences due to different configurations or performances, and may include one or more central processing units (CPU) 1122 (for example, one or more processors) and memory 1132, and one or more storage media 1130 (for example, one or more mass storage devices) storing application programs 1142 or data 1144. Among them, the memory 1132 and the storage medium 1130 can be short-term storage or permanent storage. The program stored in the storage medium 1130 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations in the device. Furthermore, the central processing unit 1122 can be configured to communicate with the storage medium 1130 to execute a series of instruction operations in the storage medium 1130 on the device 1100. The device 1100 may also include one or more power supplies 1126, one or more wired or wireless network interfaces 1150, one or more input and output interfaces 1158, and / or one or more operating systems 1141, such as Windows ServerTM, Mac OS XTM, UnixTM, LinuxTM, FreeBSDTM, etc. Any of the above methods in this embodiment can be based on Fig.11 The device shown is implemented.

[0132] This specification provides method operation steps as described in the embodiments or flow charts, but more or fewer operation steps may be included based on conventional or non-creative labor. The steps and sequence listed in the embodiments are only one way of executing the sequence of many steps and do not represent the only execution sequence. When the actual system or interrupt product is executed, it can be executed in sequence or in parallel according to the method shown in the embodiments or the drawings (for example, in a parallel processor or multi-threaded processing environment).

[0133] The structure shown in this embodiment is only a partial structure related to the scheme of the present application, and does not constitute a limitation on the device to which the scheme of the present application is applied. The specific device may include more or fewer components than shown, or combine certain components, or have different arrangements of components. It should be understood that the method, device, etc. disclosed in this embodiment can be implemented in other ways. For example, the device embodiment described above is only schematic. For example, the division of the modules is only a division of a logical function. 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 unit modules.

[0134] Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or the whole or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc., various media that can store program codes.

[0135] The embodiment of the present application also provides a computer program product or a computer program, wherein the computer program product or the computer program includes computer instructions, and the computer instructions are stored in a computer-readable storage medium. The processor of the computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the methods provided in the above various optional embodiments.

[0136] Those skilled in the art may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed in this specification can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.

[0137] As described above, the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application.

Claims

1. A load balancing method, characterized in that: The method comprises: The service provider sends an instance change notification to the name service server in response to the instance change request, wherein the instance change notification includes the changed instance information and the custom indicator information; The name service server forwards the instance change notification to other name service servers in the cluster; Each of the name service servers forwards the instance change notification to the service initiator connected thereto; Each of the service initiators updates a local routing table based on the instance information and the custom indicator information in the instance change notification; When any of the service initiators receives an access request from a client, the service initiator determines a target instance for processing the access request based on the updated local routing table, and forwards the access request to the target instance.

2. A load balancing method, characterized in that: The method comprises: receiving an instance change notification sent by a corresponding name service server in the cluster, wherein the instance change notification includes changed instance information and custom indicator information, and the instance change notification is sent by the service provider to the corresponding name service server in response to an instance change request, and forwarded by the corresponding name service server to the remaining name service servers in the cluster, and each of the name service servers can forward the instance change notification to the service initiator connected thereto; Update the local routing table based on the instance information and the custom indicator information in the instance change notification; When an access request is received from a client, a target instance for processing the access request is determined based on the updated local routing table, and the access request is forwarded to the target instance.

3. The load balancing method according to claim 2, characterized in that: The step of, upon receiving an access request from a client, determining a target instance for processing the access request based on an updated local routing table, and forwarding the access request to the target instance includes: Upon receiving an access request from a client, determining a target instance group corresponding to the access request in the local routing table; Determining whether the target instance group needs to be updated; When the target instance group needs to be updated, traverse the instances in the target instance group, and calculate the position or weight of each instance in the target instance group based on the custom indicator information of each instance in the target instance group; A target instance for processing the access request is determined based on the position or weight of each instance in the target instance group, and the access request is forwarded to the target instance.

4. The load balancing method according to claim 3, characterized in that: The step of, upon receiving an access request from a client, determining a target instance for processing the access request based on the updated local routing table, and forwarding the access request to the target instance further includes: When the target instance group does not need to be updated, obtaining a self-balancing binary search tree from a cache corresponding to the target instance group, the self-balancing binary search tree being a data structure constructed according to the position or weight of each instance in the target instance group that was most recently updated and stored in the cache; A target instance for processing the access request is determined according to the self-balancing binary search tree, and the access request is forwarded to the target instance.

5. The load balancing method according to claim 3, characterized in that: When the target instance group needs to be updated, traversing the instances in the target instance group, and calculating the position or weight of each instance in the target instance group based on the custom indicator information of each instance in the target instance group includes: When the target instance group has an instance group update tag, determining that the target instance group needs to be updated, the instance group update tag is set when any instance in the target instance group is changed; Traversing the instances in the target instance group, determining the instances in the target instance group that have instance update tags as instances to be adjusted, wherein the instance update tags are used to indicate that the instances with the tags have been changed; The weight of each of the to-be-adjusted instances in the target instance group is updated based on the custom indicator information of each of the to-be-adjusted instances in the target instance group.

6. The load balancing method according to claim 2, characterized in that: After the step of, upon receiving an access request from a client, determining a target instance for processing the access request based on an updated local routing table, and forwarding the access request to the target instance, the method further includes: Temporarily adjusting the custom indicator information of the target instance in the local routing table; When receiving a next access request from the client, determining a target instance for processing the next access request based on the temporarily adjusted local routing table; When the target service provider where the target instance is located sends an instance change notification, the temporarily adjusted local routing table is overwritten with the changed instance information and custom indicator information included in the instance change notification.

7. The load balancing method according to claim 2, characterized in that: The instance change request includes at least one of an instance online request, an instance offline request, and an indicator synchronization request initiated during instance operation.

8. A load balancing device, characterized in that: The device comprises: A notification receiving module, used to receive an instance change notification sent by a corresponding name service server in the cluster, wherein the instance change notification includes changed instance information and custom indicator information, and the instance change notification is sent by the service provider to the corresponding name service server in response to an instance change request, and is forwarded by the corresponding name service server to the remaining name service servers in the cluster, and each of the name service servers can forward the instance change notification to the service initiator connected thereto; A local routing table updating module, configured to update a local routing table based on the instance information and the custom indicator information in the instance change notification; The access request processing module is used to determine the target instance for processing the access request based on the updated local routing table after any of the service initiators receives the access request from the client, and forward the access request to the target instance.

9. The device according to claim 8, characterized in that The access request processing module includes: A target instance group determination submodule, configured to determine a target instance group corresponding to the access request in the local routing table after receiving an access request from a client; An instance group update judgment submodule, used to judge whether the target instance group needs to be updated; A calculation submodule, used for traversing the instances in the target instance group when the target instance group needs to be updated, and calculating the position or weight of each instance in the target instance group based on the custom indicator information of each instance in the target instance group; The access request processing submodule is used to determine the target instance for processing the access request based on the position or weight of each instance in the target instance group, and forward the access request to the target instance.

10. The device according to claim 9, characterized in that The access request processing module also includes: A self-balancing binary search tree acquisition submodule, used to acquire a self-balancing binary search tree from a cache corresponding to the target instance group when the target instance group does not need to be updated, the self-balancing binary search tree being a data structure constructed according to the position or weight of each instance in the target instance group that was most recently updated and stored in the cache; The access request processing submodule is further configured to determine a target instance for processing the access request according to the self-balancing binary search tree, and forward the access request to the target instance.

11. The device according to claim 9, characterized in that The calculation submodule includes: a first update determination unit, configured to determine that the target instance group needs to be updated when the target instance group has an instance group update tag, the instance group update tag being set when an instance in the target instance group changes; an instance-to-be-adjusted determining unit, configured to traverse the instances in the target instance group, and determine the instances in the target instance group having instance update tags as the instances to be adjusted, wherein the instance update tags are set when the instances are newly added to the target instance group or when the custom indicator information of the instances is changed; A weight updating unit is used to update the weight of each of the to-be-adjusted instances in the target instance group based on the custom indicator information of each of the to-be-adjusted instances in the target instance group.

12. The device according to claim 8, characterized in that The device also includes: A custom indicator information temporary adjustment module, used to temporarily adjust the custom indicator information of the target instance in the local routing table; The access request processing module is further configured to determine, when receiving a next access request from a client, a target instance for processing the next access request based on the temporarily adjusted local routing table; The custom indicator information overwriting module is used to overwrite the temporarily adjusted local routing table with the changed instance information and custom indicator information included in the instance change notification when the target service provider where the target instance is located sends an instance change notification.

13. An electronic device, characterized in that: The electronic device includes a processor and a memory, wherein the memory stores at least one instruction, at least one program, a code set or an instruction set, and the at least one instruction, the at least one program, the code set or the instruction set is loaded and executed by the processor to implement the method according to claim 1 or any one of claims 2-7.

14. A computer storage medium, characterized in that: The storage medium stores at least one instruction, at least one program, a code set or an instruction set, and the at least one instruction, at least one program, a code set or an instruction set is loaded by a processor and executed by the method according to claim 1 or any one of claims 2-7.

Citation Information

Patent Citations

  • Methods and device for selecting virtualized infrastructure manager

    CN110018898A

  • Service instance updating method and device

    CN110275724A