min/max pacing (latency between requests) (#40)

This commit is contained in:
Michael Quigley 2022-10-12 12:40:17 -04:00
parent f17a1f1446
commit 01f056784a
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62

View File

@ -36,6 +36,8 @@ type loopCmd struct {
timeoutSeconds int
minPayload int
maxPayload int
minPacingMs int
maxPacingMs int
}
func newLoopCmd() *loopCmd {
@ -53,6 +55,8 @@ func newLoopCmd() *loopCmd {
cmd.Flags().IntVarP(&r.timeoutSeconds, "timeout-seconds", "T", 30, "Time out after # seconds when sending http requests")
cmd.Flags().IntVar(&r.minPayload, "min-payload", 64, "Minimum payload size in bytes")
cmd.Flags().IntVar(&r.maxPayload, "max-payload", 10240, "Maximum payload size in bytes")
cmd.Flags().IntVar(&r.minPacingMs, "min-pacing-ms", 0, "Minimum pacing in milliseconds")
cmd.Flags().IntVar(&r.maxPacingMs, "max-pacing-ms", 0, "Maximum pacing in milliseconds")
return r
}
@ -211,6 +215,11 @@ func (l *looper) iterate() {
} else {
logrus.Errorf("looper #%d error creating request: %v", l.id, err)
}
pacingMs := l.cmd.maxPayload
if l.cmd.maxPacingMs-l.cmd.minPacingMs > 0 {
pacingMs = rand.Intn(l.cmd.maxPacingMs-l.cmd.minPacingMs) + l.cmd.minPacingMs
time.Sleep(time.Duration(pacingMs) * time.Millisecond)
}
}
}