perf: hrp boom run time related code optimization

This commit is contained in:
machongwei
2022-08-18 20:09:46 +08:00
parent e98c908c6d
commit 1306a12dff

View File

@@ -240,17 +240,11 @@ func (r *runner) getSpawnRate() float64 {
} }
func (r *runner) setRunTime(runTime int64) { func (r *runner) setRunTime(runTime int64) {
r.mutex.Lock() atomic.StoreInt64(&r.runTime, time.Now().Unix()+runTime)
defer r.mutex.Unlock()
if runTime > 0 {
r.runTime = time.Now().Unix() + runTime
}
} }
func (r *runner) getRunTime() int64 { func (r *runner) getRunTime() int64 {
r.mutex.RLock() return atomic.LoadInt64(&r.runTime)
defer r.mutex.RUnlock()
return r.runTime
} }
func (r *runner) getSpawnCount() int64 { func (r *runner) getSpawnCount() int64 {
@@ -384,11 +378,17 @@ func (r *runner) runTimeCheck(runTime int64) {
return return
} }
for range time.Tick(time.Second * 3) { var ticker = time.NewTicker(time.Second * 3)
nowTime := time.Now().Unix() for {
if nowTime > runTime { select {
r.stop() case <-r.stopChan:
return return
case <-ticker.C:
nowTime := time.Now().Unix()
if nowTime > runTime {
r.stop()
return
}
} }
} }
} }