Rework plugin tickers to prevent drift and spread write ticks (#7390)

This commit is contained in:
Daniel Nelson
2020-05-06 11:59:16 -07:00
committed by GitHub
parent c8dbf13fc1
commit fd76c8bf21
7 changed files with 530 additions and 104 deletions

View File

@@ -5,12 +5,11 @@ import (
"bytes"
"compress/gzip"
"context"
"crypto/rand"
"errors"
"fmt"
"io"
"math"
"math/big"
"math/rand"
"os"
"os/exec"
"runtime"
@@ -211,12 +210,8 @@ func RandomSleep(max time.Duration, shutdown chan struct{}) {
if max == 0 {
return
}
maxSleep := big.NewInt(max.Nanoseconds())
var sleepns int64
if j, err := rand.Int(rand.Reader, maxSleep); err == nil {
sleepns = j.Int64()
}
sleepns := rand.Int63n(max.Nanoseconds())
t := time.NewTimer(time.Nanosecond * time.Duration(sleepns))
select {
@@ -234,11 +229,7 @@ func RandomDuration(max time.Duration) time.Duration {
return 0
}
var sleepns int64
maxSleep := big.NewInt(max.Nanoseconds())
if j, err := rand.Int(rand.Reader, maxSleep); err == nil {
sleepns = j.Int64()
}
sleepns := rand.Int63n(max.Nanoseconds())
return time.Duration(sleepns)
}