Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Batch operation rate limit #4941

Merged
merged 2 commits into from
Oct 30, 2023
Merged

Batch operation rate limit #4941

merged 2 commits into from
Oct 30, 2023

Conversation

stephanos
Copy link
Contributor

@stephanos stephanos commented Oct 5, 2023

What changed?

Allow rate limiting a batch operation. Fixes #4926.

Why?

Batch operations are run server side and may effect millions of executions, this in turn may overload workers and disrupt normal operations.

How did you test it?

I started the Server locally and initiated a batch operation from the CLI (CLI changes be found here):

  • uses provided limit
  • uses server limit when not provided
  • caps it at server limit

Potential risks

Rate limiting to be incorrect and slow down processing or disrupt cluster.

Is hotfix candidate?

No

@@ -45,7 +45,6 @@ type activitiesSuite struct {
testsuite.WorkflowTestSuite

controller *gomock.Controller
env *testsuite.TestWorkflowEnvironment
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused

@stephanos stephanos force-pushed the batch-operation-rate-limit branch 2 times, most recently from fca2cc2 to 8fed2d0 Compare October 5, 2023 22:27
@stephanos stephanos force-pushed the batch-operation-rate-limit branch 3 times, most recently from efbf5b5 to 7fddbfe Compare October 30, 2023 16:37
Comment on lines +205 to +210
func (a *activities) getOperationRPS(requestedRPS float64) float64 {
maxRPS := float64(a.rps(a.namespace.String()))
if requestedRPS <= 0 || requestedRPS > maxRPS {
return maxRPS
}
return rps
return requestedRPS
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the main change; all others are just cosmetic (making fields private, fixing up formatting and comments etc.)

@@ -43,7 +43,7 @@ require (
go.opentelemetry.io/otel/metric v1.19.0
go.opentelemetry.io/otel/sdk v1.19.0
go.opentelemetry.io/otel/sdk/metric v1.19.0
go.temporal.io/api v1.24.1-0.20231003165936-bb03061759c8
go.temporal.io/api v1.25.0
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upgraded to new API version to pull in the max_operations_per_second field.

@stephanos stephanos force-pushed the batch-operation-rate-limit branch 4 times, most recently from 0734e72 to 575c3ce Compare October 30, 2023 18:42
@stephanos stephanos marked this pull request as ready for review October 30, 2023 18:53
@stephanos stephanos requested a review from a team as a code owner October 30, 2023 18:53
RPS int
// RPS sets the requests-per-second limit for the batch.
// The default (and max) is defined by `worker.BatcherRPS` in the dynamic config.
RPS float64
Copy link
Contributor Author

@stephanos stephanos Oct 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was effectively unused before.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are there so many deletions? 😕

@stephanos stephanos enabled auto-merge (squash) October 30, 2023 19:53
@stephanos stephanos merged commit 01d3e7f into main Oct 30, 2023
10 checks passed
@stephanos stephanos deleted the batch-operation-rate-limit branch October 30, 2023 20:04
stephanos added a commit that referenced this pull request Feb 21, 2024
## What changed?

Adding back one line that was accidentally removed from
#4941 after it was merged.

Line added originally:
https://github.com/temporalio/temporal/pull/4941/files#diff-c9a59445e489bd70346630f2773ad69e1723b2298fadbae50ff5c1a424917e1cR3468

## Why?
<!-- Tell your future self why have you made these changes -->

## How did you test it?
<!-- How have you verified this change? Tested locally? Added a unit
test? Checked in staging env? -->

## Potential risks
<!-- Assuming the worst case, what can be broken when deploying this
change to production? -->

## Is hotfix candidate?

No.

The code will still work since we ignore it when `requestedRPS` is zero:

```
if requestedRPS <= 0 || requestedRPS > maxRPS {
     return maxRPS
}
```
tdeebswihart pushed a commit that referenced this pull request Feb 21, 2024
## What changed?

Adding back one line that was accidentally removed from
#4941 after it was merged.

Line added originally:
https://github.com/temporalio/temporal/pull/4941/files#diff-c9a59445e489bd70346630f2773ad69e1723b2298fadbae50ff5c1a424917e1cR3468

## Why?
<!-- Tell your future self why have you made these changes -->

## How did you test it?
<!-- How have you verified this change? Tested locally? Added a unit
test? Checked in staging env? -->

## Potential risks
<!-- Assuming the worst case, what can be broken when deploying this
change to production? -->

## Is hotfix candidate?

No.

The code will still work since we ignore it when `requestedRPS` is zero:

```
if requestedRPS <= 0 || requestedRPS > maxRPS {
     return maxRPS
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a rate limit option for batch operations
2 participants