Enjoy learning class guest writer: Lao Gu

directory

  1. preface
  2. Global exception degradation
  3. Fuse is lost
  4. Fusing the drop
  5. Configuration thinking
  6. conclusion

preface

In the previous article, Gu has introduced the basic usage of sentinel and the use of sentinel-Dashboard console to configure the degradation policy, global Feign call default exceptions, and nacOS persistence to ensure that the degradation policy is not lost.

In the whole process of use, no major problems were found; But a closer look at the logs reveals some problems; And there are a lot of things to configure to solve this problem. Find an area that is inconvenient to use; And it is very inconvenient and wastes a lot of time. Let’s take a look at some of the problems

Global exception degradationIn the previous article, Gu introduced the Feign call exception global degradation strategy, so let’s briefly describe it here

The figure above shows a common service. The Consumer service invokes the Provider service through Feign. In order to ensure the stability of the system and prevent the occurrence of the Provider service, the Fallback degradation policy is configured in the Consumer serviceAfter this setting, even if the provider service fails, we can still use fallback method to obtain Plain Text===fall back=== so as to ensure the stability of the whole system, and not cause instability of consumer service due to instability of the Provider service. The technical term is to prevent the avalanche effect. Is the fallback attribute Java@FeignClient(name = “service-provider”,fallback =) added to @FeignClient annotation in the Fegin interface ProviderServiceFallback. Class) friends we consider, if we have 10 Feign external consumer calls, there are ten Feign interface, so to ensure the stability of the system, We need to configure fallback on each Feign interface. And the general degradation logic business processes are very similar, are standard business. Is it troublesome? Can the system have a global fallback processing? As described in a previous article, Sentinel Unified Treatment of Current Limiting and Degradation, you can go out and turn right to find it. This article will not repeat the implementation.

Fuse is lost

Above we introduced global degradation; To see how this works, we turn off the provider service and directly access the Consumer’s getHeader method. In the code, we get the header from the client and then call the method remotely from Feign. Look at the following code

http://localhost:8083/getHeader
Copy the code

Load balancer does not have available server for client: service-provider; Make sure the system works

{
 "statusCode": "0"."statusMessage": "Processed successfully"."data": "success"
}
Copy the code

Let’s do it again

http://localhost:8083/getHeader
Copy the code

Still error!! No matter how many times it is executed, the log still has exceptions; Although the front end is not visible!! Did the partner find the problem? Why does something happen every time? In this case, the exception is that the provider service does not exist, which is not obvious because the Consumer service immediately knows that it returned the exception; However, if the exception is returned because the Provider service takes too long to execute, the Consumer service calls time out. Then each call produces a timeout exception, which does nothing to prevent an avalanche effect. Is there a problem somewhere? Yes, we forgot to configure the degrade policy for Sentinel; The essence is the fuse downgrade strategy. The Sentinel Dashboard, which can be configured for fuse downgrading, was introduced in the previous article. How to install, friends can go to read the previous articleThe above configuration means that the minimum number of requests reaches 2 within 10 seconds, and if there is 1 exception, the fuse will be executed, and the fuse will last 10 seconds. We have executed several times and found that the exception log is missing.And the reason is thatPlain TextproviderServiceFeign.transferHeaders(); When executing Fegin remote calls, if the fuse is broken, this code will not execute the remote calls; Instead, the fallback method is called immediately. In this way, the configuration is really complete, and the stability of the protection system after fusing is achieved. Configuration Considerations We have configured a circuit breaker degrade policy with the resource name

GET:http://service-provider/transferHeaders
Copy the code

This is based on the service name + request URL. If we have a lot of remote calls to Feign; Such asIf there are many Feign interfaces, do we need to configure them all? All going to Sentinel Dashboard for configuration? And if there are many microservices, then each corresponding service must be configured one by one; Do you think it’s too much trouble. And the rules for configuring fuses are very similar, even with many of the same values.

And a lot of times we don’t remember how many Feign methods there are, so we have to look them up ourselves, which is really messy

Is there a way to configure a global circuit breaker like a global fallback? In this way, we don’t need to configure it. Whenever @feignClient calls remotely, it will automatically configure the fuse degrade policy by default. Do you have any plan? Gu will be introduced in the next article.

conclusion

Some knowledge does need to find problems in the actual combat of the enterprise, partners should be good at observation and thinking; Refactoring solutions to find better solutions that increase efficiency and reduce human intervention.

Stay tuned to the next article for details on how to implement it.