Service discovery system, method, apparatus, computer device and storage medium
By unsubscribing from services in the service registry and caching query requests, the message storm problem caused by frequent updates of service nodes in a distributed system is resolved, thus improving system stability.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- TENCENT DIGITAL TIANJIN
- Filing Date
- 2022-09-07
- Publication Date
- 2026-07-14
AI Technical Summary
In a distributed system, starting and stopping service nodes causes frequent updates to the service node list, resulting in the service registry sending a large number of service notifications and query requests to the relay server, creating a message storm and affecting system stability.
After sending a service notification, the service registry unsubscribes from the service and caches the generated query requests in the request queue. The query requests are only sent to the service registry when the cache duration reaches the threshold, thus avoiding frequent notifications and queries.
This reduces the amount of messages in the network, improves the stability of the service discovery system, avoids message storms, and ensures that the system only needs to query once to get the latest results when the service node list is updated.
Smart Images

Figure CN117714525B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a service discovery system, method, apparatus, computer device, and storage medium. Background Technology
[0002] Service discovery refers to using a service registry to record information about all services in a distributed system, enabling other services to quickly find these registered services. When a server in a distributed system starts, it can register as a service node in the service registry. In the service registry, the node identifiers of service nodes corresponding to different services are stored in different service node lists. When a service node in the distributed system stops providing services, the service registry removes that service node's node identifier from the service node list. How to implement service discovery between different services is a key focus of research in this field.
[0003] Currently, the common approach is that for any relay server in a distributed system, upon startup, it can register a subscription service with a service registry to monitor for updates to the service node list. When the list of service nodes monitored by the relay server is updated, the service registry can send a service notification to the relay server based on the subscription service. After receiving the service notification, the server sends a query request to the service registry to retrieve the updated service node list, thus achieving service discovery.
[0004] However, in the above technical solution, the service node list includes node identifiers for multiple service nodes. When any service node associated with this list starts or stops, the service node list is updated, causing the service registry to send service notifications to the relay server, which then queries the service node list. If a large number of servers associated with the service node list start or stop within a short period, the number of service notifications and query requests in the distributed system will surge, creating a message storm, congesting the network, and overloading the service registry. This can lead to information loss, service discovery failures, and other issues, affecting the stability of the distributed system. Summary of the Invention
[0005] This application provides a service discovery system, method, apparatus, computer device, and storage medium, which can reduce the amount of messages in the network, effectively solve the message storm problem, and improve the stability of the service discovery system. The technical solution is as follows:
[0006] On the one hand, a service discovery system is provided, which includes multiple service nodes, a service registry, and relay nodes;
[0007] The service registry is used to send a service notification to the relay node based on the subscription service for the service node list in response to an update of the service node list. The service node list includes the node identifier of at least one service node of the target service. The service node list is updated based on the start and stop of the at least one service node. The subscription service is the service registered by the relay node.
[0008] The service registry is also configured to cancel the subscription service in response to the service notification being sent, so that the service notification will no longer be sent to the relay node when the service node list is updated again.
[0009] The relay node is used to generate a query request based on the service notification and cache the query request in a request queue;
[0010] The relay node is also used to send the query request to the service registry and register a new subscription service in the service registry if the cache duration of the query request in the request queue reaches a duration threshold.
[0011] The service registry is used to register the subscription service on the updated list of service nodes based on the query request, and to return the updated list of service nodes to the relay node.
[0012] On the other hand, a service discovery method is provided for use in relay nodes, the method comprising:
[0013] Based on the service notification received by the subscription service for the service node list, a query request is generated. The subscription service is canceled by the service registry after the service notification is triggered. The service notification is used to indicate that the service node list has been updated. The service node list includes the node identifiers of at least one service node of the target service. The query request is used to query the updated service node list and register the subscription service for the updated service node list.
[0014] The query request is cached in the request queue;
[0015] If the cache duration of the query request in the request queue reaches the duration threshold, the query request is sent to the service registry.
[0016] Receive the updated list of service nodes returned by the service registry.
[0017] In some embodiments, the method further includes:
[0018] If no query request is cached in the request queue, or if the cache duration of the query request in the request queue has not reached the duration threshold, the timed detection step continues.
[0019] On the other hand, a service discovery device is provided for use in a relay node, the device comprising:
[0020] The generation module is used to generate a query request based on the service notification received by the subscription service for the service node list. The subscription service is canceled by the service registry after the service notification is triggered. The service notification is used to indicate that the service node list has been updated. The service node list includes the node identifiers of at least one service node of the target service. The query request is used to query the updated service node list and register the subscription service for the updated service node list.
[0021] The caching module is used to cache the query request in the request queue;
[0022] The sending module is used to send the query request to the service registry if the cache duration of the query request in the request queue reaches a duration threshold.
[0023] The receiving module is used to receive the updated list of service nodes returned by the service registry.
[0024] In some embodiments, the sending module is configured to periodically detect the request queue; if there are pending query requests cached in the request queue, obtain the cache duration of the query request; if the cache duration of the query request in the request queue reaches a duration threshold, send the query request to the service registry.
[0025] In some embodiments, the apparatus further includes:
[0026] The execution module is used to continue executing the timed detection step if no query request is cached in the request queue, or if the cache duration of the query request in the request queue has not reached the duration threshold.
[0027] In some embodiments, the service registry stores a list of multiple service nodes;
[0028] The caching module is used to obtain the list identifier of the query request, which is the same as the list identifier carried in the service notification; based on the list identifier of the query request, the query request is cached in the request queue, and the list identifier of the query request is used to indicate the type of the target service.
[0029] In some embodiments, the request queue includes multiple query requests;
[0030] The sending module includes:
[0031] A determining unit is used to determine the priority of the list identifiers corresponding to the multiple query requests, wherein the priority is used to indicate the importance of the corresponding type of service;
[0032] The sending unit is configured to send the multiple query requests to the service registry in descending order of priority when the cache duration of the multiple query requests has reached the specified duration threshold.
[0033] In some embodiments, the generation module is further configured to generate multiple query requests when multiple service notifications are received;
[0034] The device further includes:
[0035] The merging module is used to merge query requests corresponding to service notifications carrying the same list identifier based on the list identifiers carried by the multiple service notifications. The initial cache time of the merged query request is the initial cache time of the first query request before the merge.
[0036] On the other hand, a computer device is provided, the computer device including a processor and a memory, the memory being used to store at least one computer program, the at least one computer program being loaded and executed by the processor to implement the service discovery method in the embodiments of this application.
[0037] On the other hand, a computer-readable storage medium is provided, wherein at least one computer program is stored in the computer-readable storage medium, the at least one computer program being loaded and executed by a processor to implement the service discovery method as described in the embodiments of this application.
[0038] On the other hand, a computer program product is provided, including a computer program that is executed by a processor to implement the service discovery method in the embodiments of this application.
[0039] This application provides a service discovery method in a service discovery system. Since the service registry cancels its subscription service and does not establish a new subscription service after a service notification is triggered, service notifications will not be triggered again when the service node list is updated. Furthermore, by caching query requests generated based on service notifications in a request queue, relay nodes will not send query requests to the service registry or register new subscription services for a period of time before the cache duration reaches a threshold. This reduces the number of service notifications in the network during this period. When the cache duration of the query request reaches the threshold, the relay node sends a query request to the service registry. This means that only one query is needed to obtain the final result of the updated service node list during this period, eliminating the need for notifications and queries after each update. This reduces the amount of messages in the network, effectively solving the message storm problem and improving the stability of the service discovery system. Attached Figure Description
[0040] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0041] Figure 1 This is a schematic diagram of a service discovery system provided according to an embodiment of this application;
[0042] Figure 2 This is a flowchart illustrating information interaction in a service discovery system according to an embodiment of this application;
[0043] Figure 3 This is a flowchart of a service discovery method provided according to an embodiment of this application;
[0044] Figure 4 This is a flowchart of information interaction in another service discovery system provided according to an embodiment of this application;
[0045] Figure 5 This is a schematic diagram illustrating the merging of query requests according to an embodiment of this application;
[0046] Figure 6 This is a flowchart illustrating a service discovery implementation based on an embodiment of this application;
[0047] Figure 7 This is a schematic diagram of a service discovery device according to an embodiment of this application;
[0048] Figure 8This is a schematic diagram of another service discovery device provided according to an embodiment of this application;
[0049] Figure 9 This is a schematic diagram of the structure of a server according to an embodiment of this application. Detailed Implementation
[0050] To make the objectives, technical solutions, and advantages of this application clearer, the embodiments of this application will be described in further detail below with reference to the accompanying drawings.
[0051] In this application, the terms "first," "second," etc., are used to distinguish identical or similar items with essentially the same function. It should be understood that there is no logical or temporal dependency between "first," "second," and "nth," nor are there any restrictions on quantity or execution order.
[0052] In this application, the term "at least one" means one or more, and "multiple" means two or more.
[0053] It should be noted that all information (including but not limited to user device information, user personal information, etc.), data (including but not limited to data used for analysis, stored data, displayed data, etc.), and signals involved in this application have been authorized by the user or fully authorized by all parties, and the collection, use, and processing of related data must comply with the relevant laws, regulations, and standards of the relevant countries and regions. For example, the node identifiers of the service nodes involved in this application were obtained with full authorization.
[0054] For ease of understanding, the terms used in this application are explained below.
[0055] Game lobby server: mainly used to provide backend services for players entering the game.
[0056] Game backend relay server (router): also known as relay server, all messages between servers are relayed through the relay server.
[0057] FriendsVR (FriendsVR): Primarily used to provide backend services for establishing friend relationships within games.
[0058] Teamsvr (teamsvr) server: Primarily used to provide backend services for team formation in games.
[0059] ZooKeeper is a distributed application coordination service that provides functions such as configuration maintenance, domain name service, distributed synchronization, and group services.
[0060] The service discovery method provided in this application is applied to a service discovery system and can be executed by a computer device. The following describes the implementation environment of the service discovery method provided in this application, using a computer device as a node in the service discovery system. Figure 1 This is a schematic diagram of a service discovery system provided according to an embodiment of this application. See also... Figure 1 The service discovery system includes service node 101, service registry 102, and relay node 103.
[0061] In some embodiments, service node 101 can be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN (Content Delivery Network), big data, and artificial intelligence platforms. One background service corresponds to multiple service nodes. The background service can be a friend information management service, a team mode creation service, or a virtual space creation service, etc., and this application embodiment does not limit this. Service node 101 is a server providing any of the background services. When service node 101 starts, it can send a startup notification to service registry 102 to register with service registry 102.
[0062] In some embodiments, the service registry 102 can be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN (Content Delivery Network), big data, and artificial intelligence platforms. The service registry 102 is a server that provides service discovery functionality. The service registry 102 can be a ZooKeeper server, but this embodiment does not limit this. The service registry 102 stores service node lists for various services. For any service's service node list, the service node list includes the node identifier of at least one service node for that service. The service registry 102 can add the node identifier of service node 101 to the corresponding service node list based on the startup notification sent by service node 101, i.e., update the service node list.
[0063] In some embodiments, relay node 103 can be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN (Content Delivery Network), big data, and artificial intelligence platforms. Relay node 103 is a relay server, i.e., a router server, used to relay interactive information between servers providing backend services. When relay node 103 starts, it can send a startup notification to service registry 102 to register with service registry 102. Relay node 103 can also register subscription services for a list of service nodes to be followed in service registry 102, so that it can receive service notifications from service registry 102 when the list of service nodes is updated, thereby enabling it to query the list of service nodes.
[0064] Figure 2 This is a flowchart of information interaction in a service discovery system according to an embodiment of this application. See also... Figure 2 The service discovery system includes multiple service nodes, a service registry, and relay nodes. Information exchange within this service discovery system includes the following steps:
[0065] 201. In response to an update to the service node list, the service registry sends a service notification to the relay node based on the subscription service for the service node list, which includes the node identifiers of at least one service node of the target service, and the service node list is updated based on the start-up or shutdown of at least one service node, and the subscription service is the service registered by the relay node.
[0066] In this embodiment, a background service corresponds to multiple service nodes, meaning that all of these service nodes can provide the background service. The service registry stores service node lists for various services. For any given service's service node list, the list includes the node identifier of at least one service node. Taking a target service as an example, updates to the target service's service node list can occur in at least two ways: first, the service registry adds the node identifier of a service node to the list; second, the service registry removes the node identifier from the list. Specifically, the first scenario refers to the service node registering with the service registry when it starts, allowing the registry to record the services provided. The service registry can add the node identifier to the service node list. The second scenario refers to the service registry detecting service nodes that have stopped providing services due to downtime or other reasons, and removing their node identifier from the list. The subscription service is a service registered by the relay node with respect to the service node list upon startup. When the service node list is updated, the service registry can send a service notification to the relay node based on the subscription service to inform the relay node that the service node list has changed, thereby notifying the relay node whether the multiple service nodes are providing services.
[0067] 202. In response to the service notification being sent, the service registry unsubscribes from the service so that service notifications are no longer sent to relay nodes when the service node list is updated again.
[0068] In this embodiment, the subscription service is valid only once; that is, the subscription service expires whenever a service notification is triggered based on the subscription service. If a service notification has been triggered, the service registry cancels the subscription service. Afterwards, even if the service node list changes due to the starting and stopping of the multiple service nodes, the service registry will no longer send service notifications to the relay nodes.
[0069] 203. The relay node generates a query request based on the service notification and caches the query request in the request queue.
[0070] In this embodiment, the relay node generates a query request based on the service notification. This query request is used to query the updated list of service nodes and register the new subscription service in the service registry. The relay node caches this query request in a request queue, which is used to store query requests to be sent.
[0071] 204. If the cache duration of a query request in the request queue reaches the duration threshold, the relay node sends the query request to the service registry.
[0072] In this embodiment, the relay node can cache query requests for a period of time. During this period, the relay node will not send query requests to the service registry, nor will it register new subscription services with the service registry. Even if the service node list in the service registry changes, the relay node will not receive service notifications. When the caching time of a query request in the request queue reaches a threshold, the relay node sends a query request to the service registry, allowing the relay node to obtain the latest service node list for that period with only one query. Furthermore, the relay node can also register new subscription services to monitor the service provision status of multiple service nodes subsequently.
[0073] 205. Based on the query request, the service registry returns an updated list of service nodes to the relay nodes, and registers and subscribes to services on the updated list of service nodes.
[0074] In this embodiment, after receiving a query request, the service registry obtains the list of service nodes to be queried by the relay node and sends the list to the relay node so that the relay node can forward information between different service nodes based on the obtained list. The service registry can also subscribe to services for the updated list of service nodes based on the query request, so that the relay node can be notified promptly when the updated list of service nodes is updated again.
[0075] This application provides a service discovery system. Because the service registry cancels the subscription service and does not establish a new subscription service after a service notification is triggered, service notifications will not be triggered again when the service node list is updated. Furthermore, the relay node caches query requests generated based on service notifications in a request queue. For a period before the cache duration reaches a threshold, the relay node will not send query requests to the service registry or register new subscription services. This reduces the number of service notifications in the network during this period. When the cache duration of the query request reaches the threshold, the relay node sends a query request to the service registry. This means that only one query is needed to obtain the final result of the updated service node list during this period, eliminating the need for notifications and queries after each update. This reduces the amount of messages in the network, effectively solving the message storm problem and improving the stability of the service discovery system.
[0076] Figure 3 This is a flowchart of a service discovery method provided according to an embodiment of this application. See also... Figure 3In this embodiment, the service discovery method is illustrated using an example of execution by a relay node. The method includes the following steps:
[0077] 301. The relay node generates a query request based on the service notification received from the subscription service for the service node list. The subscription service is canceled by the service registry after the service notification is triggered. The service notification is used to indicate that the service node list has been updated. The service node list includes the node identifiers of at least one service node of the target service. The query request is used to query the updated service node list and register a subscription service for the updated service node list.
[0078] In this embodiment, the subscription service is a service registered by the relay node in the service registry, used to ensure that the relay node receives service notifications when the service node list in the service registry changes. The relay node generates a query request based on the same principle as in step 203, which will not be described again here.
[0079] 302. The relay node caches query requests in the request queue.
[0080] In this embodiment, the request queue can store query requests to be sent, and the number of query requests in the request queue is not limited. The relay node caches query requests in the request queue for easy management of the query requests to be sent. Each query request corresponds to a cache time.
[0081] 303. If the cache duration of a query request in the request queue reaches the duration threshold, the relay node sends the query request to the service registry.
[0082] In this embodiment of the application, the relay node sends a query request to the service registry center based on the same principle as in step 204, which will not be described again here.
[0083] 304. The relay node receives the updated list of service nodes returned by the service registry.
[0084] In this embodiment, after receiving a query request, the service registry can send an updated list of service nodes to a relay node. The relay node receives and stores the list of service nodes. Based on the stored list of service nodes, the relay node can forward information between different service nodes.
[0085] This application provides a service discovery method. Since the service registry cancels the subscription service and does not establish a new subscription service after the service notification is triggered, service notifications will not be triggered again when the service node list is updated. Furthermore, the relay node caches query requests generated based on service notifications in a request queue. For a period before the cache duration reaches a threshold, the relay node will not send query requests to the service registry or register new subscription services. This reduces the number of service notifications in the network during this period. When the cache duration of the query request reaches the threshold, the relay node sends a query request to the service registry. This means that only one query is needed to obtain the final result of the updated service node list during this period, eliminating the need for notifications and queries after each update. This reduces the amount of messages in the network, effectively solving the message storm problem and improving the stability of the service discovery system.
[0086] Figure 4 This is a flowchart of information interaction in another service discovery system provided according to an embodiment of this application. See also... Figure 4 The service discovery system includes multiple service nodes, a service registry, and relay nodes. Information exchange within this service discovery system includes the following steps:
[0087] 401. For any one of multiple service nodes, the service node sends a startup notification to the service registry center upon startup in order to register with the service registry center.
[0088] In this embodiment, the service registry provides background services for service discovery to service nodes and relay nodes in the service discovery system. When a service node starts, it can send a startup notification to the service registry to inform it that it can provide services.
[0089] 402. Based on the startup notification, the service registry adds the node identifier of the service node to the service node list, which includes the node identifier of at least one service node.
[0090] In this embodiment, the service discovery system includes multiple service nodes, which may provide the same or different types of services. The service registry can store the node identifiers of service nodes providing different services in different service node lists, and store the node identifiers of service nodes providing the same type of service in the same service node list. This embodiment primarily uses multiple service nodes providing the same type of service for illustration. Upon receiving a startup notification from any of the multiple service nodes providing the same type of service, the service registry adds the node identifier of that service node to the corresponding service node list.
[0091] For example, when the game lobby server (lobby) starts up, it registers its own service node lobby_x.xxx under the storage path / routemap / lobby in the service registry (zooKeeper). At this time, the game lobby server establishes a communication connection with the service registry and notifies the service registry of the information it provides. The game lobby server can be regarded as a service node. Here, lobby_x.xxx is the node identifier of this service node. The / routemap / lobby storage path is the storage path of the corresponding service node.
[0092] 403. In response to an update to the service node list, the service registry sends a service notification to the relay node based on the subscription service for the service node list, where the subscription service is the service registered by the relay node.
[0093] In this embodiment, the subscription service for the service node list refers to sending a service notification to the relay node when the service node list is updated, informing the relay node that the service node list has changed. When the relay node starts, it can also send a startup notification to the service registry center, informing the center that the relay node has successfully started and can provide relay information services. Upon startup, the relay node can also register a subscription service in the service registry center. This subscription service is used to send service notifications to the relay node when the service node list is updated. Different service nodes correspond to different subscription services. The relay node can register subscription services for multiple service node lists based on the types of services it wants to follow.
[0094] For example, the service registry stores three service node lists: lobby, friendsvr, and teamsvr. When any one of these service node lists is updated, the ZooKeeper service registry can send a corresponding service notification (watch notification) to the relay node. When all three service node lists are updated simultaneously, the service registry can send corresponding service notifications to each relay node individually. In short, the subscription services corresponding to different service lists are independent of each other and do not affect one another.
[0095] 404. In response to the service notification being sent, the service registry unsubscribes from the service so that service notifications are no longer sent to relay nodes when the service node list is updated again.
[0096] In this embodiment, for any subscription service corresponding to a service node list, the subscription service has a one-time validity period. That is, when a service notification has been triggered based on the subscription service, the service registry can cancel the subscription service. Before a new subscription service is registered for the service node list, even if the service node list is updated, the service notification will not be triggered again. Accordingly, after the subscription service is canceled, when any service node corresponding to the service node list starts or stops, the relay node will not receive a service notification.
[0097] 405. The relay node generates a query request based on the service notification and caches the query request in the request queue. This query request is used to query the updated list of service nodes and register the updated list of service nodes to subscribe to services.
[0098] In this embodiment, the relay node can generate a corresponding query request based on the list identifier carried in the service notification. This query request also carries the list identifier, which indicates the updated list of service nodes. The relay node caches the query request in a request queue. This request queue can store different query requests depending on the list of service nodes to be queried. That is, the relay node can store different query requests based on the type of service associated with the service node list.
[0099] In some embodiments, the relay node caches the query request in a request queue based on a list identifier. Accordingly, the relay node obtains the list identifier of the query request, which is determined based on the list identifier carried in the service notification. Then, the relay node caches the query request in the request queue based on the list identifier, where the list identifier indicates the types of services provided by the multiple service nodes associated with the service node list. The solution provided in this application embodiment, by storing query requests based on list identifiers, enables the separate management of different query requests, ensuring that each query request does not interfere with others, thus improving the stability of the service discovery system.
[0100] In some embodiments, due to the simultaneous startup of multiple service nodes or network latency preventing the service registry from unsubscribing from services in a timely manner, the relay node may receive multiple service notifications for the same list of service nodes. Upon receiving multiple service notifications, the relay node generates multiple query requests. Then, based on the list identifiers carried by the multiple service notifications, the relay node merges the query requests corresponding to service notifications carrying the same list identifier. The initial cache time of the merged query request is the same as the initial cache time of the first query request before the merge. When the service registry generates a query request, it caches it in the request queue; when the service registry generates another query request, it merges this query request with the previous one before storing it. The cache duration of the merged query request is determined by the first cached query request, and the initial cache time of the merged query request is the same as the initial cache time of the first query request before the merge. The solution provided in this application merges multiple query requests, ensuring that there is only one query request for the same service node list in the request queue. As a result, the relay node only needs to query once to obtain the final result of the updated service node list, without having to query after each update. This reduces the amount of messages in the network, effectively solves the message storm problem, and improves the stability of the service discovery system.
[0101] The relay node, based on the principles of Lua table data structure, merges multiple query requests for the same service node list. Using the list identifier as the key, the detailed data structure is as follows:
[0102] delay_get_queue={
[0103] ["lobby"]={exec_time=xxxxx},
[0104] ["teamsvr"]={exec_time=yyyyy},
[0105] ["friendsvr"]={exec_time=zzzzz},
[0106] ...
[0107] }
[0108] In this context, `delay_get_queue` represents the query queue, while `lobby`, `teamsvr`, and `friendsvr` are three list identifiers indicating the list of service nodes to be queried, i.e., the types of services provided by the corresponding service nodes. `exec_time` represents the maximum duration for which a query request can be cached, i.e., the duration threshold. The duration threshold is set using strings such as `xxxxx`, `yyyyy`, and `zzzzz`. The duration thresholds for different query requests can be the same or different; this embodiment does not impose any restrictions on this.
[0109] For example, Figure 5 This is a schematic diagram illustrating the merging of query requests according to an embodiment of this application. See also... Figure 5 The service discovery system includes multiple lobby service nodes, multiple teamsvr service nodes, and friendsvr service nodes. When multiple service nodes of the same type start simultaneously, due to network latency and the service registry not being able to unsubscribe from services in time, the relay node receives multiple service notifications, thus generating multiple query requests. The relay node then merges the query requests corresponding to service notifications carrying the same list identifier. Therefore, for service nodes providing the same service, only one query request is stored in the request queue.
[0110] 406. If the cache duration of a query request in the request queue reaches the duration threshold, the relay node sends the query request to the service registry.
[0111] In this embodiment, if the caching time of a query request has not reached the time threshold, the relay node will keep the query request cached in the request queue. In this case, since the service registry has canceled its original subscription service and has not registered a new one, the relay node will not receive a service notification even if the service node list in the service registry changes. Only when the caching time of the query request reaches the time threshold will the relay node send a query request to the service registry to obtain the latest service node list. This time threshold can be 80 milliseconds, 100 milliseconds, or 120 milliseconds, etc., and this embodiment does not impose any limitation on it.
[0112] In some embodiments, the relay node can periodically detect the request queue to process query requests in the queue in a timely manner. Accordingly, step 406 includes the following steps: The relay node periodically detects the request queue. Then, if a query request is detected to be cached in the request queue, the relay node obtains the cache duration of the query request. Then, if the cache duration of the query request reaches a duration threshold, the query request is sent to the service registry. Wherein, if no query request is cached in the request queue, or if the cache duration of the query request in the request queue has not reached the duration threshold, the periodic detection step continues. The period of periodic detection may be equal to or different from the duration threshold of the query request; this embodiment does not impose any limitation on this. The solution provided by this embodiment, by periodically detecting the request queue, can process query requests in the request queue in a timely manner. When the cache duration of a query request reaches the duration threshold, the query request is sent out promptly to obtain an updated query list in a timely manner, thereby achieving service discovery and improving the stability of the service discovery system.
[0113] For example, Figure 6 This is a flowchart illustrating a service discovery implementation according to an embodiment of this application. See also... Figure 6 Taking a lobby service node and a router relay node as an example. In the lobby service node's processing, when the lobby service node starts, it calls the `zk_init` statement to initialize the information of the services it provides. Then, the lobby service node can register with the ZooKeeper service registry, with the node identifier being `lobby_x.xxx`. This registration triggers a service notification, causing the service registry to send a `watch` notification to the router relay node. In the router relay node's processing, after receiving the `watch` notification, the router relay node caches the query request corresponding to the service notification in a request queue (`delay_get_queue`). The router relay node periodically checks (ticks) this request queue. When the cache duration of the query request in the request queue reaches a threshold, it sends the query request (`get_and_watch`) and removes the sent query request from the request queue.
[0114] In some embodiments, the request queue includes multiple query requests. Different query requests are used to query different service node lists to discover different types of services. When the caching time of multiple query requests reaches a time threshold, the relay node can send the multiple query requests separately. Accordingly, the process of the relay node sending the multiple query requests is as follows: when the caching time of multiple query requests reaches the time threshold, the relay node determines the priority of the list identifiers corresponding to the multiple query requests, which is used to indicate the importance of the corresponding type of service. Then, the relay node sends the multiple query requests to the service registry in descending order of priority. The solution provided in this application embodiment, by sending multiple query requests to the service registry in descending order of priority according to the priority of the list identifiers, enables the service node list corresponding to more important services to be obtained more quickly, which is beneficial to improving the stability of the service discovery system.
[0115] 407. Based on the query request, the service registry returns an updated list of service nodes to the relay nodes and registers subscription services for the updated list of service nodes.
[0116] In this embodiment, after receiving a query request, the service registry obtains the list of service nodes to be queried by the relay node, sends the service node list to the relay node, and registers a subscription service for the updated service node list so that it can continue to monitor whether the service node list is updated. The relay node can store the service node list sent by the storage service registry. When the relay node receives information from a service node, it can forward the information to other service nodes according to the stored service node list, thereby realizing the forwarding of information between different service nodes.
[0117] The technical solution provided in this application can reduce the amount of messages in the network and solve the problem of message storms. For example, the service discovery system includes m relay nodes and n service nodes for the target service. Before adopting the technical solution provided in this application, when the n service nodes start up together, the service registry will send n service notifications to each relay node, resulting in a total of m*n service notifications. Furthermore, newly started service nodes can also trigger the service registry to send service notifications to already started service nodes, resulting in a total of (1+2+…+(n-1)). Therefore, in this case, the total number of service notifications in the service discovery system is m*n+(1+2+…+(n-1))=m*n+n*(n-1) / 2, which is an m*n level number. Based on the same principle as service notifications, the number of query requests is also an m*n level number. After adopting the technical solution provided in this application, when the n service nodes start up together, the service registry only needs to send one service notification to each relay node, resulting in a total of m service notifications. Furthermore, among these n service nodes, a newly started service node only needs to trigger the service registry to send a service notification to the previous already started service node; in this case, the number of service notifications is n-1. Therefore, in this scenario, the total number of service notifications in the service discovery system is m+n-1, which is at the m+n level. Based on the same principle as service notifications, the number of query requests is also at the m+n level. If the service discovery system includes 50 relay nodes and 200 service nodes for the target service, the number of service notifications and query requests in the service discovery system before adopting the technical solution provided in this application was 29,900, while the number of service notifications and query requests in the service discovery system after adopting the technical solution provided in this application is 249. Thus, the message volume in the service discovery system is reduced by more than 100 times.
[0118] In the game scenario, the service discovery system includes multiple relay nodes (routers), multiple service nodes providing various services, and a service registry. The multiple service nodes providing various services include multiple game lobby service nodes (lobby), multiple game friend service nodes (friendsvr), and multiple game team service nodes (teamsvr). When a large number of players enter the game simultaneously, the multiple game lobby service nodes (lobby) will start simultaneously; similarly, when a large number of players create friend relationships or interact with friends simultaneously, the multiple game friend service nodes (friendsvr) will start simultaneously; or, when a large number of players create teams simultaneously, the multiple game team service nodes (teamsvr) will start simultaneously. Before adopting the technical solution provided in this application, for any service node providing a particular service, when m service nodes providing that service start simultaneously, the service registry sends m service notifications to each of the n relay nodes, resulting in a message volume on the order of m*n. Building upon this, when multiple servers providing various services start up simultaneously, the message volume increases dramatically, growing at the m*n level, leading to message storms, network congestion, and overload of the service registry, resulting in information loss, service discovery failures, and impacting the stability of the service discovery system. By adopting the technical solution provided in this application, for any service node providing a particular service, when m service nodes providing that service start up simultaneously, the service registry only needs to send one service notification to each of the n relay nodes. In this case, the message volume is at the m+n level. Furthermore, although the message volume increases when multiple servers providing various services start up simultaneously, the growth rate is still at the m+n level, far less than the m*n level. Therefore, the service discovery method provided in this application effectively reduces the message volume in the service discovery system within the game scenario, effectively solves the message storm problem, and improves the stability of the service discovery system.
[0119] It's important to note that in this service discovery system, the service registry periodically sends requests to each service node and determines its operational status based on whether a response is received. If the service registry does not receive a response for an extended period, it determines that the service node has stopped operating, i.e., it has ceased providing service. In the event that a service node has stopped providing service, the service registry removes its node identifier from the service node list. This step also updates the service node list. In this case, steps 403-407 are repeated.
[0120] This application provides a service discovery method in a service discovery system. Since the service registry cancels its subscription service and does not establish a new subscription service after a service notification is triggered, service notifications will not be triggered again when the service node list is updated. Furthermore, the relay node caches query requests generated based on service notifications in a request queue. For a period before the cache duration reaches a threshold, the relay node will not send query requests to the service registry or register new subscription services. This reduces the number of service notifications in the network during this period. When the cache duration of the query request reaches the threshold, the relay node sends a query request to the service registry. This means that only one query is needed to obtain the final result of the updated service node list during this period, eliminating the need for notifications and queries after each update. This reduces the amount of messages in the network, effectively solving the message storm problem and improving the stability of the service discovery system.
[0121] Figure 7 This is a schematic diagram of a service discovery apparatus according to an embodiment of this application. The service discovery apparatus is used to perform the steps of the service discovery method described above. (See also...) Figure 7 The service discovery device includes: a generation module 701, a cache module 702, a sending module 703, and a receiving module 704.
[0122] The generation module 701 is used to generate a query request based on the service notification received by the subscription service for the service node list. The subscription service is canceled by the service registry after the service notification is triggered. The service notification is used to indicate that the service node list has been updated. The service node list includes the node identifiers of at least one service node of the target service. The query request is used to query the updated service node list and register a subscription service for the updated service node list.
[0123] Cache module 702 is used to cache query requests in the request queue;
[0124] The sending module 703 is used to send a query request to the service registry if the cache duration of the query request in the request queue reaches a duration threshold.
[0125] The receiving module 704 is used to receive the updated list of service nodes returned by the service registry.
[0126] This application provides a service discovery device in a service discovery system. Since the service registry cancels its subscription service and does not establish a new subscription service after a service notification is triggered, service notifications will not be triggered again when the service node list is updated. Furthermore, by caching query requests generated based on service notifications in a request queue, relay nodes will not send query requests to the service registry or register new subscription services for a period of time before the cache duration reaches a threshold. This reduces the number of service notifications in the network during this period. When the cache duration of the query request reaches the threshold, the relay node sends a query request to the service registry. This means that only one query is needed to obtain the final result of the updated service node list during this period, eliminating the need for notifications and queries after each update. This reduces the amount of messages in the network, effectively solving the message storm problem and improving the stability of the service discovery system.
[0127] In some embodiments, Figure 8 This is a schematic diagram of another service discovery device provided according to an embodiment of this application. See also... Figure 8 The sending module 703 is used to periodically detect the request queue; if there are pending query requests cached in the request queue, it obtains the cache duration of the query requests; if the cache duration of the query requests in the request queue reaches the duration threshold, it sends the query request to the service registry.
[0128] In some embodiments, see continue to see Figure 8 The device also includes:
[0129] The execution module is used to continue the timed detection steps if there are no cached query requests in the request queue, or if the cache duration of query requests in the request queue has not reached the duration threshold.
[0130] In some embodiments, see continue to see Figure 8 The service registry stores a list of multiple service nodes;
[0131] The caching module 702 is used to obtain the list identifier of the query request, which is the same as the list identifier carried in the service notification; based on the list identifier of the query request, the query request is cached in the request queue, and the list identifier of the query request is used to indicate the type of the target service.
[0132] In some embodiments, see continue to see Figure 8 The request queue contains multiple query requests;
[0133] The transmitting module 703 includes:
[0134] The determining unit 801 is used to determine the priority of the list identifiers corresponding to multiple query requests, which is used to indicate the importance of the corresponding type of service;
[0135] Sending unit 802 is used to send multiple query requests to the service registry in descending order of priority when the cache duration of multiple query requests has reached the time threshold.
[0136] In some embodiments, see continue to see Figure 8 The generation module 701 is also used to generate multiple query requests when multiple service notifications are received;
[0137] The device also includes:
[0138] The merging module 705 is used to merge query requests corresponding to service notifications carrying the same list identifier based on the list identifiers carried by multiple service notifications. The initial cache time of the merged query request is the initial cache time of the first query request before the merge.
[0139] It should be noted that the service discovery device provided in the above embodiments is only illustrated by the division of the above functional modules when running the application. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. In addition, the service discovery device and service discovery method embodiments provided in the above embodiments belong to the same concept, and the specific implementation process can be found in the method embodiments, which will not be repeated here.
[0140] In some embodiments, the computer device is a server. Figure 9 This is a schematic diagram of a server structure according to an embodiment of this application. The server 900 can vary significantly due to different configurations or performance, and may include one or more Central Processing Units (CPUs) 901 and one or more memories 902. The memories 902 store at least one computer program, which is loaded and executed by the processor 901 to implement the service discovery methods provided in the various method embodiments described above. Of course, the server 900 may also have wired or wireless network interfaces, a keyboard, and input / output interfaces for input and output. The server 900 may also include other components for implementing device functions, which will not be elaborated upon here.
[0141] This application also provides a computer-readable storage medium storing at least one computer program, which is loaded and executed by a processor of a computer device to implement the operations performed by the computer device in the service discovery method of the above embodiments. For example, the computer-readable storage medium may be a read-only memory (ROM), a random access memory (RAM), a compact disc read-only memory (CD-ROM), magnetic tape, floppy disk, or optical data storage device, etc.
[0142] This application also provides a computer program product, including a computer program stored in a computer-readable storage medium. A processor of a computer device reads the computer program code from the computer-readable storage medium and executes the computer program code, causing the computer device to perform the service discovery methods provided in the various optional implementations described above.
[0143] Those skilled in the art will understand that all or part of the steps of the above embodiments can be implemented by hardware or by a program instructing related hardware. The program can be stored in a computer-readable storage medium, such as a read-only memory, a disk, or an optical disk.
[0144] The above description is merely an optional embodiment of this application and is not intended to limit this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.
Claims
1. A service discovery system, characterized in that, The service discovery system includes multiple service nodes, a service registry, and relay nodes; The service registry is used to send a service notification to the relay node based on the subscription service for the service node list in response to an update of the service node list. The service node list includes the node identifier of at least one service node of the target service. The service node list is updated based on the start and stop of the at least one service node. The service registry is also configured to cancel the subscription service in response to the service notification being sent, so that the service notification will no longer be sent to the relay node when the service node list is updated again. The relay node is used to generate a query request based on the service notification and cache the query request in a request queue; The relay node is also used to send the query request to the service registry if the cache duration of the query request in the request queue reaches a duration threshold. The service registry is used to return an updated list of service nodes to the relay node based on the query request, and to register the subscription service on the updated list of service nodes.
2. The system according to claim 1, characterized in that, The relay node is used to periodically detect the request queue; if there are pending query requests in the request queue, it obtains the cache duration of the query request; if the cache duration of the query request reaches the duration threshold, it sends the query request to the service registry.
3. The system according to claim 2, characterized in that, The relay node is also used to continue executing the timed detection step when there is no cached query request in the request queue, or when the cache duration of the query request in the request queue has not reached the duration threshold.
4. The system according to claim 1, characterized in that, The service registry stores a list of multiple service nodes; The relay node is used to generate the query request based on the list identifier carried in the service notification; Based on the list identifier corresponding to the query request, the query request is cached in the request queue. The list identifier is used to indicate the types of services provided by the multiple service nodes associated with the service node list.
5. The system according to claim 4, characterized in that, The request queue includes multiple query requests; The relay node is used to determine the priority of the list identifiers corresponding to the multiple query requests, and the priority is used to indicate the importance of the corresponding type of service; If the caching time of all the multiple query requests reaches the specified time threshold, the multiple query requests are sent to the service registry in descending order of priority.
6. The system according to claim 1, characterized in that, The relay node is also used to delete the query request from the request queue in response to the query request being sent.
7. A service discovery method, characterized in that, Applied to relay nodes, the method includes: Based on the service notification received by the subscription service for the service node list, a query request is generated. The subscription service is canceled by the service registry after the service notification is triggered. The service notification is used to indicate that the service node list has been updated. The service node list includes the node identifiers of at least one service node of the target service. The query request is used to query the updated service node list and register the subscription service for the updated service node list. The query request is cached in the request queue; If the cache duration of the query request in the request queue reaches the duration threshold, the query request is sent to the service registry. Receive the updated list of service nodes returned by the service registry.
8. The method according to claim 7, characterized in that, If the cache duration of the query request in the request queue reaches a duration threshold, the query request is sent to the service registry, including: The request queue is checked periodically; If there are pending query requests cached in the request queue, obtain the cache duration of the query requests; If the cache duration of the query request in the request queue reaches the duration threshold, the query request is sent to the service registry.
9. The method according to claim 7, characterized in that, The service registry stores a list of multiple service nodes; The step of caching the query request in the request queue includes: Obtain the list identifier of the query request, which is determined based on the list identifier carried in the service notification, and the list identifier of the query request is used to indicate the type of the target service; Based on the list identifier of the query request, the query request is cached in the request queue.
10. The method according to claim 9, characterized in that, The request queue includes multiple query requests; Sending the query request to the service registry includes: If the caching duration of all the multiple query requests reaches the specified duration threshold, the priority of the list identifiers corresponding to the multiple query requests is determined, and the priority is used to indicate the importance of the corresponding type of service. The multiple query requests are sent to the service registry in descending order of priority.
11. The method according to claim 7, characterized in that, The method further includes: When multiple service notifications are received, multiple query requests are generated; Based on the list identifiers carried by the multiple service notifications, the query requests corresponding to the service notifications carrying the same list identifier are merged, and the initial cache time of the merged query request is the initial cache time of the first query request before the merge.
12. A service discovery device, characterized in that, The device, applied to a relay node, includes: The generation module is used to generate a query request based on the service notification received by the subscription service for the service node list. The subscription service is canceled by the service registry after the service notification is triggered. The service notification is used to indicate that the service node list has been updated. The service node list includes the node identifiers of at least one service node of the target service. The query request is used to query the updated service node list and register the subscription service for the updated service node list. The caching module is used to cache the query request in the request queue; The sending module is used to send the query request to the service registry if the cache duration of the query request in the request queue reaches a duration threshold. The receiving module is used to receive the updated list of service nodes returned by the service registry.
13. A computer device, characterized in that, The computer device includes a processor and a memory, the memory being used to store at least one computer program, the at least one computer program being loaded by the processor and executed as the service discovery method according to any one of claims 7 to 11.
14. A computer-readable storage medium, characterized in that, The computer-readable storage medium is used to store at least one computer program for performing the service discovery method according to any one of claims 7 to 11.
15. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the service discovery method as described in any one of claims 7 to 11.