Skip to content

Instantly share code, notes, and snippets.

@tkm-kj
Last active October 13, 2020 09:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tkm-kj/bcae9ec36018f37c53b85f1cc96a925f to your computer and use it in GitHub Desktop.
Save tkm-kj/bcae9ec36018f37c53b85f1cc96a925f to your computer and use it in GitHub Desktop.
時間に応じて特定の数を大きくする(ゆっくり負荷をかけていきたい時に便利)
package main
import (
"log"
"time"
)
func main() {
startTime := time.Now()
var batchNum int64 = 10
duration := 5
multipleNum := 1.5
currentPon := 0
for {
now := time.Now()
diff := int(now.Sub(startTime).Seconds())
if diff >= 60 {
break
}
mod := diff % duration
log.Printf("mod: %d", mod)
if mod == 0 {
pon := diff / duration
if pon > currentPon { // 同じ秒数で mod が0の時は何度も通る可能性があるので1回だけしか通らないようにして batchNum が上がりすぎないようにする
currentPon = pon
log.Printf("currentPon: %d", currentPon)
batchNum = int64(float64(batchNum) * multipleNum)
}
}
log.Printf("batchNum: %d", batchNum)
time.Sleep(time.Millisecond * 200)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment