Skip to content

Commit

Permalink
Adds config for min and delta backoff poll intervals (#174)
Browse files Browse the repository at this point in the history
Co-authored-by: Dustin Metzgar <[email protected]>
  • Loading branch information
dmetzgar and dmetzgar authored Aug 31, 2023
1 parent ee65b1c commit b3a7bf4
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 11 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# Changelog

## v1.1.2
## Unreleased

### New

* Support configurable backoff intervals ([#163](https://github.com/microsoft/durabletask-mssql/pull/163)) - contributed by [@tompostler](https://github.com/tompostler)
* Support configurable max backoff intervals ([#163](https://github.com/microsoft/durabletask-mssql/pull/163)) - contributed by [@tompostler](https://github.com/tompostler)
* Support configurable min and delta backoff intervals ([#174](https://github.com/microsoft/durabletask-mssql/pull/174)) - contributed by [@dmetzgar](https://github.com/dmetzgar)

### Updates

Expand Down
9 changes: 2 additions & 7 deletions src/DurableTask.SqlServer/BackoffPollingHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ class BackoffPollingHelper
readonly RandomizedExponentialBackoffStrategy backoffStrategy;
readonly AsyncAutoResetEvent resetEvent;

public BackoffPollingHelper(TimeSpan minimumInterval, TimeSpan maximumInterval)
public BackoffPollingHelper(TimeSpan minimumInterval, TimeSpan maximumInterval, TimeSpan deltaBackoff)
{
this.backoffStrategy = new RandomizedExponentialBackoffStrategy(minimumInterval, maximumInterval);
this.backoffStrategy = new RandomizedExponentialBackoffStrategy(minimumInterval, maximumInterval, deltaBackoff);
this.resetEvent = new AsyncAutoResetEvent(signaled: false);
}

Expand Down Expand Up @@ -46,11 +46,6 @@ class RandomizedExponentialBackoffStrategy

uint backoffExponent;

public RandomizedExponentialBackoffStrategy(TimeSpan minimumInterval, TimeSpan maximumInterval)
: this(minimumInterval, maximumInterval, minimumInterval)
{
}

public RandomizedExponentialBackoffStrategy(
TimeSpan minimumInterval,
TimeSpan maximumInterval,
Expand Down
10 changes: 8 additions & 2 deletions src/DurableTask.SqlServer/SqlOrchestrationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,14 @@ public class SqlOrchestrationService : OrchestrationServiceBase
public SqlOrchestrationService(SqlOrchestrationServiceSettings? settings)
{
this.settings = ValidateSettings(settings) ?? throw new ArgumentNullException(nameof(settings));
this.orchestrationBackoffHelper = new BackoffPollingHelper(TimeSpan.FromMilliseconds(50), this.settings.MaxOrchestrationPollingInterval);
this.activityBackoffHelper = new BackoffPollingHelper(TimeSpan.FromMilliseconds(50), this.settings.MaxActivityPollingInterval);
this.orchestrationBackoffHelper = new BackoffPollingHelper(
this.settings.MinOrchestrationPollingInterval,
this.settings.MaxOrchestrationPollingInterval,
this.settings.DeltaBackoffOrchestrationPollingInterval);
this.activityBackoffHelper = new BackoffPollingHelper(
this.settings.MinActivityPollingInterval,
this.settings.MaxActivityPollingInterval,
this.settings.DeltaBackoffActivityPollingInterval);
this.traceHelper = new LogHelper(this.settings.LoggerFactory.CreateLogger("DurableTask.SqlServer"));
this.dbManager = new SqlDbManager(this.settings, this.traceHelper);
this.lockedByValue = $"{this.settings.AppName},{Process.GetCurrentProcess().Id}";
Expand Down
32 changes: 32 additions & 0 deletions src/DurableTask.SqlServer/SqlOrchestrationServiceSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ public SqlOrchestrationServiceSettings(string connectionString, string? taskHubN
[JsonProperty("maxActiveOrchestrations")]
public int MaxActiveOrchestrations { get; set; } = Environment.ProcessorCount;

/// <summary>
/// Gets or sets the minimum interval to poll for orchestrations.
/// Polling interval increases when no orchestrations or activities are found.
/// The default value is 50 milliseconds.
/// </summary>
[JsonProperty("minOrchestrationPollingInterval")]
public TimeSpan MinOrchestrationPollingInterval { get; set; } = TimeSpan.FromMilliseconds(50);

/// <summary>
/// Gets or sets the maximum interval to poll for orchestrations.
/// Polling interval increases when no orchestrations or activities are found.
Expand All @@ -101,6 +109,22 @@ public SqlOrchestrationServiceSettings(string connectionString, string? taskHubN
[JsonProperty("maxOrchestrationPollingInterval")]
public TimeSpan MaxOrchestrationPollingInterval { get; set; } = TimeSpan.FromSeconds(3);

/// <summary>
/// Gets or sets the delta backoff interval to poll for orchestrations.
/// Polling interval increases by this delta when no orchestrations are found.
/// The default value is 50 milliseconds.
/// </summary>
[JsonProperty("deltaBackoffOrchestrationPollingInterval")]
public TimeSpan DeltaBackoffOrchestrationPollingInterval { get; set; } = TimeSpan.FromMilliseconds(50);

/// <summary>
/// Gets or sets the minimum interval to poll for activities.
/// Polling interval increases when no activities are found.
/// The default value is 50 milliseconds.
/// </summary>
[JsonProperty("minActivityPollingInterval")]
public TimeSpan MinActivityPollingInterval { get; set; } = TimeSpan.FromMilliseconds(50);

/// <summary>
/// Gets or sets the maximum interval to poll for activities.
/// Polling interval increases when no activities are found.
Expand All @@ -109,6 +133,14 @@ public SqlOrchestrationServiceSettings(string connectionString, string? taskHubN
[JsonProperty("maxActivityPollingInterval")]
public TimeSpan MaxActivityPollingInterval { get; set; } = TimeSpan.FromSeconds(3);

/// <summary>
/// Gets or sets the delta backoff interval to poll for activities.
/// Polling interval increases by this delta when no activities are found.
/// The default value is 50 milliseconds.
/// </summary>
[JsonProperty("deltaBackoffActivityPollingInterval")]
public TimeSpan DeltaBackoffActivityPollingInterval { get; set; } = TimeSpan.FromMilliseconds(50);

/// <summary>
/// Gets or sets a flag indicating whether the database should be automatically created if it does not exist.
/// </summary>
Expand Down

0 comments on commit b3a7bf4

Please sign in to comment.