Documentation ¶
Index ¶
Constants ¶
const ( // KeepAlivePeriod is period checking if endpoint is alive. KeepAlivePeriod = 33 // DEFAULTUPDATEPERIOD is the default period(seconds) to update rate. DEFAULTUPDATEPERIOD = 1.0 // RateLimiterTimeout is timer waiting for a rate limiter token. RateLimiterTimeout = 10 // APIWaitMinThreshold is threshold(second) which will trigger rate limiter adjust. APIWaitMinThreshold = float64(0.01) // MAXRATELIMIT means max rate for rate limiter. MAXRATELIMIT = 100 )
Variables ¶
var (
APIReduceRateCodes = [2]int{429, 503}
)
APIReduceRateCodes is http status code set which will trigger rate limiter adjust.
Functions ¶
This section is empty.
Types ¶
type AIMDRateLimter ¶
AIMDRateLimter is rate limiter which could adjuct its' rate depending on wait time and http status code.
func (*AIMDRateLimter) AdjustRate ¶
func (limiter *AIMDRateLimter) AdjustRate(waitTime time.Duration, statusCode int)
AdjustRate adjust upper limit for rate limiter.
func (*AIMDRateLimter) Wait ¶
func (limiter *AIMDRateLimter) Wait()
Wait blocks the caller until a token is gain.
type FixRateLimiter ¶
type FixRateLimiter struct {
// contains filtered or unexported fields
}
FixRateLimiter is rate limiter which has fix rate.
func (*FixRateLimiter) AdjustRate ¶
func (limiter *FixRateLimiter) AdjustRate(waitTime time.Duration, statusCode int)
AdjustRate adjust upper limit for rate limiter, it's empty for FixRateLimiter.
func (*FixRateLimiter) Wait ¶
func (limiter *FixRateLimiter) Wait()
Wait blocks the caller until a token is gained.
type RateLimiter ¶
type RateLimiter interface { Wait() AdjustRate(time.Duration, int) // contains filtered or unexported methods }
RateLimiter limits the REST API speed.
func NewAIMDRateLimiter ¶
func NewAIMDRateLimiter(max int, period float64) RateLimiter
NewAIMDRateLimiter creates AIMD rate limiter. max ==0 disables rate limiter.
func NewFixRateLimiter ¶
func NewFixRateLimiter(max int) RateLimiter
NewFixRateLimiter creates AIMD rate limiter. max ==0 disables rate limiter.
func NewRateLimiter ¶
func NewRateLimiter(rateLimiterType Type) RateLimiter
NewRateLimiter creates rate limeter based on RateLimiterType