@@ -43,13 +43,16 @@ const (
4343
4444var (
4545 errNamespaceMismatch = errors .New ("namespace mismatch" )
46+
47+ batchQuotaRequest = quotas.Request {
48+ Token : 1 ,
49+ }
4650)
4751
4852// batchProcessorConfig holds the configuration for batch processing
4953type batchProcessorConfig struct {
5054 namespace string
5155 adjustedQuery string
52- rps dynamicconfig.IntPropertyFnWithNamespaceFilter
5356 concurrency int
5457 initialPageToken []byte
5558 initialExecutions []* commonpb.WorkflowExecution
@@ -60,7 +63,7 @@ type batchWorkerProcessor func(
6063 ctx context.Context ,
6164 taskCh chan task ,
6265 respCh chan taskResponse ,
63- rateLimiter quotas.RateLimiter ,
66+ rateLimiter quotas.RequestRateLimiter ,
6467 sdkClient sdkclient.Client ,
6568 frontendClient workflowservice.WorkflowServiceClient ,
6669 metricsHandler metrics.Handler ,
@@ -158,14 +161,12 @@ func (a *activities) processWorkflowsWithProactiveFetching(
158161 ctx context.Context ,
159162 config batchProcessorConfig ,
160163 startWorkerProcessor batchWorkerProcessor ,
164+ rateLimiter quotas.RequestRateLimiter ,
161165 sdkClient sdkclient.Client ,
162166 metricsHandler metrics.Handler ,
163167 logger log.Logger ,
164168 hbd HeartBeatDetails ,
165169) (HeartBeatDetails , error ) {
166- rateLimiter := quotas .NewDefaultOutgoingRateLimiter (func () float64 {
167- return float64 (config .rps (config .namespace ))
168- })
169170
170171 concurrency := int (math .Max (1 , float64 (config .concurrency )))
171172
@@ -319,6 +320,9 @@ func (a *activities) BatchActivityWithProtobuf(ctx context.Context, batchParams
319320 var visibilityQuery string
320321 var executions []* commonpb.WorkflowExecution
321322
323+ // Admin batch uses the host level rate limiter which applies across all namespaces and all admin batch workflows.
324+ rateLimiter := quotas .RequestRateLimiter (a .AdminBatcherRateLimiter )
325+
322326 if batchParams .AdminRequest != nil {
323327 ctx = headers .SetCallerType (ctx , headers .CallerTypePreemptable )
324328 adminReq := batchParams .AdminRequest
@@ -327,6 +331,9 @@ func (a *activities) BatchActivityWithProtobuf(ctx context.Context, batchParams
327331 } else {
328332 visibilityQuery = a .adjustQueryBatchTypeEnum (batchParams .Request .VisibilityQuery , batchParams .BatchType )
329333 executions = batchParams .Request .Executions
334+ rateLimiter = quotas .NewRequestRateLimiterAdapter (quotas .NewDefaultOutgoingRateLimiter (func () float64 {
335+ return float64 (a .rps (ns ))
336+ }))
330337 }
331338
332339 if startOver {
@@ -353,7 +360,6 @@ func (a *activities) BatchActivityWithProtobuf(ctx context.Context, batchParams
353360 config := batchProcessorConfig {
354361 namespace : ns ,
355362 adjustedQuery : visibilityQuery ,
356- rps : a .rps ,
357363 concurrency : a .getOperationConcurrency (int (batchParams .Concurrency )),
358364 initialPageToken : hbd .PageToken ,
359365 initialExecutions : executions ,
@@ -364,7 +370,7 @@ func (a *activities) BatchActivityWithProtobuf(ctx context.Context, batchParams
364370 ctx context.Context ,
365371 taskCh chan task ,
366372 respCh chan taskResponse ,
367- rateLimiter quotas.RateLimiter ,
373+ rateLimiter quotas.RequestRateLimiter ,
368374 sdkClient sdkclient.Client ,
369375 frontendClient workflowservice.WorkflowServiceClient ,
370376 metricsHandler metrics.Handler ,
@@ -373,7 +379,7 @@ func (a *activities) BatchActivityWithProtobuf(ctx context.Context, batchParams
373379 a .startTaskProcessor (ctx , batchParams , ns , taskCh , respCh , rateLimiter , sdkClient , frontendClient , metricsHandler , logger )
374380 }
375381
376- return a .processWorkflowsWithProactiveFetching (ctx , config , workerProcessor , sdkClient , metricsHandler , logger , hbd )
382+ return a .processWorkflowsWithProactiveFetching (ctx , config , workerProcessor , rateLimiter , sdkClient , metricsHandler , logger , hbd )
377383}
378384
379385func (a * activities ) getActivityLogger (ctx context.Context ) log.Logger {
@@ -420,7 +426,7 @@ func (a *activities) startTaskProcessor(
420426 namespace string ,
421427 taskCh chan task ,
422428 respCh chan taskResponse ,
423- limiter quotas.RateLimiter ,
429+ limiter quotas.RequestRateLimiter ,
424430 sdkClient sdkclient.Client ,
425431 frontendClient workflowservice.WorkflowServiceClient ,
426432 metricsHandler metrics.Handler ,
@@ -673,7 +679,7 @@ func (a *activities) processAdminTask(
673679 ctx context.Context ,
674680 batchOperation * batchspb.BatchOperationInput ,
675681 task task ,
676- limiter quotas.RateLimiter ,
682+ limiter quotas.RequestRateLimiter ,
677683) error {
678684 adminReq := batchOperation .AdminRequest
679685 switch adminReq .Operation .(type ) {
@@ -701,11 +707,11 @@ func (a *activities) processAdminTask(
701707
702708func processTask (
703709 ctx context.Context ,
704- limiter quotas.RateLimiter ,
710+ limiter quotas.RequestRateLimiter ,
705711 task task ,
706712 procFn func (* workflowpb.WorkflowExecutionInfo ) error ,
707713) error {
708- err := limiter .Wait (ctx )
714+ err := limiter .Wait (ctx , batchQuotaRequest )
709715 if err != nil {
710716 return err
711717 }
0 commit comments