File tree 3 files changed +14
-11
lines changed
3 files changed +14
-11
lines changed Original file line number Diff line number Diff line change @@ -263,14 +263,16 @@ func (f *FlowQuotaAssistant) GetQuota(commonRequest *data.CommonRateLimitRequest
263
263
if quotaResult == nil {
264
264
continue
265
265
}
266
- for i := range quotaResult .ReleaseFuncs {
267
- releaseFuncs = append (releaseFuncs , quotaResult .ReleaseFuncs [i ])
266
+ for _ , releaseFunc := range quotaResult .ReleaseFuncs {
267
+ if releaseFunc != nil {
268
+ releaseFuncs = append (releaseFuncs , releaseFunc )
269
+ }
268
270
}
269
271
// 触发限流,提前返回
270
272
if quotaResult .Code == model .QuotaResultLimited {
271
273
// 先释放资源
272
274
for i := range releaseFuncs {
273
- releaseFuncs [i ](0 )
275
+ releaseFuncs [i ]()
274
276
}
275
277
return model .QuotaFutureWithResponse (quotaResult ), nil
276
278
}
Original file line number Diff line number Diff line change 1
1
package core
2
2
3
3
import (
4
+ "github.com/polarismesh/polaris-go/pkg/log"
4
5
"github.com/polarismesh/polaris-go/plugin/ratelimiter/bbr/cpu"
5
6
"github.com/polarismesh/polaris-go/plugin/ratelimiter/bbr/window"
6
7
"math"
@@ -21,18 +22,16 @@ type (
21
22
Option func (* options )
22
23
)
23
24
24
- func init () {
25
- go collectCPUStat ()
26
- }
27
-
28
- // collectCPUStat 定期采集并更新 CPU 使用率等指标
25
+ // CollectCPUStat 定期采集并更新 CPU 使用率等指标
29
26
// cpu = cpuᵗ⁻¹ * decay + cpuᵗ * (1 - decay)
30
- func collectCPUStat () {
27
+ func CollectCPUStat () {
31
28
ticker := time .NewTicker (time .Millisecond * 500 ) // same to cpu sample rate
32
29
defer func () {
33
30
ticker .Stop ()
34
- if err := recover (); err != nil {
35
- go collectCPUStat ()
31
+ if r := recover (); r != nil {
32
+ buf := make ([]byte , 1 << 18 )
33
+ n := runtime .Stack (buf , false )
34
+ log .GetBaseLogger ().Errorf ("bbr limiter panic recovered: %v.\n runtime stack: %s" , r , buf [0 :n ])
36
35
}
37
36
}()
38
37
Original file line number Diff line number Diff line change 6
6
"github.com/polarismesh/polaris-go/pkg/plugin"
7
7
"github.com/polarismesh/polaris-go/pkg/plugin/common"
8
8
"github.com/polarismesh/polaris-go/pkg/plugin/ratelimiter"
9
+ "github.com/polarismesh/polaris-go/plugin/ratelimiter/bbr/core"
9
10
)
10
11
11
12
// BBRPlugin 基于 CPU BBR 策略的限流控制器
@@ -26,6 +27,7 @@ func (g *BBRPlugin) Name() string {
26
27
// Init 初始化插件
27
28
func (g * BBRPlugin ) Init (ctx * plugin.InitContext ) error {
28
29
g .PluginBase = plugin .NewPluginBase (ctx )
30
+ go core .CollectCPUStat ()
29
31
return nil
30
32
}
31
33
You can’t perform that action at this time.
0 commit comments