2014-01-15 22:17:40 +00:00
|
|
|
package agent
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math"
|
2014-01-15 22:34:17 +00:00
|
|
|
"math/rand"
|
2014-01-15 22:17:40 +00:00
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
// This scale factor means we will add a minute after we
|
|
|
|
// cross 128 nodes, another at 256, another at 512, etc.
|
|
|
|
// By 8192 nodes, we will scale up by a factor of 8
|
|
|
|
aeScaleThreshold = 128
|
|
|
|
)
|
|
|
|
|
|
|
|
// aeScale is used to scale the time interval at which anti-entropy
|
|
|
|
// take place. It is used to prevent saturation as the cluster size grows
|
|
|
|
func aeScale(interval time.Duration, n int) time.Duration {
|
|
|
|
// Don't scale until we cross the threshold
|
|
|
|
if n <= aeScaleThreshold {
|
|
|
|
return interval
|
|
|
|
}
|
|
|
|
|
|
|
|
multiplier := math.Ceil(math.Log2(float64(n))-math.Log2(aeScaleThreshold)) + 1.0
|
|
|
|
return time.Duration(multiplier) * interval
|
|
|
|
}
|
2014-01-15 22:34:17 +00:00
|
|
|
|
|
|
|
// Returns a random stagger interval between 0 and the duration
|
|
|
|
func randomStagger(intv time.Duration) time.Duration {
|
|
|
|
return time.Duration(uint64(rand.Int63()) % uint64(intv))
|
|
|
|
}
|