backoff.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. *
  3. * Copyright 2019 gRPC authors.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. // Package backoff provides configuration options for backoff.
  19. //
  20. // More details can be found at:
  21. // https://github.com/grpc/grpc/blob/master/doc/connection-backoff.md.
  22. //
  23. // All APIs in this package are experimental.
  24. package backoff
  25. import "time"
  26. // Config defines the configuration options for backoff.
  27. type Config struct {
  28. // BaseDelay is the amount of time to backoff after the first failure.
  29. BaseDelay time.Duration
  30. // Multiplier is the factor with which to multiply backoffs after a
  31. // failed retry. Should ideally be greater than 1.
  32. Multiplier float64
  33. // Jitter is the factor with which backoffs are randomized.
  34. Jitter float64
  35. // MaxDelay is the upper bound of backoff delay.
  36. MaxDelay time.Duration
  37. }
  38. // DefaultConfig is a backoff configuration with the default values specfied
  39. // at https://github.com/grpc/grpc/blob/master/doc/connection-backoff.md.
  40. //
  41. // This should be useful for callers who want to configure backoff with
  42. // non-default values only for a subset of the options.
  43. var DefaultConfig = Config{
  44. BaseDelay: 1.0 * time.Second,
  45. Multiplier: 1.6,
  46. Jitter: 0.2,
  47. MaxDelay: 120 * time.Second,
  48. }