Skip to content

Commit

Permalink
logging and fix logic
Browse files Browse the repository at this point in the history
Signed-off-by: Chengxuan Xing <[email protected]>
  • Loading branch information
Chengxuan committed Jun 13, 2024
1 parent 1a1cdaa commit a980fb8
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions internal/perf/perf.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,25 +539,29 @@ func (pr *perfRunner) Start() (err error) {
i := 0
lastCheckedTime := time.Now()

rateLimiter := rate.NewLimiter(rate.Limit(math.MaxFloat64), math.MaxInt)

if pr.cfg.MaxSubmissionsPerSecond > 0 {
rateLimiter = rate.NewLimiter(rate.Limit(pr.cfg.MaxSubmissionsPerSecond), pr.cfg.MaxSubmissionsPerSecond)
}
log.Infof("Sending rate: %f per second with %d burst", rateLimiter.Limit(), rateLimiter.Burst())
perfLoop:
for pr.daemon || time.Now().Unix() < pr.endTime {
timeout := time.After(60 * time.Second)

// If we've been given a maximum number of actions to perform, check if we're done
if pr.cfg.MaxActions > 0 && int64(getMetricVal(totalActionsCounter)) >= pr.cfg.MaxActions {
break perfLoop
}
rateLimiter := rate.NewLimiter(rate.Limit(math.MaxFloat64), math.MaxInt)

if pr.cfg.MaxSubmissionsPerSecond > 0 {
rateLimiter = rate.NewLimiter(rate.Limit(pr.cfg.MaxSubmissionsPerSecond), pr.cfg.MaxSubmissionsPerSecond)
}

select {
case <-signalCh:
break perfLoop
case pr.bfr <- i:
rateLimiter.Wait(pr.ctx)
err = rateLimiter.Wait(pr.ctx)
if err != nil {
log.Panic(fmt.Errorf("rate limiter failed"))
break perfLoop
}
i++
if time.Since(lastCheckedTime).Seconds() > pr.cfg.MaxTimePerAction.Seconds() {
if pr.detectDelinquentMsgs() && pr.cfg.DelinquentAction == conf.DelinquentActionExit.String() {
Expand Down

0 comments on commit a980fb8

Please sign in to comment.