Service fusing method based on distributed service gateway and related product

By recording the service error rate in the service gateway and controlling the circuit breaker, the service gateway performance is solved and the performance improvement effect is achieved.

CN119420631APending Publication Date: 2025-02-11NEUSOFT CORP
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411546331.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-31
Publication Date
2025-02-11

AI Technical Summary

Technical Problem

In the deployment architecture of a distributed service gateway, if the service is fused through redis, the service gateway needs to interact with redis, resulting in performance constraints.

Method used

By recording the error rate of each service in the service gateway and turning on the circuit breaker when the error rate exceeds the threshold, the service fuse is achieved to avoid direct interaction between the service gateway and redis.

Benefits of technology

This method decouples the dependence between service gateway and redis, improves the performance of service gateway, and avoids the performance of redis constraints.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119420631A_ABST
    Figure CN119420631A_ABST
Patent Text Reader

Abstract

The invention discloses a service fusing method based on a distributed service gateway and a related product. The method comprises the following steps: acquiring an error rate of accessing each service recorded in each service gateway; and for any service, opening a circuit breaker corresponding to the service under the condition that the error rate of the service recorded in any service gateway is greater than the corresponding error threshold. In the embodiment of the invention, the service gateway is used for recording the error rate of service access, and the gateway is used for controlling the circuit breaker corresponding to the service, so that decoupling of the service gateway and the redis is realized, and the performance of the service gateway is not restrained by the redis any more and is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of information technology, and in particular to a service fusing method based on a distributed service gateway and related products. Background Art

[0002] The deployment architecture of the distributed service gateway includes multiple service gateways, and service requests access the corresponding services through the service gateways. When the service accessed by the service request fails and becomes unavailable due to some reasons, such as internal service errors and network delays, the entire system may be paralyzed due to the avalanche effect caused by cascading failures, so the unavailable services need to be fused.

[0003] In the related art, the service fuse is implemented with the help of Remote Dictionary Server (redis). However, if the service fuse is implemented through redis, when each service request accesses the corresponding service through the service gateway, the service gateway needs to interact with redis, and the performance of the service gateway is constrained by redis. Summary of the invention

[0004] Based on the above problems, the present application provides a service fuse method and related products based on a distributed service gateway, which removes the service gateway's dependence on redis and improves the performance of the service gateway.

[0005] The embodiments of the present application disclose the following technical solutions:

[0006] In a first aspect, an embodiment of the present application provides a service fusing method based on a distributed service gateway, the method comprising:

[0007] Obtain the error rate of accessing each service recorded in each service gateway;

[0008] For any service, when the error rate of the service recorded in any service gateway is greater than the corresponding error threshold, the circuit breaker corresponding to the service is opened.

[0009] Optionally, for any service gateway, the service gateway includes multiple counters, the counters correspond to services one by one, each counter records the number of errors in accessing the corresponding service through a bit cyclic array, and obtains the corresponding error rate based on the number of errors of the service.

[0010] Optionally, each counter records the number of errors in accessing the corresponding service through a bit loop array, including:

[0011] Each counter records the number of errors in accessing the corresponding service within the window by circulating the bit array.

[0012] Optionally, the method further comprises:

[0013] Receive service requests;

[0014] Based on load balancing, the service request is forwarded to the corresponding service gateway.

[0015] Optionally, forwarding the service request to the corresponding service gateway based on load balancing includes:

[0016] Determine a service corresponding to the service request and a state of a circuit breaker corresponding to the service; wherein the state of the circuit breaker includes a first state and a second state, the first state indicates that the circuit breaker is closed, and the second state indicates that the circuit breaker is open;

[0017] When the state of the circuit breaker is the first state, the service request is forwarded to the corresponding service gateway based on load balancing.

[0018] Optionally, the method further comprises:

[0019] When the state of the circuit breaker is the second state, determining the fusing time of the circuit breaker;

[0020] When the fuse time is greater than the error threshold, the state of the circuit breaker is changed from the second state to the third state, and the service request is forwarded to the corresponding service gateway through load balancing, so that the service request accesses the service; the third state allows a service request to access the corresponding service;

[0021] When the service request accesses the service successfully, the state of the circuit breaker is changed from the third state to the first state; when the service request accesses the service unsuccessfully, the state of the circuit breaker is changed from the third state to the second state.

[0022] Optionally, the method further comprises:

[0023] For any service, when the circuit breaker corresponding to the service is opened, the error rate of accessing the service recorded in all service gateways is cleared.

[0024] In a second aspect, an embodiment of the present application provides a service fuse device based on a distributed service gateway, characterized in that the device includes: an acquisition module and a fuse module;

[0025] An acquisition module, used to obtain the error rate of accessing each service recorded in each service gateway;

[0026] The fuse module is used to open the circuit breaker corresponding to any service when the error rate of the service recorded in any service gateway is greater than the corresponding error threshold.

[0027] Optionally, the device further includes: a counter module; for any service gateway, the service gateway includes a counter module, the counter module includes multiple counters, and the counters correspond to the services one by one;

[0028] Each counter is used to record the number of errors in accessing the corresponding service through a bit cycle array, and obtain the corresponding error rate according to the number of errors of the service.

[0029] Optionally, the counter module is specifically configured to record the number of errors in accessing the corresponding service within the window by circulating the bit array.

[0030] Optionally, the device further includes: a receiving module and a forwarding module;

[0031] A receiving module, used for receiving a service request;

[0032] The forwarding module is used to forward the service request to the corresponding service gateway based on load balancing.

[0033] Optionally, a forwarding module is specifically used to determine the service corresponding to the service request and the state of the circuit breaker corresponding to the service; wherein the state of the circuit breaker includes a first state and a second state, the first state indicates that the circuit breaker is closed, and the second state indicates that the circuit breaker is open; when the state of the circuit breaker is the first state, the service request is forwarded to the corresponding service gateway based on load balancing.

[0034] Optionally, the forwarding module is also used to determine the circuit breaker's fuse time when the circuit breaker is in the second state; when the fuse time is greater than the error threshold, change the circuit breaker's state from the second state to the third state, and forward the service request to the corresponding service gateway through load balancing so that the service request accesses the service; the third state allows a service request to access the corresponding service; when the service request successfully accesses the service, change the circuit breaker's state from the third state to the first state; when the service request fails to access the service, change the circuit breaker's state from the third state to the second state.

[0035] Optionally, the device further comprises: a clearing module;

[0036] The clearing module is used to clear the error rate of accessing the service recorded in all service gateways for any service when the circuit breaker corresponding to the service is opened.

[0037] In a third aspect, an embodiment of the present application provides a computer device, comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, a service fuse method based on a distributed service gateway as in any embodiment of the first aspect is implemented.

[0038] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, in which instructions are stored. When the instructions are executed on a terminal device, the terminal device executes a service fuse method based on a distributed service gateway as in any embodiment of the first aspect.

[0039] The error rate of accessing the service is recorded by redis and the state of the circuit breaker is controlled by redis, so that the performance of the service gateway is constrained by redis. In order to improve the performance of the service gateway, the embodiment of the present application provides a service fuse method based on a distributed service gateway. First, the error rate of accessing each service recorded in each service gateway is obtained; then, for any service, when the error rate of the service recorded in any service gateway is greater than the corresponding error threshold, the circuit breaker corresponding to the service is opened. In the embodiment of the present application, the error rate of accessing the service is recorded by the service gateway, and the circuit breaker corresponding to the service is controlled by the gateway to realize the decoupling of the service gateway and redis, and the performance of the service gateway is no longer constrained by redis and is improved. BRIEF DESCRIPTION OF THE DRAWINGS

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

[0041] Figure 1 A flow chart of a service fusing method based on a distributed service gateway provided in an embodiment of the present application;

[0042] Figure 2 A schematic diagram of a deployment architecture of a distributed service gateway provided in an embodiment of the present application;

[0043] Figure 3 A flowchart of a counting method provided in an embodiment of the present application;

[0044] Figure 4 A flowchart for eliminating the influence of data in the previous window on the error amount provided by an embodiment of the present application;

[0045] Figure 5 A schematic diagram of a circuit breaker state change provided in an embodiment of the present application;

[0046] Figure 6 A flowchart of another service fusing method based on a distributed service gateway provided in an embodiment of the present application;

[0047] Figure 7A schematic diagram of the structure of a service fuse device based on a distributed service gateway provided in an embodiment of the present application;

[0048] Figure 8 A schematic diagram of the structure of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0049] In order to enable those skilled in the art to better understand the solution of the present invention, the technical solution in this embodiment will be clearly and completely described below in conjunction with the drawings in this embodiment. Obviously, the described embodiment is only a part of the embodiment of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0050] The terms "first" and "second" in the specification and claims of the present invention are used to distinguish different objects rather than to describe a specific order of objects. For example, first data and second data are used to distinguish different data rather than to describe a specific order of data.

[0051] In this embodiment, the words "exemplary" or "for example" are used to indicate examples, illustrations or explanations. Any embodiment or design described as "exemplary" or "for example" in this embodiment should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a specific way.

[0052] In the description of this embodiment, unless otherwise specified, “multiple” means two or more than two. For example, multiple processing units means two or more processing units, etc.; multiple elements means two or more elements, etc.

[0053] In order to make the following embodiments clear, the technical terms involved in this application are first introduced.

[0054] The service gateway may be an application programming interface (API) gateway, which can uniformly schedule and coordinate the interaction between various services to achieve a unified entry and exit for services.

[0055] A gateway is a device that connects two different networks. It can be a hardware device, such as a network connector and a protocol converter; it can also be a software application, such as HTTP and a reverse proxy web server (engine x, Nginx).

[0056] Services can be different parts of a system, each of which is responsible for completing specific functions. For example, services can be microservices, REST APIs, or other forms of software components, which communicate with each other through well-defined interface contracts to achieve decoupling and independent expansion between various parts of the system.

[0057] Load balancing is a technology that distributes workloads across multiple computing resources or system components to achieve better performance, reliability, and scalability.

[0058] In an embodiment of the present application, a service fuse method based on a distributed service gateway is provided. First, the error rate of accessing each service recorded in each service gateway is obtained; then, for any service, when the error rate of the service recorded in any service gateway is greater than the corresponding error threshold, the circuit breaker corresponding to the service is opened. In an embodiment of the present application, the error rate of accessing the service is recorded by the service gateway, and the state of the circuit breaker is changed by the gateway, so as to realize the decoupling of the service gateway's business from redis, thereby improving the performance of the service gateway.

[0059] The technical solution of the present application will be introduced below in conjunction with specific embodiments.

[0060] See also Figure 1 , which is a flow chart of a service fuse method based on a distributed service gateway provided in an embodiment of the present application.

[0061] like Figure 1 As shown, the method includes:

[0062] S100: The gateway obtains the error rate of accessing each service recorded in each service gateway.

[0063] For ease of understanding, the present application embodiment provides a schematic diagram of a deployment architecture of a distributed service gateway, such as Figure 2 As shown. Figure 2 In the figure, the gateways are connected to service gateway 1, service gateway 2, ... and service gateway n respectively. Service gateway 1 is connected to service 1, service 2, service 3, ... and service m. Service gateway 2 is connected to service 1, service 2, service 3, ... and service m. Service gateway 2 is connected to service 1, service 2, service 3, ... and service m. Service gateway n is connected to service 1, service 2, service 3, ... and service m.

[0064] Exemplarily, service gateway 1 records the error rates of service 1, service 2, service 3... and service m, service gateway 2 records the error rates of service 1, service 2, service 3... and service m, and service gateway n records the error rates of service 1, service 2, service 3... and service m.

[0065] In one possible implementation, each service gateway records the number of failed accesses to the corresponding service through an internal counter (for example, counter 1 in service gateway 1 records the error rate of service 1, counter 2 records the error rate of service 2…counter m records the error rate of service m; counter 1 in service gateway 2 records the error rate of service 1, counter 2 records the error rate of service 2…counter m records the error rate of service m,…counter 1 in service gateway n records the error rate of service 1, counter 2 records the error rate of service 2…counter m records the error rate of service m); and then the error rate for accessing the service is obtained by dividing the number of errors in accessing the service by the total number of accesses to the service.

[0066] Exemplarily, taking the counter 1 of the service gateway 1 as an example, the counter 1 includes a circular bit array bitArray, a window size size, a current total amount total, an error amount error, and a set error threshold errorRate. The success or failure of each request to access the service 1 is placed in the circular bit array bitArray in order, that is, the first access result is placed in the 0th bit of the bit array bitArray, the second access result is placed in the 1st bit of the bit array bitArray, and so on, until if the total amount of requests currently placed is just greater than the window size, then the bit array bitArray is placed again from the beginning, and the data to be overwritten is processed at the same time, and the error amount value is adjusted. Among them, if the access is successful, the bit array bitArray is written with "0", and if the access fails, the bit array bitArray is written with "1".

[0067] For ease of understanding, an embodiment of the present application provides a flowchart of a counting method, see Figure 3.

[0068] like Figure 3 As shown, the method includes:

[0069] S110: Obtain the access result corresponding to the Nth access request.

[0070] The access results of the service include access success and access failure; where access success is represented by "0" and access failure is represented by "1".

[0071] S120: When N is greater than the window size, it is necessary to eliminate the influence of the data in the previous window on the error amount.

[0072] The window size can be set or modified according to user needs. It should be understood that the smaller the window size, the more sensitive the service fuse; conversely, the larger the window size, the slower the service fuse. In the embodiment of the present application, adding a window to the counter can flexibly adjust the sensitivity and accuracy of the service fuse.

[0073] Furthermore, the embodiments of the present application are Figure 4 Steps S121-S123 in the above further introduce how to eliminate the influence of the data in the previous window on the error amount:

[0074] S121: N modulo size (ie, N%size) to determine the data bit corresponding to N in the circular bit array bitArray.

[0075] Exemplarily, if N modulo size is 1, then the access request corresponds to the 0th bit in the circular bit array bitArray; if N modulo size is 2, then the access request corresponds to the 1st bit in the circular bit array bitArray... and so on.

[0076] S122: When the value of the current data bit is not 1, the error amount error remains unchanged.

[0077] It should be understood that the value of the current data bit is 0, and the error value of the data bit in the previous window is not increased, so in the current window, there is no need to adjust the error value of the previous window, and the error value remains unchanged.

[0078] Exemplarily, the cyclic bit array bitArray is 8 bits, and after the previous window ends, the cyclic bit array bitArray is represented as 11001010, and the error amount error is 4. If the current data bit is the 0th bit, error remains unchanged.

[0079] S123: When the value of the current data bit is 1, the error amount is error-1.

[0080] It should be understood that the value of the current data bit is 1, and this data bit in the previous window increases the error value, so in the current window, the error value needs to be adjusted for the previous window, that is, error-1.

[0081] Exemplarily, the cyclic bit array bitArray is 8 bits, and after the previous window ends, the cyclic bit array bitArray is represented as 11001010, and the error amount error is 4. If the current data bit is the 1st bit, error-1=3.

[0082] At this point, the influence of the previous window on the error amount error has been eliminated in this window. Next, the error amount error in this window needs to be counted.

[0083] S130: When N is smaller than the window size, the current total is total+1.

[0084] It should be understood that total is the sum of access requests in each window.

[0085] For example, N is 8. In the first window, each time N increases by one, total+1; after N is greater than 8 (after the second window), total remains unchanged.

[0086] S140: Write the access result into the corresponding index of the current loop bit array bitArray.

[0087] Exemplarily, the circular bit array bitArray is 8 bits, and after the previous window ends, the circular bit array bitArray is represented as 11001010, and the current data bit is bit 1. If the access result indicates that the access fails, "1" is written to the first bit of the circular bit array bitArray, and the circular bit array bitArray is 11001010; if the access result indicates that the access is successful, "0" is written to the first bit of the circular bit array bitArray, and the circular bit array bitArray is 11001000.

[0088] S150: When the access result is 1, the error amount error+1.

[0089] Exemplarily, if "1" is written into any bit in the circular bit array bitArray, the error amount error+1; if "0" is written into any bit in the circular bit array bitArray, the error amount error remains unchanged.

[0090] S160: Calculate the error rate error / total and return the error rate to the gateway.

[0091] In an embodiment of the present application, the counter in the service gateway only occupies 1 bit of storage space by using a circular bit array to record the error rate. Compared with Redis occupying at least 1 byte of storage space, the space occupied by the embodiment of the present application is at most one-eighth of that of using Redis, saving a lot of storage space.

[0092] S200: For any service, when the error rate of the service recorded in any service gateway is greater than the corresponding error threshold, the gateway opens the circuit breaker corresponding to the service.

[0093] In the embodiments of the present application, the implementation of the circuit breaker is not specifically limited. For example, the circuit breaker can be implemented by a Hystric component.

[0094] For service 1, when the error rate about service 1 recorded in service gateway 1 exceeds the error threshold, the error rate about service 1 recorded in service gateway 2 does not exceed the error threshold, and the error rate about service 1 recorded in service gateway n does not exceed the error threshold, the gateway opens circuit breaker 1 corresponding to service 1, so that the access request is no longer sent to service 1.

[0095] It should be noted that after the circuit breaker corresponding to service 1 is opened, the error rate of service 1 in each service gateway needs to be cleared to enter the next cycle.

[0096] It should be understood that the above embodiment only takes service 1 as an example, and other services will not be described in detail here.

[0097] In the embodiment of the present application, the circuit breaker of the service is controlled by the gateway to avoid data synchronization between service gateways, thereby improving the efficiency of the service gateway.

[0098] In an embodiment of the present application, first, the error rate of accessing each service recorded in each service gateway is obtained; then, for any service, when the error rate of the service recorded in any service gateway is greater than the corresponding error threshold, the circuit breaker corresponding to the service is opened. In an embodiment of the present application, the service gateway is used to record the error rate of accessing the service, and the circuit breaker corresponding to the service is controlled by the gateway to achieve the decoupling of the service gateway and redis, and the performance of the service gateway is no longer constrained by redis and is improved.

[0099] The following will be Figure 5 , the state management of circuit breaker is introduced.

[0100] like Figure 5 As shown, the states of the circuit breaker include a first state CLOSED, a second state OPEN and a third state HALF_OPEN, wherein the first state indicates closing the circuit breaker, the second state indicates opening the circuit breaker, and the third state allows transparent transmission of an access request to the corresponding service.

[0101] It should be understood that the third state HALF_OPEN described in the embodiment of the present application is an intermediate state.

[0102] Among them, in the first state CLOSED, the service gateway normally transmits the access request to the corresponding service; in the second state OPEN, the service gateway fuses the access request and returns the fuse information; in the third state HALF_OPEN, the service gateway only transmits one access request to the service. If the access is successful, the state of the circuit breaker is switched from the third state HALF_OPEN to the first state CLOSED. If the access fails, the state of the circuit breaker is switched from the third state HALF_OPEN to the second state OPEN.

[0103] In addition, when the error rate of the service recorded by the counter in the service gateway is greater than the error threshold, the circuit breaker is switched from the first state CLOSED to the second state OPEN; if the duration of the second state OPEN exceeds the fuse time, the state of the circuit breaker is switched from the second state OPEN to the third state HALF_OPEN.

[0104] Among them, the fuse time can be set or modified according to user needs.

[0105] See also Figure 6 , this figure is a flow chart of another service fuse method based on a distributed service gateway provided in an embodiment of the present application.

[0106] like Figure 6 As shown, the method includes:

[0107] S610: The gateway receives an access request.

[0108] The embodiments of the present application do not specifically limit the services corresponding to each access request. For example, access request 1 corresponds to service 1, access request 2 corresponds to service 3, access request 3 corresponds to service 1, access request 4 corresponds to service 2... These services are not listed one by one in the embodiments of the present application.

[0109] S620: The gateway queries the status of the circuit breaker of the service corresponding to the access request.

[0110] For example, for access request 1, query the status of the circuit breaker corresponding to service 1; for access request 2, query the status of the circuit breaker corresponding to service 3; for access request 3, query the status of service 1; for access request 4, query the status corresponding to service 2... and so on, which will not be repeated here.

[0111] S630: When the state of the circuit breaker corresponding to the service is the first state CLOSED, the gateway distributes the access request to the corresponding service gateway through load balancing.

[0112] The embodiments of the present application do not specifically limit the load balancing method. For example, load balancing can be achieved by any one of a polling algorithm, a weighted polling algorithm, a random algorithm, a least connection algorithm, and a hash algorithm.

[0113] As mentioned above, when the gateway includes software, load balancing can be achieved through Nginx.

[0114] In the embodiment of the present application, access requests are distributed to multiple service gateways through load balancing, so as to balance the load of the service gateways and improve the overall processing capacity and performance of the system.

[0115] S631: The service gateway accesses the corresponding service based on the access request.

[0116] It should be understood that after accessing the corresponding service, the service will return the corresponding access result. The access result includes access success and failure. The service gateway updates the error rate of the service according to the access result.

[0117] S632: When the error rate is greater than the error threshold, the state of the circuit breaker is switched from the first state CLOSED to the second state OPEN.

[0118] It should be understood that when the error rate is less than the error threshold, this round of loop ends.

[0119] S640: When the state of the circuit breaker corresponding to the service is the second state OPEN and the service fuse time is greater than the preset time, the gateway updates the state of the circuit breaker from the second state OPEN to the third state HALF_OPEN.

[0120] S641: The gateway forwards the access request to the corresponding service gateway based on load balancing.

[0121] S642: The service gateway accesses the corresponding service based on the access request.

[0122] S643: If the access service is successful, the state of the circuit breaker is switched from the third state HALF_OPEN to the first state CLOSED.

[0123] S644: If the access service fails, the state of the circuit breaker is switched from the third state HALF_OPEN to the second state OPEN.

[0124] It should be noted that in the embodiment of the present application, if the service corresponding to any service gateway is blown or restored, the service gateway will synchronize the message of service blown or restored to other service gateways so that other service gateways will stop distributing access requests to the blown service or resume distributing access requests to the restored service.

[0125] Exemplarily, service 1 corresponding to service gateway 1 is blown, and service gateway 1 synchronizes data to service gateway 2, service gateway 3... and service gateway n; service 1 corresponding to service gateway 1 is restored after the blown, and service gateway 1 synchronizes data to service gateway 2, service gateway 3... and service gateway n.

[0126] In an embodiment of the present application, the failure rate of service access is calculated by the service gateway, and the circuit breaker corresponding to the service is controlled by the gateway to achieve decoupling of the service gateway and redis, and the performance of the service gateway is no longer constrained by redis and is improved.

[0127] In addition, the embodiment of the present application provides a service fuse device based on a distributed service gateway, and its corresponding structural diagram is shown in Figure 7 .

[0128] like Figure 7 As shown, the device includes: an acquisition module 710 and a fuse module 720;

[0129] An acquisition module 710 is used to acquire the error rate of accessing each service recorded in each service gateway;

[0130] The fuse module 720 is used to open the circuit breaker corresponding to any service when the error rate of the service recorded in any service gateway is greater than the corresponding error threshold.

[0131] Optionally, the device further includes: a counter module; for any service gateway, the service gateway includes a counter module, the counter module includes multiple counters, and the counters correspond to the services one by one;

[0132] Each counter is used to record the number of errors in accessing the corresponding service through a bit cycle array, and obtain the corresponding error rate according to the number of errors of the service.

[0133] Optionally, the counter module is specifically configured to record the number of errors in accessing the corresponding service within the window by circulating the bit array.

[0134] Optionally, the device further includes: a receiving module and a forwarding module;

[0135] A receiving module, used for receiving a service request;

[0136] The forwarding module is used to forward the service request to the corresponding service gateway based on load balancing.

[0137] Optionally, a forwarding module is specifically used to determine the service corresponding to the service request and the state of the circuit breaker corresponding to the service; wherein the state of the circuit breaker includes a first state and a second state, the first state indicates that the circuit breaker is closed, and the second state indicates that the circuit breaker is open; when the state of the circuit breaker is the first state, the service request is forwarded to the corresponding service gateway based on load balancing.

[0138] Optionally, the forwarding module is also used to determine the circuit breaker's fuse time when the circuit breaker is in the second state; when the fuse time is greater than the error threshold, change the circuit breaker's state from the second state to the third state, and forward the service request to the corresponding service gateway through load balancing so that the service request accesses the service; the third state allows a service request to access the corresponding service; when the service request successfully accesses the service, change the circuit breaker's state from the third state to the first state; when the service request fails to access the service, change the circuit breaker's state from the third state to the second state.

[0139] Optionally, the device further comprises: a clearing module;

[0140] The clearing module is used to clear the error rate of accessing the service recorded in all service gateways for any service when the circuit breaker corresponding to the service is opened.

[0141] In addition, an embodiment of the present application also provides a computer device, including a processor and a memory, the memory is used to store programs, instructions or codes, and the processor is used to execute the programs, instructions or codes in the memory to complete the service fuse method based on a distributed service gateway as in any of the aforementioned embodiments.

[0142] In addition, an embodiment of the present application also provides a computer-readable storage medium storing a computer program, and the computer program is loaded by a processor to execute the service fuse method based on a distributed service gateway of any of the aforementioned embodiments.

[0143] For a possible implementation, see Figure 8 , which is a schematic diagram of a computer device provided in an embodiment of the present application.

[0144] The computer device may include a memory 810 and a processor 820. The memory may be a random access memory (RAM), a flash memory, a read only memory (ROM), an EPROM memory, an Electronic Programmable ROM (EPROM), a register, a hard disk, a removable disk, etc.

[0145] The memory 810 may store computer instructions. When the computer instructions stored in the memory 810 are executed by the processor 820, the processor 820 may be used to execute the service fuse method based on the distributed service gateway. The memory 810 may also store data, for example, information such as the preset range and preset threshold involved in the above embodiments.

[0146] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on the computer, the process or function according to the embodiment of the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from a website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (digital subscriber line, DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, server or data center. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server, data center, etc. that includes one or more available media integrated. The available medium can be a magnetic medium, (e.g., a floppy disk, a hard disk, a tape), or a semiconductor medium (e.g., a solid state drive (solid statedisk, SSD)), etc.

[0147] The present application also provides a readable storage medium for storing the method provided in the above embodiment, for example, a random access memory (RAM), a flash memory, a read only memory (ROM), an EPROM memory, an electronic programmable ROM (EPROM), a register, a hard disk, a removable disk or any other form of storage medium in the art.

[0148] It should be noted that each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system and method embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiments. The system and method embodiments described above are merely schematic, wherein the units described as separate components may or may not be physically separated, and the components indicated as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.

[0149] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions that can be easily thought of by a person skilled in the art within the technical scope disclosed in the present application should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

Claims

1. A service fusing method based on a distributed service gateway, characterized in that: The method comprises: Obtain the error rate of accessing each service recorded in each service gateway; For any of the services, when the error rate of the service recorded in any of the service gateways is greater than the corresponding error threshold, the circuit breaker corresponding to the service is opened.

2. The method according to claim 1, characterized in that For any service gateway, the service gateway includes multiple counters, which correspond to the services one by one. Each counter records the number of errors in accessing the service through a bit loop array, and obtains the corresponding error rate based on the number of errors in the service.

3. The method according to claim 2, characterized in that Each of the counters records the number of errors in accessing the corresponding service through a bit loop array, including: Each of the counters records the number of errors in accessing the corresponding service within a window through the circular bit array.

4. The method according to any one of claims 1 to 3, characterized in that: The method further comprises: Receive service requests; The service request is forwarded to the corresponding service gateway based on load balancing.

5. The method according to claim 4, characterized in that The forwarding the service request to the corresponding service gateway based on load balancing includes: Determine a service corresponding to the service request and a state of a circuit breaker corresponding to the service; wherein the state of the circuit breaker includes a first state and a second state, the first state indicates that the circuit breaker is closed, and the second state indicates that the circuit breaker is open; When the state of the circuit breaker is the first state, the service request is forwarded to the corresponding service gateway based on load balancing.

6. The method according to claim 5, characterized in that The method further comprises: When the state of the circuit breaker is the second state, determining a fusing time of the circuit breaker; When the fuse time is greater than the error threshold, the state of the circuit breaker is changed from the second state to a third state, and the service request is forwarded to the corresponding service gateway through load balancing, so that the service request accesses the service; the third state allows a service request to access the corresponding service; When the service request accesses the service successfully, the state of the circuit breaker is changed from the third state to the first state; when the service request accesses the service unsuccessfully, the state of the circuit breaker is changed from the third state to the second state.

7. The method according to claim 1, characterized in that The method further comprises: For any of the services, when the circuit breaker corresponding to the service is opened, the error rates of access to the service recorded in all the service gateways are cleared.

8. A service fuse device based on a distributed service gateway, characterized in that: The device comprises: an acquisition module and a fuse module; The acquisition module is used to obtain the error rate of accessing each service recorded in each service gateway; The fuse module is used to open the circuit breaker corresponding to any of the services when the error rate of the service recorded in any of the service gateways is greater than the corresponding error threshold.

9. A computer device, characterized in that: include: A memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the service fusing method based on the distributed service gateway as described in any one of claims 1 to 7 is implemented.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores instructions, and when the instructions are executed on a terminal device, the terminal device executes the service fusing method based on a distributed service gateway as described in any one of claims 1 to 7.

Citation Information

Cited By

  • Intelligent traffic scheduling method and system based on application perception and storage medium

    CN122933751A