mirror of https://github.com/status-im/consul.git
Adding AEConfig and some methods to scale timing
This commit is contained in:
parent
54359b9ad6
commit
46e3075344
|
@ -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.",
|
||||
|
|
|
@ -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
|
||||
}
|
|
@ -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)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue