Merge pull request #678 from pingcap/shenli/change-retry-backoff-unit
kv: Change backoff time from Microseconds to Milliseconds
This commit is contained in:
@ -92,7 +92,7 @@ var (
|
||||
// See: http://www.awsarchitectureblog.com/2015/03/backoff.html.
|
||||
func BackOff(attempts int) int {
|
||||
upper := int(math.Min(float64(retryBackOffCap), float64(retryBackOffBase)*math.Pow(2.0, float64(attempts))))
|
||||
sleep := time.Duration(rand.Intn(upper)) * time.Microsecond
|
||||
sleep := time.Duration(rand.Intn(upper)) * time.Millisecond
|
||||
time.Sleep(sleep)
|
||||
return int(sleep)
|
||||
}
|
||||
|
||||
@ -14,6 +14,8 @@
|
||||
package kv
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
. "github.com/pingcap/check"
|
||||
)
|
||||
|
||||
@ -36,5 +38,5 @@ func (s *testTxnSuite) TestBackOff(c *C) {
|
||||
}
|
||||
|
||||
func mustBackOff(c *C, cnt, sleep int) {
|
||||
c.Assert(BackOff(cnt), LessEqual, sleep*1000)
|
||||
c.Assert(BackOff(cnt), LessEqual, sleep*int(time.Millisecond))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user