前言
系统自适应目的在于在保证系统稳定的同时尽可能提高吞吐量,是一种从整体维度综合考虑的一种限流方法。包括:系统Load、CPU使用率、整体入口QPS、总的并发线程数、平均RT。
一、参数说明
属性 | 说明 |
---|---|
highestSystemLoad | 阈值,系统最高负载,建议取值 CPU cores * 2.5 |
highestCpuUsage | 阈值,CPU使用率,取值范围[0, 1] |
qps | 阈值,单机应用维度入口QPS |
avgRt | 阈值,单机应用所有请求的平均RT |
maxThread | 阈值,单机应用的最大线程并发数 |
二、源码注解
1.代码入口
2.源码注解(一)
3.源码注解(二)
小结:系统自适应只针对入口流量;当全局QPS > 设置QPS阈值时,触发系统自适应流控; 当全局并发线程数 > 设置的线程并发阈值maxThread时,触发系统自适应流控; 当全局平均RT > 设置的平均RT阈值avgRt时,触发系统自适应流控; 当系统Load > 设置的系统最高负载阈值highestSystemLoad时,进行如下判断:当前全局并发线程数 > 系统容量时,触发触发系统自适应流控;系统容量了= maxQps * minRt / 1000。
三、BBR算法简述
1.BBR算法含义
BBR一种拥塞控制算法,主动探测出站数据(带宽)和往返时间(round-trip time,RTT),不断调整发送速率的一种算法。
For a given network connection, BBR uses recent measurements of the network's delivery rate and round-trip time to build an explicit model that
includes both the maximum recent bandwidth available to that connection, and its minimum recent round-trip delay.
BBR then uses this model to control both how fast it sends data and the maximum amount of data it's willing to allow in the network at any time.
基于丢包拥塞算法与BBR拥塞算法性能图示
2.BDP带宽延时积
BDP(Bandwidth-Delay Product),带宽延时积也就是带宽和延迟的乘积,表示允许通过的最大流量(数据)。 公式:BDP = min(RTT) * max(bandwidth)
应用到Sentinel系统自适应限流中: 公式:系统容量(BDP)= maxQps * minRt
小结:图示中红色区域面积即Sentinle中的系统容量,长度为最小RT,宽带为最大Qps,当前流量超过系统容量时触发自适应限流。
四、规则示例
格式一
[
{
"avgRt": 10,
"highestCpuUsage": 0.6,
"highestSystemLoad": 3,
"maxThread": 10,
"qps": 20
}
]
格式二
[
{
"avgRt": -1,
"highestCpuUsage": -1,
"highestSystemLoad": 3,
"maxThread": -1,
"qps": -1
},
{
"avgRt": -1,
"highestCpuUsage": 0.6,
"highestSystemLoad": -1,
"maxThread": -1,
"qps": -1
},
{
"avgRt": 10,
"highestCpuUsage": -1,
"highestSystemLoad": -1,
"maxThread": -1,
"qps": -1
},
{
"avgRt": -1,
"highestCpuUsage": -1,
"highestSystemLoad": -1,
"maxThread": -1,
"qps": 20
}
]