Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

increase and simplify backoff #827

Merged
merged 1 commit into from
Feb 10, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions profiler/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"errors"
"fmt"
"io"
"math"
"math/rand"
"mime/multipart"
"net/http"
Expand All @@ -25,18 +24,6 @@ const maxRetries = 2
var errOldAgent = errors.New("Datadog Agent is not accepting profiles. Agent-based profiling deployments " +
"require Datadog Agent >= 7.20")

// backoffDuration calculates the backoff duration given an attempt number and max duration
func backoffDuration(attempt int, max time.Duration) time.Duration {
// https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/
if attempt == 0 {
return 0
}
maxPow := float64(max / 100 * time.Millisecond)
pow := math.Min(math.Pow(2, float64(attempt)), maxPow)
ns := int64(float64(100*time.Millisecond) * pow)
return time.Duration(rand.Int63n(ns))
}

// upload tries to upload a batch of profiles. It has retry and backoff mechanisms.
func (p *profiler) upload(bat batch) error {
statsd := p.cfg.statsd
Expand All @@ -45,7 +32,7 @@ func (p *profiler) upload(bat batch) error {
err = p.doRequest(bat)
if rerr, ok := err.(*retriableError); ok {
statsd.Count("datadog.profiler.go.upload_retry", 1, nil, 1)
wait := backoffDuration(i+1, p.cfg.cpuDuration)
wait := time.Duration(rand.Int63n(p.cfg.period.Nanoseconds()))
log.Error("Uploading profile failed: %v. Trying again in %s...", rerr, wait)
time.Sleep(wait)
continue
Expand Down