Skip to content

Commit

Permalink
Documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobht committed Nov 21, 2023
1 parent cab0845 commit e263e83
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions common/quotas/dynamicratelimiterfactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@ package quotas

import "github.com/uber/cadence/common/dynamicconfig"

// LimiterFactory is used to create a Limiter for a given domain
type LimiterFactory interface {
// GetLimiter returns a new Limiter for the given domain
GetLimiter(domain string) Limiter
}

// NewSimpleDynamicRateLimiterFactory creates a new LimiterFactory which creates
// a new DynamicRateLimiter for each domain, the RPS for the DynamicRateLimiter is given by the dynamic config
func NewSimpleDynamicRateLimiterFactory(rps dynamicconfig.IntPropertyFnWithDomainFilter) LimiterFactory {
return dynamicRateLimiterFactory{
rps: rps,
Expand All @@ -38,6 +42,7 @@ type dynamicRateLimiterFactory struct {
rps dynamicconfig.IntPropertyFnWithDomainFilter
}

// GetLimiter returns a new Limiter for the given domain
func (f dynamicRateLimiterFactory) GetLimiter(domain string) Limiter {
return NewDynamicRateLimiter(func() float64 { return float64(f.rps(domain)) })
}
4 changes: 4 additions & 0 deletions common/quotas/fallbackdynamicratelimiterfactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ package quotas

import "github.com/uber/cadence/common/dynamicconfig"

// LimiterFactory is used to create a Limiter for a given domain
// the created Limiter will use the primary dynamic config if it is set
// otherwise it will use the secondary dynamic config
func NewFallbackDynamicRateLimiterFactory(
primary dynamicconfig.IntPropertyFnWithDomainFilter,
secondary dynamicconfig.IntPropertyFn,
Expand All @@ -40,6 +43,7 @@ type fallbackDynamicRateLimiterFactory struct {
secondary dynamicconfig.IntPropertyFn
}

// GetLimiter returns a new Limiter for the given domain
func (f fallbackDynamicRateLimiterFactory) GetLimiter(domain string) Limiter {
return NewDynamicRateLimiter(func() float64 {
return limitWithFallback(
Expand Down
4 changes: 4 additions & 0 deletions common/quotas/permember.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ func PerMember(service string, globalRPS, instanceRPS float64, resolver membersh
return math.Min(avgQuota, instanceRPS)
}

// NewPerMemberDynamicRateLimiterFactory creates a new LimiterFactory which creates
// a new DynamicRateLimiter for each domain, the RPS for the DynamicRateLimiter is given
// by the globalRPS and averaged by member count for a given service.
// instanceRPS is used as a fallback if globalRPS is not provided.
func NewPerMemberDynamicRateLimiterFactory(
service string,
globalRPS dynamicconfig.IntPropertyFnWithDomainFilter,
Expand Down

0 comments on commit e263e83

Please sign in to comment.