sentinel 流控规则 流控模式 流控效果
一、流控模式
1、直接
2、链路
a、yaml文件,开启链路
spring: cloud: sentinel: web-context-unify: false
b、创建kill api
@GetMapping("kill") public Order killOrder(@RequestParam Long userId, @RequestParam Long productId){ Order order = orderService.createOrder(userId, productId); return order; }
c、添加流控
假定场景:访问 create api 正常,访问kill api 做流控,需要 在createOrder添加流控
3、关联
a、假定场景
访问writeDb和readDb,readDb受限,当访问太多次writeDb
b、写接口
@GetMapping("writeDb") public String writeDb(){ return "writeDb..."; } @GetMapping("readDb") public String readDb(){ return "readDb..."; }
c、添加流控
二、流控效果
1、快速失败
只有快速失败支持(直接、关联、链路)的设置
2、Warm Up
像开车一样,速度越来越快,每秒访问的频率越来越快
3、排队等待
匀速排队