sentinel-golang
sentinel-golang copied to clipboard
General Design for Metrics(memory、cpu...) adaptive flow control
Issue Description
Type: feature request
Describe what feature you want
Additional context
refer to #348 Add any other context or screenshots about the feature request here.
自适应模块抽象方案
1.新建 adaptive 模块,可以做一些 ratio 相关的 adjustment.
type AdaptiveConfig struct {
//用户自定义名称
AdaptiveConfigName string
//自适应类型,cpu、mem...
AdaptiveType AdaptiveType
//相应自适应类型所需要的参数
LowRatio float64
HighRatio float64
LowWaterMark float64
HighWaterMark float64
}
// 根据用户配置生成的 AdaptiveController
type AdaptiveController interface {
//根据用户配置的系统自适应规则来做adjustment
CalculateSystemAdaptiveCount(count float64) float64
}
var adaptiveControllerMap map[string]*AdaptiveController
//获取指定的 AdaptiveController
func GetAdaptiveController(adaptiveName string) *AdaptiveController {
}
//加载自适应配置
func LoadAdaptiveConfig(configs []*AdaptiveConfig) (bool, error){
}
- flow模块修改
//添加字段 AdaptiveConfigName,用于指定配置的自适应规则
type Rule struct {
...
AdaptiveConfigName string
...
}
//修改 DirectTrafficShapingCalculator 如下, 目前自适应仅支持 Direct 的 Token 计算策略
func (d *DirectTrafficShapingCalculator) CalculateAllowedTokens(uint32, int32) float64 {
if d.owner.rule.AdaptiveConfigName != ""{
ac := adaptive.GetAdaptiveController(d.owner.rule.AdaptiveConfigName)
if ac != nil {
return ac.CalculateSystemAdaptiveCount(d.threshold)
}
}
return d.threshold
}
It's basically OK to me