Table of contents:
- Initial Sentinel
- flow control
- Quarantine and downgrade
- authorization rules
- Rule Persistence
Initial Sentinel
- Avalanche Problems and Solutions
- Service Protection Technology Comparison
- Sentinel introduction and installation
- Microservice Integration Sentinel
avalanche problem
A service failure in the microservice call link causes all microservices in the entire link to be unavailable, which is an avalanche.
There are four common ways to solve the avalanche problem:
- Timeout processing: set the timeout period, the request will return an error message if there is no response after a certain period of time, and will not wait endlessly
- Bulkhead mode: Limit the number of threads used by each business to avoid exhausting the resources of the entire tomcat, so it is also called thread isolation.
- Fuse degradation: There is an abnormal proportion of business execution at the same level with a circuit breaker. If the threshold is exceeded, the business will be blown and all requests to access the business will be intercepted.
- Flow control: QPS to limit business access to avoid service failure due to sudden increase in traffic.
Flow control is to prevent avalanches. The first three are service failures. How to prevent the failure from being transmitted to other services. The flow control is to limit QPS to avoid failure.
summary
What is the avalanche problem?
- Microservices call each other, because a service failure in the call chain causes the entire link to be inaccessible.
How to avoid service failure caused by instantaneous high concurrent traffic?
- flow control
How to avoid the avalanche problem caused by service failure?
- Timeout processing
- thread isolation
- downgrade circuit breaker
Service Protection Technology Comparison
Sentinel | Hystrix | |
---|---|---|
isolation strategy | Semaphore isolation | Thread pool isolation/semaphore isolation |
Circuit breaker downgrade strategy | Based on slow call ratio or abnormal ratio | Based on failure rate |
Real-time indicator implementation | sliding window | Sliding window (based on RxJava) |
rule configuration | Support multiple data sources | Multiple data sources are supported) |
Scalability | multiple scalability | plug-in form |
Annotation-based support | support | support |
Limiting | Based on QPS, support current limiting based on call relationship | limited support |
traffic shaping | Support slow start, average speed queuing mode | not support |
System Adaptive Protection | support | not support |
console | Available out of the box, you can configure rules, view second-level monitoring, machine discovery, etc. | not support |
Adaptation to Common Frameworks | Servlet、Spring Cloud、Dubbo、gRPC等 | Servlet、Spring Cloud Netflix |
Meet Sentinel
Sentinel is a microservice traffic control component open sourced by Alibaba. Official website address: https://sentinnelguard.io/zh-cn/index.html
Install Sentinel Console
Sentinel officially provides a UI console, which is convenient for us to set the current limit on the system. Available for download on GitHub. You can also use the jar package provided by the data: sentinel-dashboard-1.8.1.jar
1. Copy it to a non-Chinese directory, and then run the command:
java -jar sentinel-dashboard-1.8.1.jar
2. Then visit: localhost:8080 to see the console page, the default account and password are sentinel
If you want to modify Sentinel's default port, account, and password, you can configure it through the following:
configuration item | Defaults | illustrate |
---|---|---|
server.port | 8080 | service port |
sentinel.dashboard.auth.username | sentinel | default username |
sentinel.dashboard.auth.password | sentinel | default password |
Example: java -jar sentinel-dashbord-1.8.1.jar -Dserver.port=8090
Introduce cloud-demo
To use Sentinel, you need to combine microservices and use the csloud-demo project in the practical chapter.
The project structure is as follows:
cscloud-demo:gateway、user-service 用户服务,包含用户的CRUD、order-service 订单服务,调用user-service、feign-api 用户服务对外暴露的feign客户端、实体类
Microservice Integration Sentinel
We integrate Sentinel in order-service and connect to Sentinel's console, the steps are as follows:
1. Introduce sentinel dependencies:
<!--sentinel-->
<dependency>
<groupId>com.alibaba.cscloud</groupId>
<aitifactId>spring-cscloud-starter-alibaba-sentinel</aitifactId>
</dependency>
2. Configure the console address:
spring:
cloud:
sentinel:
transport:
dashbord: localshost:8080
3. Access any endpoint of the microservice (any controller interface of springmvc), trigger sentinel monitoring