Skip to content

Commit

Permalink
Disable eager activities if task queue rate limits is set (#2325)
Browse files Browse the repository at this point in the history
  • Loading branch information
Quinn-With-Two-Ns authored Nov 22, 2024
1 parent 2a68883 commit 16b0bb9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ public Builder setMaxConcurrentNexusExecutionSize(int maxConcurrentNexusExecutio
* it to less than 1 if needed. For example, set the number to 0.1 means you want your activity
* to be executed once every 10 seconds. This can be used to protect down stream services from
* flooding. The zero value of this uses the default value. Default is unlimited.
*
* <p>Setting this value to a non-zero value will disable eager execution for activities.
*/
public Builder setMaxTaskQueueActivitiesPerSecond(double maxTaskQueueActivitiesPerSecond) {
this.maxTaskQueueActivitiesPerSecond = maxTaskQueueActivitiesPerSecond;
Expand Down Expand Up @@ -373,7 +375,8 @@ public Builder setStickyQueueScheduleToStartTimeout(Duration timeout) {
* the workflow task back to this worker which is faster than non-eager which may be dispatched
* to a separate worker.
*
* <p>Defaults to false, meaning that eager activity execution is permitted
* <p>Defaults to false, meaning that eager activity execution is permitted. Unless you set
* MaxTaskQueueActivitiesPerSecond, then eager execution is disabled.
*/
public Builder setDisableEagerExecution(boolean disableEagerExecution) {
this.disableEagerExecution = disableEagerExecution;
Expand Down Expand Up @@ -685,7 +688,7 @@ private WorkerOptions(
this.maxHeartbeatThrottleInterval = maxHeartbeatThrottleInterval;
this.defaultHeartbeatThrottleInterval = defaultHeartbeatThrottleInterval;
this.stickyQueueScheduleToStartTimeout = stickyQueueScheduleToStartTimeout;
this.disableEagerExecution = disableEagerExecution;
this.disableEagerExecution = maxTaskQueueActivitiesPerSecond > 0 ? true : disableEagerExecution;
this.useBuildIdForVersioning = useBuildIdForVersioning;
this.buildId = buildId;
this.stickyTaskQueueDrainTimeout = stickyTaskQueueDrainTimeout;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,14 @@ public void throwsIfResourceControllerIsNotSame() {
localActivitySlotSupplier,
nexusSlotSupplier));
}

@Test
public void verifyMaxTaskQueuePerSecondsDisablesEagerExecution() {
// Verify that by default eager execution is enabled
WorkerOptions w1 = WorkerOptions.newBuilder().build();
assertEquals(false, w1.isEagerExecutionDisabled());
// Verify that setting maxTaskQueueActivitiesPerSecond disables eager
WorkerOptions w2 = WorkerOptions.newBuilder().setMaxTaskQueueActivitiesPerSecond(2.0).build();
assertEquals(true, w2.isEagerExecutionDisabled());
}
}

0 comments on commit 16b0bb9

Please sign in to comment.