Very slow SqlConnection OpenAsync/Open with Azure App Service and Azure SQL Database

Daniel Stout 16 Reputation points
2023-07-13T19:59:57.39+00:00

Periodically throughout the day, some requests to our App Service will be very slow.

Normally the Sql Connection's OpenAsync completes in less than 1ms, but it will sometimes take 5000+ms to complete.

Some other details:

  • The app service is running an ASP.NET Core 7 website
  • The app service is marked as "Always On"
  • The database is in a Standard elastic pool and is not under any load (30% DTU utilization)
  • Immediately after this slow request, the OpenAsync calls will complete very quickly again
Azure SQL Database
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
{count} vote

1 answer

Sort by: Most helpful
  1. ajkuma 28,111 Reputation points Microsoft Employee Moderator
    2023-07-14T12:17:42.86+00:00

    @Daniel Stout ,

    1/2

    Based on my understanding of your issue description, it seems like you are experiencing slow SqlConnection.Open or OpenAsync() method with Azure App Service and Azure SQL Database periodically and have tried some steps to isolate the issue.

    To narrow-down the issue further, there could be several reasons for this issue. 

    1.One of the reasons could be that you are hitting the limit while making new outbound connections. The limits you can hit include TCP Connections, which is associated with the size of the worker used. Each instance on Azure App service is initially given a pre-allocated number of 128 SNAT ports.
    The SNAT port limit affects opening connections to the same address and port combination.

    2.If your app creates connections to a mix of address and port combinations, you will not use up your SNAT ports. The SNAT ports are used up when you have repeated calls to the same address and port combination. Once a port has been released, the port is available for reuse as needed. The Azure Network load balancer reclaims SNAT port from closed connections only after waiting for 4 minutes.

     

    As outlined in this doc section #2-collect-data / review the logs to fetch more info.

    App Service provides diagnostic functionality for logging information from both the web server and the web application.

    Reference:

    Troubleshooting intermittent outbound connection errors in Azure App Service


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.