What could be causing a very wide range in performace for a SQL query from Azure Functions?

Andrew Hawes 181 Reputation points
2021-07-23T14:27:22.647+00:00

I have a WPF application that uses an API running on Azure Functions as the backend. The API is written in C# and uses EF to store and retrieve data from an Azure SQL Serverless database. Most of the time the application is very performant. However, users do notice significant delay from time to time. Using AppInsights logs and metrics I have identified that at least some of the problem lies in the fact that in a small but significant number of cases a process that usually takes less than 2 milliseconds and 95% of the time takes less than 170 milliseconds can sometimes take over 15 seconds. In this example case the process is just a simple get entity request where I am retrieving and entity by id. For all these cases the query is identical except for the id may change. And this process is just the time from when the Azure Functions C# code executes a query and gets a response. So this should be just the Azure Functions server requesting data from the Azure SQL server and getting the results. Why would this sometimes take over 15 seconds and how can I fix this.

I have a support ticket open with Azure SQL support but so far they don't have any answers. So, I thought I would ask around.

117502-image.png

Azure SQL Database
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,999 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. KalyanChanumolu-MSFT 8,331 Reputation points
    2021-07-26T04:40:44.91+00:00

    @Andrew Hawes Thank you for reaching out.

    You mentioned that you are using Azure SQL Serverless database.

    When there are no requests to an Azure SQL Serverless database for an extended period, the database is put into a paused state to save cost. More details are here
    The first request to a database in a "paused state" will "resume" the database first and then perform a query operation. This usually results in an increased response time.
    I suspect this to be the issue in your case.

    To check the Auto-Pause configuration, please navigate to the Overview blade for your database on the Azure portal.
    117759-image.png

    Serverless database is a great choice for burst workloads where you can predict the utilization patterns and can afford the latency in resuming from a paused state.
    Otherwise, you should switch to a provisioned pricing tier instead.

    Please let us know if you have any further questions.

    ----------

    If an answer is helpful, please "Accept answer" or "Up-Vote" which might help other community members reading this thread.


Your answer

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