Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make ScribeCollector reconnect on write errors
- Loading branch information
Peter Teichman
committed
Nov 7, 2014
1 parent
cadb120
commit c18860c
Showing
3 changed files
with
141 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
Space Monkey, Inc. | ||
Peter Teichman <peter@teichman.org> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package trace | ||
|
||
import "time" | ||
|
||
// backoff implements a backoff policy, randomizing its delays and | ||
// saturating at its last value. | ||
type backoff struct { | ||
millis []int | ||
} | ||
|
||
// defaultBackoff is a backoff policy ranging up to 5s. | ||
var defaultBackoff = backoff{ | ||
[]int{0, 10, 10, 100, 100, 500, 500, 3000, 3000, 5000}, | ||
} | ||
|
||
// duration returns the time duration of the n'th wait cycle in its | ||
// backoff policy. This is backoff.millis[n], randomized to avoid | ||
// thundering herds. | ||
func (b backoff) duration(n int) time.Duration { | ||
if n >= len(b.millis) { | ||
n = len(b.millis) - 1 | ||
} | ||
|
||
return time.Duration(fudge(b.millis[n])) * time.Millisecond | ||
} | ||
|
||
// fudge returns a random integer uniformly distributed in the range | ||
// [0.5 * millis .. 1.5 * millis] | ||
func fudge(millis int) int { | ||
if millis == 0 { | ||
return 0 | ||
} | ||
|
||
return millis/2 + Rng.Intn(millis) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters