Explain the use of sentinel in detail

Table of contents

1 Overview

2. Download and install

3. Application Hosting

4. Flow control

4.1. Flow control rules

4.2. Flow control mode

4.2.1. Direct mode

4.2.2. Association mode

4.2.3. Link mode

4.3. Flow control effect

4.3.1. Preheating

4.3.2. Waiting in line

5. Downgrade

5.1. Demotion Rules

5.2. Downgrade strategy

5.2.1.RT

5.2.2. Abnormal ratio

5.2.3. Abnormal number


1 Overview

Sentinel, a component in springcloud alibaba that compares to hystrix in springcloud Netflix, is a powerful distributed system protection tool that ensures the stability and availability of the microservice architecture through mechanisms such as flow control, fuse downgrade, and system load protection. It is one of the important components in the Spring Cloud ecosystem and is widely used in microservice development and operation and maintenance. Ali's annual "Double Eleven", Sentinel is one of the core components that provide a distributed protection mechanism.

Disadvantages of hystrix:

  1. There is no built-in monitoring platform, and the dashboard needs to be integrated and configured to monitor
  2. There is no graphical interface to provide configuration, and flow control, downgrade, and fusing can only be implemented at the code layer.

Advantages of sentinel:

  1. A single component that provides a graphical interface
  2. Provide a graphical interface for flow control, downgrade, and fuse configuration.

2. Download and install

download link:

https://github.com/alibaba/Sentinel/releases

Sentinel is divided into two parts:

  1. The core library is a JAVA client that provides functions such as current limiting, downgrading, and circuit breaking
  2. The console, based on the dashboard implemented by SpringBoot, completes the monitoring function.

Both are integrated in a jar package, and the two functions can be run by running the jar package.

Page address: localhost:8080

Default username and password: sentinel sentinel

3. Application Hosting

Introduce the dependency of sentinel on the application side, configure the address of sentinel and the communication port with sentinel, and then the application can be hosted by sentinel for monitoring.

rely:

<dependency>
   <groupId>com.alibaba.cloud</groupId>
   <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
   <version>${version}</version>
</dependency>

Configuration:

spring:
  cloud:
    sentinel:
      transport:
        dashboard: 127.0.0.1:8080
        port: 8719

Lazy loading:

Sentinel adopts a lazy loading mechanism. Services that have not been visited will not be monitored, and only services that have been visited will be included in the monitoring.

4. Flow control

4.1. Flow control rules

Flow control rules can be set in sentinel's flow control rules.

Resource name: URL, which must be globally unique.

Threshold Type: Limit Thread Count? Limit visits per second?

Stand-alone threshold: the access threshold for each machine

Flow control mode, flow control effect: set the way of response.

4.2. Flow control mode

4.2.1. Direct mode

After exceeding the threshold, a processing method will be given directly:

The setting here is "fail fast", and a response is given directly.

4.2.2. Association mode

When the resource associated with itself reaches the threshold, limit the flow of itself.

That is, when the resource B associated with A reaches the threshold, A is limited.

Prevent related business downtime caused by continuous sitting effect.

4.2.3. Link mode

The link mode needs to be used together with the cluster point link,

There is a default link in the cluster point link, and all access paths in the current system are under the link.

The link mode means that in addition to the access through the resource name will be flow controlled, the resource names that other services in the link call flow control will also be restricted by the configured flow control rules.

4.3. Flow control effect

4.3.1. Preheating

Warm up (warm up), that is, warm up/cold start,

That is, the system is not directly allowed to face the limit flow, but when the flow reaches a percentage of the set threshold, the system rejects all flow, takes a period of time to warm up, and then faces the limit flow after warming up.

The percentage of this threshold is related to a coefficient - the cooling factor (cold factor). The default cooling factor is 3, that is, when the instantaneous traffic reaches 1/3 of the threshold, the system will reject the subsequent traffic for a period of time (the form of rejection is to directly return a response), and then during this period of time "Preheating", after the preheating is completed, the limit flow will be processed.

This "warm-up time" can be dynamically configured, unit: second.

4.3.2. Waiting in line

Waiting in a queue, allowing concurrent requests to pass through at a uniform speed, suitable for intermittent burst traffic peaks. The incoming requests are backlogged and queued up, and the interval time is used to gradually release them. The default interval is 500 milliseconds.

Only QPS is processed for queuing, and only a threshold number of requests are released each time. Unprocessed requests that time out will directly return a response. The timeout unit is milliseconds.

5. Downgrade

Sentinel combines fuse and downgrade, and directly uses fuse to achieve downgrade.

5.1. Demotion Rules

Downgrade rules can be set in sentinel's downgrade rules.

5.2. Downgrade strategy

5.2.1.RT

RT (the new version is renamed to "slower call"), the average response time.

When more than 5 requests come in within one second, the downgrade rule is activated. When more than 30% of all incoming requests have a request response time exceeding 1000ms, the service fuse is triggered and the circuit breaker is turned on. The fuse lasts for 20 seconds. During this period Quickly return a response to the request that still wants to come in, and after 20 seconds, send a probe signal to the service to try to close the circuit breaker.

5.2.2. Abnormal ratio

If more than 3 requests come in within 1 second, the downgrade rule will be activated. More than 30% of the incoming requests will be abnormal, triggering a fuse, the circuit breaker will be opened, and the fuse will last for 10 seconds. Response, re-probe after 10 seconds, try to close the breaker.

5.2.3. Abnormal number

If more than 3 requests come in within 1 minute, the downgrade policy will be triggered. If the number of exceptions in all requests exceeds the threshold, a circuit breaker will be triggered.

Guess you like

Origin blog.csdn.net/Joker_ZJN/article/details/131360942#comments_27277909