Skip to content

Commit

Permalink
Update MaxQueuePollingInterval default for Flex Consumption apps (#2953)
Browse files Browse the repository at this point in the history
  • Loading branch information
bachuv authored Dec 3, 2024
1 parent 93eddb6 commit 62f1d13
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 1 deletion.
2 changes: 2 additions & 0 deletions release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

### New Features

- Update MaxQueuePollingInterval default for Flex Consumption apps #2953

### Bug Fixes

### Breaking Changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/// <summary>
/// Gets or sets the name of the Azure Storage connection information used to manage the underlying Azure Storage resources.
Expand Down Expand Up @@ -160,9 +161,36 @@ public string TrackingStoreConnectionStringName

/// <summary>
/// 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.
/// </summary>
/// <value>Maximum interval for polling control and work-item queues.</value>
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;
}
}

/// <summary>
/// Determines whether or not to use the old partition management strategy, or the new
Expand Down
59 changes: 59 additions & 0 deletions test/FunctionsV2/AzureStorageOptionsTests.cs
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit 62f1d13

Please sign in to comment.