流量控制规则说明

本文详细介绍了微服务流量控制的单机模式,涵盖了阈值类型(QPS、线程数)、单机阈值、流控模式(直接、关联、链路)以及流控效果(快速失败、预热、排队等待)。同时,文章讨论了不同流控模式下的资源依赖关系,并解析了预热时长和超时时间等参数。最后,通过示例展示了流量规则的配置,包括集群和非集群模式下的配置细节。
摘要由CSDN通过智能技术生成

前言

本文梳理单机流控涉及的相关规则,集群流控另文梳理。

一、阈值类型 

属性说明
QPS通过比较时间窗口的QPS与设置的阈值,进行流控的一种类型
线程数通过比较时间窗口的线程数与设置的阈值,进行流控的一种类型

二、单机阈值 

属性说明
单机阈值用户设置的QPS或线程数阈值

三、流控模式

流控模式,即针对什么样的资源依赖关系进行流控,具体类型如下:

属性说明
直接

含义:针对调用来源的限流
调用来源:由ContextUtil.enter(resourceName, origin)方法中的origin设置 
针对来源:由字段limitApp设置,取值如下:default:表示不区分调用者,流量统计来自context.getOriginNode。
{some_origin_name}:表示针对特定的调用者,流量统计来自于node.getClusterNode。
other:表示针对除 {some_origin_name} 以外的其余调用方的流量进行流量控context.getOriginNode。

关联含义:针对两个依赖或者竞争的资源的限流
链路含义:针对调用入口的限流 入口资源通过ContextUtil.enter(name)来设置

四、流控效果 

流控效果即对发生流控后结果的处理,类型如下表:

属性说明
快速失败发生流控时抛出FlowException
Warm Up

预热模式,又为冷启动,指避免流量突然进来将系统压垮,使流量缓慢增加的一种模式。
预热时长:用户自定义设置

排队等待即匀速器,使用漏桶算法使得请求匀速通过。超时时间:由用户自定义设置

五、参数说明 

流量规则由FlowRule设置,集群模式相关配置在集群流控规则中说明,字段含义如下:

属性说明
resource资源名称
limitApp限制的调用来源
grade阈值类型,默认0(0:线程数,1:QPS)
count阈值,用户设置
strategy流控模式,默认0。0:直接 1:关联 2:链路
refResource当strategy为关联时,设置关联的资源
controlBehavior流控效果,默认0。0:快速失败 1:预热模式 2:排队等待 3:预热+排队等待
warmUpPeriodSec当controlBehavior=1时,预热时长,单位秒,默认10
maxQueueingTimeMs当controlBehavior=2时,超时时间,单位毫秒,默认500毫秒
clusterMode是否为集群模式,默认false

六、规则示例 

[
    {
        "clusterConfig": {
            "fallbackToLocalWhenFail": true,
            "flowId": 81,
            "sampleCount": 10,
            "strategy": 0,
            "thresholdType": 1,
            "windowIntervalMs": 1000
        },
        "clusterMode": true,
        "controlBehavior": 0,
        "count": 3000,
        "grade": 1,
        "limitApp": "default",
        "maxQueueingTimeMs": 500,
        "resource": "flowDemo04",
        "strategy": 0,
        "warmUpPeriodSec": 10
    },
    {
        "clusterConfig": {
            "fallbackToLocalWhenFail": true,
            "flowId": 82,
            "sampleCount": 10,
            "strategy": 0,
            "thresholdType": 0,
            "windowIntervalMs": 1000
        },
        "clusterMode": true,
        "controlBehavior": 0,
        "count": 10000,
        "grade": 1,
        "limitApp": "default",
        "maxQueueingTimeMs": 500,
        "resource": "flowDemo03",
        "strategy": 0,
        "warmUpPeriodSec": 10
    },
    {
        "clusterConfig": {
            "fallbackToLocalWhenFail": true,
            "sampleCount": 10,
            "strategy": 0,
            "thresholdType": 0,
            "windowIntervalMs": 1000
        },
        "clusterMode": false,
        "controlBehavior": 1,
        "count": 1000,
        "grade": 1,
        "limitApp": "default",
        "maxQueueingTimeMs": 500,
        "resource": "flowDemo06",
        "strategy": 0,
        "warmUpPeriodSec": 5
    },
    {
        "clusterConfig": {
            "fallbackToLocalWhenFail": true,
            "sampleCount": 10,
            "strategy": 0,
            "thresholdType": 0,
            "windowIntervalMs": 1000
        },
        "clusterMode": false,
        "controlBehavior": 0,
        "count": 500,
        "grade": 1,
        "limitApp": "default",
        "maxQueueingTimeMs": 500,
        "refResource": "flowDemo4",
        "resource": "flowDemo05",
        "strategy": 1,
        "warmUpPeriodSec": 10
    },
    {
        "clusterConfig": {
            "fallbackToLocalWhenFail": true,
            "sampleCount": 10,
            "strategy": 0,
            "thresholdType": 0,
            "windowIntervalMs": 1000
        },
        "clusterMode": false,
        "controlBehavior": 0,
        "count": 5000,
        "grade": 0,
        "limitApp": "default",
        "maxQueueingTimeMs": 500,
        "resource": "flowDemo02",
        "strategy": 0,
        "warmUpPeriodSec": 10
    },
    {
        "clusterConfig": {
            "fallbackToLocalWhenFail": true,
            "sampleCount": 10,
            "strategy": 0,
            "thresholdType": 0,
            "windowIntervalMs": 1000
        },
        "clusterMode": false,
        "controlBehavior": 0,
        "count": 5000,
        "grade": 1,
        "limitApp": "default",
        "maxQueueingTimeMs": 500,
        "resource": "flowDemo01",
        "strategy": 0,
        "warmUpPeriodSec": 10
    },
    {
        "clusterConfig": {
            "fallbackToLocalWhenFail": true,
            "sampleCount": 10,
            "strategy": 0,
            "thresholdType": 0,
            "windowIntervalMs": 1000
        },
        "clusterMode": false,
        "controlBehavior": 2,
        "count": 3300,
        "grade": 1,
        "limitApp": "default",
        "maxQueueingTimeMs": 100,
        "resource": "flowDemo07",
        "strategy": 0,
        "warmUpPeriodSec": 10
    }
]

作者丨梁勇
来源丨瓜农老梁
欢迎关注公众号「瓜农老梁」


「瓜农老梁  学习同行」    

       

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值