Skip to content

Commit

Permalink
fix: 去掉rate limiter
Browse files Browse the repository at this point in the history
  • Loading branch information
zenghur committed Jul 24, 2019
1 parent b20ed16 commit 3355015
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 29 deletions.
15 changes: 3 additions & 12 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

[[constraint]]
name = "github.com/xiaojiaoyu100/cast"
version = "v1.2.3"
version = "v1.2.4"

[prune]
unused-packages = true
13 changes: 5 additions & 8 deletions diamond.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"math/rand"
"time"

"go.uber.org/ratelimit"

"github.com/sirupsen/logrus"

"github.com/xiaojiaoyu100/cast"
Expand Down Expand Up @@ -67,8 +65,6 @@ type Diamond struct {
units []Unit
errHook Hook
r *rand.Rand
longPullRate int
longPullRateLimiter ratelimit.Limiter
}

// New 产生Diamond实例
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand All @@ -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)
}
}()

Expand Down
1 change: 0 additions & 1 deletion long_pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 1 addition & 7 deletions setter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit 3355015

Please sign in to comment.