### Go Retry Library Benchmarks Source: https://github.com/sethvargo/go-retry/blob/main/README.md Displays benchmark results comparing the `sethvargo/go-retry` library against other popular Go backoff and retry libraries. This highlights its performance efficiency relative to alternatives. ```text Benchmark/cenkalti-7 13,052,668 87.3 ns/op Benchmark/lestrrat-7 902,044 1,355 ns/op Benchmark/sethvargo-7 203,914,245 5.73 ns/op ``` -------------------------------- ### Go Database Connection Retry with Fibonacci Backoff Source: https://github.com/sethvargo/go-retry/blob/main/README.md Demonstrates how to use the `go-retry` library to establish a database connection with retry logic using a Fibonacci backoff strategy. It pings the database contextually and marks connection errors as retryable to ensure robust connectivity. ```golang package main import ( "context" "database/sql" "log" "time" "github.com/sethvargo/go-retry" ) func main() { db, err := sql.Open("mysql", "...") if err != nil { log.Fatal(err) } ctx := context.Background() if err := retry.Fibonacci(ctx, 1*time.Second, func(ctx context.Context) error { if err := db.PingContext(ctx); err != nil { // This marks the error as retryable return retry.RetryableError(err) } return nil }); err != nil { log.Fatal(err) } } ``` -------------------------------- ### Go Constant Backoff Initialization Source: https://github.com/sethvargo/go-retry/blob/main/README.md Initializes a constant backoff strategy where each retry delay is a fixed duration. This is the simplest form of backoff, providing consistent wait times between retries. ```golang NewConstant(1 * time.Second) ``` -------------------------------- ### Go Fibonacci Backoff Initialization Source: https://github.com/sethvargo/go-retry/blob/main/README.md Initializes a Fibonacci backoff strategy, where delays follow the Fibonacci sequence. This provides quick initial retries that gradually slow down, ideal for network-type issues. ```golang NewFibonacci(1 * time.Second) ``` -------------------------------- ### Go Exponential Backoff Initialization Source: https://github.com/sethvargo/go-retry/blob/main/README.md Initializes an exponential backoff strategy where each subsequent retry delay doubles the previous one. This is a common strategy for network retries, allowing for increasing wait times. ```golang NewExponential(1 * time.Second) ``` -------------------------------- ### Go Adding Jitter to Backoff Source: https://github.com/sethvargo/go-retry/blob/main/README.md Applies jitter to a backoff strategy to randomize delays and prevent a 'thundering herd' problem. Demonstrates adding both a fixed amount of jitter and a percentage-based jitter to the calculated backoff duration. ```golang b := NewFibonacci(1 * time.Second) // Return the next value, +/- 500ms b = WithJitter(500*time.Millisecond, b) // Return the next value, +/- 5% of the result b = WithJitterPercent(5, b) ``` -------------------------------- ### Go Capping Individual Backoff Durations Source: https://github.com/sethvargo/go-retry/blob/main/README.md Sets a maximum duration for any single calculated backoff delay. This prevents individual sleep times from growing excessively large, even with exponential or Fibonacci strategies, ensuring reasonable wait times. ```golang b := NewFibonacci(1 * time.Second) // Ensure the maximum value is 2s. In this example, the sleep values would be // 1s, 1s, 2s, 2s, 2s, 2s... b = WithCappedDuration(2 * time.Second, b) ``` -------------------------------- ### Go Limiting Retries with MaxRetries Source: https://github.com/sethvargo/go-retry/blob/main/README.md Limits the total number of retries for a backoff strategy. This ensures the retry loop terminates after a specified number of failed attempts, preventing indefinite retries. ```golang b := NewFibonacci(1 * time.Second) // Stop after 4 retries, when the 5th attempt has failed. In this example, the worst case elapsed // time would be 1s + 1s + 2s + 3s = 7s. b = WithMaxRetries(4, b) ``` -------------------------------- ### Go Limiting Total Backoff Duration Source: https://github.com/sethvargo/go-retry/blob/main/README.md Sets a best-effort maximum for the total elapsed time spent on retries. The retry loop will terminate if the cumulative retry duration exceeds this cap, providing an overall time limit. ```golang b := NewFibonacci(1 * time.Second) // Ensure the maximum total retry time is 5s. b = WithMaxDuration(5 * time.Second, b) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.