跳到主要内容

flow_control

查看中文版本

Method Level Flow Control

Introduction

There is a config of flow control in runtime_config.json:

[
{
"type": "flowControlFilter",
"config": {
"global_switch": true,
"limit_key_type": "PATH",
"rules": [
{
"resource": "/spec.proto.runtime.v1.Runtime/SayHello",
"grade": 1,
"threshold": 5
}
]
}
}
]

this can help /spec.proto.runtime.v1.Runtime/SayHello method has a flow control feature, which means we can only access this method below 5 times in 1 second.

this code of the client is here client.go,the logic is very simple, send 10 times request to the server,and the result is below:

img.png

the previous 5 times request access is succeed while the last 5 times request is under control.

Configuration Description

config:

field_namefield_typedesc
global_switchbooleanswitch of this feature, true is open, false is close
limit_key_typeStringUnique identifier,Currently a fixed value PATH
rulesArrayrules of flow control

rules of flow control:

field_namefield_typedesc
resourceStringlimit resource identification,here is the method URL
gradeintThreshold update cycle,unit:second
thresholdintbe limited if exceed this threshold