Support passing activity task rate limit on worker options #311
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR exposes the
activity_max_tasks_per_secondoption when constructing a newTemporal::Workerinstance. This setting sets themax_tasks_per_secondoption when makingPollActivityTaskQueueRPCs to the server, which has the effect of limiting how fast the server will give out activity tasks (both new activities and retries of already-running activities).This same option is exposed in other SDKs; for example in Java it's available on the
WorkerOptionsstruct as thesetMaxTaskQueueActivitiesPerSecondoption. The doc comment added in this PR was based off of the doc comment in the Java SDK. The semantics of the valuesactivity_max_tasks_per_secondcan be (non-negative decimal number) and when it sets set on the wire (if it's > 0) was copied directly from the Java SDK's implementation, here (although it diverges slightly from the Go SDK).Motivation
Allow Ruby workers to control the rate of processing activities, to control impact on downstream systems.
Test plan
Unit tests
Existing unit tests/example unit tests pass, and the new tests I added validate that, at each step, the option is making its way to the underlying gRPC connection:
Manual tests
I also manually validated that the activity task rate limit works as expected. To do so, I modified the
examples/bin/workerscript to include a rate-limit on theWorker.newcall:Then, I ran the
AsyncHelloWorldWorkflowworkflow with 10 activities, and validated that it took around 20-30 seconds (10 activities * 0.5 activities/second + a bit of overhead/inaccuracy) for the workflow to complete:Repeating the test without the change to
examples/bin/worker(i.e. an unlimited activity task queue) shows that the rate-limit makes a meaningful difference: