[go: up one dir, main page]

WO2022111313A1 - Request processing method and micro-service system - Google Patents

Request processing method and micro-service system Download PDF

Info

Publication number
WO2022111313A1
WO2022111313A1 PCT/CN2021/130415 CN2021130415W WO2022111313A1 WO 2022111313 A1 WO2022111313 A1 WO 2022111313A1 CN 2021130415 W CN2021130415 W CN 2021130415W WO 2022111313 A1 WO2022111313 A1 WO 2022111313A1
Authority
WO
WIPO (PCT)
Prior art keywords
service instance
resource
identifier
service
request
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Ceased
Application number
PCT/CN2021/130415
Other languages
French (fr)
Chinese (zh)
Inventor
杨永坤
尹强
王和平
刘有
黄山
杨峙岳
邸帅
卢道和
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
WeBank Co Ltd
Original Assignee
WeBank Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by WeBank Co Ltd filed Critical WeBank Co Ltd
Publication of WO2022111313A1 publication Critical patent/WO2022111313A1/en
Anticipated expiration legal-status Critical
Ceased legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5027Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5027Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals
    • G06F9/505Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals considering the load
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/10Protocols in which an application is distributed across nodes in the network

Definitions

  • the embodiments of the present application relate to the field of financial technology (Fintech), and in particular, to a request processing method and a microservice system.
  • microservices when they are enabled, they will be registered with the registration center in the microservice system, such as Eureka. Through the allocation processing of the registration center, for any microservice, it can correspond to one or more service instances.
  • the client sends a service request to the microservice system
  • the name of the microservice to be requested is attached, and the gateway in the microservice system parses out the service instance corresponding to the microservice, and finally forwards the service request from the client to one of them randomly.
  • a service instance In the design of large-scale website architecture, in order to improve the service response speed when the microservice system responds to a large number of database access requests, the microservice system generally caches the data identified by the primary key in the database into each service instance, so that A stateless service can be provided.
  • the above method requires each service instance to pre-cache the full amount of data or hotspot data in the database.
  • the scale of the service instance cluster is large or the amount of data in the database is large, the redundancy cost is relatively high.
  • the present application provides a request processing method and a microservice system, which are used to respond to service requests in a simple, efficient, and low-cost manner.
  • an embodiment of the present application provides a request processing method, the method includes: a microservice system receives a first request that carries a first resource identifier sent by a first client; if the microservice system determines that the first request If the resource identifier does not carry the service instance identifier, a first service instance is allocated for the first request; the microservice system obtains the first service instance indicated by the first resource identifier from the database through the first service instance resource; the microservice system sends the first resource to the first client and caches the first resource in the first service instance; the microservice system according to the first service instance The first service instance identifier of the first resource identifier is updated to obtain the second resource identifier used to indicate the first resource.
  • the microservice system confirms whether the service instance identifier is carried by confirming the first resource identifier in the request sent by the client.
  • the microservice system can obtain the first resource indicated by the first resource identifier from the database through the service instance, and send it to the client and cache it in the service instance.
  • the microservice system can also The first resource identifier is updated, and the update process includes adding the identifier of the service instance, so that when the subsequent client requests the first resource, the service instance that has cached the first resource can directly access the service instance. respond.
  • the microservice system determines a service instance for a request for a resource, and the service instance caches the resource after obtaining the resource from the database, so that subsequent requests for the resource can reach the microservice system again.
  • the service instance can directly respond to the request, avoiding the need to cache all resources for each service instance in the microservice system, which greatly reduces the redundancy of the system.
  • the method further includes: if the microservice system determines that the first resource identifier carries a second service instance identifier, assigning the first request to the second service instance identifier A service instance; the microservice system sends the first resource indicated by the first resource identifier cached by the second service instance to the first client.
  • the microservice system in the process of confirming the first resource identifier by the microservice system, if it is confirmed that the identifier of the second service instance is carried in it, it means that the microservice system has passed the second service instance identifier before the first request enters the microservice system.
  • the service instance caches the first resource corresponding to the first request, and uses the second service instance identifier to update the first resource identifier, so the microservice system checks that the first resource identifier carries the second service instance identifier , the microservice system can directly forward the first request to the second service instance, and the second service instance uses the locally cached first resource corresponding to the first request to directly respond to the first request, thereby improving the response to the request. The efficiency of the response.
  • the first resource identifier further carries a third service instance identifier
  • the third service instance corresponding to the third service instance identifier is a backup service instance of the second service instance
  • the microservice system in the process of allocating a service instance that can serve the first request to the micro-service system, in addition to assigning a second service instance to it, it can also be assigned a third service instance (wherein the third service instance can be multiple), the third service instance is the backup service instance of the second service instance, so that before the microservice system prepares to allocate the first request to the second service instance, by determining whether the status of the second service instance is is available, that is, it is determined whether the second service instance is in a serviceable state, and when the microservice system determines that the second service instance is in an unavailable state, the microservice system can allocate the first request based on the identifier of the third service instance. to a third service instance to respond to the first request by the third service instance.
  • the third service instance is a service instance with better performance except the second service instance that is determined in advance based on the real-time and dynamic resources and load conditions of the service instance cluster and can serve the first request. Achieve the goal of high availability under the failure condition of the second service instance.
  • the method further includes: receiving, by the microservice system, a second request sent by a second client that carries the second resource identifier; the second client is obtained through a refresh mechanism the second resource identifier; the microservice system determines that the second resource identifier carries the first service instance identifier, and allocates the second request to the first service instance; the microservice The system sends the first resource cached by the first service instance to the second client.
  • the micro-service system can allocate a service instance that can serve the first request—the first service instance, and The identifier corresponding to the first resource is updated from the first resource identifier to the second resource identifier, so that if the subsequent client (ie the second client) requests the first resource corresponding to the first request again, that is, the second
  • the second request sent by the client to the microservice system carries the second resource identifier, and the second resource identifier is obtained by the second client through the refresh mechanism.
  • the microservice system can directly use the first service instance to request the second client terminal responds.
  • This method is based on the fact that the first resource has been cached in the first service instance in the microservice system, and the microservice system also updates the identifier of the first resource, that is, the relationship between the first resource and the first service instance is established. A binding/correspondence relationship, so that the microservice system can quickly respond to a request for the same resource (eg, the first resource) based on the first service instance.
  • the micro-service system updates the first resource identifier according to the first service instance identifier of the first service instance, and obtains a second resource identifier for indicating the first resource
  • the method includes: the micro-service system sequentially splices the first resource identifier and the first service instance identifier according to a set sequence, and obtains a second resource identifier for indicating the first resource.
  • the microservice system After the microservice system determines that the service instance that can serve it is the first service instance for the first request entering it for the first time, it can update the first resource identifier that identifies the first resource, such as splicing sequentially The first resource identifier and the first service instance identifier, so that the result after splicing can be the second resource identifier.
  • the second resource identifier is obtained by adding the first service instance identifier to the first resource identifier, that is, the binding/correspondence relationship between the first resource and the first service instance is established, which is convenient for the microservice system to After the second resource identifier is parsed, the first service instance can be quickly determined and the request can be forwarded.
  • the method before the obtaining the second resource identifier used to indicate the first resource, the method further includes: determining, by the micro-service system, a backup service instance of the first service instance; the micro-service system The service system sequentially splices the first resource identifier and the first service instance identifier according to the set order, and obtains the second resource identifier used to indicate the first resource, including: the micro-service system follows the set order in order The first resource identifier, the first service instance identifier and the standby service instance identifier of the standby service instance are spliced together to obtain a second resource identifier for indicating the first resource.
  • the micro-service system can not only determine the first service instance, but also determine the backup service instance of the first service instance (wherein the backup service instance The number can be multiple), so that when the first service instance is unavailable, the microservice system allocates the request to the standby service instance of the first service instance, so that the microservice system can determine the first service instance.
  • the first resource identifier is updated, the identifier of the standby service instance can be added to it, so that when the first service instance is unavailable, the microservice system can quickly allocate the request to the first service instance.
  • the backup service instance goes up to achieve the goal of high availability.
  • the micro-service system splices the first resource identifier, the first service instance identifier and the standby service instance identifier of the standby service instance in sequence according to the set order, and obtains an indicator for indicating
  • the second resource identifier of the first resource includes: the microservice system encrypts the first microservice instance identifier and the standby service instance identifier of the standby service instance to obtain encrypted information; The first resource identifier and the encrypted information are sequentially spliced in a certain order to obtain a second resource identifier for indicating the first resource.
  • the allocating the first service instance to the first request includes: for any service instance in the service instance cluster, the microservice system determines the available resources of the service instance and the Used load; according to the available resources and the used load, determine the idle degree of the service instance; the microservice system determines the service instance whose idle degree meets the set condition as the first service instance.
  • the micro-service system allocates a first service instance to the request if it determines that it does not carry a service instance identifier for the first request that enters it.
  • the allocation process can be based on real-time, dynamic resource and
  • the idle degree of each service instance is determined according to the load situation, so that the service instance whose idle degree satisfies the set condition can be determined as the first service instance.
  • the micro-service system determines the available resources and used load of the service instance for any service instance in the service instance cluster, including: any service instance of the service instance, determine the number of unused central processing unit CPU cores and unused memory of the service instance as the available resources, and determine the number of requested accesses and requests of the service instance in the preset historical period
  • the access duration is determined as the used load
  • the determining the idle degree of the service instance according to the available resources and the used load includes: the micro server system compares the available resources with the used load
  • the load ratio is determined as the idleness degree of the service instance.
  • the process of determining the idleness of service instances in the service instance cluster by the microservice system it can be carried out based on the real-time resources and load conditions of the service instance cluster in the current state.
  • the number of CPU cores and memory used as the representation of available resources, and the number of requested accesses received by the service instance and the access duration can be used as the representation of the used load.
  • an The idleness of the service instance is evaluated, which can be specifically expressed as the ratio of the available resources to the used load is defined as the idleness of the service instance.
  • the present application provides a micro-service system
  • the micro-service system includes: a receiving unit, configured to receive a first request that carries a first resource identifier sent by a first client; a processing unit, configured to determine if the If the first resource identifier does not carry a service instance identifier, a first service instance is allocated to the first request; an acquiring unit is configured to obtain the first resource identifier from the database through the first service instance. the first resource; the processing unit is further configured to send the first resource to the first client and cache the first resource in the first service instance; the processing unit is further configured to for updating the first resource identifier according to the first service instance identifier of the first service instance to obtain a second resource identifier for indicating the first resource.
  • the microservice system confirms whether the service instance identifier is carried by confirming the first resource identifier in the request sent by the client.
  • the microservice system can obtain the first resource indicated by the first resource identifier from the database through the service instance, and send it to the client and cache it in the service instance.
  • the microservice system can also The first resource identifier is updated, and the update process includes adding the identifier of the service instance, so that when the subsequent client requests the first resource, the service instance that has cached the first resource can directly access the service instance. respond.
  • the microservice system determines a service instance for a request for a resource, and the service instance caches the resource after obtaining the resource from the database, so that subsequent requests for the resource can reach the microservice system again.
  • the service instance can directly respond to the request, avoiding the need to cache all resources for each service instance in the microservice system, which greatly reduces the redundancy of the system.
  • the processing unit is further configured to: if it is determined that the first resource identifier carries a second service instance identifier, assign the first request to the second service instance ; Send the first resource indicated by the first resource identifier cached by the second service instance to the first client.
  • the microservice system in the process of confirming the first resource identifier by the microservice system, if it is confirmed that the identifier of the second service instance is carried in it, it means that the microservice system has passed the second service instance identifier before the first request enters the microservice system.
  • the service instance caches the first resource corresponding to the first request, and uses the second service instance identifier to update the first resource identifier, so the microservice system checks that the first resource identifier carries the second service instance identifier , the microservice system can directly forward the first request to the second service instance, and the second service instance uses the locally cached first resource corresponding to the first request to directly respond to the first request, thereby improving the response to the request. The efficiency of the response.
  • the first resource identifier further carries a third service instance identifier
  • the third service instance corresponding to the third service instance identifier is a backup service instance of the second service instance
  • the processing unit is further configured to: if it is determined that the second service instance is in an unavailable state, assign the first request to the third service instance.
  • the microservice system in the process of allocating a service instance that can serve the first request to the micro-service system, in addition to assigning a second service instance to it, it can also be assigned a third service instance (wherein the third service instance can be multiple), the third service instance is the backup service instance of the second service instance, so that before the microservice system prepares to allocate the first request to the second service instance, by determining whether the status of the second service instance is is available, that is, it is determined whether the second service instance is in a serviceable state, and when the microservice system determines that the second service instance is in an unavailable state, the microservice system can allocate the first request based on the identifier of the third service instance. to a third service instance to respond to the first request by the third service instance.
  • the third service instance is a service instance with better performance except the second service instance that is determined in advance based on the real-time and dynamic resources and load conditions of the service instance cluster and can serve the first request. Achieve the goal of high availability under the failure condition of the second service instance.
  • the receiving unit is further configured to: receive a second request sent by a second client that carries the second resource identifier; the second client obtains the second resource through a refresh mechanism the second resource identifier; the processing unit is further configured to: determine that the second resource identifier carries the first service instance identifier, then allocate the second request to the first service instance; The first resource cached by the first service instance is sent to the second client.
  • the micro-service system can allocate a service instance that can serve the first request—the first service instance, and The identifier corresponding to the first resource is updated from the first resource identifier to the second resource identifier, so that if the subsequent client (ie the second client) requests the first resource corresponding to the first request again, that is, the second
  • the second request sent by the client to the microservice system carries the second resource identifier, and the second resource identifier is obtained by the second client through the refresh mechanism.
  • the microservice system can directly use the first service instance to request the second client terminal responds.
  • This method is based on the fact that the first resource has been cached in the first service instance in the microservice system, and the microservice system also updates the identifier of the first resource, that is, the relationship between the first resource and the first service instance is established. A binding/correspondence relationship, so that the microservice system can quickly respond to a request for the same resource (eg, the first resource) based on the first service instance.
  • the processing unit is specifically configured to: splicing the first resource identifier and the first service instance identifier in sequence according to the set order, to obtain the first resource indicating the first resource. 2. Resource ID.
  • the microservice system After the microservice system determines that the service instance that can serve it is the first service instance for the first request entering it for the first time, it can update the first resource identifier that identifies the first resource, such as splicing sequentially The first resource identifier and the first service instance identifier, so that the result after splicing can be the second resource identifier.
  • the second resource identifier is obtained by adding the first service instance identifier to the first resource identifier, that is, the binding/correspondence relationship between the first resource and the first service instance is established, which is convenient for the microservice system to After the second resource identifier is parsed, the first service instance can be quickly determined and the request can be forwarded.
  • the processing unit is further configured to: determine a backup service instance of the first service instance; the processing unit is specifically configured to: sequentially splicing the first resources according to a set order The identifier, the first service instance identifier, and the standby service instance identifier of the standby service instance, to obtain a second resource identifier for indicating the first resource.
  • the micro-service system can not only determine the first service instance, but also determine the backup service instance of the first service instance (wherein the backup service instance The number can be multiple), so that when the first service instance is unavailable, the microservice system allocates the request to the standby service instance of the first service instance, so that the microservice system can determine the first service instance.
  • the first resource identifier is updated, the identifier of the standby service instance can be added to it, so that when the first service instance is unavailable, the microservice system can quickly allocate the request to the first service instance.
  • the backup service instance goes up to achieve the goal of high availability.
  • the processing unit is specifically configured to: encrypt the first service instance identifier and the standby service instance identifier of the standby service instance to obtain encrypted information; splicing the The first resource identifier and the encrypted information obtain a second resource identifier for indicating the first resource.
  • the processing unit is specifically configured to: for any service instance in the service instance cluster, determine the available resources and used load of the service instance; The used load is determined as the idle degree of the service instance; the service instance whose idle degree satisfies the set condition is determined as the first service instance.
  • the micro-service system allocates a first service instance to the request if it determines that it does not carry a service instance identifier for the first request that enters it.
  • the allocation process can be based on real-time, dynamic resource and
  • the idle degree of each service instance is determined according to the load situation, so that the service instance whose idle degree satisfies the set condition can be determined as the first service instance.
  • the processing unit is specifically configured to: for any service instance in the service instance cluster, determine the number of unused central processing unit CPU cores and unused memory of the service instance as The available resources, and the number of requested accesses and the requested access duration of the service instance in the preset historical period are determined as the used load; the ratio of the available resources to the used load is determined as the used load. Describes the idleness of the service instance.
  • an embodiment of the present application provides a computing device, including:
  • the processor is configured to call the program instructions stored in the memory, and execute any one of the implementation methods of the first aspect according to the obtained program.
  • an embodiment of the present application provides a computer-readable storage medium, where the computer-readable storage medium stores computer-executable instructions, and the computer-executable instructions are used to cause a computer to execute any implementation of the first aspect method.
  • FIG. 1 is a schematic diagram of a possible system architecture provided by an embodiment of the present application
  • FIG. 2 provides a request processing method according to an embodiment of the present application
  • FIG. 3 provides a microservice system according to an embodiment of the present application
  • FIG. 4 is a schematic diagram of a computing device according to an embodiment of the present application.
  • the microservice system when the microservice system responds to the service request sent by the client (the service request will carry the primary key identifier of the resource in the database), in order to achieve high availability, it will be pre-cached on any service instance in the service instance cluster.
  • Each primary key in the database identifies the corresponding resource, so that each service instance can provide a stateless service.
  • the scale of the service instance cluster is large or the amount of data in the database is large, the redundancy cost is relatively high.
  • the present application provides a schematic diagram of a possible system architecture, as shown in FIG. 1 , the architecture includes a client 110 , a microservice system 120 and a database 130 .
  • the microservice system 120 may further include a gateway 1201, a registry 1202, an alias management unit 1203, and a service instance cluster 1204, wherein the service instance cluster 1204 may include multiple service instances.
  • the gateway 1201 in the microservice system 120 may receive a service request sent by the client 110, and the service request carries the resource identifier of the resource to be requested. After the gateway 1201 receives the service request, by parsing the resource identifier in it, on the one hand, the gateway 1201 can determine the primary key identifier of the resource to be requested in the database 130, wherein the database 130 is a primary key for the stored in it On the other hand, the gateway 1201 can also determine whether the resource identifier contains the identifier of the service instance in the microservice system 120, and make corresponding response actions according to the identification result.
  • the identification results may include:
  • the gateway 1201 may send instruction information to the alias management unit 1203 in the microservice system 120, instructing the alias management unit 1203 to respond to the service in the microservice system 120.
  • the idleness of each service instance in the instance cluster 1204 is determined.
  • the alias management unit 1203 determines the idleness of each service instance, the alias management unit 1203 must return the identifier of the service instance whose idleness meets the preset condition to the gateway. 1201, so that the gateway 1201 can send the current service request together with the received service instance identifier to the identified service instance, so that the identified service instance can respond to the current service request.
  • the resource identifier includes the identifier of the service instance.
  • gateway 1201 can directly send the current service request to the identified service instance, so that the identified service instance can respond to the current service request. respond.
  • the alias management unit 1203 determines the idleness of each service instance in the service instance cluster 1204 in the microservice system 120, the service can be determined according to the real-time available resources and the used load of each service instance in the current state.
  • the idleness of the instance wherein the preset condition may be to determine the service instance with the most idleness in the service instance cluster 1204 as the service instance that can respond to this service request. Therefore, the alias management unit 1203
  • the identity of the service instance is returned to gateway 1201 .
  • the preset condition may also be to determine a number of service instances with the greatest degree of idleness in the service instance cluster 1204 as service instances that can respond to this service request, and determine the number of service instances with the greatest degree of idleness among the several service instances.
  • the service instance is determined as the service instance responding to this service request, that is, the main service instance, and the service instances other than the main service instance among the several service instances are determined as the standby service instances of the main service instance, and the alias management unit
  • 1203 is marked differently, so that the gateway 1201 can accurately distinguish the primary service instance and the backup service instance. This method can achieve high availability when the primary service instance fails.
  • the gateway 1201 can send the service request this time and the received service instance according to the identified primary service instance.
  • the identifier (including the identifier of the primary service instance and the identifier of the standby service instance) is sent to the identified primary service instance, so that the identified primary service instance can respond to this service request.
  • the process of responding to the current service request by the identified primary service instance may specifically include: on the one hand, the primary service instance can identify the primary key of the current service request, the primary service instance's identity, and the standby service instance.
  • the identifier of the service request is processed to obtain a resource identifier representing another form of representation of the resource corresponding to the service request.
  • the main service instance can be based on the primary key identifier in the service request.
  • the gateway 1201 From the database connected to the microservice system 120 Obtain the resource corresponding to the primary key identifier in 130, and after storing the acquired resource locally (referring to the main service instance), continue to send the acquired resource and the resource identifier in another form to the gateway 1201, a On the one hand, the gateway 1201 returns the resource to the client 110, thereby realizing the response to this service request; on the other hand, the gateway 1201 establishes a corresponding relationship between the resource identifier of another form and the primary key identifier of this time and stores it , so that when a subsequent client requests the same resource, the gateway 1201 confirms that another representation of the resource identifier corresponding to the resource identifier is stored in the locally cached comparison relationship, so that the gateway 1201 can refresh the other
  • the resource identifier in one form is returned to the client, so the client can request resources from the microservice system 120 by virtue of the resource identifier in another form, and the main service instance that has cached the resource (the main service instance is available) status) to
  • the gateway 1201 can continue to determine whether the main service instance is in an available state, if the main service instance is in an available state, Then the gateway 1201 can directly send this service request to the main service instance, and the main service instance directly responds to the client 110 through the locally cached resources corresponding to this service request; if the gateway 1201 determines that the main service instance In an unavailable state, the gateway 1201 can send the current service request to the standby service instance, so that the standby service instance can respond to the current service request.
  • the backup service instance of the primary service instance does not cache the resources requested by the service locally, when the primary service instance is unavailable, the backup service instance can refer to the above-mentioned primary service instance in the process of responding to the service request. The process of responding to the request will not be repeated here.
  • each service instance in the service instance cluster can be in a stable state for a long time, under the time node when the primary service instance and backup service instance that can serve it are first determined for the service request, in order to Reduce redundant caching of the same resource.
  • the main service instance caches the resources requested by the service locally, and does not allow the standby service instance to cache the resources requested by the service
  • the service request of the same resource does not cache the resources requested by the service.
  • the gateway 1202 in the microservice system 120 determines that the primary service instance is unavailable, the gateway 1202 can forward the service request to the backup service instance of the primary service instance, even though the backup service instance is not locally available.
  • the standby service instance is a service instance that is more idle than other service instances other than the non-primary service instance in the service instance cluster, that is, the standby service instance has the best performance in the current state. (based on the relatively stable performance of each service instance in the service instance cluster at different time nodes), so at this time, let the standby service instance obtain the resources corresponding to the service request according to the execution method of the original main service instance, The standby service instance will also be faster for the client to request the service.
  • the registry 1202 can receive the information that the service instance that is put into use is registered on it, and register the service instance, so that the registry 1202 can obtain the status of each service instance in the service instance cluster 1204, such as determined by heartbeat Whether the service instance is available, and obtain the data of the available resources and used load of the service instance.
  • the alias management unit 1203 can be configured to receive the indication information sent by the gateway 1201 to determine the idleness of each service instance in the service instance cluster 1204 , and after receiving the indication information, the alias management unit 1203 can obtain the service instance from the registration 1202 The available resources and used load data of each service instance in the cluster 1204, and then by performing related calculations on the available resources and the used load, the idle degree of each service instance can be determined, and the idle degree satisfies the preset conditions. The identity of the instance is returned to gateway 1201 .
  • the service instance cluster 1204 includes multiple service instances, and each service instance can be used to cache data corresponding to some primary key identifiers in the database 130 connected to the microservice system 120 .
  • an embodiment of the present application provides a request processing method. As shown in FIG. 2, the method can be executed by the microservice system shown in FIG. 1, and includes the following steps:
  • Step 201 The microservice system receives a first request that carries a first resource identifier and is sent by a first client.
  • the first request sent by the client is generated based on the primary key identifier in the database connected to the microservice system.
  • the first resource corresponding to the first request sent by the client is stored in the data by means of the primary key, so that the client can request the resource from the database by virtue of the primary key identifier.
  • the resources in the database are cached through the service instance in the micro-service system, which can reduce the direct connection between the client and the database. interaction, thereby reducing the pressure on the database.
  • the first request may be received through the gateway in the microservice system.
  • Step 202 if the microservice system determines that the first resource identifier does not carry a service instance identifier, allocate a first service instance to the first request.
  • the gateway may continue to analyze the first resource identifier to determine whether the first resource identifier carries the primary key identifier in the database, whether there is another It carries the service instance identifier. If the gateway determines that the first resource identifier does not carry the service instance identifier, that is, the gateway determines that the first resource identifier is only the primary key identifier in the database, the gateway may allocate the first service instance to the first request. The gateway may allocate the first service instance for the first request through an alias management unit in the microservice system.
  • Step 203 the microservice system obtains the first resource indicated by the first resource identifier from the database through the first service instance.
  • the gateway can forward the first request to the first service instance, so that the first service instance can Obtain the first resource indicated by the first resource identifier from the database connected to the microservice system, that is, let the first service instance pull the first resource indicated by the primary key identifier in the database from the database; on the other hand, the gateway can also The first service instance identifier of the first service instance is also forwarded to the first service instance, so that the first service instance can update the first resource identifier based on its own identifier, thereby generating a first resource identifier that can be used to indicate the first resource. 2.
  • Resource ID Resource ID
  • Step 204 the microservice system sends the first resource to the first client and caches the first resource in the first service instance.
  • the first service instance can cache the first resource locally, and on the other hand Aspects
  • the first service instance may send the first resource to the gateway, so as to send the first resource to the first client through the gateway, thereby implementing a response to the first request sent by the client.
  • Step 205 the micro-service system updates the first resource identifier according to the first service instance identifier of the first service instance, and obtains a second resource identifier for indicating the first resource.
  • the first resource identifier may be updated by the first service instance in the microservice system according to its own identifier to obtain a second resource identifier that can be used to indicate the first resource.
  • the microservice system confirms whether the service instance identifier is carried by confirming the first resource identifier in the request sent by the client.
  • the microservice system can obtain the first resource indicated by the first resource identifier from the database through the service instance, and send it to the client and cache it in the service instance.
  • the microservice system can also The first resource identifier is updated, and the update process includes adding the identifier of the service instance, so that when the subsequent client requests the first resource, the service instance that has cached the first resource can directly access the service instance. respond.
  • the microservice system determines a service instance for a request for a resource, and the service instance caches the resource after obtaining the resource from the database, so that subsequent requests for the resource can reach the microservice system again.
  • the service instance can directly respond to the request, avoiding the need to cache all resources for each service instance in the microservice system, which greatly reduces the redundancy of the system.
  • step 202 if the micro-service system determines that the first resource identifier carries a second service instance identifier, it allocates the first request to the second service instance; the micro-service system assigns the first request to the second service instance; The service system sends the first resource indicated by the first resource identifier cached by the second service instance to the first client.
  • the gateway in the microservice system receives the first request, it analyzes the first resource identifier through the gateway and finds that the first resource identifier carries the second service instance identifier, which means that when the first request enters the microservice Before the service system, there has been at least one service request that has entered the microservice system, and the second service instance in the microservice system has responded to the service request. It is understandable that at least one service request here requires The requested resource and the resource to be requested by the first request are the resources indicated by the same primary key identifier; further in the process of the microservice system responding to the service request, the microservice system has updated the resource identifier of the service request, The updated resource identifier carries the identifier of the second service instance. Therefore, the gateway can directly forward the first request to the second service instance, so that the second service instance uses the locally cached first resource indicated by the first resource identifier to respond to the client, which improves the The efficiency with which a microservice system responds to clients.
  • the first resource identifier further carries a third service instance identifier
  • the third service instance corresponding to the third service instance identifier is a backup service instance of the second service instance ;
  • the method further includes: if the micro-service system determines that the second service instance is in an unavailable state, assigning the first request to the third service instance.
  • the microservice system when the microservice system uses its internal second service instance to respond to the service request, in order to ensure the high availability of the service, the microservice system not only determines the service request for the service request It (referring to the service request) is the second service instance, and the microservice system also determines a third service instance that can serve the service request, where the third service instance is a backup service instance of the second service instance, and the third service instance
  • the number of instances can be one or more. It should be noted that, in order to reduce the redundancy of the micro-service system, in the embodiment of this application, only the database resources corresponding to the service request are cached locally by the second service instance, and the database corresponding to the service request is not required to be locally cached by the third service instance. Resources are cached.
  • the microservice system can update the primary key identifier of the service request based on the second service instance identifier of the second service instance and the third service instance identifier of the third service instance, so that the obtained first resource identifier carries the primary key identifier , the second service instance identifier and the third service instance identifier. Therefore, before the gateway in the microservice system prepares to forward the first request to the second service instance, the gateway may first determine the status of the second service instance, and when it is determined that the second service instance is unavailable, the gateway may The first request is forwarded to an alternate service instance of the second service instance, that is, the third service instance, so that the third service instance responds to the first request.
  • the process of the third service instance responding to the first request may refer to the process of the first service instance responding to the first request in the preceding steps. The process is not repeated in this application.
  • each service instance in the service instance cluster can be in a stable state for a long time, in order to reduce the For redundant caching of the same resource, although only the primary service instance caches the resources requested by the service locally, and does not allow the standby service instance to cache the resources requested by the service, when the service request for the same resource arrives
  • the gateway in the microservice system determines that the primary service instance is unavailable, the gateway can forward the service request to the backup service instance of the primary service instance, although the backup service instance does not cache the service request locally.
  • the standby service instance is a service instance that is more idle than other service instances other than the non-primary service instance in the service instance cluster, that is, the standby service instance is the service instance with the best performance in the current state ( Based on the performance of each service instance in the service instance cluster at different time nodes, the performance is relatively stable), so at this time, let the standby service instance obtain the resources corresponding to the service request according to the execution method of the original main service instance.
  • the service request on the terminal will also be relatively fast, which means that when the status of the second service instance is unavailable, the gateway forwards the first request to the standby service instance of the second service instance, that is, the third service instance.
  • the speed of responding to the first request through the third service instance will also be relatively fast, which achieves the goal of low resource redundancy and fast response to the service request.
  • the micro-service system receives a second request sent by a second client that carries the identifier of the second resource; the second client obtains the second resource through a refresh mechanism identifier; the microservice system determines that the second resource identifier carries the first service instance identifier, and then assigns the second request to the first service instance; the microservice system assigns the first service instance identifier to the first service instance.
  • the first resource cached by a service instance is sent to the second client.
  • the first service instance in the microservice system in the foregoing example responds to the first request sent by the first client
  • the first service instance updates the first resource identifier to the second resource identifier, and updates the second resource identifier to the second resource identifier.
  • the identifier is sent to the gateway in the microservice system, so that the gateway establishes and stores the corresponding relationship between the primary key identifier of the first request and the second resource identifier.
  • the service request can be processed by the microservice system
  • the gateway in the received, through the analysis of the service request, the gateway determines that the primary key identifier of the service request is stored in the comparison relationship of the local cache, so the gateway can send the second resource identifier to the second client through the refresh mechanism, In this way, the second client can re-send a service request to the micro-service system by virtue of the received second resource identifier, that is, the second request, when the gateway in the micro-service system receives the second request, through the second request Analysis of the second resource identifier carried in the request shows that the first service instance identifier is carried in it. Therefore, in order to speed up the response efficiency to the client, the gateway can directly assign the second request to the first service instance, so that the first service instance can be The instance sends the locally cached first resource to
  • the micro-service system updates the first resource identifier according to the first service instance identifier of the first service instance, and obtains a second resource identifier for indicating the first resource , including: the micro-service system sequentially splices the first resource identifier and the first service instance identifier according to the set order, and obtains a second resource identifier for indicating the first resource.
  • the gateway may combine the first service instance identifier with the first request Sent to the first service instance, on the one hand, the first service instance can obtain the first resource from the database through the primary key identifier to respond to the first client; on the other hand, in order to reduce the operating pressure of the gateway, the A service instance splices the first resource identifier (that is, the primary key identifier in the database) and the first service instance identifier in sequence according to the set order, so that the second resource identifier for indicating the first resource can be obtained, wherein the second resource identifier , a binding/correspondence relationship between the first resource and the first service instance can be established, so the first resource identifier can be updated through the first service instance in the microservice system.
  • the method before the obtaining the second resource identifier used to indicate the first resource, the method further includes: determining, by the microservice system, a backup service instance of the first service instance; the The micro-service system sequentially splices the first resource identifier and the first service instance identifier according to the set order to obtain the second resource identifier used to indicate the first resource, including: the micro-service system follows the set order The first resource identifier, the first microservice instance identifier, and the standby service instance identifier of the standby service instance are sequentially spliced to obtain a second resource identifier for indicating the first resource.
  • the alias management unit in the microservice system when the alias management unit in the microservice system receives the indication information sent by the gateway in the microservice system to determine the service instance that can serve the first request, in order to meet the high availability of the service, the alias management unit In addition to determining the first service instance that can serve it for the first request, the alias management unit can also determine the backup service instance of the first service instance, so that when the first service instance is unavailable, there can be a quick response. The standby service instance to realize the switching and transfer of service requests.
  • the alias management unit can send the first service instance identifier of the first service instance and the standby service instance identifier of the standby service instance of the first service instance to the first service instance together, so that the first service instances can follow the set order. Splicing the first resource identifier (that is, the primary key identifier in the database), the first service instance identifier and the standby service instance identifier, so that the second resource identifier for indicating the first resource can be obtained, wherein, through the second resource identifier, it is possible to establish Since the binding/correspondence relationship between the first resource and the first service instance and the backup service instance of the first service instance is initiated, the first resource identifier can be updated through the first service instance in the microservice system.
  • the micro-service system sequentially concatenates the first resource identifier, the first service instance identifier, and the standby service instance identifier of the standby service instance in a set order to obtain Indicating the second resource identifier of the first resource, including: the micro-service system encrypts the first service instance identifier and the standby service instance identifier of the standby service instance to obtain encrypted information; The first resource identifier and the encrypted information are sequentially spliced in a certain order to obtain a second resource identifier for indicating the first resource.
  • the service instance identifier may be the host's ip, host name, port and other information
  • the first service instance can first use the Base64 encoding method to process its own identification and the standby service instance identification, convert them into encrypted strings, and then the first service instance can
  • the resource identifier ie, the primary key identifier in the database
  • the allocating the first service instance to the first request includes: the microservice system determines, for any service instance in the service instance cluster, the available resources of the service instance and the Used load; according to the available resources and the used load, determine the idle degree of the service instance; the microservice system determines the service instance whose idle degree meets the set condition as the first service instance.
  • the micro-service system determines the available resources and used load of the service instance for any service instance in the service instance cluster, including: the micro-server system is for the service instance cluster. For any service instance in the service instance, determine the number of unused central processing unit CPU cores and unused memory of the service instance as the available resources, and determine the number of requested accesses and Determining the requested access duration as the used load; and determining the idle degree of the service instance according to the available resources and the used load, including: the micro server system associates the available resources with the used load. Use the ratio of load to determine the idle degree of the service instance.
  • the alias management unit in the microservice system receives the indication information sent by the gateway in the microservice system, and the indication information is used to instruct the alias management unit to allocate the first service instance for the first request.
  • the alias management unit The unit can determine the idleness of each service instance in the service instance cluster in the microservice system, and the determination process can be implemented by the following load balancing algorithm:
  • the cpu resources can be expressed as: Available memory resources can be expressed as: where c 0 is a constant; where as well as are used to represent the available resources of the machine;
  • N i the resource corresponding to the primary key identifier of the machine that has been accessed must be cached
  • T i unit: minutes
  • the alias management unit can obtain the idle rate of each machine, that is, the alias management unit can obtain the idle degree of each service instance.
  • each service instance cluster with 100 service instances, and each service instance is a virtual host with 8 cores and 16GB, the available memory is 14GB at the beginning.
  • the microservice system with the service instance cluster is used for the database resource access cache of large-scale platforms. It is assumed that the number of primary keys accessed is 10 million.
  • the number of caches of each service instance will continue to increase linearly; in order to provide a unified stateless service for each service instance, the service instance resources occupied during expansion will also increase linearly, and the expansion plans are relatively comparable.
  • Simple When the hotspot primary key changes, since the cache content of all service instances is consistent, requests can be evenly distributed to each service instance, and the cluster pressure is relatively stable.
  • the load balancing solution proposed in this application the number and load of existing service instances in a service instance cluster can be integrated, and a service instance with a lower load value can be selected.
  • the total amount of cached data is 10GB.
  • the demand for cluster resources can be greatly reduced.
  • the load balancing algorithm can automatically add more newly-added primary keys to the expanded service instance, thereby ensuring the overall load balance of the service instance cluster.
  • the load balancing algorithm can also take into account the access duration and the amount of cached data, so as to achieve more efficient load balancing.
  • the scheduling system includes a receiving unit 301, a processing unit 302, and an obtaining unit 303:
  • the receiving unit 301 is configured to receive a first request carrying a first resource identifier sent by a first client.
  • the processing unit 302 is configured to allocate a first service instance to the first request if it is determined that the first resource identifier does not carry a service instance identifier.
  • the obtaining unit 303 is configured to obtain the first resource indicated by the first resource identifier from the database through the first service instance.
  • the processing unit 302 is further configured to send the first resource to the first client and cache the first resource in the first service instance.
  • the processing unit 302 is further configured to update the first resource identifier according to the first service instance identifier of the first service instance to obtain a second resource identifier used to indicate the first resource.
  • the processing unit 302 is further configured to: if it is determined that the first resource identifier carries a second service instance identifier, assign the first request to the second service instance; Send the first resource indicated by the first resource identifier cached by the second service instance to the first client.
  • the first resource identifier also carries a third service instance identifier
  • the third service instance corresponding to the third service instance identifier is a backup service instance of the second service instance
  • the processing unit 302 is further configured to: if it is determined that the second service instance is in an unavailable state, assign the first request to the third service instance.
  • the receiving unit 301 is further configured to: receive a second request that carries the second resource identifier sent by a second client; the second client obtains the first request through a refresh mechanism two resource identifiers; the processing unit 302 is further configured to: determine that the second resource identifier carries the first service instance identifier, then allocate the second request to the first service instance; assign the first service instance identifier to the first service instance; The first resource cached by a service instance is sent to the second client.
  • the processing unit 302 is specifically configured to: splicing the first resource identifier and the first service instance identifier in sequence according to the set order to obtain a second identifier for indicating the first resource. Resource ID.
  • the processing unit 302 is further configured to: determine a backup service instance of the first service instance; the processing unit is specifically configured to: sequentially splicing the first resource identifiers according to the set order , the first service instance identifier and the standby service instance identifier of the standby service instance to obtain a second resource identifier used to indicate the first resource.
  • the processing unit 302 is specifically configured to: encrypt the first service instance identifier and the standby service instance identifier of the standby service instance to obtain encrypted information; splicing the first service instance in sequence according to the set order. A resource identifier and the encrypted information are used to obtain a second resource identifier for indicating the first resource.
  • the processing unit 302 is specifically configured to: for any service instance in the service instance cluster, determine the available resources and used load of the service instance; The idle degree of the service instance is determined by using the load; the service instance whose idle degree satisfies the set condition is determined as the first service instance.
  • the processing unit 302 is specifically configured to: for any service instance in the service instance cluster, determine the number of unused central processing unit CPU cores and unused memory of the service instance as all the service instances. the available resources, and determine the number of requested accesses and the requested access duration of the service instance in the preset historical period as the used load; determine the ratio of the available resources to the used load as the used load The idleness of the service instance.
  • Embodiments of the present application further provide a computing device, and the computing device may specifically be a desktop computer, a portable computer, a smart phone, a tablet computer, a personal digital assistant (Personal Digital Assistant, PDA), and the like.
  • the computing device may include a central processing unit (Center Processing Unit, CPU), a memory, an input/output device, etc.
  • the input device may include a keyboard, a mouse, a touch screen, etc.
  • the output device may include a display device, such as a liquid crystal display (Liquid Crystal Display, LCD), Cathode Ray Tube (CRT), etc.
  • LCD Liquid Crystal Display
  • CRT Cathode Ray Tube
  • the memory which may include read only memory (ROM) and random access memory (RAM), provides the processor with program instructions and data stored in the memory.
  • ROM read only memory
  • RAM random access memory
  • the memory may be used to store program instructions for requesting the processing method
  • the processor is configured to call the program instructions stored in the memory, and execute the request processing method according to the obtained program.
  • a schematic diagram of a computing device provided by an embodiment of the present application, the computing device includes:
  • the processor 401 is configured to read the program in the memory 402 and execute the above request processing method
  • the processor 401 may be a central processing unit (CPU for short), a network processor (NP for short), or a combination of CPU and NP. It can also be a hardware chip.
  • the above-mentioned hardware chip may be an application-specific integrated circuit (ASIC for short), a programmable logic device (PLD for short) or a combination thereof.
  • the above PLD may be a complex programmable logic device (CPLD for short), a field-programmable gate array (FPGA for short), a generic array logic (GAL for short) or any of the above. combination.
  • the memory 402 is used to store one or more executable programs, and can store data used by the processor 401 when performing operations.
  • the program may include program code, and the program code includes computer operation instructions.
  • the memory 402 may include a volatile memory (volatile memory), such as random-access memory (RAM for short); the memory 402 may also include a non-volatile memory (non-volatile memory), such as a flash memory ( flash memory), a hard disk drive (HDD for short) or a solid-state drive (SSD for short); the memory 402 may also include a combination of the above-mentioned types of memory.
  • Memory 402 stores the following elements, executable modules or data structures, or a subset thereof, or an extended set thereof:
  • Operation instructions including various operation instructions, which are used to realize various operations.
  • Operating System Includes various system programs for implementing various basic services and handling hardware-based tasks.
  • the bus 405 may be a peripheral component interconnect (PCI for short) bus or an extended industry standard architecture (Extended industry standard architecture, EISA for short) bus or the like.
  • PCI peripheral component interconnect
  • EISA Extended industry standard architecture
  • the bus can be divided into address bus, data bus, control bus and so on. For ease of presentation, only one thick line is used in FIG. 4, but it does not mean that there is only one bus or one type of bus.
  • the bus interface 404 may be a wired communication access port, a wireless bus interface or a combination thereof, wherein the wired bus interface may be, for example, an Ethernet interface.
  • the Ethernet interface can be an optical interface, an electrical interface or a combination thereof.
  • the wireless bus interface may be a WLAN interface.
  • Embodiments of the present application further provide a computer-readable storage medium, where the computer-readable storage medium stores computer-executable instructions, where the computer-executable instructions are used to cause the computer to execute the request processing method.
  • the embodiments of the present application may be provided as a method, or as a computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) having computer-usable program code embodied therein.
  • computer-usable storage media including, but not limited to, disk storage, CD-ROM, optical storage, etc.
  • These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory result in an article of manufacture comprising instruction means, the instructions
  • the apparatus implements the functions specified in the flow or flow of the flowcharts and/or the block or blocks of the block diagrams.

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Hardware Redundancy (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

A request processing method and a micro-service system, which relate to the field of Fintech. The method comprises: a micro-service system receiving a first request sent by a first client and carrying a first resource identifier (201); if it is determined that the first resource identifier does not carry a service instance identifier, allocating a first service instance to the first request (202); by means of the first service instance, acquiring, from a database, a first resource indicated by the first resource identifier (203); sending the first resource to the first client and caching the first resource in the first service instance (204); and updating the first resource identifier according to a first service instance identifier of the first service instance, so as to obtain a second resource identifier for indicating the first resource (205). The micro-service system determines a service instance for a request of a certain resource, and the resource is cached after the service instance acquires the resource from the database, so as to facilitate subsequent direct response of the service instance to the request when the request for the resource reaches the micro-service system again.

Description

一种请求处理方法及微服务系统A request processing method and microservice system

相关申请的交叉引用CROSS-REFERENCE TO RELATED APPLICATIONS

本申请要求在2020年11月24日提交中国专利局、申请号为202011327754.X、申请名称为“一种请求处理方法及微服务系统”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application claims the priority of the Chinese patent application with the application number 202011327754.X and the application title "A Request Processing Method and Microservice System" filed with the China Patent Office on November 24, 2020, the entire contents of which are incorporated by reference in this application.

技术领域technical field

本申请实施例涉及金融科技(Fintech)领域,尤其涉及一种请求处理方法及微服务系统。The embodiments of the present application relate to the field of financial technology (Fintech), and in particular, to a request processing method and a microservice system.

背景技术Background technique

随着计算机技术的发展,越来越多的技术(例如:大数据或云计算)应用在金融领域,传统金融业正在逐步向金融科技转变,在大数据技术的背景下,需要基于微服务系统来对用户请求进行响应。With the development of computer technology, more and more technologies (such as big data or cloud computing) are applied in the financial field, and the traditional financial industry is gradually transforming into financial technology. to respond to user requests.

目前,微服务启用时都会向微服务系统中的注册中心,如Eureka进行注册,通过注册中心的分配处理,则对于任一个微服务,它可对应到一个或者多个服务实例。客户端在向微服务系统发送服务请求时会附带要请求的微服务名称,并由微服务系统中的网关解析出该微服务对应的服务实例,最后将来自客户端的服务请求随机转发给其中的一个服务实例。在大型网站架构设计中,微服务系统在应对大请求量的数据库访问请求时,为了提高服务响应速度,微服务系统一般会将数据库中的主键所标识的数据缓存到每个服务实例中,这样可以提供一种无状态的服务。At present, when microservices are enabled, they will be registered with the registration center in the microservice system, such as Eureka. Through the allocation processing of the registration center, for any microservice, it can correspond to one or more service instances. When the client sends a service request to the microservice system, the name of the microservice to be requested is attached, and the gateway in the microservice system parses out the service instance corresponding to the microservice, and finally forwards the service request from the client to one of them randomly. A service instance. In the design of large-scale website architecture, in order to improve the service response speed when the microservice system responds to a large number of database access requests, the microservice system generally caches the data identified by the primary key in the database into each service instance, so that A stateless service can be provided.

上述方式要求每一个服务实例预先缓存有数据库中的全量数据或者热点数据,在服务实例集群规模较大时或者数据库中的数据量较大时,冗余成本比较高。The above method requires each service instance to pre-cache the full amount of data or hotspot data in the database. When the scale of the service instance cluster is large or the amount of data in the database is large, the redundancy cost is relatively high.

综上,目前亟需一种简单高效、且低成本的对服务请求进行响应的方法。To sum up, there is an urgent need for a simple, efficient, and low-cost method for responding to a service request.

发明内容SUMMARY OF THE INVENTION

本申请提供一种请求处理方法及微服务系统,用以实现简单高效、且低成本地对服务请求进行响应。The present application provides a request processing method and a microservice system, which are used to respond to service requests in a simple, efficient, and low-cost manner.

第一方面,本申请实施例提供一种请求处理方法,该方法包括:微服务系统接收第一客户端发送的携带第一资源标识的第一请求;所述微服务系统若确定所述第一资源标识中未携带有服务实例标识,则为所述第一请求分配第一服务实例;所述微服务系统通过所述第一服务实例从数据库中获取所述第一资源标识所指示的第一资源;所述微服务系统将所述第一资源发送至所述第一客户端并将所述第一资源缓存在所述第一服务实例中;所述微服务系统根据所述第一服务实例的第一服务实例标识更新所述第一资源标识,得到用于指示所述第一资源的第二资源标识。In a first aspect, an embodiment of the present application provides a request processing method, the method includes: a microservice system receives a first request that carries a first resource identifier sent by a first client; if the microservice system determines that the first request If the resource identifier does not carry the service instance identifier, a first service instance is allocated for the first request; the microservice system obtains the first service instance indicated by the first resource identifier from the database through the first service instance resource; the microservice system sends the first resource to the first client and caches the first resource in the first service instance; the microservice system according to the first service instance The first service instance identifier of the first resource identifier is updated to obtain the second resource identifier used to indicate the first resource.

基于该方案,微服务系统通过对客户端发送的请求中的第一资源标识进行确认,确认是否携带服务实例标识,若确认没有携带,则微服务系统可为该请求分配一个服务实例,随后,一方面,微服务系统可通过该服务实例从数据库中获取第一资源标识所指示的第一资源,并将其发送客户端以及缓存在该服务实例中,另一方面,微服务系统还可对第一资源标识进行更新,其更新过程中包括增加该服务实例的标识,如此便于后续的客户端在对第一资源进行请求时,则可以直接由已经缓存有第一资源的该服务实例对其进行响应。该方式中微服务系统通过为某一资源的请求确定一个服务实例,并由该服务实例在从数据库中获取到该资源后对资源进行缓存,便于后续的关于该资源的请求再次到达微服务系统的时候,直接可由该服务实例对请求进行响应,避免须微服务系统中的每一个服务实例缓存 有全部资源,极大地降低了系统的冗余。Based on this solution, the microservice system confirms whether the service instance identifier is carried by confirming the first resource identifier in the request sent by the client. On the one hand, the microservice system can obtain the first resource indicated by the first resource identifier from the database through the service instance, and send it to the client and cache it in the service instance. On the other hand, the microservice system can also The first resource identifier is updated, and the update process includes adding the identifier of the service instance, so that when the subsequent client requests the first resource, the service instance that has cached the first resource can directly access the service instance. respond. In this method, the microservice system determines a service instance for a request for a resource, and the service instance caches the resource after obtaining the resource from the database, so that subsequent requests for the resource can reach the microservice system again. At the time, the service instance can directly respond to the request, avoiding the need to cache all resources for each service instance in the microservice system, which greatly reduces the redundancy of the system.

在一种可能实现的方法中,所述方法还包括:所述微服务系统若确定所述第一资源标识中携带有第二服务实例标识,则将所述第一请求分配至所述第二服务实例;所述微服务系统将所述第二服务实例缓存的所述第一资源标识指示的第一资源发送给所述第一客户端。In a possible implementation method, the method further includes: if the microservice system determines that the first resource identifier carries a second service instance identifier, assigning the first request to the second service instance identifier A service instance; the microservice system sends the first resource indicated by the first resource identifier cached by the second service instance to the first client.

基于该方案,在微服务系统对第一资源标识进行确认的过程中,若确认其中携带有第二服务实例标识,则表示在第一请求进入到微服务系统之前,微服务系统已经通过第二服务实例对第一请求对应的第一资源进行了缓存,且使用第二服务实例标识对第一资源标识进行了更新,如此在微服务系统检查到第一资源标识中携带有第二服务实例标识时,微服务系统可直接将第一请求转发至第二服务实例,由第二服务实例使用本地已缓存的对应于第一请求的第一资源对第一请求直接进行响应,从而提高了对请求进行响应的效率。Based on this solution, in the process of confirming the first resource identifier by the microservice system, if it is confirmed that the identifier of the second service instance is carried in it, it means that the microservice system has passed the second service instance identifier before the first request enters the microservice system. The service instance caches the first resource corresponding to the first request, and uses the second service instance identifier to update the first resource identifier, so the microservice system checks that the first resource identifier carries the second service instance identifier , the microservice system can directly forward the first request to the second service instance, and the second service instance uses the locally cached first resource corresponding to the first request to directly respond to the first request, thereby improving the response to the request. The efficiency of the response.

在一种可能实现的方法中,所述第一资源标识中还携带有第三服务实例标识,所述第三服务实例标识对应的第三服务实例是所述第二服务实例的备用服务实例;所述方法还包括:所述微服务系统若确定所述第二服务实例处于不可用状态,则将所述第一请求分配至所述第三服务实例。In a possible implementation method, the first resource identifier further carries a third service instance identifier, and the third service instance corresponding to the third service instance identifier is a backup service instance of the second service instance; The method further includes: if the microservice system determines that the second service instance is in an unavailable state, allocating the first request to the third service instance.

基于该方案,在微服务系统为第一请求分配可服务于它的服务实例的过程中,除了可以为它分配第二服务实例,还可以为它分配第三服务实例(其中,第三服务实例的个数可为多个),第三服务实例是第二服务实例的备用服务实例,从而在微服务系统准备将第一请求分配至第二服务实例之前,通过确定第二服务实例的状态是否为可用,也即确定第二服务实例是否为可服务状态,并在微服务系统确定第二服务实例为不可用状态时,微服务系统则可基于第三服务实例的标识、将第一请求分配至第三服务实例,以由第三服务实例来对第一请求进行响应。该方式中第三服务实例为预先基于服务实例集群实时、动态的资源和负载情况而确定的、可服务于第一请求的、除去第二服务实例之外的性能较好的服务实例,如此可以实现第二服务实例故障条件下的高可用的目标。Based on this solution, in the process of allocating a service instance that can serve the first request to the micro-service system, in addition to assigning a second service instance to it, it can also be assigned a third service instance (wherein the third service instance can be multiple), the third service instance is the backup service instance of the second service instance, so that before the microservice system prepares to allocate the first request to the second service instance, by determining whether the status of the second service instance is is available, that is, it is determined whether the second service instance is in a serviceable state, and when the microservice system determines that the second service instance is in an unavailable state, the microservice system can allocate the first request based on the identifier of the third service instance. to a third service instance to respond to the first request by the third service instance. In this method, the third service instance is a service instance with better performance except the second service instance that is determined in advance based on the real-time and dynamic resources and load conditions of the service instance cluster and can serve the first request. Achieve the goal of high availability under the failure condition of the second service instance.

在一种可能实现的方法中,所述方法还包括:所述微服务系统接收第二客户端发送的携带所述第二资源标识的第二请求;所述第二客户端是通过刷新机制获得所述第二资源标识;所述微服务系统确定所述第二资源标识中携带有所述第一服务实例标识,则将所述第二请求分配至所述第一服务实例;所述微服务系统将所述第一服务实例缓存的所述第一资源发送给所述第二客户端。In a possible implementation method, the method further includes: receiving, by the microservice system, a second request sent by a second client that carries the second resource identifier; the second client is obtained through a refresh mechanism the second resource identifier; the microservice system determines that the second resource identifier carries the first service instance identifier, and allocates the second request to the first service instance; the microservice The system sends the first resource cached by the first service instance to the second client.

基于该方案,在第一客户端发出的第一请求为首次发送至微服务系统的请求时,通过微服务系统可以为第一请求分配可服务于它的服务实例——第一服务实例,并将对应于第一资源的标识从第一资源标识更新为了第二资源标识,从而若后续的客户端(即第二客户端)再次请求对应于第一请求的第一资源时,也即第二客户端向微服务系统发送的第二请求中携带了第二资源标识,该第二资源标识是第二客户端通过刷新机制得到的,微服务系统可以直接通过第一服务实例来对第二客户端进行响应。该方式基于微服务系统中的第一服务实例中已经缓存有第一资源,并且微服务系统也对第一资源的标识进行了更新,也即建立了第一资源与第一服务实例之间的绑定/对应关系,从而微服务系统可以基于第一服务实例来对同一资源(如第一资源)的请求进行快速响应。Based on this solution, when the first request sent by the first client is a request sent to the micro-service system for the first time, the micro-service system can allocate a service instance that can serve the first request—the first service instance, and The identifier corresponding to the first resource is updated from the first resource identifier to the second resource identifier, so that if the subsequent client (ie the second client) requests the first resource corresponding to the first request again, that is, the second The second request sent by the client to the microservice system carries the second resource identifier, and the second resource identifier is obtained by the second client through the refresh mechanism. The microservice system can directly use the first service instance to request the second client terminal responds. This method is based on the fact that the first resource has been cached in the first service instance in the microservice system, and the microservice system also updates the identifier of the first resource, that is, the relationship between the first resource and the first service instance is established. A binding/correspondence relationship, so that the microservice system can quickly respond to a request for the same resource (eg, the first resource) based on the first service instance.

在一种可能实现的方法中,所述微服务系统根据所述第一服务实例的第一服务实例标识更新所述第一资源标识,得到用于指示所述第一资源的第二资源标识,包括:所述微服务系统按照设定顺序依次拼接所述第一资源标识和所述第一服务实例标识,得到用于指示所述第一资源的第二资源标识。In a possible implementation method, the micro-service system updates the first resource identifier according to the first service instance identifier of the first service instance, and obtains a second resource identifier for indicating the first resource, The method includes: the micro-service system sequentially splices the first resource identifier and the first service instance identifier according to a set sequence, and obtains a second resource identifier for indicating the first resource.

基于该方案,微服务系统在为首次进入到其中的第一请求确定了可服务于它的服务实例是第一服务实例后,可对标识第一资源的第一资源标识进行更新,如依次拼接第一资源标识和第一服务实例标识,从而拼接后的结果即可为第二资源标识。该方式通过在第一资源标识中增加第一服务实例标识而得到第二资源标识,也即建立了第一资源与第一服务实 例之间的绑定/对应关系,便于在微服务系统对第二资源标识进行解析后可以快速确定第一服务实例并进行请求的转发。Based on this solution, after the microservice system determines that the service instance that can serve it is the first service instance for the first request entering it for the first time, it can update the first resource identifier that identifies the first resource, such as splicing sequentially The first resource identifier and the first service instance identifier, so that the result after splicing can be the second resource identifier. In this method, the second resource identifier is obtained by adding the first service instance identifier to the first resource identifier, that is, the binding/correspondence relationship between the first resource and the first service instance is established, which is convenient for the microservice system to After the second resource identifier is parsed, the first service instance can be quickly determined and the request can be forwarded.

在一种可能实现的方法中,所述得到用于指示所述第一资源的第二资源标识之前,还包括:所述微服务系统确定所述第一服务实例的备用服务实例;所述微服务系统按照设定顺序依次拼接所述第一资源标识和所述第一服务实例标识,得到用于指示所述第一资源的第二资源标识,包括:所述微服务系统按照设定顺序依次拼接所述第一资源标识、所述第一服务实例标识和所述备用服务实例的备用服务实例标识,得到用于指示所述第一资源的第二资源标识。In a possible implementation method, before the obtaining the second resource identifier used to indicate the first resource, the method further includes: determining, by the micro-service system, a backup service instance of the first service instance; the micro-service system The service system sequentially splices the first resource identifier and the first service instance identifier according to the set order, and obtains the second resource identifier used to indicate the first resource, including: the micro-service system follows the set order in order The first resource identifier, the first service instance identifier and the standby service instance identifier of the standby service instance are spliced together to obtain a second resource identifier for indicating the first resource.

基于该方案,微服务系统在为首次进入到其中的第一请求分配服务实例的过程中,除了可以确定第一服务实例,还可以同时确定第一服务实例的备用服务实例(其中,备用服务实例的个数可为多个),以使得在第一服务实例不可用时,由微服务系统将请求分配到第一服务实例的备用服务实例上,如此,为了微服务系统可以确定出第一服务实例的备用服务实例,则在对第一资源标识进行更新时,可在其中增加该备用服务实例的标识,如此可以在第一服务实例不可用时,微服务系统可快速将请求分配至第一服务实例的备用服务实例上去,实现了高可用的目标。Based on this solution, in the process of allocating a service instance for the first request entering it for the first time, the micro-service system can not only determine the first service instance, but also determine the backup service instance of the first service instance (wherein the backup service instance The number can be multiple), so that when the first service instance is unavailable, the microservice system allocates the request to the standby service instance of the first service instance, so that the microservice system can determine the first service instance. When the first resource identifier is updated, the identifier of the standby service instance can be added to it, so that when the first service instance is unavailable, the microservice system can quickly allocate the request to the first service instance. The backup service instance goes up to achieve the goal of high availability.

在一种可能实现的方法中,所述微服务系统按照设定顺序依次拼接所述第一资源标识、所述第一服务实例标识和所述备用服务实例的备用服务实例标识,得到用于指示所述第一资源的第二资源标识,包括:所述微服务系统加密所述第一微务实例标识和所述备用服务实例的备用服务实例标识,得到加密信息;所述微服务系统按照设定顺序依次拼接所述第一资源标识和所述加密信息,得到用于指示所述第一资源的第二资源标识。In a possible implementation method, the micro-service system splices the first resource identifier, the first service instance identifier and the standby service instance identifier of the standby service instance in sequence according to the set order, and obtains an indicator for indicating The second resource identifier of the first resource includes: the microservice system encrypts the first microservice instance identifier and the standby service instance identifier of the standby service instance to obtain encrypted information; The first resource identifier and the encrypted information are sequentially spliced in a certain order to obtain a second resource identifier for indicating the first resource.

在一种可能实现的方法中,所述为所述第一请求分配第一服务实例,包括:所述微服务系统针对服务实例集群中的任一服务实例,确定所述服务实例的可用资源和已用负载;根据所述可用资源和所述已用负载,确定所述服务实例的空闲程度;所述微服务系统将空闲程度满足设定条件的服务实例确定为所述第一服务实例。In a possible implementation method, the allocating the first service instance to the first request includes: for any service instance in the service instance cluster, the microservice system determines the available resources of the service instance and the Used load; according to the available resources and the used load, determine the idle degree of the service instance; the microservice system determines the service instance whose idle degree meets the set condition as the first service instance.

基于该方案,微服务系统对进入到其中的第一请求,若确定它未携带服务实例标识,则为该请求分配第一服务实例,该分配过程中可基于服务实例集群实时、动态的资源和负载情况来对其中的每一个服务实例的空闲程度进行确定,从而可将空闲程度满足设定条件的服务实例确定为第一服务实例。该方式通过评估服务实例集群中的服务实例的空闲程度,并将空闲程度满足设定条件的服务实例作为第一服务实例,实现了以最佳状态的服务实例来缓存请求对应的资源的目的。Based on this solution, the micro-service system allocates a first service instance to the request if it determines that it does not carry a service instance identifier for the first request that enters it. The allocation process can be based on real-time, dynamic resource and The idle degree of each service instance is determined according to the load situation, so that the service instance whose idle degree satisfies the set condition can be determined as the first service instance. By evaluating the idleness of the service instances in the service instance cluster, and taking the service instance whose idleness meets the set condition as the first service instance, the purpose of caching the resource corresponding to the request with the service instance in the best state is realized.

在一种可能实现的方法中,所述微服务系统针对服务实例集群中的任一服务实例,确定所述服务实例的可用资源和已用负载,包括:所述微服务器系统针对服务实例集群中的任一服务实例,将所述服务实例的未使用的中央处理器CPU核数和未使用内存确定为所述可用资源,以及将所述服务实例在预设历史时段中的请求访问数量和请求访问时长确定为所述已用负载;所述根据所述可用资源和所述已用负载,确定所述服务实例的空闲程度,包括:所述微服务器系统将所述可用资源与所述已用负载的比值,确定为所述服务实例的空闲程度。In a possible implementation method, the micro-service system determines the available resources and used load of the service instance for any service instance in the service instance cluster, including: any service instance of the service instance, determine the number of unused central processing unit CPU cores and unused memory of the service instance as the available resources, and determine the number of requested accesses and requests of the service instance in the preset historical period The access duration is determined as the used load; the determining the idle degree of the service instance according to the available resources and the used load includes: the micro server system compares the available resources with the used load The load ratio is determined as the idleness degree of the service instance.

基于该方案,在微服务系统对服务实例集群中的服务实例的空闲程度进行确定的过程中,可基于服务实例集群在当前状态下实时的资源和负载情况而开展,如将服务实例未使用状态的CPU核数以及内存作为可用资源的表现形式,以及可将服务实例已接收到的请求访问数量以及访问时长作为已用负载的表现形式,并可基于可用资源和已用负载来准确地对一个服务实例的空闲程度进行评估,具体可以表示为将可用资源与已用负载的比值定义为该服务实例的空闲程度。Based on this solution, in the process of determining the idleness of service instances in the service instance cluster by the microservice system, it can be carried out based on the real-time resources and load conditions of the service instance cluster in the current state. The number of CPU cores and memory used as the representation of available resources, and the number of requested accesses received by the service instance and the access duration can be used as the representation of the used load. Based on the available resources and the used load, an The idleness of the service instance is evaluated, which can be specifically expressed as the ratio of the available resources to the used load is defined as the idleness of the service instance.

第二方面,本申请实施提供一种微服务系统,该微服务系统包括:接收单元,用于接收第一客户端发送的携带第一资源标识的第一请求;处理单元,用于若确定所述第一资源标识中未携带有服务实例标识,则为所述第一请求分配第一服务实例;获取单元,用于通 过所述第一服务实例从数据库中获取所述第一资源标识所指示的第一资源;所述处理单元,还用于将所述第一资源发送至所述第一客户端并将所述第一资源缓存在所述第一服务实例中;所述处理单元,还用于根据所述第一服务实例的第一服务实例标识更新所述第一资源标识,得到用于指示所述第一资源的第二资源标识。In a second aspect, the present application provides a micro-service system, the micro-service system includes: a receiving unit, configured to receive a first request that carries a first resource identifier sent by a first client; a processing unit, configured to determine if the If the first resource identifier does not carry a service instance identifier, a first service instance is allocated to the first request; an acquiring unit is configured to obtain the first resource identifier from the database through the first service instance. the first resource; the processing unit is further configured to send the first resource to the first client and cache the first resource in the first service instance; the processing unit is further configured to for updating the first resource identifier according to the first service instance identifier of the first service instance to obtain a second resource identifier for indicating the first resource.

基于该方案,微服务系统通过对客户端发送的请求中的第一资源标识进行确认,确认是否携带服务实例标识,若确认没有携带,则微服务系统可为该请求分配一个服务实例,随后,一方面,微服务系统可通过该服务实例从数据库中获取第一资源标识所指示的第一资源,并将其发送客户端以及缓存在该服务实例中,另一方面,微服务系统还可对第一资源标识进行更新,其更新过程中包括增加该服务实例的标识,如此便于后续的客户端在对第一资源进行请求时,则可以直接由已经缓存有第一资源的该服务实例对其进行响应。该方式中微服务系统通过为某一资源的请求确定一个服务实例,并由该服务实例在从数据库中获取到该资源后对资源进行缓存,便于后续的关于该资源的请求再次到达微服务系统的时候,直接可由该服务实例对请求进行响应,避免须微服务系统中的每一个服务实例缓存有全部资源,极大地降低了系统的冗余。Based on this solution, the microservice system confirms whether the service instance identifier is carried by confirming the first resource identifier in the request sent by the client. On the one hand, the microservice system can obtain the first resource indicated by the first resource identifier from the database through the service instance, and send it to the client and cache it in the service instance. On the other hand, the microservice system can also The first resource identifier is updated, and the update process includes adding the identifier of the service instance, so that when the subsequent client requests the first resource, the service instance that has cached the first resource can directly access the service instance. respond. In this method, the microservice system determines a service instance for a request for a resource, and the service instance caches the resource after obtaining the resource from the database, so that subsequent requests for the resource can reach the microservice system again. At the time, the service instance can directly respond to the request, avoiding the need to cache all resources for each service instance in the microservice system, which greatly reduces the redundancy of the system.

在一种可能实现的方法中,所述处理单元,还用于:若确定所述第一资源标识中携带有第二服务实例标识,则将所述第一请求分配至所述第二服务实例;将所述第二服务实例缓存的所述第一资源标识指示的第一资源发送给所述第一客户端。In a possible implementation method, the processing unit is further configured to: if it is determined that the first resource identifier carries a second service instance identifier, assign the first request to the second service instance ; Send the first resource indicated by the first resource identifier cached by the second service instance to the first client.

基于该方案,在微服务系统对第一资源标识进行确认的过程中,若确认其中携带有第二服务实例标识,则表示在第一请求进入到微服务系统之前,微服务系统已经通过第二服务实例对第一请求对应的第一资源进行了缓存,且使用第二服务实例标识对第一资源标识进行了更新,如此在微服务系统检查到第一资源标识中携带有第二服务实例标识时,微服务系统可直接将第一请求转发至第二服务实例,由第二服务实例使用本地已缓存的对应于第一请求的第一资源对第一请求直接进行响应,从而提高了对请求进行响应的效率。Based on this solution, in the process of confirming the first resource identifier by the microservice system, if it is confirmed that the identifier of the second service instance is carried in it, it means that the microservice system has passed the second service instance identifier before the first request enters the microservice system. The service instance caches the first resource corresponding to the first request, and uses the second service instance identifier to update the first resource identifier, so the microservice system checks that the first resource identifier carries the second service instance identifier , the microservice system can directly forward the first request to the second service instance, and the second service instance uses the locally cached first resource corresponding to the first request to directly respond to the first request, thereby improving the response to the request. The efficiency of the response.

在一种可能实现的方法中,所述第一资源标识中还携带有第三服务实例标识,所述第三服务实例标识对应的第三服务实例是所述第二服务实例的备用服务实例;所述处理单元,还用于:若确定所述第二服务实例处于不可用状态,则将所述第一请求分配至所述第三服务实例。In a possible implementation method, the first resource identifier further carries a third service instance identifier, and the third service instance corresponding to the third service instance identifier is a backup service instance of the second service instance; The processing unit is further configured to: if it is determined that the second service instance is in an unavailable state, assign the first request to the third service instance.

基于该方案,在微服务系统为第一请求分配可服务于它的服务实例的过程中,除了可以为它分配第二服务实例,还可以为它分配第三服务实例(其中,第三服务实例的个数可为多个),第三服务实例是第二服务实例的备用服务实例,从而在微服务系统准备将第一请求分配至第二服务实例之前,通过确定第二服务实例的状态是否为可用,也即确定第二服务实例是否为可服务状态,并在微服务系统确定第二服务实例为不可用状态时,微服务系统则可基于第三服务实例的标识、将第一请求分配至第三服务实例,以由第三服务实例来对第一请求进行响应。该方式中第三服务实例为预先基于服务实例集群实时、动态的资源和负载情况而确定的、可服务于第一请求的、除去第二服务实例之外的性能较好的服务实例,如此可以实现第二服务实例故障条件下的高可用的目标。Based on this solution, in the process of allocating a service instance that can serve the first request to the micro-service system, in addition to assigning a second service instance to it, it can also be assigned a third service instance (wherein the third service instance can be multiple), the third service instance is the backup service instance of the second service instance, so that before the microservice system prepares to allocate the first request to the second service instance, by determining whether the status of the second service instance is is available, that is, it is determined whether the second service instance is in a serviceable state, and when the microservice system determines that the second service instance is in an unavailable state, the microservice system can allocate the first request based on the identifier of the third service instance. to a third service instance to respond to the first request by the third service instance. In this method, the third service instance is a service instance with better performance except the second service instance that is determined in advance based on the real-time and dynamic resources and load conditions of the service instance cluster and can serve the first request. Achieve the goal of high availability under the failure condition of the second service instance.

在一种可能实现的方法中,所述接收单元,还用于:接收第二客户端发送的携带所述第二资源标识的第二请求;所述第二客户端是通过刷新机制获得所述第二资源标识;所述处理单元,还用于:确定所述第二资源标识中携带有所述第一服务实例标识,则将所述第二请求分配至所述第一服务实例;将所述第一服务实例缓存的所述第一资源发送给所述第二客户端。In a possible implementation method, the receiving unit is further configured to: receive a second request sent by a second client that carries the second resource identifier; the second client obtains the second resource through a refresh mechanism the second resource identifier; the processing unit is further configured to: determine that the second resource identifier carries the first service instance identifier, then allocate the second request to the first service instance; The first resource cached by the first service instance is sent to the second client.

基于该方案,在第一客户端发出的第一请求为首次发送至微服务系统的请求时,通过微服务系统可以为第一请求分配可服务于它的服务实例——第一服务实例,并将对应于第一资源的标识从第一资源标识更新为了第二资源标识,从而若后续的客户端(即第二客户端)再次请求对应于第一请求的第一资源时,也即第二客户端向微服务系统发送的第二请求中携带了第二资源标识,该第二资源标识是第二客户端通过刷新机制得到的,微服务系 统可以直接通过第一服务实例来对第二客户端进行响应。该方式基于微服务系统中的第一服务实例中已经缓存有第一资源,并且微服务系统也对第一资源的标识进行了更新,也即建立了第一资源与第一服务实例之间的绑定/对应关系,从而微服务系统可以基于第一服务实例来对同一资源(如第一资源)的请求进行快速响应。Based on this solution, when the first request sent by the first client is a request sent to the micro-service system for the first time, the micro-service system can allocate a service instance that can serve the first request—the first service instance, and The identifier corresponding to the first resource is updated from the first resource identifier to the second resource identifier, so that if the subsequent client (ie the second client) requests the first resource corresponding to the first request again, that is, the second The second request sent by the client to the microservice system carries the second resource identifier, and the second resource identifier is obtained by the second client through the refresh mechanism. The microservice system can directly use the first service instance to request the second client terminal responds. This method is based on the fact that the first resource has been cached in the first service instance in the microservice system, and the microservice system also updates the identifier of the first resource, that is, the relationship between the first resource and the first service instance is established. A binding/correspondence relationship, so that the microservice system can quickly respond to a request for the same resource (eg, the first resource) based on the first service instance.

在一种可能实现的方法中,所述处理单元,具体用于:按照设定顺序依次拼接所述第一资源标识和所述第一服务实例标识,得到用于指示所述第一资源的第二资源标识。In a possible implementation method, the processing unit is specifically configured to: splicing the first resource identifier and the first service instance identifier in sequence according to the set order, to obtain the first resource indicating the first resource. 2. Resource ID.

基于该方案,微服务系统在为首次进入到其中的第一请求确定了可服务于它的服务实例是第一服务实例后,可对标识第一资源的第一资源标识进行更新,如依次拼接第一资源标识和第一服务实例标识,从而拼接后的结果即可为第二资源标识。该方式通过在第一资源标识中增加第一服务实例标识而得到第二资源标识,也即建立了第一资源与第一服务实例之间的绑定/对应关系,便于在微服务系统对第二资源标识进行解析后可以快速确定第一服务实例并进行请求的转发。Based on this solution, after the microservice system determines that the service instance that can serve it is the first service instance for the first request entering it for the first time, it can update the first resource identifier that identifies the first resource, such as splicing sequentially The first resource identifier and the first service instance identifier, so that the result after splicing can be the second resource identifier. In this method, the second resource identifier is obtained by adding the first service instance identifier to the first resource identifier, that is, the binding/correspondence relationship between the first resource and the first service instance is established, which is convenient for the microservice system to After the second resource identifier is parsed, the first service instance can be quickly determined and the request can be forwarded.

在一种可能实现的方法中,所述处理单元,还用于:确定所述第一服务实例的备用服务实例;所述处理单元,具体用于:按照设定顺序依次拼接所述第一资源标识、所述第一服务实例标识和所述备用服务实例的备用服务实例标识,得到用于指示所述第一资源的第二资源标识。In a possible implementation method, the processing unit is further configured to: determine a backup service instance of the first service instance; the processing unit is specifically configured to: sequentially splicing the first resources according to a set order The identifier, the first service instance identifier, and the standby service instance identifier of the standby service instance, to obtain a second resource identifier for indicating the first resource.

基于该方案,微服务系统在为首次进入到其中的第一请求分配服务实例的过程中,除了可以确定第一服务实例,还可以同时确定第一服务实例的备用服务实例(其中,备用服务实例的个数可为多个),以使得在第一服务实例不可用时,由微服务系统将请求分配到第一服务实例的备用服务实例上,如此,为了微服务系统可以确定出第一服务实例的备用服务实例,则在对第一资源标识进行更新时,可在其中增加该备用服务实例的标识,如此可以在第一服务实例不可用时,微服务系统可快速将请求分配至第一服务实例的备用服务实例上去,实现了高可用的目标。Based on this solution, in the process of allocating a service instance for the first request entering it for the first time, the micro-service system can not only determine the first service instance, but also determine the backup service instance of the first service instance (wherein the backup service instance The number can be multiple), so that when the first service instance is unavailable, the microservice system allocates the request to the standby service instance of the first service instance, so that the microservice system can determine the first service instance. When the first resource identifier is updated, the identifier of the standby service instance can be added to it, so that when the first service instance is unavailable, the microservice system can quickly allocate the request to the first service instance. The backup service instance goes up to achieve the goal of high availability.

在一种可能实现的方法中,所述处理单元,具体用于:加密所述第一服务实例标识和所述备用服务实例的备用服务实例标识,得到加密信息;按照设定顺序依次拼接所述第一资源标识和所述加密信息,得到用于指示所述第一资源的第二资源标识。In a possible implementation method, the processing unit is specifically configured to: encrypt the first service instance identifier and the standby service instance identifier of the standby service instance to obtain encrypted information; splicing the The first resource identifier and the encrypted information obtain a second resource identifier for indicating the first resource.

在一种可能实现的方法中,所述处理单元,具体用于:针对服务实例集群中的任一服务实例,确定所述服务实例的可用资源和已用负载;根据所述可用资源和所述已用负载,确定所述服务实例的空闲程度;将空闲程度满足设定条件的服务实例确定为所述第一服务实例。In a possible implementation method, the processing unit is specifically configured to: for any service instance in the service instance cluster, determine the available resources and used load of the service instance; The used load is determined as the idle degree of the service instance; the service instance whose idle degree satisfies the set condition is determined as the first service instance.

基于该方案,微服务系统对进入到其中的第一请求,若确定它未携带服务实例标识,则为该请求分配第一服务实例,该分配过程中可基于服务实例集群实时、动态的资源和负载情况来对其中的每一个服务实例的空闲程度进行确定,从而可将空闲程度满足设定条件的服务实例确定为第一服务实例。该方式通过评估服务实例集群中的服务实例的空闲程度,并将空闲程度满足设定条件的服务实例作为第一服务实例,实现了以最佳状态的服务实例来缓存请求对应的资源的目的。Based on this solution, the micro-service system allocates a first service instance to the request if it determines that it does not carry a service instance identifier for the first request that enters it. The allocation process can be based on real-time, dynamic resource and The idle degree of each service instance is determined according to the load situation, so that the service instance whose idle degree satisfies the set condition can be determined as the first service instance. By evaluating the idleness of the service instances in the service instance cluster, and taking the service instance whose idleness meets the set condition as the first service instance, the purpose of caching the resource corresponding to the request with the service instance in the best state is realized.

在一种可能实现的方法中,所述处理单元,具体用于:针对服务实例集群中的任一服务实例,将所述服务实例的未使用的中央处理器CPU核数和未使用内存确定为所述可用资源,以及将所述服务实例在预设历史时段中的请求访问数量和请求访问时长确定为所述已用负载;将所述可用资源与所述已用负载的比值,确定为所述服务实例的空闲程度。In a possible implementation method, the processing unit is specifically configured to: for any service instance in the service instance cluster, determine the number of unused central processing unit CPU cores and unused memory of the service instance as The available resources, and the number of requested accesses and the requested access duration of the service instance in the preset historical period are determined as the used load; the ratio of the available resources to the used load is determined as the used load. Describes the idleness of the service instance.

基于该方案,在微服务系统对服务实例集群中的服务实例的空闲程度进行确定的过程中,可基于服务实例集群在当前状态下实时的资源和负载情况而开展,如将服务实例未使用状态的CPU核数以及内存作为可用资源的表现形式,以及可将服务实例已接收到的请求访问数量以及访问时长作为已用负载的表现形式,并可基于可用资源和已用负载来准确地对一个服务实例的空闲程度进行评估,具体可以表示为将可用资源与已用负载的比值定义为该服务实例的空闲程度。第三方面,本申请实施例提供了一种计算设备,包括:Based on this solution, in the process of determining the idleness of service instances in the service instance cluster by the microservice system, it can be carried out based on the real-time resources and load conditions of the service instance cluster in the current state. The number of CPU cores and memory used as the representation of available resources, and the number of requested accesses received by the service instance and the access duration can be used as the representation of the used load. Based on the available resources and the used load, an The idleness of the service instance is evaluated, which can be specifically expressed as the ratio of the available resources to the used load is defined as the idleness of the service instance. In a third aspect, an embodiment of the present application provides a computing device, including:

存储器,用于存储程序指令;memory for storing program instructions;

处理器,用于调用所述存储器中存储的程序指令,按照获得的程序执行如第一方面任一实现方法。The processor is configured to call the program instructions stored in the memory, and execute any one of the implementation methods of the first aspect according to the obtained program.

第四方面,本申请实施例提供了一种计算机可读存储介质,所述计算机可读存储介质存储有计算机可执行指令,所述计算机可执行指令用于使计算机执行如第一方面任一实现方法。In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, where the computer-readable storage medium stores computer-executable instructions, and the computer-executable instructions are used to cause a computer to execute any implementation of the first aspect method.

附图说明Description of drawings

为了更清楚地说明本申请实施例中的技术方案,下面将对实施例描述中所需要使用的附图作简要介绍,显而易见地,下面描述中的附图仅仅是本申请的一些实施例,对于本领域的普通技术人员来讲,在不付出创造性劳动性的前提下,还可以根据这些附图获得其他的附图。In order to illustrate the technical solutions in the embodiments of the present application more clearly, the following briefly introduces the drawings used in the description of the embodiments. Obviously, the drawings in the following description are only some embodiments of the present application. For those of ordinary skill in the art, other drawings can also be obtained from these drawings without any creative effort.

图1为本申请实施例提供的一种可能的系统架构示意图;FIG. 1 is a schematic diagram of a possible system architecture provided by an embodiment of the present application;

图2为本申请实施例提供的一种请求处理方法;FIG. 2 provides a request processing method according to an embodiment of the present application;

图3为本申请实施例提供的一种微服务系统;FIG. 3 provides a microservice system according to an embodiment of the present application;

图4为本申请实施例提供的一种计算设备的示意图。FIG. 4 is a schematic diagram of a computing device according to an embodiment of the present application.

具体实施方式Detailed ways

为了使本申请的目的、技术方案和优点更加清楚,下面将结合附图对本申请作进一步地详细描述,显然,所描述的实施例仅仅是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其它实施例,都属于本申请保护的范围。In order to make the objectives, technical solutions and advantages of the present application clearer, the present application will be further described in detail below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative work fall within the protection scope of the present application.

目前,微服务系统对客户端发送的服务请求(该服务请求会携带数据库中的资源的主键标识)进行响应时,为了实现高可用,则会在服务实例集群中的任一个服务实例上预先缓存数据库中的每一个主键标识所对应的资源,从而每一个服务实例可提供一种无状态的服务。然而,该过程在服务实例集群规模较大时或者数据库中的数据量较大时,冗余成本比较高。At present, when the microservice system responds to the service request sent by the client (the service request will carry the primary key identifier of the resource in the database), in order to achieve high availability, it will be pre-cached on any service instance in the service instance cluster. Each primary key in the database identifies the corresponding resource, so that each service instance can provide a stateless service. However, in this process, when the scale of the service instance cluster is large or the amount of data in the database is large, the redundancy cost is relatively high.

针对上述技术问题,本申请提供一种可能的系统架构示意图,如图1所示,该架构包括客户端110、微服务系统120和数据库130。其中,微服务系统120中又可以包括网关1201、注册中心1202、别名管理单元1203和服务实例集群1204,其中,服务实例集群1204中可包括多个服务实例。In view of the above technical problems, the present application provides a schematic diagram of a possible system architecture, as shown in FIG. 1 , the architecture includes a client 110 , a microservice system 120 and a database 130 . The microservice system 120 may further include a gateway 1201, a registry 1202, an alias management unit 1203, and a service instance cluster 1204, wherein the service instance cluster 1204 may include multiple service instances.

其中,微服务系统120中的网关1201可接收客户端110发送的服务请求,服务请求中携带有待请求资源的资源标识。在网关1201接收到服务请求后,通过对其中的资源标识的解析,一方面,网关1201可确定待请求资源在数据库130中的主键标识,其中,数据库130是以主键的方式对存储于其中的资源进行标识;另一方面,网关1201还可以确定资源标识中是否含有微服务系统120中的服务实例的标识,并根据识别结果做出相应的响应行为。其中,识别结果可以包括:The gateway 1201 in the microservice system 120 may receive a service request sent by the client 110, and the service request carries the resource identifier of the resource to be requested. After the gateway 1201 receives the service request, by parsing the resource identifier in it, on the one hand, the gateway 1201 can determine the primary key identifier of the resource to be requested in the database 130, wherein the database 130 is a primary key for the stored in it On the other hand, the gateway 1201 can also determine whether the resource identifier contains the identifier of the service instance in the microservice system 120, and make corresponding response actions according to the identification result. The identification results may include:

情形1、资源标识中未包括服务实例的标识。Case 1. The resource identifier does not include the identifier of the service instance.

若网关1201对资源标识的解析结果为其中未包括服务实例的标识,则网关1201可以向微服务系统120中的别名管理单元1203发送指示信息,指示别名管理单元1203对微服务系统120中的服务实例集群1204中的各个服务实例的空闲程度进行确定,在别名管理单元1203确定了各个服务实例的空闲程度以后,别名管理单元1203须将其中空闲程度满足预设条件的服务实例的标识返回给网关1201,从而网关1201可以将本次的服务请求以及所接收到的服务实例的标识一并发送给所标识的服务实例,让所标识的服务实例来对本次的服务请求进行响应。If the resolution result of the resource identifier by the gateway 1201 is that the identifier of the service instance is not included, the gateway 1201 may send instruction information to the alias management unit 1203 in the microservice system 120, instructing the alias management unit 1203 to respond to the service in the microservice system 120. The idleness of each service instance in the instance cluster 1204 is determined. After the alias management unit 1203 determines the idleness of each service instance, the alias management unit 1203 must return the identifier of the service instance whose idleness meets the preset condition to the gateway. 1201, so that the gateway 1201 can send the current service request together with the received service instance identifier to the identified service instance, so that the identified service instance can respond to the current service request.

情形2、资源标识中包括服务实例的标识。Scenario 2: The resource identifier includes the identifier of the service instance.

若网关1201对资源标识的解析结果为其中包括服务实例的标识,则网关1201可以直接将本次的服务请求发送至所标识的服务实例,以让所标识的服务实例来对本次的服务请求进行响应。If the result of gateway 1201's analysis of the resource identifier is that the identifier of the service instance is included, the gateway 1201 can directly send the current service request to the identified service instance, so that the identified service instance can respond to the current service request. respond.

其中,在别名管理单元1203对微服务系统120中的服务实例集群1204中的各个服务实例的空闲程度进行确定时,可以根据各个服务实例在当前状态下实时的可用资源以及已用负载来确定服务实例的空闲程度,其中的预设条件可以是将服务实例集群1204中的空闲程度最大的服务实例确定为可响应于本次服务请求的服务实例,因此,别名管理单元1203可以将空闲程度最大的服务实例的标识返回给网关1201。可选的,预设条件还可以是将服务实例集群1204中的空闲程度最大的若干个服务实例确定为可响应于本次服务请求的服务实例,并将这若干个服务实例中的空闲程度最大的服务实例确定为响应于本次服务请求的服务实例,即主服务实例,而将这若干个服务实例中除去主服务实例外的服务实例确定为主服务实例的备用服务实例,且别名管理单元1203在将主服务实例标识以及备用服务实例标识发送给网关1201的过程中,是做了不同标记的,以使得网关1201可以准确地区分主服务实例以及备用服务实例。该方式可以在主服务实例故障时实现高可用。Wherein, when the alias management unit 1203 determines the idleness of each service instance in the service instance cluster 1204 in the microservice system 120, the service can be determined according to the real-time available resources and the used load of each service instance in the current state. The idleness of the instance, wherein the preset condition may be to determine the service instance with the most idleness in the service instance cluster 1204 as the service instance that can respond to this service request. Therefore, the alias management unit 1203 The identity of the service instance is returned to gateway 1201 . Optionally, the preset condition may also be to determine a number of service instances with the greatest degree of idleness in the service instance cluster 1204 as service instances that can respond to this service request, and determine the number of service instances with the greatest degree of idleness among the several service instances. The service instance is determined as the service instance responding to this service request, that is, the main service instance, and the service instances other than the main service instance among the several service instances are determined as the standby service instances of the main service instance, and the alias management unit In the process of sending the primary service instance ID and the backup service instance ID to the gateway 1201, 1203 is marked differently, so that the gateway 1201 can accurately distinguish the primary service instance and the backup service instance. This method can achieve high availability when the primary service instance fails.

因此,对于情形1中,在网关1201接收到别名管理单元1203发送的若干个服务实例的标识后,网关1201则可以依据所标识的主服务实例而将本次的服务请求以及所接收到服务实例的标识(包括主服务实例的标识以及备用服务实例的标识)一并发送给所标识的主服务实例,让所标识的主服务实例来对本次的服务请求进行响应。Therefore, in case 1, after the gateway 1201 receives the identifiers of several service instances sent by the alias management unit 1203, the gateway 1201 can send the service request this time and the received service instance according to the identified primary service instance. The identifier (including the identifier of the primary service instance and the identifier of the standby service instance) is sent to the identified primary service instance, so that the identified primary service instance can respond to this service request.

说明的是,在所标识的主服务实例对本次的服务请求进行响应的过程,具体可以包括:主服务实例一方面可以对本次服务请求的主键标识、主服务实例的标识以及备用服务实例的标识进行加工,得到用于表示本次服务请求对应资源的另一种表现形式的资源标识,另一方面,主服务实例可根据服务请求中的主键标识,从与微服务系统120相连的数据库130中获取该主键标识所对应的资源,在将所获取的资源在本地(指主服务实例)进行存储后,继续将所获取的资源以及另一种表现形式的资源标识发送给网关1201,一方面由网关1201将资源返回给客户端110,从而实现了对本次服务请求的响应,另一方面由网关1201对另一种表现形式的资源标识与本次的主键标识建立对应关系后进行存储,以使后续的客户端在对同一资源进行请求时,网关1201确认本地缓存的对照关系中存储有该资源标识对应的另一种表现形式的资源标识,从而网关1201可通过刷新的机制将另一种表现形式的资源标识返回给客户端,因此客户端可以凭借另一种表现形式的资源标识向微服务系统120请求资源,并由已经缓存有该资源的主服务实例(主服务实例为可用状态)来对客户端进行快速响应。It is noted that the process of responding to the current service request by the identified primary service instance may specifically include: on the one hand, the primary service instance can identify the primary key of the current service request, the primary service instance's identity, and the standby service instance. The identifier of the service request is processed to obtain a resource identifier representing another form of representation of the resource corresponding to the service request. On the other hand, the main service instance can be based on the primary key identifier in the service request. From the database connected to the microservice system 120 Obtain the resource corresponding to the primary key identifier in 130, and after storing the acquired resource locally (referring to the main service instance), continue to send the acquired resource and the resource identifier in another form to the gateway 1201, a On the one hand, the gateway 1201 returns the resource to the client 110, thereby realizing the response to this service request; on the other hand, the gateway 1201 establishes a corresponding relationship between the resource identifier of another form and the primary key identifier of this time and stores it , so that when a subsequent client requests the same resource, the gateway 1201 confirms that another representation of the resource identifier corresponding to the resource identifier is stored in the locally cached comparison relationship, so that the gateway 1201 can refresh the other The resource identifier in one form is returned to the client, so the client can request resources from the microservice system 120 by virtue of the resource identifier in another form, and the main service instance that has cached the resource (the main service instance is available) status) to respond quickly to the client.

继续说明的是,上述过程中仅由主服务实例对服务请求的资源在本地进行了缓存,主服务实例的备用服务实例的本地并未对服务请求的资源进行缓存。该方式在满足高可用的条件时还可减少系统的冗余。Further explanation is that in the above process, only the resource requested by the service is locally cached by the primary service instance, and the resource requested by the service is not locally cached by the backup service instance of the primary service instance. This method can also reduce the redundancy of the system when high availability conditions are met.

因此,对于情形2中,在网关1201解析出主服务实例的标识以及备用服务实例的标识后,网关1201则可以继续确定主服务实例是否处于一种可用的状态,若主服务实例处于可用状态,则网关1201可以将本次的服务请求直接发送至主服务实例,由主服务实例通过本地已缓存的对应于本次服务请求的资源来对客户端110直接进行响应;若网关1201确定主服务实例处于一种不可用的状态,则网关1201可以将本次的服务请求发送至备用服务实例,以让备用服务实例来对本次的服务请求进行响应。Therefore, in case 2, after the gateway 1201 resolves the identification of the main service instance and the identification of the standby service instance, the gateway 1201 can continue to determine whether the main service instance is in an available state, if the main service instance is in an available state, Then the gateway 1201 can directly send this service request to the main service instance, and the main service instance directly responds to the client 110 through the locally cached resources corresponding to this service request; if the gateway 1201 determines that the main service instance In an unavailable state, the gateway 1201 can send the current service request to the standby service instance, so that the standby service instance can respond to the current service request.

说明的是,由于主服务实例的备用服务实例本地并未缓存有服务请求的资源,因此在主服务实例不可用时,备用服务实例对服务请求进行响应的过程中可以参考上述的主服务实例对服务请求进行响应的过程,在此不赘述。It is noted that, since the backup service instance of the primary service instance does not cache the resources requested by the service locally, when the primary service instance is unavailable, the backup service instance can refer to the above-mentioned primary service instance in the process of responding to the service request. The process of responding to the request will not be repeated here.

继续说明的是,由于服务实例集群中的各个服务实例的状态可长期处于一种稳定的状态,因此在初次为服务请求确定可服务于它的主服务实例和备用服务实例的时间节点下,为了减少对同一资源的冗余缓存,此时虽然仅由主服务实例本地对该服务请求的资源进行 了缓存,而并未让备用服务实例对该服务请求的资源进行缓存,在同一资源的服务请求到达微服务系统120后,微服务系统120中的网关1202确定主服务实例为不可用状态时,网关1202可将服务请求转发至主服务实例的备用服务实例,此时尽管备用服务实例本地并未缓存该服务请求的资源,但是由于备用服务实例是服务实例集群中相比于其他的非主服务实例之外的服务实例空闲程度大的服务实例,也即备用服务实例是当前状态下性能最好的服务实例了(基于服务实例集群各个服务实例在不同时间节点下的性能处于相对稳定的状态),因此此时让备用服务实例按照当初主服务实例获取对应于该服务请求的资源的执行方法,备用服务实例对客户端的该服务请求的也将会是比较快速的。注册中心1202可接收开始投入使用的服务实例在它上面进行注册的信息,并对服务实例进行注册,从而注册中心1202可以获取服务实例集群1204中的各个服务实例的状态,如通过心跳的方式确定服务实例的是否处于可用状态,以及获取服务实例的可用资源以及已用负载的数据。Continuing to explain, since the state of each service instance in the service instance cluster can be in a stable state for a long time, under the time node when the primary service instance and backup service instance that can serve it are first determined for the service request, in order to Reduce redundant caching of the same resource. At this time, although only the main service instance caches the resources requested by the service locally, and does not allow the standby service instance to cache the resources requested by the service, the service request of the same resource does not cache the resources requested by the service. After reaching the microservice system 120, when the gateway 1202 in the microservice system 120 determines that the primary service instance is unavailable, the gateway 1202 can forward the service request to the backup service instance of the primary service instance, even though the backup service instance is not locally available. Cache the resources requested by the service, but because the standby service instance is a service instance that is more idle than other service instances other than the non-primary service instance in the service instance cluster, that is, the standby service instance has the best performance in the current state. (based on the relatively stable performance of each service instance in the service instance cluster at different time nodes), so at this time, let the standby service instance obtain the resources corresponding to the service request according to the execution method of the original main service instance, The standby service instance will also be faster for the client to request the service. The registry 1202 can receive the information that the service instance that is put into use is registered on it, and register the service instance, so that the registry 1202 can obtain the status of each service instance in the service instance cluster 1204, such as determined by heartbeat Whether the service instance is available, and obtain the data of the available resources and used load of the service instance.

别名管理单元1203可用于接收网关1201发送的确定服务实例集群1204中的各个服务实例的空闲程度的指示信息,并在接收到该指示信息后,别名管理单元1203可以从注册中1202中获取服务实例集群1204中的各个服务实例的可用资源以及已用负载的数据,然后通过对可用资源以及已用负载进行相关计算,从而可以确定各个服务实例的空闲程度,并将空闲程度满足预设条件的服务实例的标识返回给网关1201。The alias management unit 1203 can be configured to receive the indication information sent by the gateway 1201 to determine the idleness of each service instance in the service instance cluster 1204 , and after receiving the indication information, the alias management unit 1203 can obtain the service instance from the registration 1202 The available resources and used load data of each service instance in the cluster 1204, and then by performing related calculations on the available resources and the used load, the idle degree of each service instance can be determined, and the idle degree satisfies the preset conditions. The identity of the instance is returned to gateway 1201 .

服务实例集群1204中包括多个服务实例,每个服务实例可用于缓存与微服务系统120相连的数据库130中的部分主键标识对应的数据。The service instance cluster 1204 includes multiple service instances, and each service instance can be used to cache data corresponding to some primary key identifiers in the database 130 connected to the microservice system 120 .

针对上述技术问题以及图1所示的系统架构,本申请实施例提供一种请求处理方法,如图2所示,该方法可以由图1所示的微服务系统执行,包括以下步骤:In response to the above technical problems and the system architecture shown in FIG. 1, an embodiment of the present application provides a request processing method. As shown in FIG. 2, the method can be executed by the microservice system shown in FIG. 1, and includes the following steps:

步骤201,微服务系统接收第一客户端发送的携带第一资源标识的第一请求。Step 201: The microservice system receives a first request that carries a first resource identifier and is sent by a first client.

在本步骤中,客户端发送的第一请求是基于与微服务系统相连的数据库中的主键标识进行生成的。换句话说,与客户端发送的第一请求相对应的第一资源是通过主键的方式存储在数据中的,从而客户端可以凭借主键标识来向数据库请求资源。其中,在客户端向数据库请求资源的过程中,可通过微服务系统来实现,具体是通过微服务系统中的服务实例对数据库中的资源进行缓存,如此可以减少客户端与数据库之间的直接交互,从而可减轻对数据库的压力。In this step, the first request sent by the client is generated based on the primary key identifier in the database connected to the microservice system. In other words, the first resource corresponding to the first request sent by the client is stored in the data by means of the primary key, so that the client can request the resource from the database by virtue of the primary key identifier. Among them, in the process of the client requesting resources from the database, it can be realized through the micro-service system, specifically, the resources in the database are cached through the service instance in the micro-service system, which can reduce the direct connection between the client and the database. interaction, thereby reducing the pressure on the database.

在本步骤中,可以通过微服务系统中的网关对第一请求进行接收。In this step, the first request may be received through the gateway in the microservice system.

步骤202,所述微服务系统若确定所述第一资源标识中未携带有服务实例标识,则为所述第一请求分配第一服务实例。Step 202, if the microservice system determines that the first resource identifier does not carry a service instance identifier, allocate a first service instance to the first request.

在本步骤中,在微服务系统中的网关接收到第一请求后,可继续由网关对第一资源标识进行分析,以确定第一资源标识中除了携带有数据库中的主键标识外,是否还携带有服务实例标识。若网关确定第一资源标识中并未携带有服务实例标识,也即网关确定第一资源标识仅为数据库中的主键标识,则网关可以为第一请求分配第一服务实例。其中,网关可以通过微服务系统中的别名管理单元来为第一请求分配第一服务实例。In this step, after the gateway in the microservice system receives the first request, the gateway may continue to analyze the first resource identifier to determine whether the first resource identifier carries the primary key identifier in the database, whether there is another It carries the service instance identifier. If the gateway determines that the first resource identifier does not carry the service instance identifier, that is, the gateway determines that the first resource identifier is only the primary key identifier in the database, the gateway may allocate the first service instance to the first request. The gateway may allocate the first service instance for the first request through an alias management unit in the microservice system.

步骤203,所述微服务系统通过所述第一服务实例从数据库中获取所述第一资源标识所指示的第一资源。Step 203, the microservice system obtains the first resource indicated by the first resource identifier from the database through the first service instance.

在本步骤中,在微服务系统中的网关确定可服务于第一请求的第一服务实例后,则网关一方面可以将第一请求转发至第一服务实例,以让第一服务实例从与微服务系统相连的数据库中获取第一资源标识所指示的第一资源,也即让第一服务实例从数据库中拉取数据库中的主键标识所指示的第一资源;另一方面,网关还可以将第一服务实例的第一服务实例标识也转发至第一服务实例,以让第一服务实例可以基于自身的标识来对第一资源标识进行更新,从而生成可以用于指示第一资源的第二资源标识。In this step, after the gateway in the microservice system determines the first service instance that can serve the first request, on the one hand, the gateway can forward the first request to the first service instance, so that the first service instance can Obtain the first resource indicated by the first resource identifier from the database connected to the microservice system, that is, let the first service instance pull the first resource indicated by the primary key identifier in the database from the database; on the other hand, the gateway can also The first service instance identifier of the first service instance is also forwarded to the first service instance, so that the first service instance can update the first resource identifier based on its own identifier, thereby generating a first resource identifier that can be used to indicate the first resource. 2. Resource ID.

步骤204,所述微服务系统将所述第一资源发送至所述第一客户端并将所述第一资源缓存在所述第一服务实例中。Step 204, the microservice system sends the first resource to the first client and caches the first resource in the first service instance.

在本步骤中,在微服务系统中的第一服务实例从数据库中拉取到第一资源标识所指示第一资源后,第一服务实例一方面可以将第一资源在本地进行缓存,另一方面第一服务实例可以将第一资源发送给网关,以通过网关将第一资源发送至第一客户端,从而实现了对客户端发送的第一请求的响应。In this step, after the first service instance in the microservice system pulls the first resource indicated by the first resource identifier from the database, on the one hand, the first service instance can cache the first resource locally, and on the other hand Aspects The first service instance may send the first resource to the gateway, so as to send the first resource to the first client through the gateway, thereby implementing a response to the first request sent by the client.

步骤205,所述微服务系统根据所述第一服务实例的第一服务实例标识更新所述第一资源标识,得到用于指示所述第一资源的第二资源标识。Step 205, the micro-service system updates the first resource identifier according to the first service instance identifier of the first service instance, and obtains a second resource identifier for indicating the first resource.

在本步骤中,可以通过微服务系统中的第一服务实例根据自身的标识对第一资源标识进行更新,得到可以用于指示第一资源的第二资源标识。In this step, the first resource identifier may be updated by the first service instance in the microservice system according to its own identifier to obtain a second resource identifier that can be used to indicate the first resource.

基于该方案,微服务系统通过对客户端发送的请求中的第一资源标识进行确认,确认是否携带服务实例标识,若确认没有携带,则微服务系统可为该请求分配一个服务实例,随后,一方面,微服务系统可通过该服务实例从数据库中获取第一资源标识所指示的第一资源,并将其发送客户端以及缓存在该服务实例中,另一方面,微服务系统还可对第一资源标识进行更新,其更新过程中包括增加该服务实例的标识,如此便于后续的客户端在对第一资源进行请求时,则可以直接由已经缓存有第一资源的该服务实例对其进行响应。该方式中微服务系统通过为某一资源的请求确定一个服务实例,并由该服务实例在从数据库中获取到该资源后对资源进行缓存,便于后续的关于该资源的请求再次到达微服务系统的时候,直接可由该服务实例对请求进行响应,避免须微服务系统中的每一个服务实例缓存有全部资源,极大地降低了系统的冗余。Based on this solution, the microservice system confirms whether the service instance identifier is carried by confirming the first resource identifier in the request sent by the client. On the one hand, the microservice system can obtain the first resource indicated by the first resource identifier from the database through the service instance, and send it to the client and cache it in the service instance. On the other hand, the microservice system can also The first resource identifier is updated, and the update process includes adding the identifier of the service instance, so that when the subsequent client requests the first resource, the service instance that has cached the first resource can directly access the service instance. respond. In this method, the microservice system determines a service instance for a request for a resource, and the service instance caches the resource after obtaining the resource from the database, so that subsequent requests for the resource can reach the microservice system again. At the time, the service instance can directly respond to the request, avoiding the need to cache all resources for each service instance in the microservice system, which greatly reduces the redundancy of the system.

以下将结合示例分别对上述一些步骤进行详细说明。Some of the above steps will be described in detail below with reference to examples.

在上述步骤202的一个实施中,所述微服务系统若确定所述第一资源标识中携带有第二服务实例标识,则将所述第一请求分配至所述第二服务实例;所述微服务系统将所述第二服务实例缓存的所述第一资源标识指示的第一资源发送给所述第一客户端。In an implementation of the above step 202, if the micro-service system determines that the first resource identifier carries a second service instance identifier, it allocates the first request to the second service instance; the micro-service system assigns the first request to the second service instance; The service system sends the first resource indicated by the first resource identifier cached by the second service instance to the first client.

例如,在微服务系统中的网关接收到第一请求后,通过网关对第一资源标识进行分析后发现,第一资源标识中携带有第二服务实例标识,这说明在第一请求进入到微服务系统之前,已经存在过至少一个服务请求曾经进入过微服务系统中,并且已经由微服务系统中的第二服务实例对该服务请求进行响应,可以理解的是,这里的至少一个服务请求所要请求的资源与第一请求所要请求的资源为同一主键标识所指示的资源;进一步的在微服务系统对服务请求进行响应的过程中,微服务系统已经对该服务请求的资源标识进行了更新,使得更新后的资源标识中携带有第二服务实例的标识。因此,网关可以直接将第一请求转发至第二服务实例,以让第二服务实例使用本地已经缓存过的针对于第一资源标识所指示的第一资源来对客户端进行响应,如此提高了微服务系统对客户端进行响应的效率。For example, after the gateway in the microservice system receives the first request, it analyzes the first resource identifier through the gateway and finds that the first resource identifier carries the second service instance identifier, which means that when the first request enters the microservice Before the service system, there has been at least one service request that has entered the microservice system, and the second service instance in the microservice system has responded to the service request. It is understandable that at least one service request here requires The requested resource and the resource to be requested by the first request are the resources indicated by the same primary key identifier; further in the process of the microservice system responding to the service request, the microservice system has updated the resource identifier of the service request, The updated resource identifier carries the identifier of the second service instance. Therefore, the gateway can directly forward the first request to the second service instance, so that the second service instance uses the locally cached first resource indicated by the first resource identifier to respond to the client, which improves the The efficiency with which a microservice system responds to clients.

在本申请的某些实施例中,所述第一资源标识中还携带有第三服务实例标识,所述第三服务实例标识对应的第三服务实例是所述第二服务实例的备用服务实例;所述方法还包括:所述微服务系统若确定所述第二服务实例处于不可用状态,则将所述第一请求分配至所述第三服务实例。In some embodiments of the present application, the first resource identifier further carries a third service instance identifier, and the third service instance corresponding to the third service instance identifier is a backup service instance of the second service instance ; The method further includes: if the micro-service system determines that the second service instance is in an unavailable state, assigning the first request to the third service instance.

在上面的例子中,在微服务系统使用其内部的第二服务实例来对服务请求进行响应时,微服务系统为了保证服务的高可用性,因此微服务系统除了为该服务请求确定了可服务于它(指该服务请求)的第二服务实例,微服务系统还确定了可服务于该服务请求的第三服务实例,其中,第三服务实例为第二服务实例的备用服务实例,第三服务实例的个数可以为一个或者多个。说明的是,为了减少微服务系统的冗余,本申请实施例中仅让第二服务实例本地缓存有服务请求对应的数据库资源,并不要求第三服务实例本地也对该服务请求对应的数据库资源进行缓存。如此,微服务系统可以基于第二服务实例的第二服务实例标识和第三服务实例的第三服务实例标识来对服务请求的主键标识进行更新,从而得到的第一资源标识中携带有主键标识、第二服务实例标识和第三服务实例标识。因此,在微服务系统中的网关准备将第一请求转发至第二服务实例之前,网关还可首先对第二服务实例的 状态进行确定,并在确定第二服务实例为不可用时,网关则可以将第一请求转发至第二服务实例的备用服务实例,也即第三服务实例,以使第三服务实例来对第一请求进行响应。其中,在第三服务实例本地并未缓存有第一请求对应的第一资源时,第三服务实例对第一请求进行响应的过程可以参考前述步骤中第一服务实例对第一请求进行响应的过程,本申请不再赘述。In the above example, when the microservice system uses its internal second service instance to respond to the service request, in order to ensure the high availability of the service, the microservice system not only determines the service request for the service request It (referring to the service request) is the second service instance, and the microservice system also determines a third service instance that can serve the service request, where the third service instance is a backup service instance of the second service instance, and the third service instance The number of instances can be one or more. It should be noted that, in order to reduce the redundancy of the micro-service system, in the embodiment of this application, only the database resources corresponding to the service request are cached locally by the second service instance, and the database corresponding to the service request is not required to be locally cached by the third service instance. Resources are cached. In this way, the microservice system can update the primary key identifier of the service request based on the second service instance identifier of the second service instance and the third service instance identifier of the third service instance, so that the obtained first resource identifier carries the primary key identifier , the second service instance identifier and the third service instance identifier. Therefore, before the gateway in the microservice system prepares to forward the first request to the second service instance, the gateway may first determine the status of the second service instance, and when it is determined that the second service instance is unavailable, the gateway may The first request is forwarded to an alternate service instance of the second service instance, that is, the third service instance, so that the third service instance responds to the first request. Wherein, when the third service instance does not locally cache the first resource corresponding to the first request, the process of the third service instance responding to the first request may refer to the process of the first service instance responding to the first request in the preceding steps. The process is not repeated in this application.

说明的是,由于服务实例集群中的各个服务实例的状态可长期处于一种稳定的状态,因此在初次为服务请求确定可服务于它的主服务实例和备用服务实例的时间节点下,为了减少对同一资源的冗余缓存,此时虽然仅由主服务实例本地对该服务请求的资源进行了缓存,而并未让备用服务实例对该服务请求的资源进行缓存,在同一资源的服务请求到达微服务系统后,微服务系统中的网关确定主服务实例为不可用状态时,网关可将服务请求转发至主服务实例的备用服务实例,此时尽管备用服务实例本地并未缓存该服务请求的资源,但是由于备用服务实例是服务实例集群中相比于其他的非主服务实例之外的服务实例空闲程度大的服务实例,也即备用服务实例是当前状态下性能最好的服务实例了(基于服务实例集群各个服务实例在不同时间节点下的性能处于相对稳定的状态),因此此时让备用服务实例按照当初主服务实例获取对应于该服务请求的资源的执行方法,备用服务实例对客户端的该服务请求的也将会是比较快速的,也即说明在第二服务实例的状态为不可用时,网关通过将第一请求转发至第二服务实例的备用服务实例,也即第三服务实例上去,通过第三服务实例来对第一请求进行响应的速度也将是比较快速的,实现了一种资源冗余性低且还可对服务请求进行快速响应的目标。It is noted that, since the state of each service instance in the service instance cluster can be in a stable state for a long time, in order to reduce the For redundant caching of the same resource, although only the primary service instance caches the resources requested by the service locally, and does not allow the standby service instance to cache the resources requested by the service, when the service request for the same resource arrives After the microservice system, when the gateway in the microservice system determines that the primary service instance is unavailable, the gateway can forward the service request to the backup service instance of the primary service instance, although the backup service instance does not cache the service request locally. resources, but because the standby service instance is a service instance that is more idle than other service instances other than the non-primary service instance in the service instance cluster, that is, the standby service instance is the service instance with the best performance in the current state ( Based on the performance of each service instance in the service instance cluster at different time nodes, the performance is relatively stable), so at this time, let the standby service instance obtain the resources corresponding to the service request according to the execution method of the original main service instance. The service request on the terminal will also be relatively fast, which means that when the status of the second service instance is unavailable, the gateway forwards the first request to the standby service instance of the second service instance, that is, the third service instance. In the above, the speed of responding to the first request through the third service instance will also be relatively fast, which achieves the goal of low resource redundancy and fast response to the service request.

在上述步骤205的一个实施方式中,所述微服务系统接收第二客户端发送的携带所述第二资源标识的第二请求;所述第二客户端是通过刷新机制获得所述第二资源标识;所述微服务系统确定所述第二资源标识中携带有所述第一服务实例标识,则将所述第二请求分配至所述第一服务实例;所述微服务系统将所述第一服务实例缓存的所述第一资源发送给所述第二客户端。In an embodiment of the foregoing step 205, the micro-service system receives a second request sent by a second client that carries the identifier of the second resource; the second client obtains the second resource through a refresh mechanism identifier; the microservice system determines that the second resource identifier carries the first service instance identifier, and then assigns the second request to the first service instance; the microservice system assigns the first service instance identifier to the first service instance. The first resource cached by a service instance is sent to the second client.

例如,针对前述例子中微服务系统中的第一服务实例对第一客户端发送的第一请求进行响应时,第一服务实例将第一资源标识更新为第二资源标识,并将第二资源标识发送至微服务系统中的网关,以由网关在建立起第一请求的主键标识与第二资源标识的对应关系并进行存储。因而,在第一请求发生过后的某一个时间点,若存在有第二客户端继续向数据库发送与第一请求相同资源(即第一资源)的服务请求时,该服务请求可被微服务系统中的网关接收到,网关通过对该服务请求的分析,确定本地缓存的对照关系中存储有该服务请求的主键标识,因此网关可以通过刷新的机制将第二资源标识发送给第二客户端,如此第二客户端可以凭借所接收到的第二资源标识而向微服务系统重新发送一个服务请求,即第二请求,在微服务系统中的网关接收到第二请求时,通过对该第二请求所携带的第二资源标识的分析发现,其中携带有第一服务实例标识,因此为了加快对客户端的响应效率,网关可以将该第二请求直接分配至第一服务实例,以让第一服务实例将本地缓存的第一资源发送给第二客户端。For example, when the first service instance in the microservice system in the foregoing example responds to the first request sent by the first client, the first service instance updates the first resource identifier to the second resource identifier, and updates the second resource identifier to the second resource identifier. The identifier is sent to the gateway in the microservice system, so that the gateway establishes and stores the corresponding relationship between the primary key identifier of the first request and the second resource identifier. Therefore, at a certain point in time after the first request occurs, if there is a second client that continues to send a service request with the same resource (ie, the first resource) as the first request to the database, the service request can be processed by the microservice system The gateway in the received, through the analysis of the service request, the gateway determines that the primary key identifier of the service request is stored in the comparison relationship of the local cache, so the gateway can send the second resource identifier to the second client through the refresh mechanism, In this way, the second client can re-send a service request to the micro-service system by virtue of the received second resource identifier, that is, the second request, when the gateway in the micro-service system receives the second request, through the second request Analysis of the second resource identifier carried in the request shows that the first service instance identifier is carried in it. Therefore, in order to speed up the response efficiency to the client, the gateway can directly assign the second request to the first service instance, so that the first service instance can be The instance sends the locally cached first resource to the second client.

在上述步骤205的一个实施方式中,所述微服务系统根据所述第一服务实例的第一服务实例标识更新所述第一资源标识,得到用于指示所述第一资源的第二资源标识,包括:所述微服务系统按照设定顺序依次拼接所述第一资源标识和所述第一服务实例标识,得到用于指示所述第一资源的第二资源标识。In an embodiment of the above step 205, the micro-service system updates the first resource identifier according to the first service instance identifier of the first service instance, and obtains a second resource identifier for indicating the first resource , including: the micro-service system sequentially splices the first resource identifier and the first service instance identifier according to the set order, and obtains a second resource identifier for indicating the first resource.

例如,针对前述例子中微服务系统中的网关在接收到微服务系统中的别名管理单元发送的第一服务实例的第一服务实例标识,网关可以将第一服务实例标识随同第一请求一并发送给第一服务实例,一方面可以由第一服务实例通过主键标识从数据库中获取第一资源来对第一客户端进行响应,另一方面,为了可以减轻网关的操作压力,还可以由第一服务实例按照设定顺序依次拼接第一资源标识(即数据库中的主键标识)和第一服务实例标识, 从而可以得到用于指示第一资源的第二资源标识,其中,通过第二资源标识,可以建立起第一资源与第一服务实例之间的绑定/对应关系,因此可以通过微服务系统中的第一服务实例来实现对第一资源标识的更新。For example, for the gateway in the microservice system in the foregoing example, after receiving the first service instance identifier of the first service instance sent by the alias management unit in the microservice system, the gateway may combine the first service instance identifier with the first request Sent to the first service instance, on the one hand, the first service instance can obtain the first resource from the database through the primary key identifier to respond to the first client; on the other hand, in order to reduce the operating pressure of the gateway, the A service instance splices the first resource identifier (that is, the primary key identifier in the database) and the first service instance identifier in sequence according to the set order, so that the second resource identifier for indicating the first resource can be obtained, wherein the second resource identifier , a binding/correspondence relationship between the first resource and the first service instance can be established, so the first resource identifier can be updated through the first service instance in the microservice system.

在本申请的某些实施例中,所述得到用于指示所述第一资源的第二资源标识之前,还包括:所述微服务系统确定所述第一服务实例的备用服务实例;所述微服务系统按照设定顺序依次拼接所述第一资源标识和所述第一服务实例标识,得到用于指示所述第一资源的第二资源标识,包括:所述微服务系统按照设定顺序依次拼接所述第一资源标识、所述第一微务实例标识和所述备用服务实例的备用服务实例标识,得到用于指示所述第一资源的第二资源标识。In some embodiments of the present application, before the obtaining the second resource identifier used to indicate the first resource, the method further includes: determining, by the microservice system, a backup service instance of the first service instance; the The micro-service system sequentially splices the first resource identifier and the first service instance identifier according to the set order to obtain the second resource identifier used to indicate the first resource, including: the micro-service system follows the set order The first resource identifier, the first microservice instance identifier, and the standby service instance identifier of the standby service instance are sequentially spliced to obtain a second resource identifier for indicating the first resource.

例如,前述例子中,当微服务系统中的别名管理单元在接收到微服务系统中的网关发送的确定可服务于第一请求的服务实例的指示信息时,为了满足服务的高可用性,别名管理单元除了可以为第一请求确定了可服务于它的第一服务实例,别名管理单元同时还可以确定第一服务实例的备用服务实例,以实现在第一服务实例不可用时,可以有可快速响应的备用服务实例来实现服务请求的切换、转移。因此,别名管理单元可以将第一服务实例的第一服务实例标识以及第一服务实例的备用服务实例的备用服务实例标识一同发送给第一服务实例,以让第一服务实例按照设定顺序依次拼接第一资源标识(即数据库中的主键标识)、第一服务实例标识和备用服务实例标识,从而可以得到用于指示第一资源的第二资源标识,其中,通过第二资源标识,可以建立起第一资源与第一服务实例以及第一服务实例的备用服务实例之间的绑定/对应关系,因此可以通过微服务系统中的第一服务实例来实现对第一资源标识的更新。For example, in the foregoing example, when the alias management unit in the microservice system receives the indication information sent by the gateway in the microservice system to determine the service instance that can serve the first request, in order to meet the high availability of the service, the alias management unit In addition to determining the first service instance that can serve it for the first request, the alias management unit can also determine the backup service instance of the first service instance, so that when the first service instance is unavailable, there can be a quick response. The standby service instance to realize the switching and transfer of service requests. Therefore, the alias management unit can send the first service instance identifier of the first service instance and the standby service instance identifier of the standby service instance of the first service instance to the first service instance together, so that the first service instances can follow the set order. Splicing the first resource identifier (that is, the primary key identifier in the database), the first service instance identifier and the standby service instance identifier, so that the second resource identifier for indicating the first resource can be obtained, wherein, through the second resource identifier, it is possible to establish Since the binding/correspondence relationship between the first resource and the first service instance and the backup service instance of the first service instance is initiated, the first resource identifier can be updated through the first service instance in the microservice system.

在本申请的某些实施例中,所述微服务系统按照设定顺序依次拼接所述第一资源标识、所述第一服务实例标识和所述备用服务实例的备用服务实例标识,得到用于指示所述第一资源的第二资源标识,包括:所述微服务系统加密所述第一服务实例标识和所述备用服务实例的备用服务实例标识,得到加密信息;所述微服务系统按照设定顺序依次拼接所述第一资源标识和所述加密信息,得到用于指示所述第一资源的第二资源标识。In some embodiments of the present application, the micro-service system sequentially concatenates the first resource identifier, the first service instance identifier, and the standby service instance identifier of the standby service instance in a set order to obtain Indicating the second resource identifier of the first resource, including: the micro-service system encrypts the first service instance identifier and the standby service instance identifier of the standby service instance to obtain encrypted information; The first resource identifier and the encrypted information are sequentially spliced in a certain order to obtain a second resource identifier for indicating the first resource.

例如,在微服务系统中第一服务实例接收到第一请求以及第一服务实例标识、第一服务实例的备用服务实例的备用服务实例标识后,其中,服务实例标识可以为主机的ip、主机名以及端口等信息,则第一服务实例可首先运用如Base64编码的方式对自身的标识和备用服务实例标识进行处理,将其转换为加密后的字符串,然后第一服务实例可以将第一资源标识(即数据库中的主键标识)与加密后的字符串进行加密处理,从而可以得到第二资源标识。For example, after the first service instance in the microservice system receives the first request, the first service instance identifier, and the standby service instance identifier of the standby service instance of the first service instance, the service instance identifier may be the host's ip, host name, port and other information, the first service instance can first use the Base64 encoding method to process its own identification and the standby service instance identification, convert them into encrypted strings, and then the first service instance can The resource identifier (ie, the primary key identifier in the database) is encrypted with the encrypted character string, so that the second resource identifier can be obtained.

在上述步骤202的一个实施中,所述为所述第一请求分配第一服务实例,包括:所述微服务系统针对服务实例集群中的任一服务实例,确定所述服务实例的可用资源和已用负载;根据所述可用资源和所述已用负载,确定所述服务实例的空闲程度;所述微服务系统将空闲程度满足设定条件的服务实例确定为所述第一服务实例。In an implementation of the above step 202, the allocating the first service instance to the first request includes: the microservice system determines, for any service instance in the service instance cluster, the available resources of the service instance and the Used load; according to the available resources and the used load, determine the idle degree of the service instance; the microservice system determines the service instance whose idle degree meets the set condition as the first service instance.

在本申请的某些实施例中,所述微服务系统针对服务实例集群中的任一服务实例,确定所述服务实例的可用资源和已用负载,包括:所述微服务器系统针对服务实例集群中的任一服务实例,将所述服务实例的未使用的中央处理器CPU核数和未使用内存确定为所述可用资源,以及将所述服务实例在预设历史时段中的请求访问数量和请求访问时长确定为所述已用负载;所述根据所述可用资源和所述已用负载,确定所述服务实例的空闲程度,包括:所述微服务器系统将所述可用资源与所述已用负载的比值,确定为所述服务实例的空闲程度。In some embodiments of the present application, the micro-service system determines the available resources and used load of the service instance for any service instance in the service instance cluster, including: the micro-server system is for the service instance cluster. For any service instance in the service instance, determine the number of unused central processing unit CPU cores and unused memory of the service instance as the available resources, and determine the number of requested accesses and Determining the requested access duration as the used load; and determining the idle degree of the service instance according to the available resources and the used load, including: the micro server system associates the available resources with the used load. Use the ratio of load to determine the idle degree of the service instance.

例如,针对前述例子中微服务系统中的别名管理单元接收到微服务系统中的网关发送的指示信息,该指示信息用于指示别名管理单元为第一请求分配第一服务实例,此时别名管理单元可以对微服务系统的中的服务实例集群中的每一个服务实例的空闲程度进行确 定,其确定过程可以通过如下的负载均衡算法实现:For example, in the preceding example, the alias management unit in the microservice system receives the indication information sent by the gateway in the microservice system, and the indication information is used to instruct the alias management unit to allocate the first service instance for the first request. At this time, the alias management unit The unit can determine the idleness of each service instance in the service instance cluster in the microservice system, and the determination process can be implemented by the following load balancing algorithm:

首先,对于服务实例集群的机器(即服务实例)1~n,机器的cpu核数令为C i,可用内存令为R i,机器的资源令为L;则,cpu资源

Figure PCTCN2021130415-appb-000001
可表示为:
Figure PCTCN2021130415-appb-000002
可用内存资源
Figure PCTCN2021130415-appb-000003
可表示为:
Figure PCTCN2021130415-appb-000004
其中c 0为常数;其中
Figure PCTCN2021130415-appb-000005
以及
Figure PCTCN2021130415-appb-000006
均用于表示机器的可用资源; First, for the machines (ie, service instances) 1 to n in the service instance cluster, the number of cpu cores of the machine is C i , the available memory is R i , and the resource of the machine is L; then, the cpu resources
Figure PCTCN2021130415-appb-000001
can be expressed as:
Figure PCTCN2021130415-appb-000002
Available memory resources
Figure PCTCN2021130415-appb-000003
can be expressed as:
Figure PCTCN2021130415-appb-000004
where c 0 is a constant; where
Figure PCTCN2021130415-appb-000005
as well as
Figure PCTCN2021130415-appb-000006
are used to represent the available resources of the machine;

接着,定义机器i上已缓存的主键标识的数量比重为N i(访问过机器的主键标识对应的资源必被缓存),则数量比重令为

Figure PCTCN2021130415-appb-000007
则有
Figure PCTCN2021130415-appb-000008
用于表示机器的已用负载; Next, define the proportion of the number of cached primary key identifiers on machine i as N i (the resource corresponding to the primary key identifier of the machine that has been accessed must be cached), then the number proportion is set to be
Figure PCTCN2021130415-appb-000007
then there are
Figure PCTCN2021130415-appb-000008
Used to represent the used load of the machine;

再接着,定义机器i在过去24小时接收访问的主键标识的访问总时长为T i(单位:分钟),则时间比重令为

Figure PCTCN2021130415-appb-000009
则有
Figure PCTCN2021130415-appb-000010
用于表示机器的已用负载; Next, define the total access duration of the primary key identifier that machine i received access to in the past 24 hours as T i (unit: minutes), then the time proportion is set to be
Figure PCTCN2021130415-appb-000009
then there are
Figure PCTCN2021130415-appb-000010
Used to represent the used load of the machine;

最后,定义机器空闲率为E i,E i可由以下公式得出:

Figure PCTCN2021130415-appb-000011
其中根据经验值c 1:c 2=1:3,c 3:c 4=1:1。 Finally, define the machine idle rate E i , E i can be derived from the following formula:
Figure PCTCN2021130415-appb-000011
Wherein according to the empirical value c 1 :c 2 =1:3, c 3 :c 4 =1:1.

根据上述公式,别名管理单元可以得到各个机器的空闲率,也即别名管理单元可以得到各个服务实例的空闲程度。According to the above formula, the alias management unit can obtain the idle rate of each machine, that is, the alias management unit can obtain the idle degree of each service instance.

为了可以达到较好的响应效率,本申请实施例中可以将设定条件定义为:由服务实例集群中当前空闲程度最大的服务实例来对第一请求进行响应。因此,别名管理单元通过对服务实例集群中的各个服务实例的空闲程度的比较,可以得到空闲程度最高的服务实例为Em=max(E i),i=1,2,3……n,如此别名管理单元则将该空闲程度最高的服务实例确定为第一服务实例。 In order to achieve better response efficiency, in this embodiment of the present application, the setting condition may be defined as: the service instance with the largest current idle degree in the service instance cluster responds to the first request. Therefore, by comparing the idleness of each service instance in the service instance cluster, the alias management unit can obtain that the service instance with the highest idleness is Em=max(E i ), i=1, 2, 3...n, and so on The alias management unit determines the service instance with the highest idle degree as the first service instance.

下面再以一个例子对比背景技术中无状态服务应用缓存方案与本申请的实例绑定方案。Hereinafter, an example is used to compare the stateless service application caching solution in the background art with the example binding solution of the present application.

设对于一个拥有100个服务实例的服务实例集群,且设每个服务实例是8核、16GB的虚拟主机,一开始可用内存均为14GB。设具有该服务实例集群的微服务系统用于大型平台的数据库资源访问缓存,假设访问的主键数量是1千万个,每个主键的缓存信息包括id、主服务实例、备用服务实例、名称、所属子系统、创建用户等内容,大小约为1KB,则所有主键的缓存大约需要10^7/10^6=10GB。Assume that for a service instance cluster with 100 service instances, and each service instance is a virtual host with 8 cores and 16GB, the available memory is 14GB at the beginning. The microservice system with the service instance cluster is used for the database resource access cache of large-scale platforms. It is assumed that the number of primary keys accessed is 10 million. The cache information of each primary key includes id, primary service instance, standby service instance, name, The sub-system, creating users, etc., are about 1KB in size, and the cache of all primary keys needs about 10^7/10^6=10GB.

下面对比不同方案的缓存效果:The following compares the caching effects of different schemes:

背景技术的方案:每台机器上缓存所有主键:每个服务实例将占用10GB内存,总共大约100*10GB=1TB,其中冗余的数据量为1TB/10GB=100倍。并且随着主键的增多,每个服务实例的缓存数量会持续线性加大;为了每个服务实例都提供统一的无状态服务,扩容时占用的服务实例资源也会同样线性增加,扩容方案相对比较简单。当热点主键发生变化时,由于所有服务实例缓存内容一致,请求可以均匀分散到各个服务实例,集群压力比较稳定。The solution of the background art: all primary keys are cached on each machine: each service instance will occupy 10GB of memory, a total of about 100*10GB=1TB, and the redundant data volume is 1TB/10GB=100 times. And with the increase of primary keys, the number of caches of each service instance will continue to increase linearly; in order to provide a unified stateless service for each service instance, the service instance resources occupied during expansion will also increase linearly, and the expansion plans are relatively comparable. Simple. When the hotspot primary key changes, since the cache content of all service instances is consistent, requests can be evenly distributed to each service instance, and the cluster pressure is relatively stable.

本申请提出的负载均衡方案:可综合服务实例集群现有服务实例数量及负载,选取负载值较低的服务实例。对于1千万的主键,缓存总数据量为10GB,由于默认不会在主服务实例的备用服务实例上缓存主键数据,所以没有冗余,平均每个节点缓存数据为10GB/100=100MB,相比背景技术的方案可以大为减少集群资源的需求。当数据量增加一倍时,平均每个服务实例的数据量也会增加一倍。当扩容一台服务实例时,负载均衡算法可自动将新增的主键更多添加到扩容的服务实例上,从而保证服务实例集群整体负载的均衡性。当热点主键发生变化时,负载均衡算法也能同时兼顾访问时长和缓存数据量,从而实现更加高效负载均衡。The load balancing solution proposed in this application: the number and load of existing service instances in a service instance cluster can be integrated, and a service instance with a lower load value can be selected. For 10 million primary keys, the total amount of cached data is 10GB. By default, the primary key data will not be cached on the standby service instance of the primary service instance, so there is no redundancy. The average cache data of each node is 10GB/100=100MB. Compared with the solution of the background art, the demand for cluster resources can be greatly reduced. When the data volume doubles, the average data volume per service instance also doubles. When a service instance is expanded, the load balancing algorithm can automatically add more newly-added primary keys to the expanded service instance, thereby ensuring the overall load balance of the service instance cluster. When the hotspot primary key changes, the load balancing algorithm can also take into account the access duration and the amount of cached data, so as to achieve more efficient load balancing.

基于同样的构思,本申请实施例提供一种微服务系统,如图3所示,该调度系统包括接收单元301、处理单元302和获取单元303:Based on the same concept, an embodiment of the present application provides a micro-service system. As shown in FIG. 3 , the scheduling system includes a receiving unit 301, a processing unit 302, and an obtaining unit 303:

接收单元301,用于接收第一客户端发送的携带第一资源标识的第一请求。The receiving unit 301 is configured to receive a first request carrying a first resource identifier sent by a first client.

处理单元302,用于若确定所述第一资源标识中未携带有服务实例标识,则为所述第一请求分配第一服务实例。The processing unit 302 is configured to allocate a first service instance to the first request if it is determined that the first resource identifier does not carry a service instance identifier.

获取单元303,用于通过所述第一服务实例从数据库中获取所述第一资源标识所指示的第一资源。The obtaining unit 303 is configured to obtain the first resource indicated by the first resource identifier from the database through the first service instance.

处理单元302,还用于将所述第一资源发送至所述第一客户端并将所述第一资源缓存在所述第一服务实例中。The processing unit 302 is further configured to send the first resource to the first client and cache the first resource in the first service instance.

处理单元302,还用于根据所述第一服务实例的第一服务实例标识更新所述第一资源标识,得到用于指示所述第一资源的第二资源标识。The processing unit 302 is further configured to update the first resource identifier according to the first service instance identifier of the first service instance to obtain a second resource identifier used to indicate the first resource.

进一步的,对于该微服务系统,处理单元302,还用于:若确定所述第一资源标识中携带有第二服务实例标识,则将所述第一请求分配至所述第二服务实例;将所述第二服务实例缓存的所述第一资源标识指示的第一资源发送给所述第一客户端。Further, for the micro-service system, the processing unit 302 is further configured to: if it is determined that the first resource identifier carries a second service instance identifier, assign the first request to the second service instance; Send the first resource indicated by the first resource identifier cached by the second service instance to the first client.

进一步的,对于该微服务系统,所述第一资源标识中还携带有第三服务实例标识,所述第三服务实例标识对应的第三服务实例是所述第二服务实例的备用服务实例;处理单元302,还用于:若确定所述第二服务实例处于不可用状态,则将所述第一请求分配至所述第三服务实例。Further, for the micro-service system, the first resource identifier also carries a third service instance identifier, and the third service instance corresponding to the third service instance identifier is a backup service instance of the second service instance; The processing unit 302 is further configured to: if it is determined that the second service instance is in an unavailable state, assign the first request to the third service instance.

进一步的,对于该微服务系统,接收单元301,还用于:接收第二客户端发送的携带所述第二资源标识的第二请求;所述第二客户端是通过刷新机制获得所述第二资源标识;处理单元302,还用于:确定所述第二资源标识中携带有所述第一服务实例标识,则将所述第二请求分配至所述第一服务实例;将所述第一服务实例缓存的所述第一资源发送给所述第二客户端。Further, for the micro-service system, the receiving unit 301 is further configured to: receive a second request that carries the second resource identifier sent by a second client; the second client obtains the first request through a refresh mechanism two resource identifiers; the processing unit 302 is further configured to: determine that the second resource identifier carries the first service instance identifier, then allocate the second request to the first service instance; assign the first service instance identifier to the first service instance; The first resource cached by a service instance is sent to the second client.

进一步的,对于该微服务系统,处理单元302,具体用于:按照设定顺序依次拼接所述第一资源标识和所述第一服务实例标识,得到用于指示所述第一资源的第二资源标识。Further, for the micro-service system, the processing unit 302 is specifically configured to: splicing the first resource identifier and the first service instance identifier in sequence according to the set order to obtain a second identifier for indicating the first resource. Resource ID.

进一步的,对于该微服务系统,处理单元302,还用于:确定所述第一服务实例的备用服务实例;所述处理单元,具体用于:按照设定顺序依次拼接所述第一资源标识、所述第一服务实例标识和所述备用服务实例的备用服务实例标识,得到用于指示所述第一资源的第二资源标识。Further, for the micro-service system, the processing unit 302 is further configured to: determine a backup service instance of the first service instance; the processing unit is specifically configured to: sequentially splicing the first resource identifiers according to the set order , the first service instance identifier and the standby service instance identifier of the standby service instance to obtain a second resource identifier used to indicate the first resource.

进一步的,对于该微服务系统,处理单元302,具体用于:加密所述第一服务实例标识和所述备用服务实例的备用服务实例标识,得到加密信息;按照设定顺序依次拼接所述第一资源标识和所述加密信息,得到用于指示所述第一资源的第二资源标识。Further, for the micro-service system, the processing unit 302 is specifically configured to: encrypt the first service instance identifier and the standby service instance identifier of the standby service instance to obtain encrypted information; splicing the first service instance in sequence according to the set order. A resource identifier and the encrypted information are used to obtain a second resource identifier for indicating the first resource.

进一步的,对于该微服务系统,处理单元302,具体用于:针对服务实例集群中的任一服务实例,确定所述服务实例的可用资源和已用负载;根据所述可用资源和所述已用负载,确定所述服务实例的空闲程度;将空闲程度满足设定条件的服务实例确定为所述第一服务实例。Further, for the micro-service system, the processing unit 302 is specifically configured to: for any service instance in the service instance cluster, determine the available resources and used load of the service instance; The idle degree of the service instance is determined by using the load; the service instance whose idle degree satisfies the set condition is determined as the first service instance.

进一步的,对于该微服务系统,处理单元302,具体用于:针对服务实例集群中的任一服务实例,将所述服务实例的未使用的中央处理器CPU核数和未使用内存确定为所述可用资源,以及将所述服务实例在预设历史时段中的请求访问数量和请求访问时长确定为所述已用负载;将所述可用资源与所述已用负载的比值,确定为所述服务实例的空闲程度。Further, for the micro-service system, the processing unit 302 is specifically configured to: for any service instance in the service instance cluster, determine the number of unused central processing unit CPU cores and unused memory of the service instance as all the service instances. the available resources, and determine the number of requested accesses and the requested access duration of the service instance in the preset historical period as the used load; determine the ratio of the available resources to the used load as the used load The idleness of the service instance.

本申请实施例还提供了一种计算设备,该计算设备具体可以为桌面计算机、便携式计算机、智能手机、平板电脑、个人数字助理(Personal Digital Assistant,PDA)等。该计算设备可以包括中央处理器(Center Processing Unit,CPU)、存储器、输入/输出设备等,输入设备可以包括键盘、鼠标、触摸屏等,输出设备可以包括显示设备,如液晶显示器(Liquid Crystal Display,LCD)、阴极射线管(Cathode Ray Tube,CRT)等。Embodiments of the present application further provide a computing device, and the computing device may specifically be a desktop computer, a portable computer, a smart phone, a tablet computer, a personal digital assistant (Personal Digital Assistant, PDA), and the like. The computing device may include a central processing unit (Center Processing Unit, CPU), a memory, an input/output device, etc., the input device may include a keyboard, a mouse, a touch screen, etc., and the output device may include a display device, such as a liquid crystal display (Liquid Crystal Display, LCD), Cathode Ray Tube (CRT), etc.

存储器,可以包括只读存储器(ROM)和随机存取存储器(RAM),并向处理器提供存储器中存储的程序指令和数据。在本申请实施例中,存储器可以用于存储请求处理方法的程序指令;The memory, which may include read only memory (ROM) and random access memory (RAM), provides the processor with program instructions and data stored in the memory. In this embodiment of the present application, the memory may be used to store program instructions for requesting the processing method;

处理器,用于调用所述存储器中存储的程序指令,按照获得的程序执行请求处理方法。The processor is configured to call the program instructions stored in the memory, and execute the request processing method according to the obtained program.

如图4所示,为本申请实施例提供的一种计算设备的示意图,该计算设备包括:As shown in FIG. 4, a schematic diagram of a computing device provided by an embodiment of the present application, the computing device includes:

处理器401、存储器402、收发器403、总线接口404;其中,处理器401、存储器402与收发器403之间通过总线405连接;A processor 401, a memory 402, a transceiver 403, and a bus interface 404; wherein, the processor 401, the memory 402 and the transceiver 403 are connected through a bus 405;

所述处理器401,用于读取所述存储器402中的程序,执行上述请求处理方法;The processor 401 is configured to read the program in the memory 402 and execute the above request processing method;

处理器401可以是中央处理器(central processing unit,简称CPU),网络处理器(network processor,简称NP)或者CPU和NP的组合。还可以是硬件芯片。上述硬件芯片可以是专用集成电路(application-specific integrated circuit,简称ASIC),可编程逻辑器件(programmable logic device,简称PLD)或其组合。上述PLD可以是复杂可编程逻辑器件(complex programmable logic device,简称CPLD),现场可编程逻辑门阵列(field-programmable gate array,简称FPGA),通用阵列逻辑(generic array logic,简称GAL)或其任意组合。The processor 401 may be a central processing unit (CPU for short), a network processor (NP for short), or a combination of CPU and NP. It can also be a hardware chip. The above-mentioned hardware chip may be an application-specific integrated circuit (ASIC for short), a programmable logic device (PLD for short) or a combination thereof. The above PLD may be a complex programmable logic device (CPLD for short), a field-programmable gate array (FPGA for short), a generic array logic (GAL for short) or any of the above. combination.

所述存储器402,用于存储一个或多个可执行程序,可以存储所述处理器401在执行操作时所使用的数据。The memory 402 is used to store one or more executable programs, and can store data used by the processor 401 when performing operations.

具体地,程序可以包括程序代码,程序代码包括计算机操作指令。存储器402可以包括易失性存储器(volatile memory),例如随机存取存储器(random-access memory,简称RAM);存储器402也可以包括非易失性存储器(non-volatile memory),例如快闪存储器(flash memory),硬盘(hard disk drive,简称HDD)或固态硬盘(solid-state drive,简称SSD);存储器402还可以包括上述种类的存储器的组合。Specifically, the program may include program code, and the program code includes computer operation instructions. The memory 402 may include a volatile memory (volatile memory), such as random-access memory (RAM for short); the memory 402 may also include a non-volatile memory (non-volatile memory), such as a flash memory ( flash memory), a hard disk drive (HDD for short) or a solid-state drive (SSD for short); the memory 402 may also include a combination of the above-mentioned types of memory.

存储器402存储了如下的元素,可执行模块或者数据结构,或者它们的子集,或者它们的扩展集:Memory 402 stores the following elements, executable modules or data structures, or a subset thereof, or an extended set thereof:

操作指令:包括各种操作指令,用于实现各种操作。Operation instructions: including various operation instructions, which are used to realize various operations.

操作系统:包括各种系统程序,用于实现各种基础业务以及处理基于硬件的任务。Operating System: Includes various system programs for implementing various basic services and handling hardware-based tasks.

总线405可以是外设部件互连标准(peripheral component interconnect,简称PCI)总线或扩展工业标准结构(extended industry standard architecture,简称EISA)总线等。总线可以分为地址总线、数据总线、控制总线等。为便于表示,图4中仅用一条粗线表示,但并不表示仅有一根总线或一种类型的总线。The bus 405 may be a peripheral component interconnect (PCI for short) bus or an extended industry standard architecture (Extended industry standard architecture, EISA for short) bus or the like. The bus can be divided into address bus, data bus, control bus and so on. For ease of presentation, only one thick line is used in FIG. 4, but it does not mean that there is only one bus or one type of bus.

总线接口404可以为有线通信接入口,无线总线接口或其组合,其中,有线总线接口例如可以为以太网接口。以太网接口可以是光接口,电接口或其组合。无线总线接口可以为WLAN接口。The bus interface 404 may be a wired communication access port, a wireless bus interface or a combination thereof, wherein the wired bus interface may be, for example, an Ethernet interface. The Ethernet interface can be an optical interface, an electrical interface or a combination thereof. The wireless bus interface may be a WLAN interface.

本申请实施例还提供了一种计算机可读存储介质,所述计算机可读存储介质存储有计算机可执行指令,所述计算机可执行指令用于使计算机执行请求处理方法。Embodiments of the present application further provide a computer-readable storage medium, where the computer-readable storage medium stores computer-executable instructions, where the computer-executable instructions are used to cause the computer to execute the request processing method.

本领域内的技术人员应明白,本申请的实施例可提供为方法、或计算机程序产品。因此,本申请可采用完全硬件实施例、完全软件实施例、或结合软件和硬件方面的实施例的形式。而且,本申请可采用在一个或多个其中包含有计算机可用程序代码的计算机可用存储介质(包括但不限于磁盘存储器、CD-ROM、光学存储器等)上实施的计算机程序产品的形式。As will be appreciated by those skilled in the art, the embodiments of the present application may be provided as a method, or as a computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) having computer-usable program code embodied therein.

本申请是参照根据本申请实施例的方法、设备(系统)、和计算机程序产品的流程图和/或方框图来描述的。应理解可由计算机程序指令实现流程图和/或方框图中的每一流程和/或方框、以及流程图和/或方框图中的流程和/或方框的结合。可提供这些计算机程序指令到通用计算机、专用计算机、嵌入式处理机或其他可编程数据处理设备的处理器以产生一个机器,使得通过计算机或其他可编程数据处理设备的处理器执行的指令产生用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的 装置。The present application is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the present application. It will be understood that each process and/or block in the flowchart illustrations and/or block diagrams, and combinations of processes and/or blocks in the flowchart illustrations and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to the processor of a general purpose computer, special purpose computer, embedded processor or other programmable data processing device to produce a machine such that the instructions executed by the processor of the computer or other programmable data processing device produce Means for implementing the functions specified in a flow or flow of a flowchart and/or a block or blocks of a block diagram.

这些计算机程序指令也可存储在能引导计算机或其他可编程数据处理设备以特定方式工作的计算机可读存储器中,使得存储在该计算机可读存储器中的指令产生包括指令装置的制造品,该指令装置实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能。These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory result in an article of manufacture comprising instruction means, the instructions The apparatus implements the functions specified in the flow or flow of the flowcharts and/or the block or blocks of the block diagrams.

这些计算机程序指令也可装载到计算机或其他可编程数据处理设备上,使得在计算机或其他可编程设备上执行一系列操作步骤以产生计算机实现的处理,从而在计算机或其他可编程设备上执行的指令提供用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的步骤。These computer program instructions can also be loaded on a computer or other programmable data processing device to cause a series of operational steps to be performed on the computer or other programmable device to produce a computer-implemented process such that The instructions provide steps for implementing the functions specified in the flow or blocks of the flowcharts and/or the block or blocks of the block diagrams.

尽管已描述了本申请的优选实施例,但本领域内的技术人员一旦得知了基本创造性概念,则可对这些实施例作出另外的变更和修改。所以,所附权利要求意欲解释为包括优选实施例以及落入本申请范围的所有变更和修改。While the preferred embodiments of the present application have been described, additional changes and modifications to these embodiments may occur to those skilled in the art once the basic inventive concepts are known. Therefore, the appended claims are intended to be construed to include the preferred embodiment and all changes and modifications that fall within the scope of this application.

显然,本领域的技术人员可以对本申请进行各种改动和变型而不脱离本申请的精神和范围。这样,倘若本申请的这些修改和变型属于本申请权利要求及其等同技术的范围之内,则本申请也意图包含这些改动和变型在内。Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.

Claims (11)

一种请求处理方法,其特征在于,包括:A request processing method, comprising: 微服务系统接收第一客户端发送的携带第一资源标识的第一请求;The microservice system receives the first request that carries the first resource identifier and sent by the first client; 所述微服务系统若确定所述第一资源标识中未携带有服务实例标识,则为所述第一请求分配第一服务实例;The micro-service system allocates a first service instance for the first request if it is determined that the first resource identifier does not carry a service instance identifier; 所述微服务系统通过所述第一服务实例从数据库中获取所述第一资源标识所指示的第一资源;The micro-service system obtains the first resource indicated by the first resource identifier from the database through the first service instance; 所述微服务系统将所述第一资源发送至所述第一客户端并将所述第一资源缓存在所述第一服务实例中;The microservice system sends the first resource to the first client and caches the first resource in the first service instance; 所述微服务系统根据所述第一服务实例的第一服务实例标识更新所述第一资源标识,得到用于指示所述第一资源的第二资源标识。The micro-service system updates the first resource identifier according to the first service instance identifier of the first service instance, and obtains a second resource identifier for indicating the first resource. 如权利要求1所述的方法,其特征在于,The method of claim 1, wherein: 所述方法还包括:The method also includes: 所述微服务系统若确定所述第一资源标识中携带有第二服务实例标识,则将所述第一请求分配至所述第二服务实例;The micro-service system allocates the first request to the second service instance if it is determined that the first resource identifier carries a second service instance identifier; 所述微服务系统将所述第二服务实例缓存的所述第一资源标识指示的第一资源发送给所述第一客户端。The microservice system sends the first resource indicated by the first resource identifier cached by the second service instance to the first client. 如权利要求2所述的方法,其特征在于,所述第一资源标识中还携带有第三服务实例标识,所述第三服务实例标识对应的第三服务实例是所述第二服务实例的备用服务实例;The method according to claim 2, wherein the first resource identifier further carries a third service instance identifier, and the third service instance corresponding to the third service instance identifier is an identifier of the second service instance. Standby service instance; 所述方法还包括:The method also includes: 所述微服务系统若确定所述第二服务实例处于不可用状态,则将所述第一请求分配至所述第三服务实例。If it is determined that the second service instance is in an unavailable state, the microservice system allocates the first request to the third service instance. 如权利要求1所述的方法,其特征在于,The method of claim 1, wherein: 所述方法还包括:The method also includes: 所述微服务系统接收第二客户端发送的携带所述第二资源标识的第二请求;所述第二客户端是通过刷新机制获得所述第二资源标识;The micro-service system receives a second request sent by a second client that carries the second resource identifier; the second client obtains the second resource identifier through a refresh mechanism; 所述微服务系统确定所述第二资源标识中携带有所述第一服务实例标识,则将所述第二请求分配至所述第一服务实例;The micro-service system determines that the second resource identifier carries the first service instance identifier, and allocates the second request to the first service instance; 所述微服务系统将所述第一服务实例缓存的所述第一资源发送给所述第二客户端。The microservice system sends the first resource cached by the first service instance to the second client. 如权利要求1-4任一项所述的方法,其特征在于,The method of any one of claims 1-4, wherein, 所述微服务系统根据所述第一服务实例的第一服务实例标识更新所述第一资源标识,得到用于指示所述第一资源的第二资源标识,包括:The micro-service system updates the first resource identifier according to the first service instance identifier of the first service instance, and obtains a second resource identifier for indicating the first resource, including: 所述微服务系统按照设定顺序依次拼接所述第一资源标识和所述第一服务实例标识,得到用于指示所述第一资源的第二资源标识。The micro-service system sequentially splices the first resource identifier and the first service instance identifier according to a set sequence, to obtain a second resource identifier for indicating the first resource. 如权利要求5所述的方法,其特征在于,The method of claim 5, wherein: 所述得到用于指示所述第一资源的第二资源标识之前,还包括:Before the obtaining the second resource identifier used to indicate the first resource, the method further includes: 所述微服务系统确定所述第一服务实例的备用服务实例;The microservice system determines an alternate service instance of the first service instance; 所述微服务系统按照设定顺序依次拼接所述第一资源标识和所述第一服务实例标识,得到用于指示所述第一资源的第二资源标识,包括:The micro-service system sequentially splices the first resource identifier and the first service instance identifier according to the set order to obtain a second resource identifier for indicating the first resource, including: 所述微服务系统按照设定顺序依次拼接所述第一资源标识、所述第一微务实例标识和所述备用服务实例的备用服务实例标识,得到用于指示所述第一资源的第二资源标识。The micro-service system splices the first resource identifier, the first micro-service instance identifier, and the standby service instance identifier of the standby service instance in sequence according to the set order, and obtains a second identifier for indicating the first resource. Resource ID. 如权利要求6所述的方法,其特征在于,The method of claim 6, wherein: 所述微服务系统按照设定顺序依次拼接所述第一资源标识、所述第一服务实例标识和所述备用服务实例的备用服务实例标识,得到用于指示所述第一资源的第二资源标识,包 括:The micro-service system splices the first resource identifier, the first service instance identifier and the standby service instance identifier of the standby service instance in sequence according to the set order, and obtains a second resource for indicating the first resource identification, including: 所述微服务系统加密所述第一服务实例标识和所述备用服务实例的备用服务实例标识,得到加密信息;The micro-service system encrypts the first service instance identifier and the standby service instance identifier of the standby service instance to obtain encrypted information; 所述微服务系统按照设定顺序依次拼接所述第一资源标识和所述加密信息,得到用于指示所述第一资源的第二资源标识。The micro-service system sequentially splices the first resource identifier and the encrypted information according to the set order, to obtain a second resource identifier for indicating the first resource. 如权利要求1-4任一项所述的方法,其特征在于,The method of any one of claims 1-4, wherein, 所述为所述第一请求分配第一服务实例,包括:The allocating a first service instance for the first request includes: 所述微服务系统针对服务实例集群中的任一服务实例,确定所述服务实例的可用资源和已用负载;根据所述可用资源和所述已用负载,确定所述服务实例的空闲程度;The microservice system determines the available resources and used load of the service instance for any service instance in the service instance cluster; and determines the idleness of the service instance according to the available resources and the used load; 所述微服务系统将空闲程度满足设定条件的服务实例确定为所述第一服务实例。The micro-service system determines the service instance whose idle degree meets the set condition as the first service instance. 如权利要求8所述的方法,其特征在于,The method of claim 8, wherein: 所述微服务系统针对服务实例集群中的任一服务实例,确定所述服务实例的可用资源和已用负载,包括:For any service instance in the service instance cluster, the microservice system determines the available resources and used load of the service instance, including: 所述微服务器系统针对服务实例集群中的任一服务实例,将所述服务实例的未使用的中央处理器CPU核数和未使用内存确定为所述可用资源,以及将所述服务实例在预设历史时段中的请求访问数量和请求访问时长确定为所述已用负载;For any service instance in the service instance cluster, the micro-server system determines the number of unused central processing unit CPU cores and unused memory of the service instance as the available resources, and sets the service instance in the pre-defined service instance. Let the number of requested accesses and the requested access duration in the historical period be determined as the used load; 所述根据所述可用资源和所述已用负载,确定所述服务实例的空闲程度,包括:The determining the idleness level of the service instance according to the available resources and the used load includes: 所述微服务器系统将所述可用资源与所述已用负载的比值,确定为所述服务实例的空闲程度。The micro-server system determines the ratio of the available resources to the used load as the idle degree of the service instance. 一种微服务系统,其特征在于,包括:A microservice system, characterized in that it includes: 接收单元,用于接收第一客户端发送的携带第一资源标识的第一请求;a receiving unit, configured to receive a first request carrying a first resource identifier sent by a first client; 处理单元,用于若确定所述第一资源标识中未携带有服务实例标识,则为所述第一请求分配第一服务实例;a processing unit, configured to allocate a first service instance to the first request if it is determined that the first resource identifier does not carry a service instance identifier; 获取单元,用于通过所述第一服务实例从数据库中获取所述第一资源标识所指示的第一资源;an obtaining unit, configured to obtain the first resource indicated by the first resource identifier from the database through the first service instance; 所述处理单元,还用于将所述第一资源发送至所述第一客户端并将所述第一资源缓存在所述第一服务实例中;the processing unit, further configured to send the first resource to the first client and cache the first resource in the first service instance; 所述处理单元,还用于根据所述第一服务实例的第一服务实例标识更新所述第一资源标识,得到用于指示所述第一资源的第二资源标识。The processing unit is further configured to update the first resource identifier according to the first service instance identifier of the first service instance to obtain a second resource identifier used to indicate the first resource. 一种计算机可读存储介质,其特征在于,所述存储介质存储有计算机可执行指令,所述计算机可执行指令用于使计算机执行如权利要求1-9任一项所述的方法。A computer-readable storage medium, characterized in that the storage medium stores computer-executable instructions, and the computer-executable instructions are used to cause a computer to execute the method according to any one of claims 1-9.
PCT/CN2021/130415 2020-11-24 2021-11-12 Request processing method and micro-service system Ceased WO2022111313A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202011327754.XA CN112346871A (en) 2020-11-24 2020-11-24 Request processing method and micro-service system
CN202011327754.X 2020-11-24

Publications (1)

Publication Number Publication Date
WO2022111313A1 true WO2022111313A1 (en) 2022-06-02

Family

ID=74365568

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2021/130415 Ceased WO2022111313A1 (en) 2020-11-24 2021-11-12 Request processing method and micro-service system

Country Status (2)

Country Link
CN (1) CN112346871A (en)
WO (1) WO2022111313A1 (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115473809A (en) * 2022-08-27 2022-12-13 深圳市凯迪仕智能科技有限公司 Configuration processing method and device based on micro-service architecture and storage medium
CN117255136A (en) * 2023-11-15 2023-12-19 博泰车联网(南京)有限公司 Routing method, micro-service system, device and storage medium
WO2024066503A1 (en) * 2022-09-27 2024-04-04 华为云计算技术有限公司 Service invocation method and apparatus

Families Citing this family (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112346871A (en) * 2020-11-24 2021-02-09 深圳前海微众银行股份有限公司 Request processing method and micro-service system
CN113806104A (en) * 2021-08-02 2021-12-17 北京房江湖科技有限公司 Interface access request processing method, API gateway, server and system
CN113986745B (en) * 2021-11-02 2025-02-18 中国银行股份有限公司 A testing method, device and storage medium for a routing component
CN115514819B (en) * 2022-09-26 2025-05-13 和利时卡优倍科技有限公司 A service scheduling method, device and equipment
CN116668546A (en) * 2023-05-26 2023-08-29 中国银行股份有限公司 Service routing method, microservice unit architecture, electronic device and storage medium

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108696895A (en) * 2017-04-07 2018-10-23 华为技术有限公司 Resource acquiring method, apparatus and system
US20200127939A1 (en) * 2018-10-22 2020-04-23 Affirmed Networks, Inc. Distributed database-driven resource management and locking in a cloud native mobile core network node architecture
CN111371684A (en) * 2020-03-02 2020-07-03 中国邮政储蓄银行股份有限公司 Routing processing method and device and double-activity data center system
CN111752861A (en) * 2020-06-28 2020-10-09 中国平安财产保险股份有限公司 Application multi-level caching method, device, client and storage medium
CN112346871A (en) * 2020-11-24 2021-02-09 深圳前海微众银行股份有限公司 Request processing method and micro-service system

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9917746B2 (en) * 2014-11-04 2018-03-13 Futurewei Technologies, Inc. Adaptive allocation of server resources
CN110971623B (en) * 2018-09-28 2023-02-17 中兴通讯股份有限公司 Micro-service instance elastic scaling method and device and storage medium
CN111125170A (en) * 2019-12-22 2020-05-08 浪潮电子信息产业股份有限公司 Cross-service data acquisition method and device of micro-service and micro-service equipment
CN111600930B (en) * 2020-04-09 2022-12-09 网宿科技股份有限公司 Micro-service request traffic management method, device, server and storage medium
CN111683144B (en) * 2020-06-08 2022-06-17 北京字节跳动网络技术有限公司 Method and device for processing access request, computer equipment and storage medium

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108696895A (en) * 2017-04-07 2018-10-23 华为技术有限公司 Resource acquiring method, apparatus and system
US20200127939A1 (en) * 2018-10-22 2020-04-23 Affirmed Networks, Inc. Distributed database-driven resource management and locking in a cloud native mobile core network node architecture
CN111371684A (en) * 2020-03-02 2020-07-03 中国邮政储蓄银行股份有限公司 Routing processing method and device and double-activity data center system
CN111752861A (en) * 2020-06-28 2020-10-09 中国平安财产保险股份有限公司 Application multi-level caching method, device, client and storage medium
CN112346871A (en) * 2020-11-24 2021-02-09 深圳前海微众银行股份有限公司 Request processing method and micro-service system

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115473809A (en) * 2022-08-27 2022-12-13 深圳市凯迪仕智能科技有限公司 Configuration processing method and device based on micro-service architecture and storage medium
WO2024066503A1 (en) * 2022-09-27 2024-04-04 华为云计算技术有限公司 Service invocation method and apparatus
CN117255136A (en) * 2023-11-15 2023-12-19 博泰车联网(南京)有限公司 Routing method, micro-service system, device and storage medium
CN117255136B (en) * 2023-11-15 2024-02-27 博泰车联网(南京)有限公司 A routing method, microservice system, device and storage medium

Also Published As

Publication number Publication date
CN112346871A (en) 2021-02-09

Similar Documents

Publication Publication Date Title
WO2022111313A1 (en) Request processing method and micro-service system
US20190196875A1 (en) Method, system and computer program product for processing computing task
CN106817432B (en) Method, system and device for elastic stretching of virtual resources in cloud computing environment
WO2019165665A1 (en) Domain name resolution method, server and system
WO2019237594A1 (en) Session persistence method and apparatus, and computer device and storage medium
US11546307B2 (en) Method to implement multi-tenant/shared Redis cluster using envoy
CN114124968B (en) Load balancing method, device, equipment and medium based on market data
WO2021232860A1 (en) Communication method, apparatus and system
CN109951543A (en) Data search method, device and network device for CDN node
US11847161B2 (en) Data processing method and apparatus, device, and storage medium
US20240205292A1 (en) Data processing method and apparatus, computer device, and computer-readable storage medium
CN115859261A (en) Password cloud service method, platform, equipment and storage medium
US11881996B2 (en) Input and output for target device communication
CN112395070A (en) Data processing system and method
US12081625B2 (en) Session based data persistency
CN113574518B (en) In-memory normalization of cache objects to reduce cache memory footprint
CN112839071B (en) Training system, training data access method and device, electronic equipment and medium
US20240089339A1 (en) Caching across multiple cloud environments
CN112866355B (en) System and method for server failover and load balancing
US11233739B2 (en) Load balancing system and method
CN110399313B (en) System and method for improving cache performance
CN114793234B (en) Message processing method, device, equipment and storage medium
US12547626B1 (en) Database query distribution
CN113468140A (en) Data migration processing method, electronic device and computer-readable storage medium
US12309142B2 (en) Information security system and method for secure data transmission among user profiles using a blockchain network

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 21896814

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

32PN Ep: public notification in the ep bulletin as address of the adressee cannot be established

Free format text: NOTING OF LOSS OF RIGHTS PURSUANT TO RULE 112(1) EPC (EPO FORM 1205A DATED 12.09.2023)

122 Ep: pct application non-entry in european phase

Ref document number: 21896814

Country of ref document: EP

Kind code of ref document: A1