File tree Expand file tree Collapse file tree 3 files changed +14
-11
lines changed Expand file tree Collapse file tree 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
263263 if quotaResult == nil {
264264 continue
265265 }
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+ }
268270 }
269271 // 触发限流,提前返回
270272 if quotaResult .Code == model .QuotaResultLimited {
271273 // 先释放资源
272274 for i := range releaseFuncs {
273- releaseFuncs [i ](0 )
275+ releaseFuncs [i ]()
274276 }
275277 return model .QuotaFutureWithResponse (quotaResult ), nil
276278 }
Original file line number Diff line number Diff line change 11package core
22
33import (
4+ "github.com/polarismesh/polaris-go/pkg/log"
45 "github.com/polarismesh/polaris-go/plugin/ratelimiter/bbr/cpu"
56 "github.com/polarismesh/polaris-go/plugin/ratelimiter/bbr/window"
67 "math"
@@ -21,18 +22,16 @@ type (
2122 Option func (* options )
2223)
2324
24- func init () {
25- go collectCPUStat ()
26- }
27-
28- // collectCPUStat 定期采集并更新 CPU 使用率等指标
25+ // CollectCPUStat 定期采集并更新 CPU 使用率等指标
2926// cpu = cpuᵗ⁻¹ * decay + cpuᵗ * (1 - decay)
30- func collectCPUStat () {
27+ func CollectCPUStat () {
3128 ticker := time .NewTicker (time .Millisecond * 500 ) // same to cpu sample rate
3229 defer func () {
3330 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 ])
3635 }
3736 }()
3837
Original file line number Diff line number Diff line change 66 "github.com/polarismesh/polaris-go/pkg/plugin"
77 "github.com/polarismesh/polaris-go/pkg/plugin/common"
88 "github.com/polarismesh/polaris-go/pkg/plugin/ratelimiter"
9+ "github.com/polarismesh/polaris-go/plugin/ratelimiter/bbr/core"
910)
1011
1112// BBRPlugin 基于 CPU BBR 策略的限流控制器
@@ -26,6 +27,7 @@ func (g *BBRPlugin) Name() string {
2627// Init 初始化插件
2728func (g * BBRPlugin ) Init (ctx * plugin.InitContext ) error {
2829 g .PluginBase = plugin .NewPluginBase (ctx )
30+ go core .CollectCPUStat ()
2931 return nil
3032}
3133
You can’t perform that action at this time.
0 commit comments