Skip to content

Commit 16b0bb9

Browse files
Disable eager activities if task queue rate limits is set (#2325)
1 parent 2a68883 commit 16b0bb9

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

temporal-sdk/src/main/java/io/temporal/worker/WorkerOptions.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ public Builder setMaxConcurrentNexusExecutionSize(int maxConcurrentNexusExecutio
220220
* it to less than 1 if needed. For example, set the number to 0.1 means you want your activity
221221
* to be executed once every 10 seconds. This can be used to protect down stream services from
222222
* flooding. The zero value of this uses the default value. Default is unlimited.
223+
*
224+
* <p>Setting this value to a non-zero value will disable eager execution for activities.
223225
*/
224226
public Builder setMaxTaskQueueActivitiesPerSecond(double maxTaskQueueActivitiesPerSecond) {
225227
this.maxTaskQueueActivitiesPerSecond = maxTaskQueueActivitiesPerSecond;
@@ -373,7 +375,8 @@ public Builder setStickyQueueScheduleToStartTimeout(Duration timeout) {
373375
* the workflow task back to this worker which is faster than non-eager which may be dispatched
374376
* to a separate worker.
375377
*
376-
* <p>Defaults to false, meaning that eager activity execution is permitted
378+
* <p>Defaults to false, meaning that eager activity execution is permitted. Unless you set
379+
* MaxTaskQueueActivitiesPerSecond, then eager execution is disabled.
377380
*/
378381
public Builder setDisableEagerExecution(boolean disableEagerExecution) {
379382
this.disableEagerExecution = disableEagerExecution;
@@ -685,7 +688,7 @@ private WorkerOptions(
685688
this.maxHeartbeatThrottleInterval = maxHeartbeatThrottleInterval;
686689
this.defaultHeartbeatThrottleInterval = defaultHeartbeatThrottleInterval;
687690
this.stickyQueueScheduleToStartTimeout = stickyQueueScheduleToStartTimeout;
688-
this.disableEagerExecution = disableEagerExecution;
691+
this.disableEagerExecution = maxTaskQueueActivitiesPerSecond > 0 ? true : disableEagerExecution;
689692
this.useBuildIdForVersioning = useBuildIdForVersioning;
690693
this.buildId = buildId;
691694
this.stickyTaskQueueDrainTimeout = stickyTaskQueueDrainTimeout;

temporal-sdk/src/test/java/io/temporal/worker/WorkerOptionsTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,4 +164,14 @@ public void throwsIfResourceControllerIsNotSame() {
164164
localActivitySlotSupplier,
165165
nexusSlotSupplier));
166166
}
167+
168+
@Test
169+
public void verifyMaxTaskQueuePerSecondsDisablesEagerExecution() {
170+
// Verify that by default eager execution is enabled
171+
WorkerOptions w1 = WorkerOptions.newBuilder().build();
172+
assertEquals(false, w1.isEagerExecutionDisabled());
173+
// Verify that setting maxTaskQueueActivitiesPerSecond disables eager
174+
WorkerOptions w2 = WorkerOptions.newBuilder().setMaxTaskQueueActivitiesPerSecond(2.0).build();
175+
assertEquals(true, w2.isEagerExecutionDisabled());
176+
}
167177
}

0 commit comments

Comments
 (0)