1
0
mirror of https://github.com/go-micro/go-micro.git synced 2024-12-24 10:07:04 +02:00

exponentialBackoff was changed from power function to exponential function

This commit is contained in:
Evgeniy 2020-01-30 17:25:07 +03:00
parent 21e0932339
commit f6fcfcb8fc
2 changed files with 3 additions and 6 deletions

View File

@ -8,10 +8,7 @@ import (
type BackoffFunc func(ctx context.Context, req Request, attempts int) (time.Duration, error) type BackoffFunc func(ctx context.Context, req Request, attempts int) (time.Duration, error)
// exponential backoff // exponential backoff multiplied by a factor of 0.1 second.
func exponentialBackoff(ctx context.Context, req Request, attempts int) (time.Duration, error) { func exponentialBackoff(ctx context.Context, req Request, attempts int) (time.Duration, error) {
if attempts == 0 { return time.Duration(math.Pow(float64(attempts), math.E)) * time.Millisecond * 100, nil
return time.Duration(0), nil
}
return time.Duration(math.Pow(10, float64(attempts))) * time.Millisecond, nil
} }

View File

@ -22,6 +22,6 @@ func TestBackoff(t *testing.T) {
t.Fatalf("Expected greater than %v, got %v", delta, d) t.Fatalf("Expected greater than %v, got %v", delta, d)
} }
delta = time.Millisecond * time.Duration(math.Pow(10, float64(i+1))) delta = time.Millisecond * 100 * time.Duration(math.Pow(math.E, float64(i)))
} }
} }