Skip to content

Commit daff5f1

Browse files
authored
Add separate dynamic config knobs for internal-frontend rate limiting (#3800)
1 parent d527a19 commit daff5f1

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

common/dynamicconfig/constants.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ const (
165165
FrontendMaxNamespaceRPSPerInstance = "frontend.namespaceRPS"
166166
// FrontendMaxNamespaceBurstPerInstance is workflow namespace burst limit
167167
FrontendMaxNamespaceBurstPerInstance = "frontend.namespaceBurst"
168-
// FrontendMaxNamespaceCountPerInstance is workflow namespace count limit per second
168+
// FrontendMaxNamespaceCountPerInstance limits concurrent task queue polls per namespace per instance
169169
FrontendMaxNamespaceCountPerInstance = "frontend.namespaceCount"
170170
// FrontendMaxNamespaceVisibilityRPSPerInstance is namespace rate limit per second for visibility APIs.
171171
// This config is EXPERIMENTAL and may be changed or removed in a later release.
@@ -177,11 +177,18 @@ const (
177177
// The limit is evenly distributed among available frontend service instances.
178178
// If this is set, it overwrites per instance limit "frontend.namespaceRPS".
179179
FrontendGlobalNamespaceRPS = "frontend.globalNamespaceRPS"
180+
// InternalFrontendGlobalNamespaceRPS is workflow namespace rate limit per second across
181+
// all internal-frontends.
182+
InternalFrontendGlobalNamespaceRPS = "internal-frontend.globalNamespaceRPS"
180183
// FrontendGlobalNamespaceVisibilityRPS is workflow namespace rate limit per second for the whole cluster for visibility API.
181184
// The limit is evenly distributed among available frontend service instances.
182185
// If this is set, it overwrites per instance limit "frontend.namespaceRPS.visibility".
183186
// This config is EXPERIMENTAL and may be changed or removed in a later release.
184187
FrontendGlobalNamespaceVisibilityRPS = "frontend.globalNamespaceRPS.visibility"
188+
// InternalFrontendGlobalNamespaceVisibilityRPS is workflow namespace rate limit per second
189+
// across all internal-frontends.
190+
// This config is EXPERIMENTAL and may be changed or removed in a later release.
191+
InternalFrontendGlobalNamespaceVisibilityRPS = "internal-frontend.globalNamespaceRPS.visibility"
185192
// FrontendThrottledLogRPS is the rate limit on number of log messages emitted per second for throttled logger
186193
FrontendThrottledLogRPS = "frontend.throttledLogRPS"
187194
// FrontendShutdownDrainDuration is the duration of traffic drain during shutdown

service/frontend/fx.go

+21-4
Original file line numberDiff line numberDiff line change
@@ -270,14 +270,28 @@ func RateLimitInterceptorProvider(
270270
}
271271

272272
func NamespaceRateLimitInterceptorProvider(
273+
serviceName primitives.ServiceName,
273274
serviceConfig *Config,
274275
namespaceRegistry namespace.Registry,
275276
frontendServiceResolver membership.ServiceResolver,
276277
) *interceptor.NamespaceRateLimitInterceptor {
278+
var globalNamespaceRPS, globalNamespaceVisibilityRPS dynamicconfig.IntPropertyFnWithNamespaceFilter
279+
280+
switch serviceName {
281+
case primitives.FrontendService:
282+
globalNamespaceRPS = serviceConfig.GlobalNamespaceRPS
283+
globalNamespaceVisibilityRPS = serviceConfig.GlobalNamespaceVisibilityRPS
284+
case primitives.InternalFrontendService:
285+
globalNamespaceRPS = serviceConfig.InternalFEGlobalNamespaceRPS
286+
globalNamespaceVisibilityRPS = serviceConfig.InternalFEGlobalNamespaceVisibilityRPS
287+
default:
288+
panic("invalid service name")
289+
}
290+
277291
rateFn := func(namespace string) float64 {
278292
return namespaceRPS(
279293
serviceConfig.MaxNamespaceRPSPerInstance,
280-
serviceConfig.GlobalNamespaceRPS,
294+
globalNamespaceRPS,
281295
frontendServiceResolver,
282296
namespace,
283297
)
@@ -286,7 +300,7 @@ func NamespaceRateLimitInterceptorProvider(
286300
visibilityRateFn := func(namespace string) float64 {
287301
return namespaceRPS(
288302
serviceConfig.MaxNamespaceVisibilityRPSPerInstance,
289-
serviceConfig.GlobalNamespaceVisibilityRPS,
303+
globalNamespaceVisibilityRPS,
290304
frontendServiceResolver,
291305
namespace,
292306
)
@@ -393,8 +407,11 @@ func FEReplicatorNamespaceReplicationQueueProvider(
393407
return replicatorNamespaceReplicationQueue
394408
}
395409

396-
func ServiceResolverProvider(membershipMonitor membership.Monitor) (membership.ServiceResolver, error) {
397-
return membershipMonitor.GetResolver(primitives.FrontendService)
410+
func ServiceResolverProvider(
411+
membershipMonitor membership.Monitor,
412+
serviceName primitives.ServiceName,
413+
) (membership.ServiceResolver, error) {
414+
return membershipMonitor.GetResolver(serviceName)
398415
}
399416

400417
func AdminHandlerProvider(

service/frontend/service.go

+4
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ type Config struct {
7979
MaxNamespaceVisibilityRPSPerInstance dynamicconfig.IntPropertyFnWithNamespaceFilter
8080
MaxNamespaceVisibilityBurstPerInstance dynamicconfig.IntPropertyFnWithNamespaceFilter
8181
GlobalNamespaceRPS dynamicconfig.IntPropertyFnWithNamespaceFilter
82+
InternalFEGlobalNamespaceRPS dynamicconfig.IntPropertyFnWithNamespaceFilter
8283
GlobalNamespaceVisibilityRPS dynamicconfig.IntPropertyFnWithNamespaceFilter
84+
InternalFEGlobalNamespaceVisibilityRPS dynamicconfig.IntPropertyFnWithNamespaceFilter
8385
MaxIDLengthLimit dynamicconfig.IntPropertyFn
8486
WorkerBuildIdSizeLimit dynamicconfig.IntPropertyFn
8587
DisallowQuery dynamicconfig.BoolPropertyFnWithNamespaceFilter
@@ -193,7 +195,9 @@ func NewConfig(dc *dynamicconfig.Collection, numHistoryShards int32, esIndexName
193195
MaxNamespaceVisibilityRPSPerInstance: dc.GetIntPropertyFilteredByNamespace(dynamicconfig.FrontendMaxNamespaceVisibilityRPSPerInstance, 10),
194196
MaxNamespaceVisibilityBurstPerInstance: dc.GetIntPropertyFilteredByNamespace(dynamicconfig.FrontendMaxNamespaceVisibilityBurstPerInstance, 10),
195197
GlobalNamespaceRPS: dc.GetIntPropertyFilteredByNamespace(dynamicconfig.FrontendGlobalNamespaceRPS, 0),
198+
InternalFEGlobalNamespaceRPS: dc.GetIntPropertyFilteredByNamespace(dynamicconfig.InternalFrontendGlobalNamespaceRPS, 0),
196199
GlobalNamespaceVisibilityRPS: dc.GetIntPropertyFilteredByNamespace(dynamicconfig.FrontendGlobalNamespaceVisibilityRPS, 0),
200+
InternalFEGlobalNamespaceVisibilityRPS: dc.GetIntPropertyFilteredByNamespace(dynamicconfig.InternalFrontendGlobalNamespaceVisibilityRPS, 0),
197201
MaxIDLengthLimit: dc.GetIntProperty(dynamicconfig.MaxIDLengthLimit, 1000),
198202
WorkerBuildIdSizeLimit: dc.GetIntProperty(dynamicconfig.WorkerBuildIdSizeLimit, 1000),
199203
MaxBadBinaries: dc.GetIntPropertyFilteredByNamespace(dynamicconfig.FrontendMaxBadBinaries, namespace.MaxBadBinaries),

0 commit comments

Comments
 (0)