Calling Azure function 150 times over HTTP throws an exception

I am running asp.net mvc web application on Azure. In one method, I make several HTTP requests to the Azure API. As part of this Azure feature, I use DbContextto insert new records into the database.

// Method in web application making http requests to azure function web api
public async Task CreateRecords() {
    int amountOfCalls = 150;
    var allTasks = new List<Task<HttpResponseMessage>>();

    for (int i = 0; i < amountOfCalls; i++) {
        var task = HttpClientInstance.Instance.PostAsync(<uri>, new StringContent(i.ToString()));
        allTasks.Add(task);
    }

    await Task.WhenAll(allTasks); // Gives an exception
}

If the parameter is amountOfCallsset to 25, 50, or 100, everything is fine. However, when I set amountOfCallsto 150, it initially inserts some records into the database, but in the end this leads to an error:

Unable to connect to the remote server.

So, at first I thought it should be something with the maximum concurrent entries of the Azure sql database. So I upgraded it to the S9 price level (1600 DTU with a maximum of 3200 simultaneous inputs marked here ).

. , Azure. Azure. , Application Insights. , DbContext ( ):

type: System.InvalidOperationException

: WebApp.DataAccess.PocDbContext..ctor

requestName: InsertRecordFunction

requestDuration: 55,643.2201

Azure :

[DependencyInjectionConfig(typeof(DependencyConfig))] // Autofac
public static class InsertRecordFunction
{
    [FunctionName("InsertRecordFunction")]
    public static async Task<HttpResponseMessage> Run(
        [HttpTrigger(AuthorizationLevel.Function, "post", Route = "InsertRecordFunction")]HttpRequestMessage req,
        TraceWriter log,
        [Inject]IRecordDataService recordDataService)
    {
        log.Info("InsertRecordFunction was triggered by Http.");
        try {
            await recordDataService.AddRandomRecordAsync();
        }
        catch (Exception ex) {
            return req.CreateErrorResponse(HttpStatusCode.InternalServerError, ex);
        }

        return req.CreateResponse(HttpStatusCode.OK);
    }

ctor PocDbContext :

public PocDbContext() : base("DefaultConnection") {
    Database.SetInitializer<PocDbContext>(null);
}

, Azure sql. , SqlAzureExecutionStrategy ( ).

- - api Azure Web App, () HttpClient? , , ? .

Update

Application Insights :

. . , - , .

, Azure sql.

+4
1

ADO.NET, Entity Framework ( SQL Server (ADO.NET)):

ADO.NET. , , .

:

, , (100 ).

Max Pool Size > 150 .

+3

Source: https://habr.com/ru/post/1690747/


All Articles