SpringBoot 微服务限流、熔断、降级Sentinel

一、前言

Sentinel 是面向分布式服务架构的高可用流量防护组件,主要以流量为切入点,从限流、流量整形、熔断降级、系统负载保护、热点防护等多个维度来帮助开发者保障微服务的稳定性。

例如抢购秒杀系统,在很短的时间会有非常大的并发请求过来,如果不做限流可能一下子服务器就崩了。

二、安装

下载地址:https://github.com/alibaba/Sentinel/releases

运行

java -Dserver.port=8080 -Dcsp.sentinel.dashboard.server=localhost:8080 -Dproject.name=sentinel-dashboard -jar sentinel-dashboard.jar

访问:http://localhost:8080/
SpringBoot 微服务限流、熔断、降级Sentinel_第1张图片

用户名和密码:sentinel

三、使用

3.1 maven 依赖

pom.xml中加入如下依赖:

<dependency>
    <groupId>com.alibaba.cloudgroupId>
    <artifactId>spring-cloud-starter-alibaba-sentinelartifactId>
dependency>

3.2 application.properties

# dashboard
spring.cloud.sentinel.transport.dashboard=localhost:8080

四、测试

jmeter循环请求。
可以看到qps(Queries-per-second)2万左右。
SpringBoot 微服务限流、熔断、降级Sentinel_第2张图片

加上流量控制,qps 5000封顶
SpringBoot 微服务限流、熔断、降级Sentinel_第3张图片

监控台可以看到通过的qps封顶5000,其它的都被拒绝了。
SpringBoot 微服务限流、熔断、降级Sentinel_第4张图片

流量控制规则多种,有快速失败、Warm Up、排队等待。可以根据实际情况来配置。
SpringBoot 微服务限流、熔断、降级Sentinel_第5张图片

五、结语

源码地址:https://github.com/tigerleeli/xiaohuge-blog/tree/master/spring-cloud-alibaba-sentinel

同步微信公众号:小虎哥的技术博客
SpringBoot 微服务限流、熔断、降级Sentinel_第6张图片

你可能感兴趣的:(后端系列,spring,cloud,spring,cloud,alibaba,微服务,先留降级,Sentinel)