Request processing method and device, equipment and medium
By introducing UID routing policies in the proxy gateway, determining the target service instance to route service requests of the same user ID, the problem of low cache hit rate in distributed systems is solved, and the effect of reducing external interface calls and improving system performance is achieved.
Patent Information
- Application Number
- CN202411735154.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-29
- Publication Date
- 2025-03-04
AI Technical Summary
In large-scale distributed systems, due to the randomness of service requests, multiple service requests from the same user may fall on different service instances, resulting in a decrease in the cached data hit rate and the number of calls to the external interface cannot be reduced.
By introducing UID routing policies in the proxy gateway, based on user identity and service instance information of the distributed cluster, the hash algorithm is used to determine the target service instance, so that multiple service requests of the same user identity are routed to the same service instance.
It significantly improves the hit rate of the local cache of service instances, reduces the number of external interface calls, reduces the dependence and resource consumption of distributed systems on external resources, improves system performance and stability, and reduces operation and maintenance costs.
Smart Images

Figure CN119561987A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer technology, and in particular to a request processing method, device, equipment and medium. Background Art
[0002] Currently, in large-scale distributed systems, service instances are usually supported by clusters of multiple servers. In order to improve the response speed of user requests, distributed systems usually cache data obtained from external interfaces. For example, when a user accesses an application, his request may require the service instance to call an external interface to obtain data. This data can be cached for a period of time to reduce the number of repeated calls to the external interface and improve system performance.
[0003] However, due to the randomness of service requests, multiple service requests from the same user may fall on different service instances, resulting in a decrease in the cache data hit rate and a failure to reduce the number of calls to the external interface. Summary of the invention
[0004] In order to solve the above technical problems or at least partially solve the above technical problems, the present disclosure provides a request processing method, apparatus, device and medium.
[0005] An embodiment of the present disclosure provides a request processing method, which is applied to a proxy gateway, and the method includes: receiving a service request sent by a requester, and obtaining a user identifier based on the service request; determining a target service instance based on the user identifier and service instance information of a distributed cluster; forwarding the service request to the target service instance, and receiving a request result in which the target service instance responds to the service request based on locally cached data, and forwarding the request result to the requester.
[0006] Optionally, determining the target service instance based on the user identifier and the service instance information of the distributed cluster includes: performing a hash calculation on the user identifier and the total number of current service instances of the distributed cluster based on a preset hash algorithm to obtain a target service instance identifier; and using the service instance corresponding to the target service instance identifier in the distributed cluster as the target service instance.
[0007] Optionally, determining the target service instance based on the user identifier and the service instance information of the distributed cluster includes: obtaining a target hash space corresponding to the service instance identifier of the distributed cluster; performing a hash calculation on the user identifier based on a preset hash algorithm to obtain a user hash value, and mapping the user hash value to the target hash space to obtain a user hash position; determining the target service instance hash position in the target hash space based on the user hash position and a preset query direction, and using the service instance corresponding to the target service instance hash position as the target service instance.
[0008] Optionally, the method also includes: obtaining the service instance identifier of each service instance in the distributed cluster, and performing hash calculation on the service instance identifier based on the hash algorithm to obtain the service instance hash value of each service instance; mapping the service instance hash value of each service instance to a pre-built initial hash space to obtain the target hash space including the service instance hash position corresponding to each service instance.
[0009] Optionally, the method also includes: obtaining instance update information of the distributed cluster; determining to add a service instance based on the instance update information, and calculating the added service instance hash value of the added service instance and mapping it to the target hash space to obtain the added service instance hash position; determining a shared service instance hash position based on the added service instance hash position and the query direction, and using the service instance corresponding to the shared service instance hash position as the shared service instance of the added service instance.
[0010] Optionally, the method also includes: determining a deleted service instance based on the instance update information, and determining a deleted service instance hash position on the target hash space corresponding to the deleted service instance; determining a candidate service instance hash position based on the deleted service instance hash position and the query direction, and using the service instance corresponding to the candidate service instance hash position as a candidate service instance for the deleted service instance.
[0011] Optionally, the method also includes: configuring each service instance in the distributed cluster to correspond to multiple virtual service instances, and obtaining a virtual service instance identifier of each virtual service instance; performing hash calculation on the virtual service instance identifier based on the hash algorithm to obtain a virtual service instance hash value of each virtual service instance; mapping the virtual service instance hash value of each virtual service instance to the target hash space to obtain a virtual service instance hash position corresponding to each virtual service instance in the target hash space; determining the target service instance hash position in the target hash space based on the user hash position and a preset query direction, and taking the service instance corresponding to the target service instance hash position as the target service instance, including: determining the target virtual service instance hash position from all the virtual service instance hash positions based on the user hash position and the query direction, and obtaining the target virtual service instance corresponding to the target virtual service instance hash position, and taking the service instance to which the target virtual service instance belongs as the target service instance.
[0012] Optionally, the method also includes: obtaining historical service request volume and historical access service instances within a historical time period; analyzing the historical service request volume and the historical access service instances based on a preset machine learning algorithm, and adjusting the hash algorithm and / or the initial hash space based on the analysis results.
[0013] Optionally, when the service request is the first request, the request result is that the target service instance obtains data from an external system based on an external interface in response to the service request; wherein, the target service instance caches the data obtained from the external system locally and sets the data cache time based on the request frequency of the service request.
[0014] The disclosed embodiment also provides a request processing device, which is applied to a proxy gateway, and the device includes: a receiving and obtaining module, which is used to receive a service request sent by a requester and obtain a user identifier based on the service request; a determination module, which is used to determine a target service instance based on the user identifier and service instance information of a distributed cluster; a processing module, which is used to forward the service request to the target service instance, receive a request result of the target service instance responding to the service request based on locally cached data, and forward the request result to the requester.
[0015] An embodiment of the present disclosure also provides an electronic device, which includes: a processor; a memory for storing executable instructions of the processor; the processor is used to read the executable instructions from the memory and execute the executable instructions to implement the request processing method provided by the embodiment of the present disclosure.
[0016] The embodiment of the present disclosure further provides a computer-readable storage medium, wherein the storage medium stores a computer program, and the computer program is used to execute the request processing method provided by the embodiment of the present disclosure.
[0017] The embodiments of the present disclosure also provide a computer program product, including a computer program, wherein the computer program is executed by a processor as the request processing method provided in the embodiments of the present application.
[0018] The above-mentioned technical scheme provided by the embodiment of the present disclosure can route multiple service requests of the same user identifier to the same service instance, thereby greatly improving the hit rate of the local cache of the service instance, thereby reducing the number of external interface calls, reducing the dependence of the distributed system on external resources and the resource consumption and cost during the operation of the distributed system, improving the performance and stability of the distributed system while reducing the operation and maintenance costs, and reducing repeated external interface calls when processing a large number of service requests, effectively reducing the time and resource consumption of request processing, and improving the request processing efficiency.
[0019] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present disclosure, nor is it intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the present disclosure.
[0021] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0022] Figure 1 A request processing flow diagram provided for related technologies;
[0023] Figure 2 A flowchart of a request processing method provided by an embodiment of the present disclosure;
[0024] Figure 3 A schematic diagram of a request processing flow provided by an embodiment of the present disclosure;
[0025] Figure 4 A schematic diagram of a request processing flow provided by an embodiment of the present disclosure;
[0026] Figure 5 A schematic diagram of a request processing flow provided by an embodiment of the present disclosure;
[0027] Figure 6 A schematic diagram of a request processing flow provided by an embodiment of the present disclosure;
[0028] Figure 7 A schematic diagram of a request processing flow provided by an embodiment of the present disclosure;
[0029] Figure 8 A schematic diagram of a request processing flow provided by an embodiment of the present disclosure;
[0030] Fig. 9 A schematic diagram of a request processing flow provided by an embodiment of the present disclosure;
[0031] Fig.10 A flowchart of a request processing method provided by an embodiment of the present disclosure;
[0032] Fig.11 A flowchart of a request processing method provided by an embodiment of the present disclosure;
[0033] Fig.12 A schematic diagram of the structure of a request processing device provided in an embodiment of the present disclosure;
[0034] Fig.13 A schematic diagram of the structure of an electronic device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION
[0035] In order to more clearly understand the above-mentioned objectives, features and advantages of the present disclosure, the scheme of the present disclosure will be further described below. It should be noted that the embodiments of the present disclosure and the features in the embodiments can be combined with each other without conflict.
[0036] In the following description, many specific details are set forth to facilitate a full understanding of the present disclosure, but the present disclosure may also be implemented in other ways different from those described herein; it is obvious that the embodiments in the specification are only part of the embodiments of the present disclosure, rather than all of the embodiments.
[0037] In the existing request processing scenario, users can send service requests through applications, front-end web pages, etc., and a cluster composed of multiple servers provides service instances to respond to the service requests. In order to improve the response efficiency, the service instance can cache the data obtained by the external interface, that is, the cached content is stored in the service instance's own memory. When the cache is effective, it can reduce the calls to the external interface. However, due to the randomness of service requests, multiple accesses to the same UID (UserIdentifier) may fall on different instances, resulting in a decrease in the cache hit rate.
[0038] For easier understanding, please refer to Figure 1 A request processing flow diagram provided by the related technology shown in FIG. Figure 1 As shown, the service request is sent to the distributed cluster through the request direction, and the service request is randomly distributed on different service instances, for example Figure 1 The first request with UID "123456" is distributed to instance 1, so that UID "123456" calls the external interface for the first time to obtain data from the external system and caches it in instance 1, that is, the external interface is queried according to the UID and the data is cached. Then the second request with UID "123456" is distributed to instance 2, so that UID "123456" calls the external interface for the second time to obtain data from the external system and cache it in instance 2.
[0039] Therefore, when the same UID in the related technology requests services multiple times, although the results are cached in the local cache, the cache hit rate cannot be improved because the requests are distributed on different service instances, and the number of calls to the external interface cannot be reduced.
[0040] In view of the existing methods, in large-scale distributed systems, although local cache is used to reduce calls to external interfaces, due to the randomness of service requests, multiple accesses to the same UID may be scattered to different service instances, resulting in the inability to reuse cached data, and the cache hit rate is still low, resulting in a high number of external interface calls. The technical problem, this disclosure proposes a request processing method, which uses a proxy gateway to route service requests to a specified service instance based on user identification and service instance information of a distributed cluster, so that multiple service requests for the same UID will be consistently routed to the same service instance, thereby significantly improving the hit rate of the local cache, reducing calls to external interfaces, and improving the stability and efficiency of request processing. The following is a detailed explanation:
[0041] Figure 2 The flowchart of a request processing method provided by the embodiment of the present disclosure is as follows. The method can be applied to a proxy gateway, which can be a computer, a server, etc., without limitation. Figure 2 As shown, the method mainly includes the following steps S202 to S206:
[0042] Step S202: receiving a service request sent by a requester, and obtaining a user identifier based on the service request.
[0043] In the embodiments of the present disclosure, the requesting party can be understood as an application, a front-end web page, etc., and the user can send a service request based on the application, the front-end web page, etc. according to actual usage needs. For example, when a user accesses an application, he needs to watch a video of the application and needs to send a request service to play the video through the application.
[0044] In the embodiment of the present disclosure, the user identifier can uniquely identify a user. When a service request is sent based on the requesting party, the service request includes the user identifier, and the user identifier can be obtained by parsing the service request.
[0045] Step S204: determining a target service instance based on the user identifier and the service instance information of the distributed cluster.
[0046] In the disclosed embodiment, the service instance information includes the total number of current service instances in the distributed cluster, that is, the number of service instances currently deployed in the distributed cluster; a service instance identifier that can uniquely identify a service instance, etc., which is selected and set according to the actual application scenario; a service instance can be understood as a server node in a distributed cluster, and the distributed cluster includes multiple service instances, and the target service instance is a specific service instance among the multiple service instances.
[0047] In the embodiments of the present disclosure, there are many ways to determine the target service instance based on the user identifier and the service instance information of the distributed cluster. As an example, the number of service instances in the distributed cluster usually does not change. The user identifier and the current total number of service instances of the distributed cluster can be hashed based on a preset hash algorithm to obtain the target service instance identifier, and the service instance corresponding to the target service instance identifier in the distributed cluster is used as the target service instance.
[0048] As another example, service instances in a distributed cluster often change, such as adding online service instances or taking some service instances offline, etc. The user identifier is hashed based on a preset hash algorithm to obtain a user hash value, and the user hash value is mapped to a target hash space including a service instance hash position corresponding to each service instance to obtain the user hash position. The target service instance hash position in the target hash space is obtained based on the user hash position and the preset query direction, and the service instance corresponding to the target service instance hash position is used as the target service instance.
[0049] As another example, a service instance frequently accessed by the user identification may be determined as the target service instance based on the historical service request volume and historical access service instances corresponding to the user identification.
[0050] The above three methods are only examples of determining the target service instance based on the user identifier and the service instance information of the distributed cluster. The embodiments of the present disclosure do not specifically limit the method of determining the target service instance based on the user identifier and the service instance information of the distributed cluster.
[0051] Step S206: forward the service request to the target service instance, receive the request result of the target service instance responding to the service request based on the locally cached data, and forward the request result to the requester.
[0052] In an embodiment of the present disclosure, when the service request is the first request, the request result is that the target service instance obtains data from an external system based on an external interface in response to the service request, wherein the target service instance caches the data obtained from the external system locally and sets the data cache time based on the request frequency of the service request.
[0053] That is to say, when the target service instance responds to the service request of the user ID for the first time, it needs to cache the data obtained from the external system locally. In order to further improve data processing efficiency and stability, it is also necessary to set the data cache time. In order to further meet user needs, the data cache time can be updated in real time based on the request frequency of the user ID, such as how many service requests are sent in an hour.
[0054] In the disclosed embodiment, when the target service instance receives a service request based on the user identifier of the proxy gateway again, it can respond to the service request based on the locally cached data to obtain the request result and send it to the proxy gateway, and the proxy gateway forwards the request result to the requester.
[0055] That is to say, within the data cache time, that is, as long as the target service instance has locally cached data, the service request can be responded to based on the locally cached data to obtain the request result and send it to the proxy gateway, thereby improving data processing efficiency.
[0056] For ease of understanding, reference can also be made to the embodiments of the present disclosure. Figure 3 A request processing flow diagram shown in FIG. 1 takes the user identifier and the total number of current service instances of the distributed cluster as an example to determine the target service instance. Compared with Figure 1 The embodiment of the present disclosure introduces a UID routing strategy at the proxy gateway layer, that is, a target service instance is determined by performing a hash calculation based on a hash algorithm according to a user identifier and the total number of current service instances, so that service requests with the same UID are fixedly routed to the target service instance, thereby greatly improving the hit rate of the local cache of the service instance and reducing the number of external interface calls.
[0057] Specifically, Figure 3 As shown, a proxy gateway is added between the requester and the distributed cluster. The request processing method of the embodiment of the present disclosure is applied to the proxy gateway. When receiving a service request, the proxy gateway obtains a user identifier, such as Figure 3 For a service request with UID "123456", the target service instance is determined by performing a hash calculation based on the UID "123456" and the total number of current service instances. For example, Figure 3Instance 2 in the example, so that any service request with UID "123456" is routed to instance 2 through the proxy gateway for response. Therefore, the data cached in instance 2 can respond to multiple service requests with UID "123456", improve the local cache hit rate and reduce the number of external interface calls.
[0058] In this way, multiple service requests for the same user ID can be routed to the same service instance, which greatly improves the hit rate of the local cache of the service instance, thereby reducing the number of external interface calls, reducing the distributed system's dependence on external resources and the resource consumption and cost of the distributed system during operation, improving the performance and stability of the distributed system while reducing operation and maintenance costs, and reducing repeated external interface calls when processing a large number of service requests, effectively reducing the time and resource consumption of request processing, and improving request processing efficiency.
[0059] In some embodiments, the target service instance is determined based on the user identifier and the service instance information of the distributed cluster, including: performing a hash calculation on the user identifier and the total number of current service instances of the distributed cluster based on a preset hash algorithm to obtain the target service instance identifier, and taking the service instance corresponding to the target service instance identifier in the distributed cluster as the target service instance.
[0060] In the embodiments of the present disclosure, the hash algorithm may be selected and set according to the actual application, such as SHA-1, MD5 and other hash functions.
[0061] In an embodiment of the present disclosure, the current total number of service instances refers to the number of service instances in the distributed cluster that can currently respond to service requests. As an example, after the service instances are deployed in the distributed cluster, a message can be sent to the proxy gateway so that the proxy gateway obtains the number of all deployed service instances in the distributed cluster; as another example, the distributed cluster is monitored at a preset frequency to obtain the current total number of service instances; as another example, heartbeat messages are sent between the proxy gateway and the service instances to determine the total number of all currently online service instances, that is, the current total number of service instances.
[0062] In the embodiment of the present disclosure, the target service instance identifier can uniquely identify a target service instance, and in this way, multiple service requests of the user identifier can be routed to the target service instance for response.
[0063] Specifically, the proxy gateway obtains the current total number of service instances in the distributed cluster, for example, there are currently 100 service instances; the user identifier UID is hashed modulo and allocated according to the current total number of service instances, for example, the UID is hashed as "UID.hashCode()%100", thereby ensuring that service requests with the same UID are routed to fixed service instances. For example, service requests with UID "803803123" are always routed to the server with service instance number 23.
[0064] Specifically, the UID routing strategy is implemented through the proxy gateway to ensure that the same UID is routed to the same service instance. In other words, the user's first service request will call the external system and then cache the data locally in the service instance. If the UID is accessed multiple times before the cached data expires, the external system will not be called again. This improves the cache hit rate and reduces the number of interface calls to the external system. Figure 3 As shown, if the service request with UID "123456" is routed to instance 2 by the proxy gateway, and the data of the interface of the external system is requested for local cache, if the user sends service requests multiple times, the relevant data is directly taken from the cache of instance 2 to respond to the service request, without obtaining the data of the external system from the interface.
[0065] In the above embodiment, the problem of low cache hit rate caused by random distribution of service requests for the same UID to different service instances is solved. The UID is hashed and modulo assigned by the proxy gateway according to the total number of current service instances, so that service requests for the same UID are fixedly routed to a specific service instance, thereby greatly improving the hit rate of the local cache of the service instance and reducing the number of external interface calls.
[0066] Based on the above description, if the total number of current service instances changes, there may still be a situation where service requests for the same UID are routed to different service instances. That is to say, the service instances in the distributed cluster may store elastic situations such as going online and offline, which may lead to changes in routing policies and scenarios where a large number of caches are invalidated. That is, when new service instances are added or existing service instances are removed, the aforementioned hash modulo algorithm usually causes a large amount of data to need to be redistributed. For example, the current total number of service instances is N, where N is a positive integer, and is mapped to one of the N service instances through the hash algorithm "hash(UID)%N". When the current total number of service instances N changes, the hash modulo calculation results of most data will also change, and most of the data will need to be redistributed to the new service instances, resulting in a large amount of data migration.
[0067] For example, Figure 4As shown, suppose there is a distributed cluster, the initial number of service instances is 2 (ie N = 2), for example, the hash value calculation result of a user ID is 15, that is, "hash (UID) = 15", and then "hash (UID) % 2" is calculated, that is, "15% 2 = 1", then the service request of the user ID will be routed to instance 1; when the distributed cluster needs to add a service instance, so that the total number of current service instances becomes 3 (ie N = 3), the same hash value 15 will recalculate the new instance distribution "15% 2 = 0". In this way, the service request of the user ID will be routed to instance 0.
[0068] That is, when the total number of current service instances changes, the hash modulo results of almost all user identifiers will change, resulting in a significant drop in the cache hit rate when the service instances change.
[0069] In order to ensure the hit rate of the local cache of the service instance and reduce the number of external interface calls, in some embodiments, the target service instance is determined based on the user identifier and the service instance information of the distributed cluster, including: obtaining a target hash space corresponding to the service instance identifier of the distributed cluster, performing a hash calculation on the user identifier based on a preset hash algorithm to obtain a user hash value, and mapping the user hash value to the target hash space to obtain a user hash position, determining the target service instance hash position in the target hash space based on the user hash position and a preset query direction, and using the service instance corresponding to the target service instance hash position as the target service instance.
[0070] In some embodiments, the method also includes: obtaining a service instance identifier for each service instance in the distributed cluster, and performing a hash calculation on the service instance identifier based on a hash algorithm to obtain a service instance hash value for each service instance, mapping the service instance hash value for each service instance to a pre-built initial hash space to obtain a target hash space including the service instance hash position corresponding to each service instance.
[0071] In the embodiment of the present disclosure, the initial hash space is preset to be constructed, that is, the entire initial hash space (usually a fixed range, such as 0 to 2 ^ 32-1) is organized into a virtual ring. The starting point and the end point of the initial hash space are connected to form a ring structure, such as Figure 5 As shown in the figure, the range can be adjusted according to the number of service instances. For example, if there are many service instances, 2 ^ 32-1 adjusted to 2 ^ 64-1, etc., select the setting according to the application scenario.
[0072] In the embodiment of the present disclosure, after constructing the initial hash space, it is necessary to obtain the service instance identifier of each service instance for hash calculation to obtain the service instance hash value of each service instance, map the service instance hash value of each service instance to the initial hash space, and obtain the target hash space including the service instance hash position corresponding to each service instance. That is, each service instance is mapped to the initial hash space through a certain hash function (such as SHA-1, MD5, etc.). Figure 5 The position of a point on the hash ring shown in FIG. 1 can also be called the service instance hash position, such as Figure 6 The example 1, example 2 and example 3 shown in the figure respectively represent the example 1, example 2 and example 3 in the target hash space ( Figure 6 The corresponding service instance hash position on the hash ring shown in FIG.
[0073] In the embodiment of the present disclosure, the service instance identifier of the distributed cluster has a corresponding target hash space, that is, the target hash space of different distributed clusters is different. After obtaining the target hash space corresponding to the service instance identifier of the distributed cluster, the user identifier is hashed by the same hash algorithm to obtain the user hash value, and the user hash value is mapped to the target hash space to obtain the user hash position. That is to say, the UID is mapped to a point on the hash ring through the same hash function, which is called the user hash position, such as Figure 7 The user identifier K1, user identifier K2 and user identifier K3 shown in the figure respectively represent the user identifier K1, user identifier K2 and user identifier K3 in the target hash space ( Figure 7 The corresponding user hash position on the hash ring shown.
[0074] In the disclosed embodiment, the query direction is preset, which can be either clockwise or counterclockwise, so as to determine the target service instance hash position in the target hash space based on the user hash position and the preset query direction, and use the service instance corresponding to the target service instance hash position as the target service instance. For example, by searching for the nearest service instance in a clockwise direction, the UID is assigned to the corresponding service instance. That is, each UID is processed by the first service instance in the clockwise direction that is greater than the current user hash value. Figure 7 As shown, instance 1 is responsible for processing the service request of user identifier K1, instance 2 is responsible for processing the service request of user identifier K2, and instance 3 is responsible for processing the service request of user identifier K3.
[0075] In the above embodiment, when the total number of current service instances changes, multiple service requests of the same user identifier can still be routed to the same service instance, ensuring the hit rate of the local cache of the service instance and reducing the number of external interface calls. This is suitable for dynamic addition and deletion of service instances and can effectively solve the problem of low local cache hit rate when the distributed system is expanded or reduced in capacity.
[0076] In some embodiments, the method also includes: obtaining instance update information of the distributed cluster, determining to add a service instance based on the instance update information, and calculating the added service instance hash value of the added service instance and mapping it to the target hash space to obtain the added service instance hash position, determining the shared service instance hash position based on the added service instance hash position and the query direction, and using the service instance corresponding to the shared service instance hash position as the shared service instance of the added service instance.
[0077] In some embodiments, the method also includes: determining the deleted service instance based on the instance update information, and determining the deleted service instance hash position on the target hash space corresponding to the deleted service instance, determining the candidate service instance hash position based on the deleted service instance hash position and the query direction, and using the service instance corresponding to the candidate service instance hash position as a candidate service instance for the deleted service instance.
[0078] In the embodiments of the present disclosure, whether adding or deleting a service instance in a distributed cluster, the proxy gateway can obtain instance update information, such as receiving a mentality message sent by the service instance or monitoring each service instance, so that the proxy gateway can obtain the addition of service instances and / or deletion of service instances.
[0079] In the embodiment of the present disclosure, after obtaining the added service instance, the added service instance hash value of the added service instance is calculated and mapped to the target hash space to obtain the added service instance hash position, and then the shared service instance hash position is determined according to the query direction, and the service instance corresponding to the shared service instance hash position is used as the shared service instance of the added service instance, for example Figure 8 The added service instance is instance 4, so the service instance corresponding to the hash position of the shared service instance is determined in a clockwise direction as instance 2 as the shared service instance of instance 4, that is, instance 2 and instance 4 are jointly responsible for the service request of user identifier K2; for example, Figure 7 Instance 1 is deleted, and based on the hash position of instance 1 and the clockwise direction, the service instance corresponding to the hash position of the candidate service instance is determined to be instance 2 as the candidate service instance for deleting the service instance, that is, instance 2 will be responsible for the service requests of user identifier K1 and user identifier K2.
[0080] In the disclosed embodiment, when a new service instance is added, the position of the instance in the target hash space is determined, and the new service instance only needs to take over a portion of the data of a service instance in the query direction, such as clockwise, while the data distribution of other service instances remains unchanged, thereby reducing the amount of data reallocation; when a service instance is removed, the data borne by the service instance is transferred to the next service instance in the query direction, such as clockwise, while the data distribution of other service instances remains unchanged, and the amount of cache failure is also very small.
[0081] In the above embodiment, when the distributed system is expanded or reduced in capacity, it can still route multiple service requests of the same user identifier to the same service instance, thereby ensuring the hit rate of the local cache of the service instance and further improving the data processing efficiency and effect.
[0082] Based on the above description of the embodiment, Figure 8 As shown in the figure, after adding instance 4, instance 2 and instance 4 respectively bear the traffic of the original instance 2. Then the traffic of these two instances is halved compared with that of instance 1 and instance 3, resulting in load imbalance.
[0083] In order to further balance the load, in some embodiments, the method also includes: configuring each service instance in the distributed cluster to correspond to multiple virtual service instances, and obtaining a virtual service instance identifier of each virtual service instance, performing hash calculation on the virtual service instance identifier based on a hash algorithm to obtain a virtual service instance hash value of each virtual service instance, mapping the virtual service instance hash value of each virtual service instance to the target hash space, and obtaining the virtual service instance hash position corresponding to each virtual service instance in the target hash space.
[0084] In some embodiments, the target service instance hash position is determined in the target hash space based on the user hash position and a preset query direction, and the service instance corresponding to the target service instance hash position is used as the target service instance, including: determining the target virtual service instance hash position from all the virtual service instance hash positions based on the user hash position and the query direction, and obtaining the target virtual service instance corresponding to the target virtual service instance hash position, and using the service instance to which the target virtual service instance belongs as the target service instance.
[0085] In the disclosed embodiment, each service instance (physical instance) may correspond to multiple virtual service instances, so that each service instance will correspond to multiple hash positions on the hash ring (target hash space). The virtual service instance can achieve a load balancing effect when the actual service instances are unevenly distributed.
[0086] Specifically, each service instance in the distributed cluster is configured to correspond to multiple virtual service instances. For example, if there are three service instances A, B, and C, each service instance is configured to correspond to three virtual service instances: service instance A has virtual service instances A1, A2, and A3; service instance B has virtual service instances B1, B2, and B3; and service instance C has virtual service instances C1, C2, and C3. The virtual service instances calculate different virtual service instance hash positions through hash functions, and these virtual service instance hash positions are scattered throughout the hash ring (target hash space).
[0087] Specifically, based on the user hash position and the query direction, the target virtual service instance hash position is determined from all virtual service instance hash positions, and the target virtual service instance corresponding to the target virtual service instance hash position is obtained, and the service instance to which the target virtual service instance belongs is used as the target service instance. For example, when the user identifier K1 is written, the user hash position of the user identifier K1 in the target hash space is calculated by a hash function, and then the nearest target virtual service instance hash position is found according to the query direction, for example, in a clockwise direction. If the target virtual service instance A2 corresponding to the target virtual service instance hash position is found, the service instance A to which the target virtual service instance A2 belongs is used as the target service instance, and the service request of the user identifier K1 will be assigned to service instance A for processing.
[0088] For example, Fig. 9 As shown in the figure, the positions of the virtual service instances corresponding to the three service instances A, B and C in the target hash space (hash ring) are as follows: Fig. 9 As shown, for example, when service instance A is deleted, virtual service instances A1, A2, and A3 are unavailable. At this time, the service requests corresponding to the original virtual service instances A1, A2, and A3 can be transferred to virtual service instances B1, B2, and B3 and / or virtual service instances C1, C2, and C3 according to the query direction, for example, in a clockwise direction. It can be seen that the changes in the virtual service instances in the target hash space are relatively small, and only the service requests need to be redistributed within a small range.
[0089] In the above embodiment, when service instances (physical instances) increase or decrease, the changes in individual virtual service instances in the target hash space will only affect the distribution of service requests within a corresponding small range, and will not cause a large amount of data to be re-routed, thereby further improving the stability of the system and the request processing effect.
[0090] In some embodiments, the method also includes: obtaining historical service request volumes and historical access service instances within a historical time period, analyzing the historical service request volumes and historical access service instances based on a preset machine learning algorithm, and adjusting the hash algorithm and / or initial hash space based on the analysis results.
[0091] In the embodiments of the present disclosure, the historical request volume refers to the total number of requests for each user identifier UID within a historical time period. By analyzing the historical request volume, it is possible to identify which UIDs have higher request frequencies and which UIDs have lower request frequencies. Historical access to service instances can be understood as recording the service instances to which each UID was routed in the past, as well as the cache hit rates and performance of these service instances, so as to analyze whether certain UIDs are more likely to hit the cache on certain service instances, or whether certain service instances process service requests from certain UIDs more efficiently, etc.
[0092] In the embodiments of the present disclosure, the machine learning algorithm may be a linear regression algorithm, a support vector machine algorithm, etc., and may be selected and set according to actual application needs.
[0093] In the disclosed embodiments, the machine learning algorithm can predict future access patterns based on historical data, and make smarter decisions on the adjustment of the hash algorithm or the initial hash space; that is, by analyzing the historical request volume and the historical access service instances, the routing strategy of each UID can be adjusted in real time so that it can be more accurately allocated to the appropriate service instance, thereby maximizing the cache hit rate and reducing the number of external interface calls.
[0094] In some embodiments, real-time load information can also be obtained, that is, the current load status of each service instance, such as CPU usage, memory usage, network traffic, number of concurrent requests, etc., so that it can be determined whether the service request needs to be reallocated to a service instance with lower load based on the real-time load information.
[0095] In some embodiments, real-time request volume can also be obtained, that is, the current service request volume changes can be analyzed, especially during peak hours, to avoid overloading of certain service instances by dynamically adjusting the UID routing strategy.
[0096] In an embodiment of the present disclosure, historical service request volumes and historical access service instances are analyzed based on a preset machine learning algorithm, and the hash algorithm and / or the initial hash space are adjusted based on the analysis results. For example, if a service instance exhibits a higher cache hit rate in historically processing certain UIDs, then the probability of these UIDs being assigned to the service instance can be increased; in addition, if a service instance performs poorly in certain circumstances (such as excessive load), the probability of being assigned to the service instance can be temporarily reduced.
[0097] In the disclosed embodiment, the distribution density of UIDs among service instances is controlled by adjusting the size of the hash space; for example, when the number of service instances increases, the hash space can be appropriately expanded to reduce hash conflicts and further optimize routing accuracy.
[0098] It should be noted that historical data such as historical service request volume and historical access service instances are mainly used for analysis and modeling to understand access patterns and instance performance over a long period of time and help optimize the overall routing strategy; real-time data such as real-time load information and real-time request volume are mainly used for dynamic adjustment and real-time optimization to ensure load balance and efficient processing at a specific point in time. Generally, historical data is suitable for long-term trend analysis, while real-time data is suitable for immediate load balancing and optimization.
[0099] In the above embodiment, the routing strategy of the UID is dynamically adjusted according to historical access data and real-time load conditions through a machine learning algorithm, thereby further improving routing accuracy and cache hit rate.
[0100] In some embodiments, when the service request is the first request, the request result is that the target service instance obtains data from the external system based on the external interface in response to the service request; wherein, the target service instance caches the data obtained from the external system locally and sets the data cache time based on the request frequency of the service request.
[0101] Specifically, when the target service instance responds to the service request of the user identifier for the first time, it needs to cache the data obtained from the external system locally. In order to further improve data processing efficiency and stability, it is also necessary to set the data cache time. In order to further meet user needs, the data cache time can be updated in real time based on the request frequency of the user identifier, such as how many service requests are sent in an hour.
[0102] In the above embodiment, the expiration time of the cache is dynamically adjusted according to the access frequency and change of the data to optimize the utilization efficiency of the cache.
[0103] Fig.10 The present invention provides a flowchart of a request processing method, which mainly includes the following steps S1002 to S1008:
[0104] Step S1002: receiving a service request sent by a requester, and obtaining a user identifier based on the service request.
[0105] Step S1004: performing hash calculation on the user identifier and the total number of current service instances of the distributed cluster based on a preset hash algorithm to obtain a target service instance identifier.
[0106] Step S1006: taking the service instance corresponding to the target service instance identifier in the distributed cluster as the target service instance.
[0107] Step S1008: forwarding the service request to the target service instance, receiving the request result of the target service instance responding to the service request based on the locally cached data, and forwarding the request result to the requester.
[0108] In the disclosed embodiment, the user can send a service request based on an application, a front-end web page, etc. according to actual usage needs, obtain the current total number of service instances in the distributed cluster at the proxy gateway, hash the user identifier UID according to the current total number of service instances to calculate the target service instance identifier, and use the service instance corresponding to the target service instance identifier in the distributed cluster as the target service instance. When the target service instance responds to the service request of the user identifier for the first time, it needs to cache the data obtained from the external system locally. When the target service instance receives a service request based on the user identifier of the proxy gateway again, it can respond to the service request based on the locally cached data to obtain the request result and send it to the proxy gateway, and the proxy gateway forwards the request result to the requesting party.
[0109] Therefore, the UID is hashed and modulo-assigned on the proxy gateway side, so that service requests with the same UID are fixedly routed to a specific service instance, thereby improving the cache hit rate and reducing the number of calls to the external interface.
[0110] Fig.11 The present invention provides a flowchart of a request processing method provided in an embodiment of the present invention. The method mainly includes the following steps S1102 to S1108:
[0111] Step S1102: receiving a service request sent by a requester, and obtaining a user identifier based on the service request.
[0112] Step 1104, obtain the target hash space corresponding to the service instance identifier of the distributed cluster, perform hash calculation on the user identifier based on a preset hash algorithm to obtain a user hash value, and map the user hash value to the target hash space to obtain a user hash position.
[0113] Step 1106, determining the target service instance hash position in the target hash space based on the user hash position and the preset query direction, and taking the service instance corresponding to the target service instance hash position as the target service instance.
[0114] Step 1108: forward the service request to the target service instance, receive the request result of the target service instance responding to the service request based on the locally cached data, and forward the request result to the requester.
[0115] In an embodiment of the present disclosure, a service instance identifier of each service instance in a distributed cluster is obtained, and a hash calculation is performed on the service instance identifier based on a hash algorithm to obtain a service instance hash value of each service instance, and the service instance hash value of each service instance is mapped to a pre-built initial hash space to obtain a target hash space including the service instance hash position corresponding to each service instance.
[0116] In the disclosed embodiment, a user can send a service request based on an application, a front-end web page, etc. according to actual usage needs. After obtaining the target hash space corresponding to the service instance identifier of the distributed cluster, the user identifier is hashed through the same hash algorithm to obtain the user hash value, and the user hash value is mapped to the target hash space to obtain the user hash position.
[0117] In the embodiment of the present disclosure, a query direction is pre-set, which can be either clockwise or counterclockwise, so that the target service instance hash position is determined in the target hash space based on the user hash position and the preset query direction, and the service instance corresponding to the target service instance hash position is used as the target service instance. When the target service instance responds to the service request identified by the user for the first time, the data obtained from the external system needs to be cached locally. When the target service instance receives a service request based on the user identifier of the proxy gateway again, it can respond to the service request based on the locally cached data to obtain the request result and send it to the proxy gateway, and the proxy gateway forwards the request result to the requester.
[0118] Therefore, a consistent hashing algorithm is used to solve the cache invalidation problem caused by dynamic adjustment of the number of instances, further improving system performance and stability. That is to say, when the number of instances is dynamically adjusted, only the affected service requests are remapped to avoid large-scale cache invalidation and maintain the validity of most cached data.
[0119] In summary, the service request method in the embodiment of the present invention can significantly improve the overall performance and stability of the distributed system by improving the local cache hit rate and reducing the number of external interface calls, reduce the system's dependence on external resources, reduce the system's response delay and failure risk, and improve user experience and service availability; in addition, the improvement in cache hit rate means fewer external interface calls, which reduces resource consumption and costs during system operation; at the same time, by optimizing load balancing and cache management, the complexity and cost of system operation and maintenance are reduced, and the maintainability and management efficiency of the system are improved; and when processing a large number of user requests, repeated external interface calls are reduced, which effectively reduces data processing time and resource consumption, optimizes the system's data access path, speeds up data response speed, and improves the system's processing efficiency and throughput.
[0120] Corresponding to the aforementioned request processing method, the embodiment of the present disclosure further provides a request processing device, Fig.12 This is a schematic diagram of the structure of a request processing device provided in an embodiment of the present disclosure. The device can be implemented by software and / or hardware and is applied to a proxy gateway. The device includes:
[0121] The receiving and obtaining module 1202 is used to receive a service request sent by a requester and obtain a user identifier based on the service request;
[0122] A determination module 1204, configured to determine a target service instance based on the user identifier and the service instance information of the distributed cluster;
[0123] The processing module 1206 is used to forward the service request to the target service instance, receive the request result of the target service instance responding to the service request based on the locally cached data, and forward the request result to the requester.
[0124] The above-mentioned device provided by the embodiment of the present disclosure can route multiple service requests of the same user identifier to the same service instance, thereby greatly improving the hit rate of the local cache of the service instance, thereby reducing the number of external interface calls, reducing the dependence of the distributed system on external resources and the resource consumption and cost during the operation of the distributed system, improving the performance and stability of the distributed system while reducing operation and maintenance costs, and when processing a large number of service requests, reducing repeated external interface calls, effectively reducing the time and resource consumption of request processing, and improving request processing efficiency.
[0125] In some embodiments, the determination module 1204 is specifically used to: perform hash calculation on the user identifier and the total number of current service instances of the distributed cluster based on a preset hash algorithm to obtain a target service instance identifier; and use the service instance corresponding to the target service instance identifier in the distributed cluster as the target service instance.
[0126] In some embodiments, the determination module 1204 includes: a first acquisition unit, used to acquire a target hash space corresponding to the service instance identifier of the distributed cluster; a calculation mapping unit, used to perform hash calculation on the user identifier based on a preset hash algorithm to obtain a user hash value, and map the user hash value to the target hash space to obtain a user hash position; a query unit, used to determine the target service instance hash position in the target hash space based on the user hash position and a preset query direction, and use the service instance corresponding to the target service instance hash position as the target service instance.
[0127] In some embodiments, the device also includes: an acquisition calculation unit, used to obtain the service instance identifier of each service instance in the distributed cluster, and perform hash calculation on the service instance identifier based on the hash algorithm to obtain the service instance hash value of each service instance; a first mapping unit, used to map the service instance hash value of each service instance to a pre-constructed initial hash space to obtain the target hash space including the service instance hash position corresponding to each service instance.
[0128] In some embodiments, the device also includes: a second acquisition unit, used to acquire instance update information of the distributed cluster; a determination calculation unit, used to determine to add a service instance based on the instance update information, and calculate the added service instance hash value of the added service instance and map it to the target hash space to obtain the added service instance hash position; a first determination unit, used to determine the shared service instance hash position based on the added service instance hash position and the query direction, and use the service instance corresponding to the shared service instance hash position as the shared service instance of the added service instance.
[0129] In some embodiments, the device also includes: a third acquisition unit, used to determine the deleted service instance based on the instance update information, and determine the deleted service instance hash position on the target hash space corresponding to the deleted service instance; a second determination unit, used to determine the candidate service instance hash position based on the deleted service instance hash position and the query direction, and the service instance corresponding to the candidate service instance hash position is used as a candidate service instance of the deleted service instance.
[0130] In some embodiments, the device also includes: a configuration unit, configured to configure each service instance in the distributed cluster to correspond to multiple virtual service instances, and obtain a virtual service instance identifier of each virtual service instance; a calculation unit, used to perform hash calculation on the virtual service instance identifier based on the hash algorithm to obtain a virtual service instance hash value of each virtual service instance; a second mapping unit, used to map the virtual service instance hash value of each virtual service instance to the target hash space to obtain a virtual service instance hash position corresponding to each virtual service instance in the target hash space; the query unit, specifically used to: determine the target virtual service instance hash position from all the virtual service instance hash positions based on the user hash position and the query direction, and obtain the target virtual service instance corresponding to the target virtual service instance hash position, and use the service instance to which the target virtual service instance belongs as the target service instance.
[0131] In some embodiments, the device also includes: a data acquisition module for acquiring historical service request volumes and historical access service instances within a historical time period; an analysis and adjustment module for analyzing the historical service request volumes and the historical access service instances based on a preset machine learning algorithm, and adjusting the hash algorithm and / or the initial hash space based on the analysis results.
[0132] In some embodiments, when the service request is the first request, the request result is that the target service instance obtains data from an external system based on an external interface in response to the service request; wherein, the target service instance caches the data obtained from the external system locally and sets the data cache time based on the request frequency of the service request.
[0133] The request processing device provided in the embodiments of the present disclosure can execute the request processing method provided in any embodiment of the present disclosure, and has the corresponding functional modules and beneficial effects of the execution method.
[0134] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the above-described device embodiment can refer to the corresponding process in the method embodiment, and will not be repeated here.
[0135] An embodiment of the present disclosure provides an electronic device, which includes: a storage device on which a computer program is stored; and a processing device for executing the computer program in the storage device to implement the steps of any method in the present disclosure.
[0136] Reference below Fig.13 , which shows a schematic diagram of the structure of an electronic device 1300 suitable for implementing the embodiment of the present disclosure. The terminal device in the embodiment of the present disclosure may include but is not limited to mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), vehicle terminals (such as vehicle navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Fig.13 The electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.
[0137] like Fig.13 As shown, the electronic device 1300 may include a processing device 1301 (e.g., a central processing unit, a graphics processor, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 1302 or a program loaded from a storage device 1308 into a random access memory (RAM) 1303. In the RAM 1303, various programs and data required for the operation of the electronic device 1300 are also stored. The processing device 1301, the ROM 1302, and the RAM 1303 are connected to each other via a bus 1304. An input / output (I / O) interface 1305 is also connected to the bus 1304.
[0138] Typically, the following devices may be connected to the I / O interface 1305: an input device 1306 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 1307 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 1308 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1309. The communication device 1309 may allow the electronic device 1300 to communicate with other devices wirelessly or by wire to exchange data. Although Fig.13 The electronic device 1300 is shown with various devices, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead.
[0139] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a non-transitory computer-readable medium, and the computer program contains program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication device 1309, or installed from the storage device 1308, or installed from the ROM 1302. When the computer program is executed by the processing device 1301, the above-mentioned functions defined in the method of the embodiment of the present disclosure are executed.
[0140] In addition to the above-mentioned methods and devices, the embodiments of the present disclosure may also be a computer program product, which includes computer program instructions, which, when executed by a processor, cause the processor to perform the image processing method provided by the embodiments of the present disclosure. The computer program product may be written in any combination of one or more programming languages to write program codes for performing the operations of the embodiments of the present disclosure, the programming languages including object-oriented programming languages such as Java, C++, etc., and also conventional procedural programming languages such as "C" language or similar programming languages. The program code may be executed entirely on a user computing device, partially on a user device, as an independent software package, partially on a user computing device and partially on a remote computing device, or entirely on a remote computing device or server.
[0141] In addition, the embodiment of the present disclosure may also be a computer-readable storage medium on which computer program instructions are stored. When the computer program instructions are executed by a processor, the processor executes the request processing method provided by the embodiment of the present disclosure.
[0142] The computer readable storage medium can adopt any combination of one or more readable media. The readable medium can be a readable signal medium or a readable storage medium. The readable storage medium can include, for example, but is not limited to, a system, device or device of electricity, magnetism, light, electromagnetic, infrared, or semiconductor, or any combination of the above. More specific examples (non-exhaustive list) of readable storage media include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.
[0143] The embodiments of the present disclosure also provide a computer program product, including a computer program / instruction, which implements the request processing method in the embodiments of the present disclosure when executed by a processor.
[0144] It is understandable that before using the technical solutions disclosed in the various embodiments of the present disclosure, the types, scope of use, usage scenarios, etc. of the personal information involved in the present disclosure should be informed to the user and the user's authorization should be obtained in an appropriate manner in accordance with relevant laws and regulations.
[0145] For example, in response to receiving an active request from a user, a prompt message is sent to the user to clearly prompt the user that the operation requested to be performed will require obtaining and using the user's personal information. Thus, the user can autonomously choose whether to provide personal information to software or hardware such as an electronic device, application, server, or storage medium that performs the operation of the technical solution of the present disclosure according to the prompt message.
[0146] As an optional but non-limiting implementation, in response to receiving an active request from the user, the prompt information may be sent to the user in the form of a pop-up window, in which the prompt information may be presented in text form. In addition, the pop-up window may also carry a selection control for the user to choose "agree" or "disagree" to provide personal information to the electronic device.
[0147] It is understandable that the above notification and the process of obtaining user authorization are merely illustrative and do not constitute a limitation on the implementation of the present disclosure. Other methods that meet relevant laws and regulations may also be applied to the implementation of the present disclosure.
[0148] It should be noted that, in this article, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0149] The above description is only a specific embodiment of the present disclosure, so that those skilled in the art can understand or implement the present disclosure. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present disclosure. Therefore, the present disclosure will not be limited to the embodiments described herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A request processing method, characterized in that: Applied to a proxy gateway, the method comprises: Receiving a service request sent by a requester, and obtaining a user identifier based on the service request; Determine a target service instance based on the user identifier and service instance information of the distributed cluster; The service request is forwarded to the target service instance, and a request result of the target service instance responding to the service request based on the locally cached data is received, and the request result is forwarded to the requester.
2. The method according to claim 1, characterized in that The determining the target service instance based on the user identifier and the service instance information of the distributed cluster includes: Performing a hash calculation on the user identifier and the total number of current service instances of the distributed cluster based on a preset hash algorithm to obtain a target service instance identifier; The service instance corresponding to the target service instance identifier in the distributed cluster is used as the target service instance.
3. The method according to claim 1, characterized in that The determining the target service instance based on the user identifier and the service instance information of the distributed cluster includes: Obtaining a target hash space corresponding to a service instance identifier of the distributed cluster; Performing hash calculation on the user identifier based on a preset hash algorithm to obtain a user hash value, and mapping the user hash value to the target hash space to obtain a user hash position; The target service instance hash position is determined in the target hash space based on the user hash position and the preset query direction, and the service instance corresponding to the target service instance hash position is used as the target service instance.
4. The method according to claim 3, characterized in that The method further comprises: Obtaining a service instance identifier of each service instance in the distributed cluster, and performing hash calculation on the service instance identifier based on the hash algorithm to obtain a service instance hash value of each service instance; The service instance hash value of each service instance is mapped to a pre-constructed initial hash space to obtain the target hash space including the service instance hash position corresponding to each service instance.
5. The method according to claim 4, characterized in that The method further comprises: Obtaining instance update information of the distributed cluster; Determine to add a service instance based on the instance update information, and calculate the added service instance hash value of the added service instance and map it to the target hash space to obtain the added service instance hash position; The shared service instance hash position is determined based on the added service instance hash position and the query direction, and the service instance corresponding to the shared service instance hash position is used as the shared service instance of the added service instance.
6. The method according to claim 4, characterized in that The method further comprises: Determine a deletion service instance based on the instance update information, and determine a deletion service instance hash position on the target hash space corresponding to the deletion service instance; A candidate service instance hash position is determined based on the deleted service instance hash position and the query direction, and a service instance corresponding to the candidate service instance hash position is used as a candidate service instance for the deleted service instance.
7. The method according to claim 4, characterized in that The method further comprises: Configuring each service instance in the distributed cluster to correspond to multiple virtual service instances, and obtaining a virtual service instance identifier of each virtual service instance; Performing hash calculation on the virtual service instance identifier based on the hash algorithm to obtain a virtual service instance hash value of each virtual service instance; Mapping the virtual service instance hash value of each virtual service instance to the target hash space to obtain a virtual service instance hash position corresponding to each virtual service instance in the target hash space; The determining the target service instance hash position in the target hash space based on the user hash position and the preset query direction, and taking the service instance corresponding to the target service instance hash position as the target service instance, includes: The target virtual service instance hash position is determined from all the virtual service instance hash positions based on the user hash position and the query direction, and the target virtual service instance corresponding to the target virtual service instance hash position is obtained, and the service instance to which the target virtual service instance belongs is used as the target service instance.
8. The method according to claim 4, characterized in that The method further comprises: Obtain the historical service request volume and historical access service instances within the historical time period; The historical service request volume and the historical access service instance are analyzed based on a preset machine learning algorithm, and the hash algorithm and / or the initial hash space are adjusted based on the analysis result.
9. The method according to claim 1, characterized in that: When the service request is the first request, the request result is that the target service instance obtains data from the external system based on the external interface in response to the service request; wherein, the target service instance caches the data obtained from the external system locally and sets the data cache time based on the request frequency of the service request.
10. A request processing device, characterized in that: Applied to a proxy gateway, the device comprises: A receiving and obtaining module, used for receiving a service request sent by a requester, and obtaining a user identifier based on the service request; A determination module, configured to determine a target service instance based on the user identifier and the service instance information of the distributed cluster; The processing module is used to forward the service request to the target service instance, receive the request result of the target service instance responding to the service request based on the locally cached data, and forward the request result to the requester.
11. An electronic device, characterized in that: The electronic device comprises: a storage device having a computer program stored thereon; A processing device, used to execute the computer program in the storage device to implement the steps of the request processing method described in any one of claims 1 to 9.
12. A computer-readable storage medium, characterized in that: The storage medium stores a computer program, and the computer program is used to execute the request processing method described in any one of claims 1 to 9.