File tree 3 files changed +9
-3
lines changed
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
256
256
return model .QuotaFutureWithResponse (resp ), nil
257
257
}
258
258
var maxWaitMs int64 = 0
259
+ // releaseFuncs release 方法列表。如果有多个 window,用这个列表收集所有 window 的 release 方法
259
260
var releaseFuncs = make ([]model.ReleaseFunc , 0 , len (windows ))
260
261
for _ , window := range windows {
261
262
window .Init ()
262
263
quotaResult := window .AllocateQuota (commonRequest )
263
264
if quotaResult == nil {
264
265
continue
265
266
}
267
+ // 收集所有 window 的 release 方法
266
268
for _ , releaseFunc := range quotaResult .ReleaseFuncs {
267
269
if releaseFunc != nil {
268
270
releaseFuncs = append (releaseFuncs , releaseFunc )
Original file line number Diff line number Diff line change @@ -21,16 +21,15 @@ type CPU interface {
21
21
Info () Info
22
22
}
23
23
24
- func init () {
24
+ func Init () error {
25
25
var (
26
26
err error
27
27
)
28
28
stats , err = newCgroupCPU ()
29
29
if err != nil {
30
- // fmt.Printf("cgroup cpu init failed(%v),switch to psutil cpu\n", err)
31
30
stats , err = newPsutilCPU (interval )
32
31
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 ( ))
34
33
}
35
34
}
36
35
go func () {
@@ -44,6 +43,7 @@ func init() {
44
43
}
45
44
}
46
45
}()
46
+ return nil
47
47
}
48
48
49
49
// Stat cpu stat.
Original file line number Diff line number Diff line change 7
7
"github.com/polarismesh/polaris-go/pkg/plugin/common"
8
8
"github.com/polarismesh/polaris-go/pkg/plugin/ratelimiter"
9
9
"github.com/polarismesh/polaris-go/plugin/ratelimiter/bbr/core"
10
+ "github.com/polarismesh/polaris-go/plugin/ratelimiter/bbr/cpu"
10
11
)
11
12
12
13
// BBRPlugin 基于 CPU BBR 策略的限流控制器
@@ -27,6 +28,9 @@ func (g *BBRPlugin) Name() string {
27
28
// Init 初始化插件
28
29
func (g * BBRPlugin ) Init (ctx * plugin.InitContext ) error {
29
30
g .PluginBase = plugin .NewPluginBase (ctx )
31
+ if err := cpu .Init (); err != nil {
32
+ return err
33
+ }
30
34
go core .CollectCPUStat ()
31
35
return nil
32
36
}
You can’t perform that action at this time.
0 commit comments