0

I have an ASP.NET Core 6 application using EF Core and SQL Azure 'Business Critical' pricing tier with 2 VCPUs. 90% of the time the application is lightning fast, but occasionally throughout the day, it will get into a state where the requests are very slow...10-15 seconds. This sluggishness lasts for 1-2 mins then everything is back to normal.

I have lots of logging installed and so far I have not been able to pinpoint the problem. I use Serilog and SEQ to find long running requests and queries and my research as been unfruitful. When I see a long running request, I look at other requests around that time period to see whats going on and nothing obvious jumps out.

Web server CPU, database CPU are never anywhere close to pegged when this problem occurs (or ever). When the problem occurs, there also doesn't appear to be any blocking. I have a script that I can run to identify blocking queries and it doesn't return any result.

It definitely feels like a database problem though, because when the problem occurs I can hit endpoints with no database access and they return very fast...under 100ms. When I hit an endpoint with database calls, they hang until the "problem" is over, and then everything responds sub 100ms again. It doesn't seem to matter what table is being accessed so there isn't any locking going on that would affect this.

Azure Web App (2 instances Premium v2) Azure SQL Database: Business Critical tier with 2 VCPU

I would love some ideas of where to look or where to add some logging.

UPDATE: SEQ logs show that during the request pipeline, the database calls are definitely hanging, but it doesn't appear to be happening on the database side, it appears to be happening on the webserver itself.

When the problem occurs, I point my local dev environment at the production SQL server, it still handles requests instantly. It now feels like it is something on the WebServer but only as it relates to SQL calls. If the endpoint has no SQL calls, it responds instantly. Could there be an issue with EF core leaving connections open to the DB?

5
  • 1
    Enable azure application insights then you can do end to end tracing and much more. learn.microsoft.com/en-us/azure/azure-monitor/app/asp-net-core. And learn.microsoft.com/en-us/azure/azure-sql/database/… Commented Dec 24, 2023 at 20:47
  • In summary, very slow is 10 seconds, and normal is two seconds? Commented Dec 25, 2023 at 10:54
  • @GregAskew no. Normal is sub 100ms, when the problem occurs requests take 10-20 seconds...sometimes more. Commented Dec 27, 2023 at 13:47
  • Some new information: When the problem occurs, I point my local dev environment at the production SQL server, it still handles requests instantly. It now feels like it is something on the WebServer but only as it relates to SQL calls. If the endpoint has no SQL calls, it responds instantly. Could there be an issue with EF core leaving connections open to the DB? Commented Jan 10, 2024 at 14:27
  • Could there be an issue with EF core leaving connections open to the DB? no, and it's fairly easy to verify this, and contexts are created and deleted and typically don't have resources open long. You also probably don't need any sophisticated EF features either. Commented Jan 10, 2024 at 15:32

1 Answer 1

0

Make sure the issue is not associated with the Azure SQL automated backups and their impact in performance while they occur. The following query can help you correlate that. The query return dates in UTC time.

Select * from sys.dm_database_backups ORDER BY backup_finish_date DESC 

In addition, outdated statistics may be causing high compilation times of T-SQL statements impacting then the performance. Please set asynchronous statistics update on using below ALTER statement. In addition, use Ola Hallengren scripts to defragment indexes and update statistics daily.

ALTER DATABASE [YourDatabaseName] SET AUTO_UPDATE_STATISTICS_ASYNC ON

5
  • It looks like backups are running every 5 mins based on that query. I haven't found specific timing related to the the issue im having. It appears to happen randomly, probably 1-2 times a day. Commented Dec 27, 2023 at 13:47
  • Verify if differential or full backups occur at that time. Transaction Log backups should no impact performance. Commented Dec 27, 2023 at 14:28
  • Yea, the timestamps don't seem to correlate to anything. Differential is happening once a week, and incremental twice a day and log every 5 mins. Commented Dec 27, 2023 at 15:15
  • @ChrisKooken try further instructions I just added to my original answer. Commented Dec 28, 2023 at 12:57
  • thanks! I've read a bit about this and turned it on to see how it performs over the next few days Commented Dec 28, 2023 at 18:20

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.