File tree Expand file tree Collapse file tree 3 files changed +9
-3
lines changed Expand file tree Collapse file tree 3 files changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -256,13 +256,15 @@ func (f *FlowQuotaAssistant) GetQuota(commonRequest *data.CommonRateLimitRequest
256256 return model .QuotaFutureWithResponse (resp ), nil
257257 }
258258 var maxWaitMs int64 = 0
259+ // releaseFuncs release 方法列表。如果有多个 window,用这个列表收集所有 window 的 release 方法
259260 var releaseFuncs = make ([]model.ReleaseFunc , 0 , len (windows ))
260261 for _ , window := range windows {
261262 window .Init ()
262263 quotaResult := window .AllocateQuota (commonRequest )
263264 if quotaResult == nil {
264265 continue
265266 }
267+ // 收集所有 window 的 release 方法
266268 for _ , releaseFunc := range quotaResult .ReleaseFuncs {
267269 if releaseFunc != nil {
268270 releaseFuncs = append (releaseFuncs , releaseFunc )
Original file line number Diff line number Diff line change @@ -21,16 +21,15 @@ type CPU interface {
2121 Info () Info
2222}
2323
24- func init () {
24+ func Init () error {
2525 var (
2626 err error
2727 )
2828 stats , err = newCgroupCPU ()
2929 if err != nil {
30- // fmt.Printf("cgroup cpu init failed(%v),switch to psutil cpu\n", err)
3130 stats , err = newPsutilCPU (interval )
3231 if err != nil {
33- panic ( fmt .Sprintf ("cgroup cpu init failed!err:=%v " , err ))
32+ return fmt .Errorf ("cgroup cpu init failed! err: %s " , err . Error ( ))
3433 }
3534 }
3635 go func () {
@@ -44,6 +43,7 @@ func init() {
4443 }
4544 }
4645 }()
46+ return nil
4747}
4848
4949// Stat cpu stat.
Original file line number Diff line number Diff line change 77 "github.com/polarismesh/polaris-go/pkg/plugin/common"
88 "github.com/polarismesh/polaris-go/pkg/plugin/ratelimiter"
99 "github.com/polarismesh/polaris-go/plugin/ratelimiter/bbr/core"
10+ "github.com/polarismesh/polaris-go/plugin/ratelimiter/bbr/cpu"
1011)
1112
1213// BBRPlugin 基于 CPU BBR 策略的限流控制器
@@ -27,6 +28,9 @@ func (g *BBRPlugin) Name() string {
2728// Init 初始化插件
2829func (g * BBRPlugin ) Init (ctx * plugin.InitContext ) error {
2930 g .PluginBase = plugin .NewPluginBase (ctx )
31+ if err := cpu .Init (); err != nil {
32+ return err
33+ }
3034 go core .CollectCPUStat ()
3135 return nil
3236}
You can’t perform that action at this time.
0 commit comments