Skip to content

Commit 657dd91

Browse files
authored
feat: Expose nonStickyToStickyPollRatio WorkerOption (#1254)
1 parent b649606 commit 657dd91

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

packages/core-bridge/src/conversions.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,9 @@ impl ObjectHandleConversionsExt for Handle<'_, JsObject> {
332332
js_optional_getter!(cx, self, "shutdownGraceTimeMs", JsNumber)
333333
.map(|num| Duration::from_millis(num.value(cx) as u64));
334334

335+
let nonsticky_to_sticky_poll_ratio =
336+
js_value_getter!(cx, self, "nonStickyToStickyPollRatio", JsNumber) as f32;
337+
335338
match WorkerConfigBuilder::default()
336339
.worker_build_id(js_value_getter!(cx, self, "buildId", JsString))
337340
.client_identity_override(Some(js_value_getter!(cx, self, "identity", JsString)))
@@ -342,6 +345,7 @@ impl ObjectHandleConversionsExt for Handle<'_, JsObject> {
342345
.max_outstanding_local_activities(max_outstanding_local_activities)
343346
.max_concurrent_wft_polls(max_concurrent_wft_polls)
344347
.max_concurrent_at_polls(max_concurrent_at_polls)
348+
.nonsticky_to_sticky_poll_ratio(nonsticky_to_sticky_poll_ratio)
345349
.max_cached_workflows(max_cached_workflows)
346350
.sticky_queue_schedule_to_start_timeout(sticky_queue_schedule_to_start_timeout)
347351
.graceful_shutdown_period(graceful_shutdown_period)

packages/core-bridge/ts/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ export interface WorkerOptions {
286286
maxConcurrentActivityTaskExecutions: number;
287287
maxConcurrentWorkflowTaskExecutions: number;
288288
maxConcurrentLocalActivityExecutions: number;
289+
nonStickyToStickyPollRatio: number;
289290

290291
/**
291292
* Maximum number of Workflow tasks to poll concurrently.

packages/test/src/run-a-worker.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ async function main() {
2222
activities,
2323
workflowsPath: require.resolve('./workflows'),
2424
taskQueue: 'test',
25+
nonStickyToStickyPollRatio: 0.5,
2526
});
2627
await worker.run();
2728
console.log('Worker gracefully shutdown');

packages/worker/src/worker-options.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,20 @@ export interface WorkerOptions {
256256
*/
257257
maxConcurrentWorkflowTaskExecutions?: number;
258258

259+
/**
260+
* `maxConcurrentWorkflowTaskPolls` * this number = the number of max pollers that will
261+
* be allowed for the nonsticky queue when sticky tasks are enabled. If both defaults are used,
262+
* the sticky queue will allow 8 max pollers while the nonsticky queue will allow 2. The
263+
* minimum for either poller is 1, so if `maxConcurrentWorkflowTaskPolls` is 1 and sticky queues are
264+
* enabled, there will be 2 concurrent polls.
265+
*
266+
* ⚠️ This API is experimental and may be removed in the future if the poll scaling algorithm changes.
267+
*
268+
* @experimental This API is experimental and may be removed in the future if the poll scaling algorithm changes.
269+
* @default 0.2
270+
*/
271+
nonStickyToStickyPollRatio?: number;
272+
259273
/**
260274
* Maximum number of Workflow Tasks to poll concurrently.
261275
*
@@ -514,6 +528,7 @@ export type WorkerOptionsWithDefaults = WorkerOptions &
514528
| 'maxConcurrentWorkflowTaskExecutions'
515529
| 'maxConcurrentWorkflowTaskPolls'
516530
| 'maxConcurrentActivityTaskPolls'
531+
| 'nonStickyToStickyPollRatio'
517532
| 'enableNonLocalActivities'
518533
| 'stickyQueueScheduleToStartTimeout'
519534
| 'maxCachedWorkflows'
@@ -564,6 +579,9 @@ export interface ReplayWorkerOptions
564579
| 'maxConcurrentActivityTaskExecutions'
565580
| 'maxConcurrentLocalActivityExecutions'
566581
| 'maxConcurrentWorkflowTaskExecutions'
582+
| 'maxConcurrentActivityTaskPolls'
583+
| 'maxConcurrentWorkflowTaskPolls'
584+
| 'nonStickyToStickyPollRatio'
567585
| 'maxHeartbeatThrottleInterval'
568586
| 'defaultHeartbeatThrottleInterval'
569587
| 'debugMode'
@@ -649,6 +667,7 @@ export function addDefaultWorkerOptions(options: WorkerOptions): WorkerOptionsWi
649667
namespace,
650668
reuseV8Context,
651669
sinks,
670+
nonStickyToStickyPollRatio,
652671
...rest
653672
} = options;
654673
const debugMode = options.debugMode || isSet(process.env.TEMPORAL_DEBUG);
@@ -686,6 +705,7 @@ export function addDefaultWorkerOptions(options: WorkerOptions): WorkerOptionsWi
686705
reuseV8Context: reuseV8Context ?? false,
687706
debugMode: debugMode ?? false,
688707
interceptors: appendDefaultInterceptors({}),
708+
nonStickyToStickyPollRatio: nonStickyToStickyPollRatio ?? 0.2,
689709
sinks: { ...defaultSinks(), ...sinks },
690710
...rest,
691711
maxConcurrentWorkflowTaskExecutions,

0 commit comments

Comments
 (0)