Add a random delay to avoid synchronized registration at swarm join.

Signed-off-by: Dong Chen <dongluo.chen@docker.com>
This commit is contained in:
Dong Chen 2015-11-12 16:17:29 -08:00
parent 9dc6ce8d0f
commit 36ca8ff63f
1 changed files with 7 additions and 0 deletions

View File

@ -1,6 +1,7 @@
package cli
import (
"math/rand"
"regexp"
"time"
@ -48,6 +49,12 @@ func join(c *cli.Context) {
log.Fatal(err)
}
// add a random delay [0,hb) at start to avoid synchronized registration
r := rand.New(rand.NewSource(time.Now().UTC().UnixNano()))
delay := time.Duration(r.Int63n(int64(hb)))
log.Infof("Add a random delay %s to avoid synchronized registration", delay)
time.Sleep(delay)
for {
log.WithFields(log.Fields{"addr": addr, "discovery": dflag}).Infof("Registering on the discovery service every %s...", hb)
if err := d.Register(addr); err != nil {