示例#1
0
文件: ratio.go 项目: huhoo/vulcand
func newRatioController(tm timetools.TimeProvider, rampUp time.Duration) *ratioController {
	return &ratioController{
		duration: rampUp,
		tm:       tm,
		start:    tm.UtcNow(),
	}
}
示例#2
0
文件: bucket.go 项目: huhoo/vulcand
// newTokenBucket crates a `tokenBucket` instance for the specified `Rate`.
func newTokenBucket(rate *rate, clock timetools.TimeProvider) *tokenBucket {
	return &tokenBucket{
		period:          rate.period,
		timePerToken:    time.Duration(int64(rate.period) / rate.average),
		burst:           rate.burst,
		clock:           clock,
		lastRefresh:     clock.UtcNow(),
		availableTokens: rate.burst,
	}
}