diff --git a/release_notes.md b/release_notes.md index 3babbb06b..812793b79 100644 --- a/release_notes.md +++ b/release_notes.md @@ -20,6 +20,8 @@ ### New Features +- Update MaxQueuePollingInterval default for Flex Consumption apps #2953 + ### Bug Fixes ### Breaking Changes diff --git a/src/WebJobs.Extensions.DurableTask/Options/AzureStorageOptions.cs b/src/WebJobs.Extensions.DurableTask/Options/AzureStorageOptions.cs index fa5bba98e..500ba04b3 100644 --- a/src/WebJobs.Extensions.DurableTask/Options/AzureStorageOptions.cs +++ b/src/WebJobs.Extensions.DurableTask/Options/AzureStorageOptions.cs @@ -18,6 +18,7 @@ public class AzureStorageOptions private const int MaxTaskHubNameSize = 45; private const int MinTaskHubNameSize = 3; private const string TaskHubPadding = "Hub"; + private TimeSpan maxQueuePollingInterval; /// /// Gets or sets the name of the Azure Storage connection information used to manage the underlying Azure Storage resources. @@ -160,9 +161,36 @@ public string TrackingStoreConnectionStringName /// /// Gets or sets the maximum queue polling interval. + /// We update the default value to 1 second for the Flex Consumption SKU + /// because of a known cold start latency with Flex Consumption + /// and Durable Functions. + /// The default value is 30 seconds for all other SKUs. /// /// Maximum interval for polling control and work-item queues. - public TimeSpan MaxQueuePollingInterval { get; set; } = TimeSpan.FromSeconds(30); + public TimeSpan MaxQueuePollingInterval + { + get + { + if (this.maxQueuePollingInterval == TimeSpan.Zero) + { + if (string.Equals(Environment.GetEnvironmentVariable("WEBSITE_SKU"), "FlexConsumption", StringComparison.OrdinalIgnoreCase)) + { + this.maxQueuePollingInterval = TimeSpan.FromSeconds(1); + } + else + { + this.maxQueuePollingInterval = TimeSpan.FromSeconds(30); + } + } + + return this.maxQueuePollingInterval; + } + + set + { + this.maxQueuePollingInterval = value; + } + } /// /// Determines whether or not to use the old partition management strategy, or the new diff --git a/test/FunctionsV2/AzureStorageOptionsTests.cs b/test/FunctionsV2/AzureStorageOptionsTests.cs new file mode 100644 index 000000000..a54845c1b --- /dev/null +++ b/test/FunctionsV2/AzureStorageOptionsTests.cs @@ -0,0 +1,59 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Xunit; + +namespace Microsoft.Azure.WebJobs.Extensions.DurableTask.Tests +{ + public class AzureStorageOptionsTests + { +#if !FUNCTIONS_V1 + [Fact] + [Trait("Category", PlatformSpecificHelpers.TestCategory)] + public void MaxQueuePollingInterval_NonFlexConsumption_DefaultValue() + { + Environment.SetEnvironmentVariable("WEBSITE_SKU", "Free"); + + var options = new AzureStorageOptions(); + Assert.Equal(TimeSpan.FromSeconds(30), options.MaxQueuePollingInterval); + } + + [Fact] + [Trait("Category", PlatformSpecificHelpers.TestCategory)] + public void MaxQueuePollingInterval_NonFlexConsumption_SetCustomValue() + { + Environment.SetEnvironmentVariable("WEBSITE_SKU", "Free"); + + var options = new AzureStorageOptions(); + options.MaxQueuePollingInterval = TimeSpan.FromSeconds(4); + Assert.Equal(TimeSpan.FromSeconds(4), options.MaxQueuePollingInterval); + } + + [Fact] + [Trait("Category", PlatformSpecificHelpers.TestCategory)] + public void MaxQueuePollingInterval_FlexConsumption_DefaultValue() + { + Environment.SetEnvironmentVariable("WEBSITE_SKU", "FlexConsumption"); + + var options = new AzureStorageOptions(); + Assert.Equal(TimeSpan.FromSeconds(1), options.MaxQueuePollingInterval); + } + + [Fact] + [Trait("Category", PlatformSpecificHelpers.TestCategory)] + public void MaxQueuePollingInterval_FlexConsumption_SetCustomValue() + { + Environment.SetEnvironmentVariable("WEBSITE_SKU", "FlexConsumption"); + + var options = new AzureStorageOptions(); + options.MaxQueuePollingInterval = TimeSpan.FromSeconds(6); + Assert.Equal(TimeSpan.FromSeconds(6), options.MaxQueuePollingInterval); + } +#endif + } +}