Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds config for min and delta backoff poll intervals #174

Merged
merged 2 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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