Agent registration and service calling method, machine room network and electronic equipment
By introducing a load balancer and cross-datacenter synchronization channels into the data center network, dynamic registration and global synchronization of service instances are achieved, solving the problem of inconsistent data in the registry center in the microservice architecture, improving the availability and stability of service calls, and ensuring the global consistency of service information and the accuracy of call paths.
Patent Information
- Application Number
- CN202511153907.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-18
- Publication Date
- 2025-11-21
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
In a microservice architecture, because the registry centers of each data center operate independently and lack a data synchronization mechanism, it is difficult to keep the data of the registry centers of different data centers consistent, resulting in service call failures or data inconsistencies. Moreover, if the registry center of a data center fails, it will seriously affect the availability of the system.
By setting up a load balancer in the data center network, a cross-data center synchronization channel is formed, enabling dynamic registration and global synchronization of service instances. The load balancer receives registration requests, generates registration information, and synchronizes it to the global service directory through the cross-data center synchronization channel. Combined with the global service directory, the service instance and call path are determined. Utilizing the load balancer's intelligent selection and dynamic adjustment, the registration information is ensured to spread quickly and accurately across multiple data centers, and service calls are performed efficiently.
It improves the availability and stability of service calls between data centers, avoids service discovery failures caused by data asynchrony in the registry center, ensures global consistency of service information and accuracy of call paths, and improves the efficiency and stability of service calls.
Smart Images

Figure CN121000792A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of service registration, in particular to a proxy registration and service calling method, a machine room network and an electronic device. BACKGROUND
[0002] In a micro-service architecture, a service registration and discovery mechanism is the basis for efficient operation of a distributed system. In order to ensure the running performance in a single machine room environment, the prior art usually adopts a scheme of independently deploying a registration center in each machine room, and after a service instance is started, it is directly registered with the registration center in the machine room, and the calling between services is completed by obtaining the address information of the target service from the registration center.
[0003] In the related art, due to the independent operation of the registration centers in each machine room, and the lack of data synchronization mechanism, the registration center data in different machine rooms is difficult to keep consistent, thereby causing problems such as service calling failure or data inconsistency, and once the registration center in a machine room fails, the services in the machine room will not be able to normally register and discover, seriously affecting the usability of the system. SUMMARY
[0004] The problem solved by the present application is how to improve the stability of service registration and calling.
[0005] To solve the above problems, the present application provides a proxy registration and service calling method, a machine room network and an electronic device.
[0006] In a first aspect, the present application provides a proxy registration and service calling method applied to a machine room network, the machine room network comprising a plurality of machine rooms, each machine room being provided with a registration center and a load balancer, and the load balancers of each machine room being connected to form a cross-machine room synchronization channel; the method comprising:
[0007] When a service business of the machine room is started, the load balancer is used to obtain a registration request of the service business and forward it to the registration center, the registration center is used to register the service business according to the registration request, and the registration information of the service business is obtained; and the registration information is sent to the load balancer of other machine rooms through the cross-machine room synchronization channel, so as to synchronize the registration information to the global service directory of the machine room network;
[0008] When the machine room performs service calling, the load balancer is used to obtain a service calling request, and according to the service calling request combined with the registration information in the global service directory, a service instance and a calling path corresponding to the service instance are determined, and the load balancer is used to call the service instance along the calling path.
[0009] Optionally, before the load balancer obtains the registration request of the service business and forwards to the registration center, it further comprises:
[0010] When the service business of the machine room is started, the instance metadata of the service business is obtained, and the instance metadata comprises a service identifier, an instance network address, a health check port, and a machine room identifier;
[0011] According to the service identifier, the instance network address, the health check port, and the machine room identifier of the service business, the registration request of the service business is generated.
[0012] Optionally, the registration information is sent to the load balancer of other machine rooms through the cross-machine room synchronization channel to synchronize the registration information to the global service directory of the machine room network, comprising:
[0013] The registration information is broadcast in real time to the load balancer of all other machine rooms through the cross-machine room synchronization channel;
[0014] The registration information of the service business is synchronized to the registration center of other machine rooms through the load balancer of other machine rooms;
[0015] The registration information is updated to the global service directory through the registration center.
[0016] Optionally, according to the service call request in combination with the registration information in the global service directory, the service instance and the call path corresponding to the service instance are determined, comprising:
[0017] The load balancer obtains the service call request, and extracts all candidate service instances corresponding to the service call request from the global service directory according to the service call request;
[0018] All candidate service instances are screened to obtain the service instance;
[0019] According to the machine room corresponding to the service instance and the network path of the machine room, the call path is generated.
[0020] Optionally, the all candidate service instances are screened to obtain the service instance, comprising:
[0021] The health of each candidate service instance is detected through the health check port of the candidate service instance to obtain the health status of each candidate service instance;
[0022] According to the health status, the candidate service instances are preliminarily screened to obtain the primary screening service instance;
[0023] acquire network delay and concurrency volume between the screening service instance and a load balancer of the machine room where the service call is made;
[0024] assign a priority weight to each of the candidate service instances according to the network delay and the concurrency volume of the candidate service instance;
[0025] sort all the candidate service instances according to the priority weight of the candidate service instance, and select the service instance according to the sorting result.
[0026] Optionally, the determining of the service instance and the calling path corresponding to the service instance according to the service call request and the registration information in the global service directory comprises:
[0027] if the machine room where the service instance is located is consistent with the machine room where the service call is made, a local path pointing to the service instance is taken as the calling path;
[0028] if the machine room where the service instance is located is inconsistent with the machine room where the service call is made, network delay, packet loss rate and bandwidth utilization rate between the machine room where the service instance is located and the machine room where the service call is made are acquired in real time through a ZooKeeper; real-time performance scores of the service instance on each cross-machine-room path are calculated according to the network delay, the packet loss rate and the bandwidth utilization rate; and the calling path is obtained according to the real-time performance scores.
[0029] Optionally, the calling of the service instance along the calling path through the load balancer comprises:
[0030] when the calling path is a cross-machine-room path, a machine room routing mark is added to the service call request through the load balancer, and the service call request is sent to the load balancer corresponding to the service instance along the calling path;
[0031] the service call request is forwarded to the service instance for calling through the load balancer corresponding to the service instance, and the service call result is obtained;
[0032] the service call result is returned to the load balancer of the machine room where the service call is made according to the machine room routing mark through the load balancer corresponding to the service instance;
[0033] the service call result is sent to a requester of the service call request through the load balancer of the machine room where the service call is made.
[0034] Optionally, the calling the service instance along the calling path by the load balancer comprises:
[0035] When the calling path is the local room path, the service calling request is forwarded to the service instance by the load balancer along the calling path for calling, and the service calling result is obtained;
[0036] The service calling result is sent to the requester of the service calling request by the load balancer.
[0037] In a second aspect, the present application provides a computer room network, which comprises a plurality of computer rooms, each of which is provided with a registration center and a load balancer, and the load balancers of the computer rooms are connected to form a cross-computer room synchronization channel.
[0038] The load balancer is configured to obtain a registration request of a service business and forward the registration request to the registration center when the service business of the computer room is started.
[0039] The registration center is configured to register the service business according to the registration request, obtain registration information of the service business, and send the registration information to the load balancer.
[0040] The load balancer is further configured to send the registration information to the load balancer of another computer room through the cross-computer room synchronization channel, so as to synchronize the registration information to a global service directory of the computer room network.
[0041] The load balancer is further configured to obtain a service calling request when the computer room performs service calling, determine a service instance and a calling path corresponding to the service instance according to the service calling request and the registration information in the global service directory, and call the service instance along the calling path.
[0042] In a third aspect, the present application provides an electronic device comprising a memory and a processor.
[0043] The memory is configured to store a computer program.
[0044] The processor is configured to implement the proxy registration and service calling method according to claims 1-8 when executing the computer program.
[0045] The agent registration and service calling method, the machine room network and the electronic equipment of the present application firstly realize dynamic registration and global synchronization of service instances through a load balancer when service registration is performed. Specifically, when service business is started, the load balancer forwards the registration request, obtains the registration information of the service business, and synchronizes it to the global service directory, thereby not only simplifying the service registration process, but also ensuring that the registration information can be quickly and accurately propagated between multiple machine rooms through the intervention of the load balancer. Compared with the traditional distributed registration center scheme, the present application avoids the problem of service discovery failure caused by the asynchronous data of the registration center. Through the cross-machine room synchronization mechanism of the load balancer, the registration center data of all machine rooms is ensured to be consistent, providing a reliable foundation for subsequent service calling, so that the service calling party can accurately find the required service instance, thereby improving the availability and stability of service calling between machine rooms. In terms of service calling, when the machine room performs service calling, the load balancer obtains the service calling request and determines the service instance and calling path in combination with the registration information in the global service directory, ensuring that the appropriate instance and path can be selected for each service call, thereby improving the efficiency of service calling and effectively avoiding the situation of service unavailability caused by network problems or service instance overload. The present application realizes the deep integration and optimization of service registration and service calling through the load balancer, ensures the global consistency of service information, and provides accurate guidance for service calling. At the same time, the load balancer is used to improve the efficiency and stability of service calling through intelligent selection and dynamic adjustment. The present application realizes efficient synchronization of service registration information and intelligent optimization of service calling by taking the load balancer as the core component, significantly improving the stability of service registration and calling in the multi-machine room scenario. BRIEF DESCRIPTION OF DRAWINGS
[0046] Figure 1 The flowchart of the agent registration and service calling method of the embodiment of the present application is shown in the figure.
[0047] Figure 2 The structure diagram of the machine room network of the embodiment of the present application is shown in the figure.
[0048] Figure 3 The structure diagram of the machine room network of the embodiment of the present application is shown in the figure. DETAILED DESCRIPTION
[0049] In order to make the above objectives, characteristics and advantages of the present application more apparent, concrete embodiments of the present application will be described in detail below with reference to the drawings. Although some embodiments of the present application are shown in the drawings, it should be understood that the present application can be implemented in various forms, and should not be interpreted as being limited to the embodiments set forth herein, but rather, these embodiments are provided in order to more thoroughly and completely understand the present application. It should be understood that the drawings and embodiments of the present application are for exemplary purposes only, and are not intended to limit the scope of protection of the present application.
[0050] It should be understood that each of the steps recited in the method embodiments of the present application can be performed in different orders, and / or in parallel. In addition, the method embodiments can include additional steps and / or omit the steps shown. The scope of the present application is not limited in this respect.
[0051] The term "comprising" and variations thereof as used herein are open-ended, that is "including but not limited to"; the term "based on" is "based, at least in part, on"; the term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments"; the term "optional" means "optional in at least some embodiments". Related definitions are given throughout the detailed description. It should be noted that the concepts mentioned in the present application are merely for distinguishing different devices, modules or units, and are not intended to limit the functions of these devices, modules or units.
[0052] It should be noted that the modification of "one" or "multiple" mentioned in the present application is illustrative rather than limiting, and those skilled in the art should understand that, unless otherwise explicitly indicated in the context, it should be understood as "one or more".
[0053] It should be noted that the information (including but not limited to user device information, user personal information, etc.), data (including but not limited to data for analysis, stored data, displayed data, etc.) and signals involved in the present application are authorized by the user or fully authorized by all parties, and the collection, use and processing of related data need to comply with relevant laws, regulations and standards of relevant countries and regions, and provide corresponding operation portal for user to choose authorization or refusal.
[0054] In combination Figure 1 As shown in the drawings, the proxy registration and service calling method provided by the embodiments of the present application is applied to a machine room network, the machine room network includes multiple machine rooms, each machine room is provided with a registration center and a load balancer, and the load balancers of each machine room are connected to form a cross-machine room synchronization channel.
[0055] In particular, in combinationFigure 2 As shown, the machine room network is composed of multiple machine rooms, each of which deploys load balancers and registration centers, and the load balancers communicate with each other through cross-machine room synchronization channels to realize real-time synchronization and global consistency of service registration information.
[0056] The method comprises:
[0057] When the service business of the machine room is started, the load balancer obtains the registration request of the service business and forwards it to the registration center, the registration center registers the service business according to the registration request, and obtains the registration information of the service business; and the registration information is sent to the load balancer of other machine rooms through the cross-machine room synchronization channel, so as to synchronize the registration information to the global service directory of the machine room network.
[0058] Specifically, the load balancer is the core component of the machine room in service registration, which ensures that the service instance can be accurately identified and globally visible when it is started. When the service business in the machine room is started, the load balancer first obtains the instance metadata of the service instance, which includes service identification, instance network address, health check port, machine room identification and other key information. These metadata are the basis for service discovery and invocation in a distributed environment. The load balancer then generates a registration request according to these metadata, forwards the registration request to the local machine room's registration center, and finally synchronizes the registration information to the global service directory, which is used to store and manage all service instance registration information, including detailed information of all service instances in all machine rooms, such as service identification, instance network address, health status and belonging machine room. The global service directory enables the service invoker to quickly and accurately find the required service instance, regardless of the location of the instance. Through the global service directory, cross-machine room service discovery and invocation can be realized, ensuring the efficiency and reliability of service invocation. Not only simplifies the service registration process, but also ensures that the registration information can be quickly and accurately propagated between multiple machine rooms through the intervention of the load balancer. Through this mechanism, the global service directory always maintains the latest state, ensuring the consistency and accuracy of service instance registration information between multiple machine rooms. Compared with the traditional distributed registration center solution, the present application avoids the problem of service discovery failure caused by asynchronous registration center data. Through the cross-machine room synchronization mechanism of the load balancer, the registration center data of all machine rooms is consistent, providing a reliable basis for subsequent service invocation, so that the service invoker can accurately find the required service instance.
[0059] When the machine room makes a service call, the load balancer obtains a service call request, and according to the service call request and the registration information in the global service directory, determines a service instance and a calling path corresponding to the service instance, and calls the service instance along the calling path through the load balancer.
[0060] Specifically, when the machine room makes a service call, the load balancer first obtains a service call request, and then determines a service instance and a calling path according to the registration information in the global service directory. Specifically, first, the load balancer extracts all candidate service instances corresponding to the service call request from the global service directory; then, the candidate service instances are subjected to multi-level screening, which in a preferred embodiment of the present application can include health state detection, network delay measurement, and concurrent semaphore evaluation. Through these screening steps, the load balancer can select a suitable service instance and generate a corresponding calling path for it. This dynamic routing strategy based on real-time network conditions and load conditions not only improves the efficiency of service calls, but also effectively avoids the situation of service unavailability caused by network problems or service instance overload. In addition, in another preferred embodiment of the present application, the load balancer also has a multi-path load balancing mechanism. Specifically, when the main path fails or its performance decreases, it can automatically switch to a backup path to ensure the continuity of service calls. For example, when the delay or packet loss rate of the main path exceeds a preset threshold, the load balancer automatically switches to the backup path and writes the switching event back to the ZooKeeper to ensure global synchronization. This automatic switching mechanism not only reduces the risk of service interruption, but also improves the fault tolerance of the machine room, enabling the machine room to operate stably in a complex network environment.
[0061] After the service instance and the calling path are determined, the load balancer sends a service call request to the service instance along the calling path. Before sending the request, the load balancer will add a machine room routing mark to the service call request according to whether the calling path is a cross-machine room path, so that the service instance can accurately identify the request source and process it. After the service instance processes the request, it returns the service call result to the load balancer, which in turn returns the result to the requester of the service call request, not only ensuring the efficiency of service calls, but also achieving the transparency and stability of service calls through the intervention of the load balancer. In a preferred embodiment of the present application, if the calling path fails or its performance deteriorates during execution, the load balancer will immediately recalculate the backup path and transparently retry the service call request.
[0062] The agent registration and service calling method of the application first realizes dynamic registration and global synchronization of service instances through a load balancer when service registration is performed. Specifically, when service business starts, the load balancer forwards the registration request, obtains the registration information of the service business, and synchronizes it to the global service directory, thereby not only simplifying the service registration process, but also ensuring that the registration information can be quickly and accurately transmitted between multiple machine rooms through the intervention of the load balancer. Compared with the traditional distributed registration center scheme, the application avoids the service discovery failure problem caused by the asynchronous registration center data. Through the cross-machine room synchronization mechanism of the load balancer, the registration center data of all machine rooms is ensured to be consistent, providing a reliable basis for subsequent service calling, so that the service calling party can accurately find the required service instance, thereby improving the availability and stability of service calling between machine rooms. In terms of service calling, when the machine room performs service calling, the load balancer obtains the service calling request and determines the service instance and calling path in combination with the registration information in the global service directory, ensuring that the appropriate instance and path can be selected for each service calling, thereby improving the efficiency of service calling and effectively avoiding the service unavailability caused by network problems or service instance overload. The application realizes the deep integration and optimization of service registration and service calling through the load balancer, ensures the global consistency of service information, and provides accurate guidance for service calling. At the same time, the load balancer improves the efficiency and stability of service calling through intelligent selection and dynamic adjustment. The application realizes efficient synchronization of service registration information and intelligent optimization of service calling by taking the load balancer as the core component, significantly improving the stability of service registration and calling in the multi-machine room scenario.
[0063] Optionally, before the load balancer obtains the registration request of the service business and forwards it to the registration center, it further includes:
[0064] When the service business of the machine room starts, the instance metadata of the service business is obtained, and the instance metadata includes service identification, instance network address, health check port and machine room identification;
[0065] According to the service identification, instance network address, health check port and machine room identification of the service business, the registration request of the service business is generated.
[0066] Specifically, the generation of the registration request is achieved by obtaining the instance metadata of the service business through the load balancer. Specifically, when the service business is started, the load balancer collects the instance metadata including the service identifier, the instance network address, the health check port and the machine room identifier. The instance metadata is the basis for the service to be accurately identified and called in the distributed environment. Among them, the service identifier is used to uniquely identify the service, the instance network address is used to determine the network location of the service instance, the health check port is used to monitor the health status of the service instance, and the machine room identifier is used to distinguish the machine room where the service instance is located. These information together constitute the registration request of the service instance, which is forwarded to the registration center through the load balancer. This process not only simplifies the service registration process, but also ensures that the registration information can be quickly and accurately transmitted between multiple machine rooms through the load balancer.
[0067] In the embodiment of the application, by obtaining the detailed metadata of the service instance, an accurate and comprehensive registration request can be generated to ensure the information integrity and accuracy of the service instance in the global service directory. This accurate registration information provides a solid foundation for subsequent service calls, so that the calling party can quickly and accurately find the required service instance, thereby improving the availability and stability of the registration process.
[0068] Optionally, the sending of the registration information to the load balancer of other machine rooms through the cross-machine room synchronization channel to synchronize the registration information to the global service directory of the machine room network comprises:
[0069] The registration information is broadcasted in real time to the load balancer of all other machine rooms through the cross-machine room synchronization channel;
[0070] The registration information of the service business is synchronized to the registration center of other machine rooms through the load balancer of other machine rooms;
[0071] The registration information is updated to the global service directory through the registration center.
[0072] Specifically, in combination with Figure 3As shown, each load balancer of each machine room is connected through a cross-machine room synchronization channel. After generating the registration information of a service instance, the load balancer not only synchronizes the registration information to the local registration center, but also broadcasts the registration information to all load balancers of other machine rooms in real time through the cross-machine room synchronization channel. These load balancers as intermediate nodes further synchronize the registration information to the registration center of the respective machine room. Through this multi-level synchronization mechanism, the registration information can be quickly and accurately propagated to every registration center in the entire machine room network, thereby ensuring the consistency of the global service directory. In the preferred embodiment of the present application, not only the efficient forwarding capability of the load balancer is relied on, but also the listening mechanism of the distributed coordination service such as ZooKeeper is used, so that the load balancer of each machine room can acquire and update the registration information in real time. This real-time synchronization mechanism effectively solves the service call failure or data inconsistency problem caused by unsynchronized registration information in the traditional distributed system, and provides a reliable basis for service call in the distributed system. In summary, the load balancer not only ensures that the registration information of the service instance can be quickly discovered in the global range, but also improves the overall response speed and stability of the service call, so that the distributed system can efficiently support cross-machine room service call.
[0073] In the embodiment of the present application, the registration information is broadcasted to all load balancers of other machine rooms in real time through the cross-machine room synchronization channel, so that the registration information can be quickly propagated between multiple machine rooms. This fast propagation mechanism not only reduces the delay of service call, but also improves the response speed of the machine room when registering the service.
[0074] Optionally, the method further comprises:
[0075] The load balancer acquires the service call request, extracts all candidate service instances corresponding to the service call request from the global service directory according to the service call request, and filters all the candidate service instances to obtain the service instance.
[0076] The load balancer acquires the service call request, extracts all candidate service instances corresponding to the service call request from the global service directory according to the service call request, and filters all the candidate service instances to obtain the service instance.
[0077] The load balancer acquires the service call request, extracts all candidate service instances corresponding to the service call request from the global service directory according to the service call request, and filters all the candidate service instances to obtain the service instance.
[0078] Specifically, when a service in a machine room needs to call other services, the service call request is first obtained through a load balancer. Then, all candidate service instances corresponding to the call request are extracted from the global service directory. These candidate service instances contain key information such as service identification, instance network address, health status, and belonging machine room. In order to ensure the efficiency and reliability of the call, the load balancer will perform multi-level screening on these candidate service instances. The screening process includes but is not limited to health status detection, network delay measurement, and concurrent semaphore evaluation. Through these screening steps, the load balancer can select the appropriate service instance and generate the corresponding call path, considering not only the health status of the service instance but also the network delay and load situation, ensuring that the most suitable instance and path are selected for each service call. In addition, in the preferred embodiment of the present invention, the load balancer also supports a multi-path load balancing mechanism, which can automatically switch to a backup path when the main path fails or performance decreases.
[0079] In the embodiment of the present invention, by extracting candidate service instances from the global service directory, all possible service instances can be quickly obtained, providing a comprehensive basis for subsequent screening. Secondly, the multi-level screening mechanism ensures the degree of adaptation of the selected service instance to the call demand, improving the efficiency and response speed of service call. In addition, the generated call path further optimizes the service call process, reducing the call delay. Finally, the support of multi-path load balancing mechanism can automatically switch to a backup path when the main path fails, ensuring the continuity of service call and further improving the fault tolerance and high availability of service call.
[0080] Optionally, the screening of all the candidate service instances to obtain the service instance comprises:
[0081] Perform health detection on each of the candidate service instances through the health check port of the candidate service instance to obtain the health status of each of the candidate service instances;
[0082] Perform primary screening on the candidate service instances according to the health status to obtain primary screening service instances;
[0083] Obtain the network delay and concurrent semaphore between the primary screening service instances and the load balancer of the machine room performing service call;
[0084] According to the network delay and the concurrent semaphore of the candidate service instances, assign a priority weight to each of the candidate service instances;
[0085] According to the priority weight of the candidate service instances, sort all the candidate service instances, and select the service instance according to the sorting result.
[0086] Specifically, first, the health state of each candidate service instance is obtained by health detection through its health check port. The health detection step is the basis for ensuring the availability of service instances, and only healthy instances can be further considered for service calls. Subsequently, the candidate service instances are preliminarily screened according to the health state, and those unhealthy, i.e. unavailable, instances are removed, obtaining preliminarily screened service instances. This preliminary screening process effectively reduces the number of instances that need to be evaluated subsequently, improving the screening efficiency. Next, the load balancer obtains the network delay and concurrency signal between the preliminarily screened service instances and the load balancer of the machine room where the service call is made. The network delay reflects the response speed of the call, and the concurrency signal indicates the current load of the service instance. These two parameters are key indicators for evaluating whether the service instance is suitable for undertaking a new call. According to these parameters, a priority weight is assigned to each candidate service instance, and instances with low network delay and light load are preferentially selected. Finally, all candidate service instances are sorted according to the priority weight, and the optimal service instance is selected for the call, ensuring the efficiency of the service call. Through this multi-level screening and sorting mechanism, the present application can intelligently select the optimal service instance, and even in a complex network environment, it can ensure the success rate and response speed of the service call.
[0087] In combination Figure 3As shown, in the preferred embodiment of the present application, after the service business A is started in the machine room 1, it generates a registration request containing the service identity "A", the instance network address "192.168.1.1:8080", the health check port "8081" and the machine room identity "machine room 1" through the load balancer ALB1. After sending the request to the local registration center for registration, the registration information is broadcast to the load balancer 2 in the machine room 2 through the cross-machine room synchronization channel of the ZooKeeper, and then the load balancer 2 is synchronized to the registration center in the machine room 2, and finally updated to the global service directory. When the service business B in the machine room 2 needs to call the service business A, it obtains the service call request through the load balancer 2. All candidate service instances corresponding to the service call request are extracted from the global service directory, including the instance of the service business A in the machine room 1. Next, the health of the service business A is detected through the health check port "8081" of the service instance A. The health detection is completed by sending a specific health check request (such as an HTTP GET request or a TCP heartbeat packet) to the health check port. If the service instance A can successfully respond to the health check request and return the expected health status code (such as HTTP 200 OK), it is considered that the instance is in a healthy state; if the service instance A cannot respond to the health check request or the returned health status code indicates an exception (such as HTTP 500 Internal Server Error), it is considered that the instance is in an unhealthy state. If the service instance A successfully responds to the health check request and returns the health status code, it is confirmed that the service instance A is in a healthy state. Subsequently, the candidate service instances are preliminarily screened according to the health status, and the unhealthy instances are excluded to obtain the preliminarily screened service instances. In this example, the service instance A passes the preliminary screening and becomes one of the preliminarily screened service instances. Next, the network delay and the concurrent signal quantity between the preliminarily screened service instances and the load balancer 2 in the machine room 2 where the service is called are obtained. Assuming that the network delay between the load balancer 2 in the machine room 2 and the service instance A is 10 ms, and the current concurrent signal quantity is 50. According to these parameters, the service instance A is assigned a priority weight, and all candidate service instances are sorted. Finally, according to the sorting result, the optimal service instance is selected as the calling target, the calling path is generated, and the calling is completed along the path and the result is returned to the service business B. The whole process not only ensures the efficiency of service calling, but also ensures that the called service instance is available through the health detection mechanism, thereby improving the reliability and stability of service calling.
[0088] In the preferred embodiment of the present application, unhealthy service instances can be quickly excluded through health detection and primary screening, ensuring that the selected instances are all available. This process not only improves the success rate of the call, but also reduces the call failure or timeout problem caused by selecting an unavailable instance. Secondly, by obtaining network delay and concurrency semaphore and assigning priority weight accordingly, it can intelligently select service instances with low network delay and light load, thereby optimizing the call path and improving the response speed and performance of the call. Finally, by dynamically sorting and selecting the optimal instance to adapt to the changing network and load conditions, it ensures that the most suitable instance is selected for each service call.
[0089] Optionally, the determining of the service instance and the call path corresponding to the service instance according to the service call request and the registration information in the global service directory comprises:
[0090] If the machine room where the service instance is located is consistent with the machine room where the service call is made, the local path pointing to the service instance is taken as the call path.
[0091] If the machine room where the service instance is located is inconsistent with the machine room where the service call is made, the network delay, packet loss rate and bandwidth utilization rate between the machine room where the service instance is located and the machine room where the service call is made are obtained in real time through ZooKeeper; the real-time performance score of the service instance on each cross-machine room path is calculated according to the network delay, the packet loss rate and the bandwidth utilization rate; and the call path is obtained according to the real-time performance score.
[0092] Specifically, when the service instance and the caller are located in the same machine room, the local path pointing to the service instance is directly selected as the call path. This local priority strategy not only reduces the delay of cross-machine room call, but also improves the response speed of cross-machine room call. However, when the service instance and the caller are located in different machine rooms, the load balancer obtains the network delay, packet loss rate and bandwidth utilization rate between the machine room where the service instance is located and the current machine room in real time through ZooKeeper, so as to reflect the real-time situation of the current network state. The load balancer calculates the real-time performance score of each cross-machine room path according to these parameters, which comprehensively considers the network delay, packet loss rate and bandwidth utilization rate, and can fully reflect the performance of the path. Finally, the optimal call path is selected according to the real-time performance score, ensuring the efficiency and reliability of the service call. This dynamic path selection mechanism not only can cope with the changes of network state, but also can automatically adjust the call path in complex network environment.
[0093] In combination with Figure 3In the preferred embodiment of the present application, as shown, in the specific implementation, assuming that service business A is started in machine room 1, after generating a registration request containing service identifier "A", instance network address "192.168.1.1:8080", health check port "8081" and machine room identifier "machine room 1" through load balancer ALB1, the request is sent to the local registration center for registration, and then the registration information is broadcast to the load balancer 2 of machine room 2 through the cross-machine room synchronization channel of ZooKeeper, and the load balancer 2 is synchronized to the registration center of machine room 2, and finally updated to the global service directory. When service business B in machine room 2 needs to call service business A, the service call request is obtained through load balancer 2. All candidate service instances corresponding to the service call request are extracted from the global service directory, including the instance of service business A in machine room 1. Next, the load balancer performs health detection on service business A through the health check port "8081" of service instance A. Assuming that service instance A successfully responds to the health check request and returns a health status code, confirming that service instance A is in a healthy state. Then, check whether the machine room where service instance A is located is consistent with the machine room where service business B is located. Since service business A is in machine room 1 and service business B is in machine room 2, they are not consistent, so the load balancer obtains the network delay, packet loss rate and bandwidth utilization between machine room 1 and machine room 2 in real time through ZooKeeper. Assuming that the measured network delay is 10ms, the packet loss rate is 0.1%, and the bandwidth utilization is 30%. According to these parameters, the real-time performance score of the cross-machine room path is calculated. Assuming that the performance score formula is:
[0094]
[0095] where C is a constant for adjusting the magnitude of the score (e.g. 100), D is the network delay (unit: milliseconds, ms), L is the packet loss rate (unit: percentage, e.g. 0.1% means 0.001), and U is the bandwidth utilization (unit: percentage, e.g. 30% means 0.3). According to the real-time performance score, the path with the highest performance score is selected as the call path. The call is completed along this path and the result is returned to service business B. The whole process not only ensures the efficiency of service call, but also ensures the optimal selection of call path through dynamic evaluation of network parameters.
[0096] In the embodiment of the present application, through the local priority strategy, the load balancer can quickly select the local path for service call, reducing the delay of cross-machine room call. Secondly, when the service instance and the caller are located in different machine rooms, by obtaining the network parameters in real time and calculating the real-time performance score, the optimal call path can be dynamically selected. This dynamic path selection mechanism not only can cope with the changes of network state, but also can automatically adjust the call path in complex network environment, ensuring the efficiency and reliability of service call.
[0097] Optionally, the calling the service instance along the calling path by the load balancer comprises:
[0098] When the calling path is a cross-machine room path, adding a machine room routing mark to the service calling request by the load balancer, and then sending the service calling request to the load balancer corresponding to the service instance along the calling path;
[0099] Forwarding, by the load balancer corresponding to the service instance, the service calling request to the service instance for calling to obtain the service calling result;
[0100] Returning, by the load balancer corresponding to the service instance, the service calling result to the load balancer of the machine room performing service calling according to the machine room routing mark;
[0101] Sending, by the load balancer of the machine room performing service calling, the service calling result to the requester of the service calling request.
[0102] Specifically, when the calling path is a cross-machine room path, first adding a machine room routing mark to the service calling request by the load balancer. The mark contains the information of the target machine room, ensuring that the request can be correctly routed to the load balancer of the target machine room. Then, the load balancer sends the service calling request to the load balancer corresponding to the target service instance along the calling path. After receiving the request, the target load balancer forwards the request to the corresponding service instance for calling according to the machine room routing mark. After the service instance processes the request, the service calling result is generated and returned to the load balancer of the machine room initiating the calling through the target load balancer. Finally, the load balancer of the machine room initiating the calling sends the service calling result to the requester according to the machine room routing mark, ensuring the efficiency and accuracy of cross-machine room calling. In this way, the load balancer can effectively manage the cross-machine room service calling and ensure the stable operation of the cross-machine room.
[0103] In the embodiment of the application, by adding a machine room routing mark to the service calling request, it is ensured that the request can be correctly routed to the target machine room, reducing the calling failure caused by routing errors. Secondly, the request is forwarded to the corresponding service instance by the load balancer of the target machine room, effectively managing the cross-machine room service calling.
[0104] Optionally, the calling the service instance along the calling path by the load balancer comprises:
[0105] When the calling path is the local room path, the service calling request is forwarded to the service instance along the calling path by the load balancer for calling, and the service calling result is obtained;
[0106] The service calling result is sent to the requester of the service calling request by the load balancer.
[0107] Specifically, when the calling path is the local room path, the service calling request is forwarded to the service instance along the calling path by the load balancer for calling, not only reducing the delay of cross-room calling, but also improving the response speed of cross-room calling service. Specifically, when the service calling request is in the local room, the load balancer first receives the request and selects the most suitable service instance for calling according to the pre-configured routing rules and real-time network state. The load balancer quickly forwards the request to the target service instance through the high-speed network of the local room, ensuring the efficiency of calling. After the service instance processes the request, the service calling result is returned to the requester through the load balancer.
[0108] In the embodiment of the application, the service calling request is forwarded to the service instance along the calling path by the load balancer, so that the request can be quickly and accurately sent to the target instance, reducing the calling delay. Secondly, the service calling result is returned to the requester by the load balancer, ensuring the accuracy and timeliness of the calling result. This mechanism not only improves the response speed of cross-room calling service, but also reduces the complexity of cross-room calling.
[0109] The application also provides a room network, comprising a plurality of rooms, each of which is provided with a registration center and a load balancer, and the load balancers of each room are connected to form a cross-room synchronization channel.
[0110] The load balancer is used to obtain the registration request of the service business and forward it to the registration center when the service business of the room is started.
[0111] The registration center is used to register the service business according to the registration request, obtain the registration information of the service business, and send the registration information to the load balancer.
[0112] The load balancer is also used to send the registration information to the load balancer of other rooms through the cross-room synchronization channel, so as to synchronize the registration information to the global service directory of the room network.
[0113] The load balancer is further configured to, when the machine room makes a service call, acquire a service call request, determine a service instance and a call path corresponding to the service instance according to the service call request and the registration information in the global service directory, and call the service instance along the call path.
[0114] The machine room network of the present application has the same advantages as the above-mentioned agent registration and service calling method compared with the prior art, and thus will not be described here again.
[0115] The present application further provides an electronic device comprising a memory and a processor.
[0116] The memory is configured to store a computer program.
[0117] The processor is configured to, when executing the computer program, implement the above-mentioned agent registration and service calling method.
[0118] The electronic device of the present application has the same advantages as the above-mentioned agent registration and service calling method compared with the prior art, and thus will not be described here again.
[0119] Although the present application has been disclosed as above, the protection scope of the present application is not limited to this. Those skilled in the art can make various modifications and changes without departing from the spirit and scope of the present application, and these modifications and changes shall fall within the protection scope of the present application.
Claims
1. A method for proxy registration and service invocation, characterized in that, The method is applied to a data center network, which includes multiple data centers, each equipped with a registration center and a load balancer, and the load balancers in each data center are interconnected to form a cross-data center synchronization channel; the method includes: When the service in the data center is started, the load balancer obtains the registration request of the service and forwards it to the registration center. The registration center registers the service according to the registration request to obtain the registration information of the service. The registration information is then sent to the load balancers of other data centers through the cross-data center synchronization channel to synchronize the registration information to the global service directory of the data center network. When the data center makes a service call, it obtains the service call request through the load balancer, and determines the service instance and the call path corresponding to the service instance based on the service call request and the registration information in the global service directory. The load balancer then calls the service instance along the call path.
2. The agent registration and service invocation method according to claim 1, characterized in that, Before obtaining the service registration request through the load balancer and forwarding it to the registration center, the process further includes: When the service business in the data center is started, the instance metadata of the service business is obtained. The instance metadata includes the service identifier, instance network address, health check port and data center identifier. The registration request for the service is generated based on the service identifier, the instance network address, the health check port, and the data center identifier.
3. The agent registration and service invocation method according to claim 1, characterized in that, The step of sending the registration information to the load balancers of other data centers through the cross-data center synchronization channel to synchronize the registration information to the global service directory of the data center network includes: The registration information is broadcast in real time to the load balancers of all other data centers through the cross-data center synchronization channel; The registration information of the service business is synchronized to the registration center of the other data centers through the load balancers of the other data centers; The registration information is updated to the global service directory through the registration center.
4. The proxy registration and service invocation method according to claim 1, characterized in that, The step of determining the service instance and the corresponding call path based on the service call request and the registration information in the global service directory includes: The load balancer obtains the service call request and extracts all candidate service instances corresponding to the service call request from the global service directory. The service instances are obtained by filtering all the candidate service instances; The call path is generated based on the data center corresponding to the service instance and the network path of the data center.
5. The agent registration and service invocation method according to claim 4, characterized in that, The step of filtering all the candidate service instances to obtain the service instances includes: By using the health check port of the candidate service instance, a health check is performed on each candidate service instance to obtain the health status of each candidate service instance; Based on the health status, the candidate service instances are initially screened to obtain the initial screened service instances; Obtain the network latency and concurrent semaphores between the initial screening service instance and the load balancer in the data center where the service is invoked; Priority weights are assigned to each candidate service instance based on the network latency and concurrent semaphores of the candidate service instances. Based on the priority weight of the candidate service instances, all candidate service instances are sorted, and the service instance is selected based on the sorting result.
6. The agent registration and service invocation method according to claim 4, characterized in that, The step of determining the service instance and the corresponding call path based on the service call request and the registration information in the global service directory includes: If the data center where the service instance is located is the same as the data center where the service call is made, then the local path pointing to the service instance will be used as the call path; If the data center where the service instance is located is different from the data center where the service call is made, then ZooKeeper is used to obtain the network latency, packet loss rate and bandwidth utilization between the data center where the service instance is located and the data center where the service call is made in real time; based on the network latency, the packet loss rate and the bandwidth utilization, the real-time performance score of the service instance on each cross-data center path is calculated; based on the real-time performance score, the call path is obtained.
7. The agent registration and service invocation method according to claim 6, characterized in that, The step of invoking the service instance along the call path via the load balancer includes: When the call path is a cross-data center path, the load balancer adds a data center routing tag to the service call request, and then sends the service call request to the load balancer corresponding to the service instance along the call path; The service call request is forwarded to the service instance by the load balancer corresponding to the service instance for invocation, and the service call result is obtained. The service call result is returned to the load balancer of the data center that made the service call, based on the data center routing tag and the load balancer corresponding to the service instance. The load balancer in the data center that made the service call sends the service call result to the requester of the service call request.
8. The agent registration and service invocation method according to claim 6, characterized in that, The step of invoking the service instance along the call path via the load balancer includes: When the call path is a local data center path, the load balancer forwards the service call request to the service instance along the call path to make the call and obtain the service call result. The load balancer sends the service call result to the requester of the service call request.
9. A data center network, characterized in that, The data center network includes multiple data centers, each of which is equipped with a registration center and a load balancer, and the load balancers of each data center are connected to form a cross-data center synchronization channel. The load balancer is used to obtain the registration request of the service business when the service business in the data center is started and forward it to the registration center; The registration center is used to register the service business according to the registration request, obtain the registration information of the service business, and send the registration information to the load balancer. The load balancer is also used to send the registration information to load balancers in other data centers through the cross-data center synchronization channel, so as to synchronize the registration information to the global service directory of the data center network; The load balancer is also used to obtain a service call request when the data center makes a service call, and determine the service instance and the call path corresponding to the service instance based on the service call request and the registration information in the global service directory, and call the service instance along the call path.
10. An electronic device, characterized in that, Including memory and processor; The memory is used to store computer programs; The processor is configured to implement the agent registration and service invocation method as described in claims 1-8 when executing the computer program.