ratelimiter

package
v2.0.0-alpha4+incompat... Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 7, 2015 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Overview

Package ratelimiter implements rate limiting functionality.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RateLimiter

type RateLimiter struct {
	// contains filtered or unexported fields
}

RateLimiter was inspired by https://github.com/golang/go/wiki/RateLimiting. However, the go example is not good for setting high qps limits because it will cause the ticker to fire too often. Also, the ticker will continue to fire when the system is idle. This new Ratelimiter achieves the same thing, but by using just counters with no tickers or channels.

func NewRateLimiter

func NewRateLimiter(maxCount int, interval time.Duration) *RateLimiter

NewRateLimiter creates a new RateLimiter. maxCount is the max burst allowed while interval specifies the duration for a burst. The effective rate limit is equal to maxCount/interval. For example, if you want to a max QPS of 5000, and want to limit bursts to no more than 500, you'd specify a maxCount of 500 and an interval of 100*time.Millilsecond.

func (*RateLimiter) Allow

func (rl *RateLimiter) Allow() bool

Allow returns true if a request is within the rate limit norms. Otherwise, it returns false.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL