Skip to content

Commit 5b43303

Browse files
authored
Merge pull request #107918 from lisaguthrie/faqupdates
Updates around throttling
2 parents bd40e9f + f2b9f46 commit 5b43303

File tree

3 files changed

+73
-35
lines changed

3 files changed

+73
-35
lines changed

articles/azure-app-configuration/enable-dynamic-configuration-aspnet-core.md

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ ms.custom: mvc
2121
---
2222
# Tutorial: Use dynamic configuration in an ASP.NET Core app
2323

24-
ASP.NET Core has a pluggable configuration system that can read configuration data from a variety of sources. It can handle changes on the fly without causing an application to restart. ASP.NET Core supports the binding of configuration settings to strongly typed .NET classes. It injects them into your code by using the various `IOptions<T>` patterns. One of these patterns, specifically `IOptionsSnapshot<T>`, automatically reloads the application's configuration when the underlying data changes. You can inject `IOptionsSnapshot<T>` into controllers in your application to access the most recent configuration stored in Azure App Configuration.
24+
ASP.NET Core has a pluggable configuration system that can read configuration data from a variety of sources. It can handle changes dynamically without causing an application to restart. ASP.NET Core supports the binding of configuration settings to strongly typed .NET classes. It injects them into your code by using the various `IOptions<T>` patterns. One of these patterns, specifically `IOptionsSnapshot<T>`, automatically reloads the application's configuration when the underlying data changes. You can inject `IOptionsSnapshot<T>` into controllers in your application to access the most recent configuration stored in Azure App Configuration.
2525

26-
You also can set up the App Configuration ASP.NET Core client library to refresh a set of configuration settings dynamically using a middleware. As long as the web app continues to receive requests, the configuration settings continue to get updated with the configuration store.
26+
You also can set up the App Configuration ASP.NET Core client library to refresh a set of configuration settings dynamically using a middleware. The configuration settings get updated with the configuration store each time as long as the web app receives requests.
2727

28-
In order to keep the settings updated and avoid too many calls to the configuration store, a cache is used for each setting. Until the cached value of a setting has expired, the refresh operation does not update the value, even when the value has changed in the configuration store. The default expiration time for each request is 30 seconds, but it can be overridden if required.
28+
App Configuration automatically caches each setting to avoid too many calls to the configuration store. The refresh operation waits until the cached value of a setting expires to update that setting, even when its value changes in the configuration store. The default cache expiration time is 30 seconds. You can override this expiration time, if necessary.
2929

3030
This tutorial shows how you can implement dynamic configuration updates in your code. It builds on the web app introduced in the quickstarts. Before you continue, finish [Create an ASP.NET Core app with App Configuration](./quickstart-aspnet-core-app.md) first.
3131

@@ -45,6 +45,16 @@ To do this tutorial, install the [.NET Core SDK](https://dotnet.microsoft.com/do
4545

4646
Before you continue, finish [Create an ASP.NET Core app with App Configuration](./quickstart-aspnet-core-app.md) first.
4747

48+
## Add a sentinel key
49+
50+
A *sentinel key* is a special key used to signal when configuration has changed. Your app monitors the sentinel key for changes. When a change is detected, you refresh all configuration values. This approach reduces the overall number of requests made by your app to App Configuration, compared to monitoring all keys for changes.
51+
52+
1. In the Azure portal, select **Configuration Explorer > Create > Key-value**.
53+
54+
1. For **Key**, enter *TestApp:Settings:Sentinel*. For **Value**, enter 1. Leave **Label** and **Content type** blank.
55+
56+
1. Select **Apply**.
57+
4858
## Reload data from App Configuration
4959

5060
1. Add a reference to the `Microsoft.Azure.AppConfiguration.AspNetCore` NuGet package by running the following command:
@@ -68,11 +78,10 @@ Before you continue, finish [Create an ASP.NET Core app with App Configuration](
6878
{
6979
options.Connect(settings["ConnectionStrings:AppConfig"])
7080
.ConfigureRefresh(refresh =>
71-
{
72-
refresh.Register("TestApp:Settings:BackgroundColor")
73-
.Register("TestApp:Settings:FontColor")
74-
.Register("TestApp:Settings:Message");
75-
});
81+
{
82+
refresh.Register("TestApp:Settings:Sentinel", refreshAll: true)
83+
.SetCacheExpiration(new TimeSpan(0, 5, 0));
84+
});
7685
});
7786
})
7887
.UseStartup<Startup>();
@@ -88,21 +97,27 @@ Before you continue, finish [Create an ASP.NET Core app with App Configuration](
8897
{
8998
var settings = config.Build();
9099
config.AddAzureAppConfiguration(options =>
91-
{
100+
{
92101
options.Connect(settings["ConnectionStrings:AppConfig"])
93-
.ConfigureRefresh(refresh =>
94-
{
95-
refresh.Register("TestApp:Settings:BackgroundColor")
96-
.Register("TestApp:Settings:FontColor")
97-
.Register("TestApp:Settings:Message");
98-
});
102+
.ConfigureRefresh(refresh =>
103+
{
104+
refresh.Register("TestApp:Settings:Sentinel", refreshAll: true)
105+
.SetCacheExpiration(new TimeSpan(0, 5, 0));
106+
});
99107
});
100108
})
101109
.UseStartup<Startup>());
102110
```
103111
---
104112
105-
The `ConfigureRefresh` method is used to specify the settings used to update the configuration data with the App Configuration store when a refresh operation is triggered. In order to actually trigger a refresh operation, a refresh middleware needs to be configured for the application to refresh the configuration data when any change occurs.
113+
The `ConfigureRefresh` method is used to specify the settings used to update the configuration data with the App Configuration store when a refresh operation is triggered. The `refreshAll` parameter to the `Register` method indicates that all configuration values should be refreshed if the sentinel key changes.
114+
115+
Also, the `SetCacheExpiration` method overrides the default cache expiration time of 30 seconds, specifying a time of 5 minutes instead. This reduces the number of requests made to App Configuration.
116+
117+
> [!NOTE]
118+
> For testing purposes, you may want to lower the cache expiration time.
119+
120+
To actually trigger a refresh operation, you'll need to configure a refresh middleware for the application to refresh the configuration data when any change occurs. You'll see how to do this in a later step.
106121
107122
2. Add a *Settings.cs* file that defines and implements a new `Settings` class.
108123
@@ -199,10 +214,7 @@ Before you continue, finish [Create an ASP.NET Core app with App Configuration](
199214
```
200215
---
201216
202-
The middleware uses the refresh configuration specified in the `AddAzureAppConfiguration` method in `Program.cs` to trigger a refresh for each request received by the ASP.NET Core web app. For each request, a refresh operation is triggered and the client library checks if the cached value for the registered configuration settings have expired. For the cached values that have expired, the values for the settings are updated with the App Configuration store, and the remaining values remain unchanged.
203-
204-
> [!NOTE]
205-
> The default cache expiration time for a configuration setting is 30 seconds, but can be overridden by calling the `SetCacheExpiration` method on the options initializer passed as an argument to the `ConfigureRefresh` method.
217+
The middleware uses the refresh configuration specified in the `AddAzureAppConfiguration` method in `Program.cs` to trigger a refresh for each request received by the ASP.NET Core web app. For each request, a refresh operation is triggered and the client library checks if the cached value for the registered configuration setting has expired. If it's expired, it's refreshed.
206218
207219
## Use the latest configuration data
208220
@@ -279,7 +291,7 @@ Before you continue, finish [Create an ASP.NET Core app with App Configuration](
279291
}
280292
h1 {
281293
color: @ViewData["FontColor"];
282-
font-size: @ViewData["FontSize"];
294+
font-size: @ViewData["FontSize"]px;
283295
}
284296
</style>
285297
<head>
@@ -297,38 +309,35 @@ Before you continue, finish [Create an ASP.NET Core app with App Configuration](
297309
298310
dotnet build
299311
300-
2. After the build successfully completes, run the following command to run the web app locally:
312+
1. After the build successfully completes, run the following command to run the web app locally:
301313
302314
dotnet run
315+
1. Open a browser window, and go to the URL shown in the `dotnet run` output.
303316
304-
3. Open a browser window, and go to `http://localhost:5000`, which is the default URL for the web app hosted locally.
305-
306-
![Quickstart app launch local](./media/quickstarts/aspnet-core-app-launch-local-before.png)
317+
![Launching quickstart app locally](./media/quickstarts/aspnet-core-app-launch-local-before.png)
307318
308-
4. Sign in to the [Azure portal](https://portal.azure.com). Select **All resources**, and select the App Configuration store instance that you created in the quickstart.
319+
1. Sign in to the [Azure portal](https://portal.azure.com). Select **All resources**, and select the App Configuration store instance that you created in the quickstart.
309320
310-
5. Select **Configuration Explorer**, and update the values of the following keys:
321+
1. Select **Configuration Explorer**, and update the values of the following keys:
311322
312323
| Key | Value |
313324
|---|---|
314325
| TestApp:Settings:BackgroundColor | green |
315326
| TestApp:Settings:FontColor | lightGray |
316327
| TestApp:Settings:Message | Data from Azure App Configuration - now with live updates! |
328+
| TestApp:Settings:Sentinel | 2 |
317329
318-
6. Refresh the browser page to see the new configuration settings. More than one refresh of the browser page may be required for the changes to be reflected.
330+
1. Refresh the browser page to see the new configuration settings. You may need to refresh more than once for the changes to be reflected.
319331
320-
![Quickstart app refresh local](./media/quickstarts/aspnet-core-app-launch-local-after.png)
321-
322-
> [!NOTE]
323-
> Since the configuration settings are cached with a default expiration time of 30 seconds, any changes made to the settings in the App Configuration store would only be reflected in the web app when the cache has expired.
332+
![Launching updated quickstart app locally](./media/quickstarts/aspnet-core-app-launch-local-after.png)
324333
325334
## Clean up resources
326335
327336
[!INCLUDE [azure-app-configuration-cleanup](../../includes/azure-app-configuration-cleanup.md)]
328337
329338
## Next steps
330339
331-
In this tutorial, you enabled your ASP.NET Core web app to dynamically refresh configuration settings from App Configuration. To learn how to use an Azure managed identity to streamline the access to App Configuration, continue to the next tutorial.
340+
In this tutorial, you enabled your ASP.NET Core web app to dynamically refresh configuration settings from App Configuration. To learn how to use an Azure-managed identity to streamline the access to App Configuration, continue to the next tutorial.
332341
333342
> [!div class="nextstepaction"]
334343
> [Managed identity integration](./howto-integrate-azure-managed-service-identity.md)

articles/azure-app-configuration/faq.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ See [best practices](./howto-best-practices.md).
6363

6464
## How much does App Configuration cost?
6565

66-
There are two pricing tiers:
66+
There are two pricing tiers:
6767

6868
- Free tier
6969
- Standard tier.
@@ -95,6 +95,25 @@ You can upgrade from the Free tier to the Standard tier at any time.
9595

9696
You can't downgrade a store from the Standard tier to the Free tier. You can create a new store in the Free tier and then [import configuration data into that store](howto-import-export-data.md).
9797

98+
## Are there any limits on the number of requests made to App Configuration?
99+
100+
Configuration stores in the Free tier are limited to 1,000 requests per day. Configuration stores in the Standard tier may experience temporary throttling when the request rate exceeds 20,000 requests per hour.
101+
102+
When a store reaches its limit, it will return HTTP status code 429 for all requests made until the time period expires. The `retry-after-ms` header in the response gives a suggested wait time (in milliseconds) before retrying the request.
103+
104+
If your application regularly experiences HTTP status code 429 responses, consider redesigning it to reduce the number of requests made. For more information, see [Reduce requests made to App Configuration](./howto-best-practices.md#reduce-requests-made-to-app-configuration)
105+
106+
## My application receives HTTP status code 429 responses. Why?
107+
108+
You'll receive an HTTP status code 429 response under these circumstances:
109+
110+
* Exceeding the daily request limit for a store in the Free tier.
111+
* Temporary throttling due to a high request rate for a store in the Standard tier.
112+
* Excessive bandwidth usage.
113+
* Attempting to create or modify a key when the storage quote is exceeded.
114+
115+
Check the body of the 429 response for the specific reason why the request failed.
116+
98117
## How can I receive announcements on new releases and other information related to App Configuration?
99118

100119
Subscribe to our [GitHub announcements repo](https://github.com/Azure/AppConfiguration-Announcements).

articles/azure-app-configuration/howto-best-practices.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,19 @@ You can provide access to App Configuration for web apps or functions by using a
6969
* Use Azure managed identities to access the App Configuration store. For more information, see [Integrate with Azure managed identities](howto-integrate-azure-managed-service-identity.md).
7070
* Push configuration from App Configuration to App Service. App Configuration provides an export function (in Azure portal and the Azure CLI) that sends data directly into App Service. With this method, you don't need to change the application code at all.
7171

72+
## Reduce requests made to App Configuration
73+
74+
Excessive requests to App Configuration can result in throttling or overage charges. To reduce the number of requests made:
75+
76+
* Increase the refresh timeout, especially if your configuration values do not change frequently. Specify a new refresh timeout using the [`SetCacheExpiration` method](/dotnet/api/microsoft.extensions.configuration.azureappconfiguration.azureappconfigurationrefreshoptions.setcacheexpiration).
77+
78+
* Watch a single *sentinel key*, rather than watching individual keys. Refresh all configuration only if the sentinel key changes. See [Use dynamic configuration in an ASP.NET Core app](enable-dynamic-configuration-aspnet-core.md) for an example.
79+
80+
* Use Azure Event Grid to receive notifications when configuration changes, rather than constantly polling for any changes. See [Route Azure App Configuration events to a web endpoint](./howto-app-configuration-event.md) for more information
81+
7282
## Importing configuration data into App Configuration
7383

74-
App Configuration offers the option to bulk [import](https://aka.ms/azconfig-importexport1) your configuration settings from your current configuration files using either the Azure Portal or CLI. You can also use the same options to export values from App Configuration, for example between related stores. If you’d like to set up an ongoing sync with your GitHub repo, you can use our [GitHub Action](https://aka.ms/azconfig-gha2) so that you can continue using your existing source control practices while getting the benefits of App Configuration.
84+
App Configuration offers the option to bulk [import](https://aka.ms/azconfig-importexport1) your configuration settings from your current configuration files using either the Azure portal or CLI. You can also use the same options to export values from App Configuration, for example between related stores. If you’d like to set up an ongoing sync with your GitHub repo, you can use our [GitHub Action](https://aka.ms/azconfig-gha2) so that you can continue using your existing source control practices while getting the benefits of App Configuration.
7585

7686
## Next steps
7787

0 commit comments

Comments
 (0)