• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

temporalio / sdk-java / #272

21 Jun 2024 08:17PM UTC coverage: 77.548% (+0.04%) from 77.506%
#272

push

github

web-flow
Resource based tuner (#2110)

275 of 338 new or added lines in 11 files covered. (81.36%)

12 existing lines in 5 files now uncovered.

19522 of 25174 relevant lines covered (77.55%)

0.78 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

83.08
/temporal-sdk/src/main/java/io/temporal/worker/WorkerOptions.java
1
/*
2
 * Copyright (C) 2022 Temporal Technologies, Inc. All Rights Reserved.
3
 *
4
 * Copyright (C) 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5
 *
6
 * Modifications copyright (C) 2017 Uber Technologies, Inc.
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this material except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 *   http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
20

21
package io.temporal.worker;
22

23
import static java.lang.Double.compare;
24

25
import com.google.common.base.Preconditions;
26
import io.temporal.common.Experimental;
27
import io.temporal.serviceclient.WorkflowServiceStubsOptions;
28
import io.temporal.worker.tuning.*;
29
import java.time.Duration;
30
import java.util.Objects;
31
import javax.annotation.Nonnull;
32
import javax.annotation.Nullable;
33

34
public final class WorkerOptions {
35

36
  public static Builder newBuilder() {
37
    return new Builder();
1✔
38
  }
39

40
  public static Builder newBuilder(WorkerOptions options) {
41
    return new Builder(options);
1✔
42
  }
43

44
  public static WorkerOptions getDefaultInstance() {
45
    return DEFAULT_INSTANCE;
1✔
46
  }
47

48
  static final Duration DEFAULT_STICKY_SCHEDULE_TO_START_TIMEOUT = Duration.ofSeconds(5);
1✔
49

50
  static final Duration DEFAULT_STICKY_TASK_QUEUE_DRAIN_TIMEOUT = Duration.ofSeconds(0);
1✔
51

52
  private static final WorkerOptions DEFAULT_INSTANCE;
53

54
  static {
55
    DEFAULT_INSTANCE = WorkerOptions.newBuilder().validateAndBuildWithDefaults();
1✔
56
  }
1✔
57

58
  public static final class Builder {
59

60
    private static final int DEFAULT_MAX_CONCURRENT_WORKFLOW_TASK_POLLERS = 5;
61
    private static final int DEFAULT_MAX_CONCURRENT_ACTIVITY_TASK_POLLERS = 5;
62
    private static final int DEFAULT_MAX_CONCURRENT_WORKFLOW_TASK_EXECUTION_SIZE = 200;
63
    private static final int DEFAULT_MAX_CONCURRENT_ACTIVITY_EXECUTION_SIZE = 200;
64
    private static final int DEFAULT_MAX_CONCURRENT_LOCAL_ACTIVITY_EXECUTION_SIZE = 200;
65
    private static final long DEFAULT_DEADLOCK_DETECTION_TIMEOUT = 1000;
66
    private static final Duration DEFAULT_MAX_HEARTBEAT_THROTTLE_INTERVAL = Duration.ofSeconds(60);
1✔
67
    private static final Duration DEFAULT_DEFAULT_HEARTBEAT_THROTTLE_INTERVAL =
1✔
68
        Duration.ofSeconds(30);
1✔
69

70
    private double maxWorkerActivitiesPerSecond;
71
    private int maxConcurrentActivityExecutionSize;
72
    private int maxConcurrentWorkflowTaskExecutionSize;
73
    private int maxConcurrentLocalActivityExecutionSize;
74
    private double maxTaskQueueActivitiesPerSecond;
75
    private int maxConcurrentWorkflowTaskPollers;
76
    private int maxConcurrentActivityTaskPollers;
77
    private boolean localActivityWorkerOnly;
78
    private long defaultDeadlockDetectionTimeout;
79
    private Duration maxHeartbeatThrottleInterval;
80
    private Duration defaultHeartbeatThrottleInterval;
81
    private Duration stickyQueueScheduleToStartTimeout;
82
    private boolean disableEagerExecution;
83
    private String buildId;
84
    private boolean useBuildIdForVersioning;
85
    private Duration stickyTaskQueueDrainTimeout;
86
    private WorkerTuner workerTuner;
87
    private String identity;
88

89
    private Builder() {}
90

91
    private Builder(WorkerOptions o) {
1✔
92
      if (o == null) {
1✔
93
        return;
1✔
94
      }
95
      this.maxWorkerActivitiesPerSecond = o.maxWorkerActivitiesPerSecond;
1✔
96
      this.maxConcurrentActivityExecutionSize = o.maxConcurrentActivityExecutionSize;
1✔
97
      this.maxConcurrentWorkflowTaskExecutionSize = o.maxConcurrentWorkflowTaskExecutionSize;
1✔
98
      this.maxConcurrentLocalActivityExecutionSize = o.maxConcurrentLocalActivityExecutionSize;
1✔
99
      this.workerTuner = o.workerTuner;
1✔
100
      this.maxTaskQueueActivitiesPerSecond = o.maxTaskQueueActivitiesPerSecond;
1✔
101
      this.maxConcurrentWorkflowTaskPollers = o.maxConcurrentWorkflowTaskPollers;
1✔
102
      this.maxConcurrentActivityTaskPollers = o.maxConcurrentActivityTaskPollers;
1✔
103
      this.localActivityWorkerOnly = o.localActivityWorkerOnly;
1✔
104
      this.defaultDeadlockDetectionTimeout = o.defaultDeadlockDetectionTimeout;
1✔
105
      this.maxHeartbeatThrottleInterval = o.maxHeartbeatThrottleInterval;
1✔
106
      this.defaultHeartbeatThrottleInterval = o.defaultHeartbeatThrottleInterval;
1✔
107
      this.stickyQueueScheduleToStartTimeout = o.stickyQueueScheduleToStartTimeout;
1✔
108
      this.disableEagerExecution = o.disableEagerExecution;
1✔
109
      this.useBuildIdForVersioning = o.useBuildIdForVersioning;
1✔
110
      this.buildId = o.buildId;
1✔
111
      this.stickyTaskQueueDrainTimeout = o.stickyTaskQueueDrainTimeout;
1✔
112
    }
1✔
113

114
    /**
115
     * @param maxWorkerActivitiesPerSecond Maximum number of activities started per second by this
116
     *     worker. Default is 0 which means unlimited.
117
     * @return {@code this}
118
     *     <p>If worker is not fully loaded while tasks are backing up on the service consider
119
     *     increasing {@link #setMaxConcurrentActivityTaskPollers(int)}.
120
     *     <p>Note that this is a per worker limit. Use {@link
121
     *     #setMaxTaskQueueActivitiesPerSecond(double)} to set per task queue limit across multiple
122
     *     workers.
123
     */
124
    public Builder setMaxWorkerActivitiesPerSecond(double maxWorkerActivitiesPerSecond) {
125
      if (maxWorkerActivitiesPerSecond < 0) {
1✔
126
        throw new IllegalArgumentException(
×
127
            "Negative maxWorkerActivitiesPerSecond value: " + maxWorkerActivitiesPerSecond);
128
      }
129
      this.maxWorkerActivitiesPerSecond = maxWorkerActivitiesPerSecond;
1✔
130
      return this;
1✔
131
    }
132

133
    /**
134
     * @param maxConcurrentActivityExecutionSize Maximum number of activities executed in parallel.
135
     *     Default is 200, which is chosen if set to zero.
136
     * @return {@code this}
137
     *     <p>Note setting is mutually exclusive with {@link #setWorkerTuner(WorkerTuner)}
138
     */
139
    public Builder setMaxConcurrentActivityExecutionSize(int maxConcurrentActivityExecutionSize) {
140
      if (maxConcurrentActivityExecutionSize < 0) {
1✔
141
        throw new IllegalArgumentException(
×
142
            "Negative maxConcurrentActivityExecutionSize value: "
143
                + maxConcurrentActivityExecutionSize);
144
      }
145
      this.maxConcurrentActivityExecutionSize = maxConcurrentActivityExecutionSize;
1✔
146
      return this;
1✔
147
    }
148

149
    /**
150
     * @param maxConcurrentWorkflowTaskExecutionSize Maximum number of simultaneously executed
151
     *     workflow tasks. Default is 200, which is chosen if set to zero.
152
     * @return {@code this}
153
     *     <p>Note that this is not related to the total number of open workflows which do not need
154
     *     to be loaded in a worker when they are not making state transitions.
155
     *     <p>Note setting is mutually exclusive with {@link #setWorkerTuner(WorkerTuner)}
156
     */
157
    public Builder setMaxConcurrentWorkflowTaskExecutionSize(
158
        int maxConcurrentWorkflowTaskExecutionSize) {
159
      if (maxConcurrentWorkflowTaskExecutionSize < 0) {
1✔
160
        throw new IllegalArgumentException(
×
161
            "Negative maxConcurrentWorkflowTaskExecutionSize value: "
162
                + maxConcurrentWorkflowTaskExecutionSize);
163
      }
164
      this.maxConcurrentWorkflowTaskExecutionSize = maxConcurrentWorkflowTaskExecutionSize;
1✔
165
      return this;
1✔
166
    }
167

168
    /**
169
     * @param maxConcurrentLocalActivityExecutionSize Maximum number of local activities executed in
170
     *     parallel. Default is 200, which is chosen if set to zero.
171
     * @return {@code this}
172
     *     <p>Note setting is mutually exclusive with {@link #setWorkerTuner(WorkerTuner)}
173
     */
174
    public Builder setMaxConcurrentLocalActivityExecutionSize(
175
        int maxConcurrentLocalActivityExecutionSize) {
176
      if (maxConcurrentLocalActivityExecutionSize < 0) {
1✔
177
        throw new IllegalArgumentException(
×
178
            "Negative maxConcurrentLocalActivityExecutionSize value: "
179
                + maxConcurrentLocalActivityExecutionSize);
180
      }
181
      this.maxConcurrentLocalActivityExecutionSize = maxConcurrentLocalActivityExecutionSize;
1✔
182
      return this;
1✔
183
    }
184

185
    /**
186
     * Optional: Sets the rate limiting on number of activities that can be executed per second.
187
     * This is managed by the server and controls activities per second for the entire task queue
188
     * across all the workers. Notice that the number is represented in double, so that you can set
189
     * it to less than 1 if needed. For example, set the number to 0.1 means you want your activity
190
     * to be executed once every 10 seconds. This can be used to protect down stream services from
191
     * flooding. The zero value of this uses the default value. Default is unlimited.
192
     */
193
    public Builder setMaxTaskQueueActivitiesPerSecond(double maxTaskQueueActivitiesPerSecond) {
194
      this.maxTaskQueueActivitiesPerSecond = maxTaskQueueActivitiesPerSecond;
1✔
195
      return this;
1✔
196
    }
197

198
    /**
199
     * Sets the maximum number of simultaneous long poll requests to the Temporal Server to retrieve
200
     * workflow tasks. Changing this value will affect the rate at which the worker is able to
201
     * consume tasks from a task queue.
202
     *
203
     * <p>Due to internal logic where pollers alternate between sticky and non-sticky queues, this
204
     * value cannot be 1 and will be adjusted to 2 if set to that value.
205
     *
206
     * <p>Default is 5, which is chosen if set to zero.
207
     */
208
    public Builder setMaxConcurrentWorkflowTaskPollers(int maxConcurrentWorkflowTaskPollers) {
209
      this.maxConcurrentWorkflowTaskPollers = maxConcurrentWorkflowTaskPollers;
1✔
210
      return this;
1✔
211
    }
212

213
    /**
214
     * Number of simultaneous poll requests on workflow task queue. Note that the majority of the
215
     * workflow tasks will be using host local task queue due to caching. So try incrementing {@link
216
     * WorkerFactoryOptions.Builder#setWorkflowHostLocalPollThreadCount(int)} before this one.
217
     *
218
     * <p>Default is 5, which is chosen if set to zero.
219
     *
220
     * @deprecated Use {@link #setMaxConcurrentWorkflowTaskPollers}
221
     */
222
    @Deprecated
223
    public Builder setWorkflowPollThreadCount(int workflowPollThreadCount) {
224
      return setMaxConcurrentWorkflowTaskPollers(workflowPollThreadCount);
×
225
    }
226

227
    /**
228
     * Number of simultaneous poll requests on activity task queue. Consider incrementing if the
229
     * worker is not throttled due to `MaxActivitiesPerSecond` or
230
     * `MaxConcurrentActivityExecutionSize` options and still cannot keep up with the request rate.
231
     *
232
     * <p>Default is 5, which is chosen if set to zero.
233
     */
234
    public Builder setMaxConcurrentActivityTaskPollers(int maxConcurrentActivityTaskPollers) {
235
      this.maxConcurrentActivityTaskPollers = maxConcurrentActivityTaskPollers;
1✔
236
      return this;
1✔
237
    }
238

239
    /**
240
     * Number of simultaneous poll requests on activity task queue. Consider incrementing if the
241
     * worker is not throttled due to `MaxActivitiesPerSecond` or
242
     * `MaxConcurrentActivityExecutionSize` options and still cannot keep up with the request rate.
243
     *
244
     * <p>Default is 5, which is chosen if set to zero.
245
     *
246
     * @deprecated Use {@link #setMaxConcurrentActivityTaskPollers}
247
     */
248
    @Deprecated
249
    public Builder setActivityPollThreadCount(int activityPollThreadCount) {
250
      return setMaxConcurrentActivityTaskPollers(activityPollThreadCount);
×
251
    }
252

253
    /**
254
     * If set to true worker would only handle workflow tasks and local activities. Non-local
255
     * activities will not be executed by this worker.
256
     *
257
     * <p>Default is false.
258
     */
259
    public Builder setLocalActivityWorkerOnly(boolean localActivityWorkerOnly) {
260
      this.localActivityWorkerOnly = localActivityWorkerOnly;
1✔
261
      return this;
1✔
262
    }
263

264
    /**
265
     * @param defaultDeadlockDetectionTimeoutMs time period in ms that will be used to detect
266
     *     workflows deadlock. Default is 1000ms, which is chosen if set to zero.
267
     *     <p>Specifies an amount of time in milliseconds that workflow tasks are allowed to execute
268
     *     without interruption. If workflow task runs longer than specified interval without
269
     *     yielding (like calling an Activity), it will fail automatically.
270
     * @return {@code this}
271
     * @see io.temporal.internal.sync.PotentialDeadlockException
272
     */
273
    public Builder setDefaultDeadlockDetectionTimeout(long defaultDeadlockDetectionTimeoutMs) {
274
      if (defaultDeadlockDetectionTimeoutMs < 0) {
1✔
275
        throw new IllegalArgumentException(
×
276
            "Negative defaultDeadlockDetectionTimeout value: " + defaultDeadlockDetectionTimeoutMs);
277
      }
278
      this.defaultDeadlockDetectionTimeout = defaultDeadlockDetectionTimeoutMs;
1✔
279
      return this;
1✔
280
    }
281

282
    /**
283
     * @param interval the maximum amount of time between sending each pending heartbeat to the
284
     *     server. Regardless of heartbeat timeout, no pending heartbeat will wait longer than this
285
     *     amount of time to send. Default is 60s, which is chosen if set to null or 0.
286
     * @return {@code this}
287
     */
288
    public Builder setMaxHeartbeatThrottleInterval(@Nullable Duration interval) {
289
      Preconditions.checkArgument(
×
290
          interval == null || !interval.isNegative(),
×
291
          "Negative maxHeartbeatThrottleInterval value: %s",
292
          interval);
293
      this.maxHeartbeatThrottleInterval = interval;
×
294
      return this;
×
295
    }
296

297
    /**
298
     * @param interval the default amount of time between sending each pending heartbeat to the
299
     *     server. This is used if the ActivityOptions do not provide a HeartbeatTimeout. Otherwise,
300
     *     the interval becomes a value a bit smaller than the given HeartbeatTimeout. Default is
301
     *     30s, which is chosen if set to null or 0.
302
     * @return {@code this}
303
     */
304
    public Builder setDefaultHeartbeatThrottleInterval(@Nullable Duration interval) {
305
      Preconditions.checkArgument(
×
306
          interval == null || !interval.isNegative(),
×
307
          "Negative defaultHeartbeatThrottleInterval value: %s",
308
          interval);
309
      this.defaultHeartbeatThrottleInterval = interval;
×
310
      return this;
×
311
    }
312

313
    /**
314
     * Timeout for a workflow task routed to the "sticky worker" - host that has the workflow
315
     * instance cached in memory. Once it times out, then it can be picked up by any worker.
316
     *
317
     * <p>Default value is 5 seconds.
318
     */
319
    public Builder setStickyQueueScheduleToStartTimeout(Duration timeout) {
320
      this.stickyQueueScheduleToStartTimeout = timeout;
1✔
321
      return this;
1✔
322
    }
323

324
    /**
325
     * Disable eager activities. If set to true, eager execution will not be requested for
326
     * activities requested from workflows bound to this Worker.
327
     *
328
     * <p>Eager activity execution means the server returns requested eager activities directly from
329
     * the workflow task back to this worker which is faster than non-eager which may be dispatched
330
     * to a separate worker.
331
     *
332
     * <p>Defaults to false, meaning that eager activity execution is permitted
333
     */
334
    public Builder setDisableEagerExecution(boolean disableEagerExecution) {
335
      this.disableEagerExecution = disableEagerExecution;
×
336
      return this;
×
337
    }
338

339
    /**
340
     * Opts the worker in to the Build-ID-based versioning feature. This ensures that the worker
341
     * will only receive tasks which it is compatible with. For more information see: TODO: Doc link
342
     *
343
     * <p>Defaults to false
344
     */
345
    @Experimental
346
    public Builder setUseBuildIdForVersioning(boolean useBuildIdForVersioning) {
347
      this.useBuildIdForVersioning = useBuildIdForVersioning;
1✔
348
      return this;
1✔
349
    }
350

351
    /**
352
     * Set a unique identifier for this worker. The identifier should be stable with respect to the
353
     * code the worker uses for workflows, activities, and interceptors. For more information see:
354
     * TODO: Doc link
355
     *
356
     * <p>A Build Id must be set if {@link #setUseBuildIdForVersioning(boolean)} is set true.
357
     */
358
    @Experimental
359
    public Builder setBuildId(String buildId) {
360
      this.buildId = buildId;
1✔
361
      return this;
1✔
362
    }
363

364
    /**
365
     * During graceful shutdown, as when calling {@link WorkerFactory#shutdown()}, if the workflow
366
     * cache is enabled, this timeout controls how long to wait for the sticky task queue to drain
367
     * before shutting down the worker. If set the worker will stop making new poll requests on the
368
     * normal task queue, but will continue to poll the sticky task queue until the timeout is
369
     * reached. This value should always be greater than clients rpc long poll timeout, which can be
370
     * set via {@link WorkflowServiceStubsOptions.Builder#setRpcLongPollTimeout(Duration)}.
371
     *
372
     * <p>Default is not to wait.
373
     */
374
    @Experimental
375
    public Builder setStickyTaskQueueDrainTimeout(Duration stickyTaskQueueDrainTimeout) {
376
      this.stickyTaskQueueDrainTimeout = stickyTaskQueueDrainTimeout;
1✔
377
      return this;
1✔
378
    }
379

380
    /**
381
     * Set a {@link WorkerTuner} to determine how slots will be allocated for different types of
382
     * tasks.
383
     */
384
    @Experimental
385
    public Builder setWorkerTuner(WorkerTuner workerTuner) {
386
      this.workerTuner = workerTuner;
1✔
387
      return this;
1✔
388
    }
389

390
    /** Override identity of the worker primary specified in a WorkflowClient options. */
391
    public Builder setIdentity(String identity) {
392
      this.identity = identity;
×
393
      return this;
×
394
    }
395

396
    public WorkerOptions build() {
397
      return new WorkerOptions(
1✔
398
          maxWorkerActivitiesPerSecond,
399
          maxConcurrentActivityExecutionSize,
400
          maxConcurrentWorkflowTaskExecutionSize,
401
          maxConcurrentLocalActivityExecutionSize,
402
          workerTuner,
403
          maxTaskQueueActivitiesPerSecond,
404
          maxConcurrentWorkflowTaskPollers,
405
          maxConcurrentActivityTaskPollers,
406
          localActivityWorkerOnly,
407
          defaultDeadlockDetectionTimeout,
408
          maxHeartbeatThrottleInterval,
409
          defaultHeartbeatThrottleInterval,
410
          stickyQueueScheduleToStartTimeout,
411
          disableEagerExecution,
412
          useBuildIdForVersioning,
413
          buildId,
414
          stickyTaskQueueDrainTimeout,
415
          identity);
416
    }
417

418
    public WorkerOptions validateAndBuildWithDefaults() {
419
      Preconditions.checkState(
1✔
420
          maxWorkerActivitiesPerSecond >= 0, "negative maxActivitiesPerSecond");
421
      Preconditions.checkState(
1✔
422
          maxConcurrentActivityExecutionSize >= 0, "negative maxConcurrentActivityExecutionSize");
423
      Preconditions.checkState(
1✔
424
          maxConcurrentWorkflowTaskExecutionSize >= 0,
425
          "negative maxConcurrentWorkflowTaskExecutionSize");
426
      Preconditions.checkState(
1✔
427
          maxConcurrentLocalActivityExecutionSize >= 0,
428
          "negative maxConcurrentLocalActivityExecutionSize");
429
      if (workerTuner != null) {
1✔
430
        Preconditions.checkState(
1✔
431
            maxConcurrentActivityExecutionSize == 0,
432
            "maxConcurrentActivityExecutionSize must not be set if workerTuner is set");
433
      }
434
      if (workerTuner != null) {
1✔
435
        Preconditions.checkState(
1✔
436
            maxConcurrentWorkflowTaskExecutionSize == 0,
437
            "maxConcurrentWorkflowTaskExecutionSize must not be set if workerTuner is set");
438
      }
439
      if (workerTuner != null) {
1✔
440
        Preconditions.checkState(
1✔
441
            maxConcurrentLocalActivityExecutionSize == 0,
442
            "maxConcurrentLocalActivityExecutionSize must not be set if workerTuner is set");
443
      }
444
      Preconditions.checkState(
1✔
445
          maxTaskQueueActivitiesPerSecond >= 0, "negative taskQueueActivitiesPerSecond");
446
      Preconditions.checkState(
1✔
447
          maxConcurrentWorkflowTaskPollers >= 0, "negative maxConcurrentWorkflowTaskPollers");
448
      Preconditions.checkState(
1✔
449
          maxConcurrentActivityTaskPollers >= 0, "negative maxConcurrentActivityTaskPollers");
450
      Preconditions.checkState(
1✔
451
          defaultDeadlockDetectionTimeout >= 0, "negative defaultDeadlockDetectionTimeout");
452
      Preconditions.checkState(
1✔
453
          stickyQueueScheduleToStartTimeout == null
454
              || !stickyQueueScheduleToStartTimeout.isNegative(),
1✔
455
          "negative stickyQueueScheduleToStartTimeout");
456
      if (useBuildIdForVersioning) {
1✔
457
        Preconditions.checkState(
1✔
458
            buildId != null && !buildId.isEmpty(),
1✔
459
            "buildId must be set non-empty if useBuildIdForVersioning is set true");
460
      }
461
      Preconditions.checkState(
1✔
462
          stickyTaskQueueDrainTimeout == null || !stickyTaskQueueDrainTimeout.isNegative(),
1✔
463
          "negative stickyTaskQueueDrainTimeout");
464

465
      return new WorkerOptions(
1✔
466
          maxWorkerActivitiesPerSecond,
467
          maxConcurrentActivityExecutionSize == 0
1✔
468
              ? DEFAULT_MAX_CONCURRENT_ACTIVITY_EXECUTION_SIZE
1✔
469
              : maxConcurrentActivityExecutionSize,
1✔
470
          maxConcurrentWorkflowTaskExecutionSize == 0
1✔
471
              ? DEFAULT_MAX_CONCURRENT_WORKFLOW_TASK_EXECUTION_SIZE
1✔
472
              : maxConcurrentWorkflowTaskExecutionSize,
1✔
473
          maxConcurrentLocalActivityExecutionSize == 0
1✔
474
              ? DEFAULT_MAX_CONCURRENT_LOCAL_ACTIVITY_EXECUTION_SIZE
1✔
475
              : maxConcurrentLocalActivityExecutionSize,
1✔
476
          workerTuner,
477
          maxTaskQueueActivitiesPerSecond,
478
          maxConcurrentWorkflowTaskPollers == 0
1✔
479
              ? DEFAULT_MAX_CONCURRENT_WORKFLOW_TASK_POLLERS
1✔
480
              : maxConcurrentWorkflowTaskPollers,
1✔
481
          maxConcurrentActivityTaskPollers == 0
1✔
482
              ? DEFAULT_MAX_CONCURRENT_ACTIVITY_TASK_POLLERS
1✔
483
              : maxConcurrentActivityTaskPollers,
1✔
484
          localActivityWorkerOnly,
485
          defaultDeadlockDetectionTimeout == 0
1✔
486
              ? DEFAULT_DEADLOCK_DETECTION_TIMEOUT
1✔
487
              : defaultDeadlockDetectionTimeout,
1✔
488
          maxHeartbeatThrottleInterval == null || maxHeartbeatThrottleInterval.isZero()
1✔
489
              ? DEFAULT_MAX_HEARTBEAT_THROTTLE_INTERVAL
1✔
490
              : maxHeartbeatThrottleInterval,
1✔
491
          defaultHeartbeatThrottleInterval == null || defaultHeartbeatThrottleInterval.isZero()
1✔
492
              ? DEFAULT_DEFAULT_HEARTBEAT_THROTTLE_INTERVAL
1✔
493
              : defaultHeartbeatThrottleInterval,
1✔
494
          stickyQueueScheduleToStartTimeout == null
1✔
495
              ? DEFAULT_STICKY_SCHEDULE_TO_START_TIMEOUT
1✔
496
              : stickyQueueScheduleToStartTimeout,
1✔
497
          disableEagerExecution,
498
          useBuildIdForVersioning,
499
          buildId,
500
          stickyTaskQueueDrainTimeout == null
1✔
501
              ? DEFAULT_STICKY_TASK_QUEUE_DRAIN_TIMEOUT
1✔
502
              : stickyTaskQueueDrainTimeout,
1✔
503
          identity);
504
    }
505
  }
506

507
  private final double maxWorkerActivitiesPerSecond;
508
  private final int maxConcurrentActivityExecutionSize;
509
  private final int maxConcurrentWorkflowTaskExecutionSize;
510
  private final int maxConcurrentLocalActivityExecutionSize;
511
  private final WorkerTuner workerTuner;
512
  private final double maxTaskQueueActivitiesPerSecond;
513
  private final int maxConcurrentWorkflowTaskPollers;
514
  private final int maxConcurrentActivityTaskPollers;
515
  private final boolean localActivityWorkerOnly;
516
  private final long defaultDeadlockDetectionTimeout;
517
  private final Duration maxHeartbeatThrottleInterval;
518
  private final Duration defaultHeartbeatThrottleInterval;
519
  private final @Nonnull Duration stickyQueueScheduleToStartTimeout;
520
  private final boolean disableEagerExecution;
521
  private final boolean useBuildIdForVersioning;
522
  private final String buildId;
523
  private final Duration stickyTaskQueueDrainTimeout;
524
  private final String identity;
525

526
  private WorkerOptions(
527
      double maxWorkerActivitiesPerSecond,
528
      int maxConcurrentActivityExecutionSize,
529
      int maxConcurrentWorkflowTaskExecutionSize,
530
      int maxConcurrentLocalActivityExecutionSize,
531
      WorkerTuner workerTuner,
532
      double maxTaskQueueActivitiesPerSecond,
533
      int workflowPollThreadCount,
534
      int activityPollThreadCount,
535
      boolean localActivityWorkerOnly,
536
      long defaultDeadlockDetectionTimeout,
537
      Duration maxHeartbeatThrottleInterval,
538
      Duration defaultHeartbeatThrottleInterval,
539
      @Nonnull Duration stickyQueueScheduleToStartTimeout,
540
      boolean disableEagerExecution,
541
      boolean useBuildIdForVersioning,
542
      String buildId,
543
      Duration stickyTaskQueueDrainTimeout,
544
      String identity) {
1✔
545
    this.maxWorkerActivitiesPerSecond = maxWorkerActivitiesPerSecond;
1✔
546
    this.maxConcurrentActivityExecutionSize = maxConcurrentActivityExecutionSize;
1✔
547
    this.maxConcurrentWorkflowTaskExecutionSize = maxConcurrentWorkflowTaskExecutionSize;
1✔
548
    this.maxConcurrentLocalActivityExecutionSize = maxConcurrentLocalActivityExecutionSize;
1✔
549
    this.workerTuner = workerTuner;
1✔
550
    this.maxTaskQueueActivitiesPerSecond = maxTaskQueueActivitiesPerSecond;
1✔
551
    this.maxConcurrentWorkflowTaskPollers = workflowPollThreadCount;
1✔
552
    this.maxConcurrentActivityTaskPollers = activityPollThreadCount;
1✔
553
    this.localActivityWorkerOnly = localActivityWorkerOnly;
1✔
554
    this.defaultDeadlockDetectionTimeout = defaultDeadlockDetectionTimeout;
1✔
555
    this.maxHeartbeatThrottleInterval = maxHeartbeatThrottleInterval;
1✔
556
    this.defaultHeartbeatThrottleInterval = defaultHeartbeatThrottleInterval;
1✔
557
    this.stickyQueueScheduleToStartTimeout = stickyQueueScheduleToStartTimeout;
1✔
558
    this.disableEagerExecution = disableEagerExecution;
1✔
559
    this.useBuildIdForVersioning = useBuildIdForVersioning;
1✔
560
    this.buildId = buildId;
1✔
561
    this.stickyTaskQueueDrainTimeout = stickyTaskQueueDrainTimeout;
1✔
562
    this.identity = identity;
1✔
563
  }
1✔
564

565
  public double getMaxWorkerActivitiesPerSecond() {
566
    return maxWorkerActivitiesPerSecond;
1✔
567
  }
568

569
  public int getMaxConcurrentActivityExecutionSize() {
570
    return maxConcurrentActivityExecutionSize;
1✔
571
  }
572

573
  public int getMaxConcurrentWorkflowTaskExecutionSize() {
574
    return maxConcurrentWorkflowTaskExecutionSize;
1✔
575
  }
576

577
  public int getMaxConcurrentLocalActivityExecutionSize() {
578
    return maxConcurrentLocalActivityExecutionSize;
1✔
579
  }
580

581
  public double getMaxTaskQueueActivitiesPerSecond() {
582
    return maxTaskQueueActivitiesPerSecond;
1✔
583
  }
584

585
  /**
586
   * @deprecated use {@link #getMaxConcurrentWorkflowTaskPollers}
587
   */
588
  @Deprecated
589
  public int getWorkflowPollThreadCount() {
590
    return getMaxConcurrentWorkflowTaskPollers();
×
591
  }
592

593
  public int getMaxConcurrentWorkflowTaskPollers() {
594
    return maxConcurrentWorkflowTaskPollers;
1✔
595
  }
596

597
  /**
598
   * @deprecated use {@link #getMaxConcurrentActivityTaskPollers}
599
   */
600
  @Deprecated
601
  public int getActivityPollThreadCount() {
602
    return getMaxConcurrentActivityTaskPollers();
×
603
  }
604

605
  public int getMaxConcurrentActivityTaskPollers() {
606
    return maxConcurrentActivityTaskPollers;
1✔
607
  }
608

609
  public long getDefaultDeadlockDetectionTimeout() {
610
    return defaultDeadlockDetectionTimeout;
1✔
611
  }
612

613
  public boolean isLocalActivityWorkerOnly() {
614
    return localActivityWorkerOnly;
1✔
615
  }
616

617
  public Duration getMaxHeartbeatThrottleInterval() {
618
    return maxHeartbeatThrottleInterval;
1✔
619
  }
620

621
  public Duration getDefaultHeartbeatThrottleInterval() {
622
    return defaultHeartbeatThrottleInterval;
1✔
623
  }
624

625
  @Nonnull
626
  public Duration getStickyQueueScheduleToStartTimeout() {
627
    return stickyQueueScheduleToStartTimeout;
1✔
628
  }
629

630
  public boolean isEagerExecutionDisabled() {
631
    return disableEagerExecution;
1✔
632
  }
633

634
  public boolean isUsingBuildIdForVersioning() {
635
    return useBuildIdForVersioning;
1✔
636
  }
637

638
  public String getBuildId() {
639
    return buildId;
1✔
640
  }
641

642
  public Duration getStickyTaskQueueDrainTimeout() {
643
    return stickyTaskQueueDrainTimeout;
1✔
644
  }
645

646
  public WorkerTuner getWorkerTuner() {
647
    return workerTuner;
1✔
648
  }
649

650
  @Nullable
651
  public String getIdentity() {
652
    return identity;
1✔
653
  }
654

655
  @Override
656
  public boolean equals(Object o) {
657
    if (this == o) return true;
1✔
658
    if (o == null || getClass() != o.getClass()) return false;
1✔
659
    WorkerOptions that = (WorkerOptions) o;
1✔
660
    return compare(maxWorkerActivitiesPerSecond, that.maxWorkerActivitiesPerSecond) == 0
1✔
661
        && maxConcurrentActivityExecutionSize == that.maxConcurrentActivityExecutionSize
662
        && maxConcurrentWorkflowTaskExecutionSize == that.maxConcurrentWorkflowTaskExecutionSize
663
        && maxConcurrentLocalActivityExecutionSize == that.maxConcurrentLocalActivityExecutionSize
664
        && compare(maxTaskQueueActivitiesPerSecond, that.maxTaskQueueActivitiesPerSecond) == 0
1✔
665
        && maxConcurrentWorkflowTaskPollers == that.maxConcurrentWorkflowTaskPollers
666
        && maxConcurrentActivityTaskPollers == that.maxConcurrentActivityTaskPollers
667
        && localActivityWorkerOnly == that.localActivityWorkerOnly
668
        && defaultDeadlockDetectionTimeout == that.defaultDeadlockDetectionTimeout
669
        && disableEagerExecution == that.disableEagerExecution
670
        && useBuildIdForVersioning == that.useBuildIdForVersioning
671
        && Objects.equals(workerTuner, that.workerTuner)
1✔
672
        && Objects.equals(maxHeartbeatThrottleInterval, that.maxHeartbeatThrottleInterval)
1✔
673
        && Objects.equals(defaultHeartbeatThrottleInterval, that.defaultHeartbeatThrottleInterval)
1✔
674
        && Objects.equals(stickyQueueScheduleToStartTimeout, that.stickyQueueScheduleToStartTimeout)
1✔
675
        && Objects.equals(buildId, that.buildId)
1✔
676
        && Objects.equals(stickyTaskQueueDrainTimeout, that.stickyTaskQueueDrainTimeout)
1✔
677
        && Objects.equals(identity, that.identity);
1✔
678
  }
679

680
  @Override
681
  public int hashCode() {
682
    return Objects.hash(
×
683
        maxWorkerActivitiesPerSecond,
×
684
        maxConcurrentActivityExecutionSize,
×
685
        maxConcurrentWorkflowTaskExecutionSize,
×
686
        maxConcurrentLocalActivityExecutionSize,
×
687
        workerTuner,
UNCOV
688
        maxTaskQueueActivitiesPerSecond,
×
689
        maxConcurrentWorkflowTaskPollers,
×
690
        maxConcurrentActivityTaskPollers,
×
691
        localActivityWorkerOnly,
×
692
        defaultDeadlockDetectionTimeout,
×
693
        maxHeartbeatThrottleInterval,
694
        defaultHeartbeatThrottleInterval,
695
        stickyQueueScheduleToStartTimeout,
696
        disableEagerExecution,
×
697
        useBuildIdForVersioning,
×
698
        buildId,
699
        stickyTaskQueueDrainTimeout,
700
        identity);
701
  }
702

703
  @Override
704
  public String toString() {
705
    return "WorkerOptions{"
×
706
        + "maxWorkerActivitiesPerSecond="
707
        + maxWorkerActivitiesPerSecond
708
        + ", maxConcurrentActivityExecutionSize="
709
        + maxConcurrentActivityExecutionSize
710
        + ", maxConcurrentWorkflowTaskExecutionSize="
711
        + maxConcurrentWorkflowTaskExecutionSize
712
        + ", maxConcurrentLocalActivityExecutionSize="
713
        + maxConcurrentLocalActivityExecutionSize
714
        + ", workerTuner="
715
        + workerTuner
716
        + ", maxTaskQueueActivitiesPerSecond="
717
        + maxTaskQueueActivitiesPerSecond
718
        + ", maxConcurrentWorkflowTaskPollers="
719
        + maxConcurrentWorkflowTaskPollers
720
        + ", maxConcurrentActivityTaskPollers="
721
        + maxConcurrentActivityTaskPollers
722
        + ", localActivityWorkerOnly="
723
        + localActivityWorkerOnly
724
        + ", defaultDeadlockDetectionTimeout="
725
        + defaultDeadlockDetectionTimeout
726
        + ", maxHeartbeatThrottleInterval="
727
        + maxHeartbeatThrottleInterval
728
        + ", defaultHeartbeatThrottleInterval="
729
        + defaultHeartbeatThrottleInterval
730
        + ", stickyQueueScheduleToStartTimeout="
731
        + stickyQueueScheduleToStartTimeout
732
        + ", disableEagerExecution="
733
        + disableEagerExecution
734
        + ", useBuildIdForVersioning="
735
        + useBuildIdForVersioning
736
        + ", buildId='"
737
        + buildId
738
        + '\''
739
        + ", stickyTaskQueueDrainTimeout="
740
        + stickyTaskQueueDrainTimeout
741
        + ", identity="
742
        + identity
743
        + '}';
744
  }
745
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc