Adding AEConfig and some methods to scale timing

This commit is contained in:
Armon Dadgar 2014-01-15 12:17:40 -10:00
parent e3159d0318
commit 177a91c3f9
3 changed files with 54 additions and 0 deletions

View File

@ -11,12 +11,18 @@ import (
"path/filepath"
"sort"
"strings"
"time"
)
// Config is the configuration that can be set for an Agent.
// Some of this is configurable as CLI flags, but most must
// be set using a configuration file.
type Config struct {
// AEInterval controls the anti-entropy interval. This is how often
// the agent attempts to reconcile it's local state with the server'
// representation of our state. Defaults to every 60s.
AEInterval time.Duration
// Bootstrap is used to bring up the first Consul server, and
// permits that node to elect itself leader
Bootstrap bool
@ -96,6 +102,7 @@ type dirEnts []os.FileInfo
// DefaultConfig is used to return a sane default configuration
func DefaultConfig() *Config {
return &Config{
AEInterval: time.Minute,
Datacenter: consul.DefaultDC,
DNSAddr: "127.0.0.1:8600",
Domain: "consul.",

25
command/agent/util.go Normal file
View File

@ -0,0 +1,25 @@
package agent
import (
"math"
"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
}

View File

@ -0,0 +1,22 @@
package agent
import (
"testing"
"time"
)
func TestAEScale(t *testing.T) {
intv := time.Minute
if v := aeScale(intv, 100); v != intv {
t.Fatalf("Bad: %v", v)
}
if v := aeScale(intv, 200); v != 2*intv {
t.Fatalf("Bad: %v", v)
}
if v := aeScale(intv, 1000); v != 4*intv {
t.Fatalf("Bad: %v", v)
}
if v := aeScale(intv, 10000); v != 8*intv {
t.Fatalf("Bad: %v", v)
}
}