I have an application running in Azure. It has a .NET framework API deployed as an App Service, connected to a Microsoft Sql Server. The .NET framework app uses Entity Framework Code First to access the database.
Usually, the application runs smoothly. However, from time to time, one single endpoint becomes unresponsive (i.e. takes minutes to return an answer). This endpoint is doing a query, through EntityFramework, and retrieving just a few data points from the database. This is the code, executed for 2 to 8 sensors (does not make any difference):
List<Measurement> result = CreateContext().Measurements
.Where(m => m.MeasurementSeries.SensorInfoID == sensorId)
.Where(m => m.MeasurementSeries.StartTime <= toTime && m.MeasurementSeries.EndTime >= fromTime)
.Where(m => m.Time > fromTime && m.Time <= toTime)
.OrderByDescending(m => m.Time)
.ToList();
By looking at the metrics (from ApplicationInsight, too) I see no weird query being executed. I see the expected query, and the database compute utilization jumping to 100%.
The same query, executed from the same code, connected to the same remote database, but with the .NET Framework app running locally, takes less than a second and less than 1% compute from the database. When the query (eventually) finishes, the database compute utilization goes back to zero. The API compute utilization is very low, always. Executing the same SQL query directly to the database takes less than a second.
All other endpoints, some of which make heavier queries to the database, work fine.
I tried re-running the same query multiple times and from multiple sources, restarting, stopping and starting, re-deploying the application. Nothing happens. Last time, after half a day, it just started working again. This time it's been over a day, and nothing.
Do you have any pointer to where to look for the issue? If there are more information I can provide, please let me know, because I may have not thought about them and it can help me figuring out the problem, too.