diff --git a/Gopkg.lock b/Gopkg.lock index e2147da..f6cf32b 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -39,17 +39,8 @@ [[projects]] name = "github.com/xiaojiaoyu100/cast" packages = ["."] - revision = "9b2d9b934d63eb190975fdf9bc603d16b1ae7a5b" - version = "v1.2.3" - -[[projects]] - branch = "master" - name = "go.uber.org/ratelimit" - packages = [ - ".", - "internal/clock" - ] - revision = "c15da02342779cb6dc027fc95ee2277787698f36" + revision = "c03cdc3473d98a516a0b9da5e4467dfed305c25e" + version = "v1.2.4" [[projects]] branch = "master" @@ -74,6 +65,6 @@ [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "9f2ec9dc9563691987ba4e214df33faf2b923c4a90bbb945ff2ecb6e8cfd141e" + inputs-digest = "3d5e1c94928e8ef986c981e4aba3df17191e4b1ea06c2cdbe9e546e2cf9cdebe" solver-name = "gps-cdcl" solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml index 12421a0..e612b10 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -27,7 +27,7 @@ [[constraint]] name = "github.com/xiaojiaoyu100/cast" - version = "v1.2.3" + version = "v1.2.4" [prune] unused-packages = true diff --git a/diamond.go b/diamond.go index 6d137fd..10b8dab 100644 --- a/diamond.go +++ b/diamond.go @@ -4,8 +4,6 @@ import ( "math/rand" "time" - "go.uber.org/ratelimit" - "github.com/sirupsen/logrus" "github.com/xiaojiaoyu100/cast" @@ -67,8 +65,6 @@ type Diamond struct { units []Unit errHook Hook r *rand.Rand - longPullRate int - longPullRateLimiter ratelimit.Limiter } // New 产生Diamond实例 @@ -98,7 +94,6 @@ func New(addr, tenant, accessKey, secretKey string, setters ...Setter) (*Diamond option: option, c: c, r: r, - longPullRate: 6, } for _, setter := range setters { @@ -107,11 +102,13 @@ func New(addr, tenant, accessKey, secretKey string, setters ...Setter) (*Diamond } } - d.longPullRateLimiter = ratelimit.New(d.longPullRate) - return d, nil } +func randomIntInRange(min, max int) int { + return rand.Intn(max-min) + min +} + // Add 添加想要关心的配置单元 func (d *Diamond) Add(unit Unit) { unit.ch = make(chan Config) @@ -131,7 +128,7 @@ func (d *Diamond) Add(unit Unit) { if newContentMD5 != "" { contentMD5 = newContentMD5 } - time.Sleep(time.Second) + time.Sleep(time.Duration(randomIntInRange(20, 100)) * time.Millisecond) } }() diff --git a/long_pull.go b/long_pull.go index f756451..1c21dbb 100644 --- a/long_pull.go +++ b/long_pull.go @@ -14,7 +14,6 @@ const ( // LongPull 监听配置 func (d *Diamond) LongPull(unit Unit, contentMD5 string) (string, error) { - d.longPullRateLimiter.Take() ip, err := d.QueryIP() if err != nil { return "", err diff --git a/setter.go b/setter.go index d4a076b..822ad22 100644 --- a/setter.go +++ b/setter.go @@ -3,10 +3,4 @@ package aliacm // Setter configures the diamond. type Setter func(d *Diamond) error -// WithLongPullRate sets long pull rate. -func WithLongPullRate(rate int) Setter { - return func(d *Diamond) error { - d.longPullRate = rate - return nil - } -} +