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 DbContext
to insert new records into the database.
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);
}
If the parameter is amountOfCalls
set to 25, 50, or 100, everything is fine. However, when I set amountOfCalls
to 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))]
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.