func NewThrottle()

in lib/throttle.go [96:123]


func NewThrottle(Capacity int, CacheRate int, MaxRatePerItem int) (*Throttle, error) {
	if MaxRatePerItem <= 0 {
		glog.Info("No throttling will be done")
	}

	cache, err := lru.New(int(Capacity))
	if err != nil {
		return nil, err
	}

	// Keep track of the item creation rate.
	var cacheLimiter *rate.Limiter
	if CacheRate <= 0 {
		glog.Info("No cache rate limiting will be done")
		cacheLimiter = rate.NewLimiter(rate.Inf, 1) // bucket size is ignored
	} else {
		cacheLimiter = rate.NewLimiter(rate.Limit(CacheRate), CacheRate)
	}

	throttle := &Throttle{
		lru:            cache,
		maxRatePerItem: MaxRatePerItem,
		cacheLimiter:   cacheLimiter,
		cacheRate:      CacheRate,
	}

	return throttle, nil
}