SpringCloud Gateway higher-order limiting the Sentinel, the fuse

Foreword

Why do you need the service fuse and downgrade ? Micro service is currently a major trend in the industry, the principle is the responsibility of a single functional module independent child into service , reduce the coupling between services, call each other between services . But this will be some problems:

 

 

The figure above a large number of micro-services call each other , there are a lot of dependencies , there will inevitably be a service failure , such as ServiceD problems, leading to ServiceG, ServiceF, ServiceA, ServiceB have a problem, and then affect other services into a cascade failure , eventually leading to system unavailability collapse, is serving an avalanche .

Of course, there are some scenes, some of the time period for certain services appear high concurrent situation, and some of those services take up the shortage of resources is clearly not reasonable, then you need some service downgrade, weakening take up system resources .

Familiar Spring Cloud's junior partner, the first response should be is Hystrix . But the pity is that Netflix has announced that for Hystrix stop updating . So what better choice? In addition to the official Spring Cloud recommended resilience4j , there are now consolidated under Spring Cloud Alibaba Sentinel small partners can focus on investigation and selection of the target.

What is Sentinel

Sentinel is a from Ali development -oriented lightweight distributed service architecture flow control products , mainly in the flow as the starting point, the flow control, fuse downgraded protection system load multiple dimensions such as to help protect the stability of our services . Sentinel uses divided into two parts:

1, sentinel-dashboard: with hystrix-dashboard similar, but it is more powerful. In addition Like hystrix-dashboard provides real-time monitoring, but also provides flow control rules, rules-line fuse maintenance and other functions.

2, client integration: each micro-services client needs to integrate the client package and configuration of sentinel to monitor the information will be reported to the dashboard display and real-time changes or limiting fuse rules and so on.

Deploy Sentinel Dashboard

download link

Github to search elements sentinel above to see his releases, and now the latest version V1.6.3, click to download

Run Sentinel.jar default port 8080 Sentinel is, of course, you can also change other ports, setting it at startup on the line. When we start to let him run in the background.

  1. nohup java -jar sentinel-dashboard-1.6.3.jar &

Log Sentinel console

ip + port number to access the service , a user name and password are: sentinel

 

 

After landing into to see the flow control and set rules downgrade

 

 

Sentinel gateway support

Sentinel support for mainstream Spring Cloud Gateway, Zuul and other API Gateway be limiting.

 

 

Sentinel 1.6.0 introduced Sentinel API Gateway Adapter Common module , this module contains rules limiting the gateway API and custom entities and management logic:

1, GatewayFlowRule : Gateway limiting rule, this according to their own routing scene gateway design , can be limiting for API grouping different route or custom support for the request parameters, Header, source IP and other customized Limiting.

2, ApiDefinition : the API defined user-defined packets, can be seen as some combination of matching the URL . For example, we can define an API called myapi, requested path mode / foo / ** and / baz / ** returned into myapi the API grouped below. When the current limit may be directed to be limiting the API Packet custom dimensions .

Gateway limiting rules GatewayFlowRule 

 

Fields explained as follows:

1, resource: resource name

API user name or group name route gateway custom.

2、resourceMode

Rules are for the API Gateway's route (RESOURCEMODEROUTEID) or user in the Sentinel API custom grouping (RESOURCEMODECUSTOMAPI_NAME), default route.

3、grade

Limiting index dimensions , with rules limiting grade field.

4, count: limit threshold 5, intervalSec

Statistics window of time, in seconds, the default is 1 second (currently only parameter limiting entry into force).

6、controlBehavior

Traffic shaping control effect, with controlBehavior field limiting rules, currently supports rapid and uniform line failure modes, the default is to fail fast .

7、burst

The number of requests to deal with unexpected request additional permissible (currently only parameter limiting entry into force).

8、maxQueueingTimeoutMs

Longest queue queuing time at a constant speed mode, in milliseconds, the queuing effect only on the constant speed mode.

9, paramItem parameters limiting configuration . If not provided, it means not limiting parameters for the gateway rule will be converted into common flow control rules; otherwise the rule will be converted into a hot spot. Where the fields are: parseStrategy : extracting parameters from the request policy , currently supports four modes to extract the source * IP (PARAMPARSESTRATEGYCLIENTIP) * Host ( PARAMPARSESTRATEGYHOST) * any Header (PARAMPARSESTRATEGYHEADER) * arbitrary URL parameters (PARAMPARSESTRATEGYURLPARAM)

fieldName : If the extraction method selected Header mode or URL parameters mode, you need to specify the corresponding header name or URL parameter names. pattern and matchStrategy : reserved for parameter matching characteristics

Rules can be loaded via the gateway GatewayRuleManager.loadRules (rules) manual, or by GatewayRuleManager.register2Property (property) registered a dynamic rule source dynamic push (the recommended way)

Gateway flow control implementation principles

 

FIG on the overall process is as follows:

1, will go through filter Sentinel achieved when the external request Gateway enters the API , which will in turn be routed / API matched packet, the request parameters and analytical properties assembly.

2, the Sentinel will parse the request to the gateway according to the properties of the flow control rule is configured , and is assembled in accordance with the parameters of the parameter array index order, the final pass in SphU.entry (res, args).

. 3, the Sentinel the API Gateway Adapter Module adds a GatewayFlowSlot the Common to the Slot Chain , designed to make regular checks gateway.

. 4, GatewayFlowSlot extracts hot parameter rule generated from the GatewayRuleManager sequentially checks the rules based on the passed parameter. If a rule is not a request for attributes, it will be in the inserted position of the last preset constant parameter , to achieve the effect of the general flow control . note:

When loaded through GatewayRuleManager when GatewayFlowRule gateway flow control rules , whether or not a request for limiting properties, the bottom will be the Sentinel gateway rules into the hot flow control parameter rule ParamFlowRule , in GatewayRuleManager in normal isolated hot parameter rule storage. Sentinel conversion based on the configuration attribute request, set the parameters for the index idx gateway flow control rules , and synchronization to the hot parameter rule generated in

 

to sum up

Sentinel from the 1.6.0 version to start, provided SpringCloud Gateway adapter module , two resources can provide current limiting dimensions:

. 1, route dimensions: routing entry that is configured in the Spring configuration file, the resource name corresponding routeId

2, a custom API dimensions: the user can use the Sentinel API provided from the API to define some packets

Guess you like

Origin www.cnblogs.com/Soy-technology/p/11589016.html