qpslimiter

package
v0.0.0-...-5dc8409 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2018 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultRate = 2147483647
)

constant qps default rate

Variables

This section is empty.

Functions

func GetQPSRate

func GetQPSRate(rateConfig string) (int, bool)

GetQPSRate get qps rate

func GetSpecificKey

func GetSpecificKey(sourceName, serviceType, serviceName, schemaID, OperationID string) string

GetSpecificKey get specific key

Types

type Clock

type Clock interface {
	Now() time.Time
	Sleep(time.Duration)
}

Clock is the minimum necessary interface to instantiate a rate limiter with a clock or mock clock, compatible with clocks created using github.com/andres-erbsen/clock.

type Limiter

type Limiter interface {
	// Take should block to make sure that the RPS is met.
	Take() time.Time
}

Limiter is used to rate-limit some process, possibly across goroutines. The process is expected to call Take() before every iteration, which may block to throttle the goroutine.

func New

func New(rate int, opts ...Option) Limiter

New returns a Limiter that will limit to the given RPS.

type OperationMeta

type OperationMeta struct {
	MicroServiceName       string
	SchemaQualifiedName    string
	OperationQualifiedName string
}

OperationMeta operation meta struct

func InitSchemaOperations

func InitSchemaOperations(i *invocation.Invocation) *OperationMeta

InitSchemaOperations initialize schema operations

func (*OperationMeta) GetMicroServiceName

func (op *OperationMeta) GetMicroServiceName() string

GetMicroServiceName get micro-service name

func (*OperationMeta) GetMicroServiceSchemaOpQualifiedName

func (op *OperationMeta) GetMicroServiceSchemaOpQualifiedName() string

GetMicroServiceSchemaOpQualifiedName get micro-service schema operation qualified name

func (*OperationMeta) GetSchemaQualifiedName

func (op *OperationMeta) GetSchemaQualifiedName() string

GetSchemaQualifiedName get schema qualified name

type Option

type Option func(l *limiter)

Option configures a Limiter.

var WithoutSlack Option = withoutSlackOption

WithoutSlack is an option for ratelimit.New that initializes the limiter without any initial tolerance for bursts of traffic.

func WithClock

func WithClock(clock Clock) Option

WithClock returns an option for ratelimit.New that provides an alternate Clock implementation, typically a mock Clock for testing.

type QPSLimiterMap

type QPSLimiterMap struct {
	KeyMap map[string]Limiter
	sync.RWMutex
}

QPSLimiterMap qps limiter map struct

func GetQPSTrafficLimiter

func GetQPSTrafficLimiter() *QPSLimiterMap

GetQPSTrafficLimiter get qps traffic limiter

func (*QPSLimiterMap) DeleteRateLimiter

func (qpsL *QPSLimiterMap) DeleteRateLimiter(key string)

DeleteRateLimiter delete rate limiter

func (*QPSLimiterMap) GetQPSRateWithPriority

func (qpsL *QPSLimiterMap) GetQPSRateWithPriority(op *OperationMeta) (int, string)

GetQPSRateWithPriority get qps rate with priority

func (*QPSLimiterMap) ProcessDefaultRateRpsTokenReq

func (qpsL *QPSLimiterMap) ProcessDefaultRateRpsTokenReq(key string, qpsRate int)

ProcessDefaultRateRpsTokenReq process default rate pps token request

func (*QPSLimiterMap) ProcessQPSTokenReq

func (qpsL *QPSLimiterMap) ProcessQPSTokenReq(key string, qpsRate int)

ProcessQPSTokenReq process qps token request

func (*QPSLimiterMap) UpdateRateLimit

func (qpsL *QPSLimiterMap) UpdateRateLimit(key string, value interface{})

UpdateRateLimit update rate limit

Jump to

Keyboard shortcuts

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