diff --git a/common/quotas/dynamicratelimiterfactory.go b/common/quotas/dynamicratelimiterfactory.go index 9d4812f3309..4cee698c13e 100644 --- a/common/quotas/dynamicratelimiterfactory.go +++ b/common/quotas/dynamicratelimiterfactory.go @@ -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, @@ -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)) }) } diff --git a/common/quotas/fallbackdynamicratelimiterfactory.go b/common/quotas/fallbackdynamicratelimiterfactory.go index 37ffa01efe4..21d6831f043 100644 --- a/common/quotas/fallbackdynamicratelimiterfactory.go +++ b/common/quotas/fallbackdynamicratelimiterfactory.go @@ -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, @@ -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( diff --git a/common/quotas/permember.go b/common/quotas/permember.go index ee21925d7ca..023bd2a8dca 100644 --- a/common/quotas/permember.go +++ b/common/quotas/permember.go @@ -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,