Skip to end of metadata
Go to start of metadata

You are viewing an old version of this content. View the current version.

Compare with Current View Version History

« Previous Version 4 Current »

Functions in a function app share resources. Among those shared resources are connections: HTTP connections, database connections, and connections to services such as Azure Storage.

The potentiel issue

The method to avoid to use more connections that we need

We can reuse client instances rather than creating new ones with each function invocation : use a single static client (for example, .NET clients - HttpClient, DocumentClient, Azure Storage Clients,…).

Example with Http request

// Create a single, static HttpClient
private static HttpClient httpClient = new HttpClient();

public static async Task Run(string input)
{
    var response = await httpClient.GetAsync("https://example.com");
    // Rest of function
}

Remark : We don't dispose of a static client because we aren't done using it when the function ends. We want the static client to live for the duration of the application. So, we don’t need to implement the IDisposable Interface in code.

Example with zure Cosmos DB client

  • No labels