One, foreword
Sentinel is a high-availability traffic protection component for distributed service architecture. It mainly takes traffic as the entry point and helps developers guarantee the stability of microservices from multiple dimensions such as traffic limiting, traffic shaping, fuse downgrading, system load protection and hotspot protection.
For example, in a very short period of time, there will be very large concurrent requests. If you do not limit the flow, the server may collapse suddenly.
Second, the installation
Download: github.com/alibaba/Sen…
run
java -Dserver.port=8080 -Dcsp.sentinel.dashboard.server=localhost:8080 -Dproject.name=sentinel-dashboard -jar sentinel-dashboard.jar
Copy the code
Access:http://localhost:8080/ Username and password: sentinel
Three, use,
3.1 the maven rely on
Add the following dependencies to pom.xml:
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
Copy the code
3.2 application. The properties
# dashboard
spring.cloud.sentinel.transport.dashboard=localhost:8080
Copy the code
Four, test,
withjmeter
Loop requests. The value of QPS (Queries per second) is about 20,000.
With flow control, QPS 5000 is capped
The monitor can see the QPS cap 5000 passed, all others are rejected.
There are various traffic control rules, including fast failure, Warm Up, and queue waiting. The value can be configured as required.
Five, the conclusion
Source code address: github.com/tigerleeli/…
Synchronize wechat official account: Little Tiger’s technology blog