Skip to content

Commit

Permalink
ci test
Browse files Browse the repository at this point in the history
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
  • Loading branch information
CabinfeverB committed Oct 26, 2023
1 parent e300b85 commit 59d9e23
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
22 changes: 11 additions & 11 deletions pkg/ratelimit/bbr.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,10 @@ package ratelimit

import (
"math"
"sort"
"sync/atomic"
"time"

"github.com/pingcap/log"
"github.com/tikv/pd/pkg/window"
"go.uber.org/zap"
)

const (
Expand Down Expand Up @@ -162,23 +159,24 @@ func (l *bbr) getMaxPASS() int64 {
}
}
rawMaxPass := int64(l.passStat.Reduce(func(iterator window.Iterator) float64 {
sli := make([]float64, 0, l.cfg.Bucket-1)
var result = 1.0
var result = 0.0
for i := 1; iterator.Next() && i < l.cfg.Bucket; i++ {
bucket := iterator.Bucket()
count := 0.0
for _, p := range bucket.Points {
count += p
}
sli = append(sli, count)
result = math.Max(result, count)
}

sort.Slice(sli, func(i, j int) bool {
return sli[i] > sli[j]
})
return result
}))
// don't save cache when no update, and default is 1.
if rawMaxPass < 1 {
rawMaxPass = 1
}
if rawMaxPass == 1 {
return rawMaxPass
}
l.maxPASSCache.Store(&cache{
val: rawMaxPass,
time: time.Now(),
Expand All @@ -205,12 +203,14 @@ func (l *bbr) getMinRT() int64 {
for _, p := range bucket.Points {
total += p
}
log.Info("getMinRT", zap.Float64("total", total), zap.Int64("bucket.Count", bucket.Count))
avg := total / float64(bucket.Count)
result = math.Min(result, avg)
}
return result
})))
if rawMinRT == int64(time.Minute) {
return rawMinRT
}
if rawMinRT <= 0 {
rawMinRT = 1
}
Expand Down
13 changes: 6 additions & 7 deletions pkg/ratelimit/bbr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ import (
"testing"
"time"

"github.com/pingcap/log"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
)

var (
Expand Down Expand Up @@ -98,10 +96,11 @@ func TestBBRMinRt(t *testing.T) {
}()
time.Sleep(bucketDuration)
wg.Wait()
log.Info("round ================= ", zap.Int("i", i))
// due to extra time cost in `Sleep`.
re.Less(int64(1000), bbr.getMinRT())
re.Greater(int64(1300), bbr.getMinRT())
if i > 0 {
// due to extra time cost in `Sleep`.
re.Less(int64(1000), bbr.getMinRT())
re.Greater(int64(1300), bbr.getMinRT())
}
}

for i := 0; i < 10; i++ {
Expand Down Expand Up @@ -141,7 +140,7 @@ func TestBDP(t *testing.T) {
WithWindow(windowSizeTest),
WithBucket(bucketNumTest),
}
cfg = newConfig(optsForTest...)
cfg := newConfig(optsForTest...)
bucketDuration := windowSizeTest / time.Duration(bucketNumTest)
_, feedback := createConcurrencyFeedback()
bbr := newBBR(cfg, feedback)
Expand Down

0 comments on commit 59d9e23

Please sign in to comment.