Azure Web Api - Waiting for Sql Connectivity every 4 minutes and 30 minutes

In the ApiController request, I track the length of time I wait for Sql Connection to open.

await t.TrackDependencyAsync(async() => { await sqlConnection.OpenAsync(); return true; }, "WaitingSqlConnection"); 


If my request is not called for at least 5 minutes, then any new call will see that the duration of OpenAsync will be huge (c. 3s) instead of immediate.

I would like to understand the reason to eradicate this crazy slowness.

UPDATE

I created an endpoint to open SqlConnection . If I wait more than 5 minutes, then call this OpenConnection , then call any other request, OpenConnection will bear the expected cost indicated above, but the request will not.

Therefore, I planned to work on Azure to start every minute and call the OpenConnection . However, when I make requests from my http client, I take the time out. It was as if the open SqlConnection was somehow associated with http client ip ...

In addition, these 5-minute windows are typical of DNS TTL ... However, 3s for the DNS lookup of the database endpoint is too long. It can't be.

UPDATE 2

The time observed at the htt client level seems to be the result of both a pending connection and some other delays (dns lookup?).

Here is a table summarizing what I am observing:

enter image description here

UPDATE 3

The difference between rows 3 and 4 of my table is the time spent in TCP / IP Connect and HTTPS Handshake according to Fiddler. Let not concentrate on this on this post, but only on the time spent waiting for the opening of SqlConnection .

UPDATE 4

In fact, I think that both moments of expectation have the same reason.
The server needs to “maintain” its connection to the database, and the client needs to “support” its connection to the server.

UPDATE 5

I had a job working every 4 minutes to open SqlConnection , but from time to time it depended on the expected cost. Therefore, I think the idle time is 4 minutes, not 5 (therefore, I updated this post).
Therefore, I updated the scheduled work every minute. then I realized that they still bear the expected cost, but regularly every 30 minutes (therefore, I updated this heading).
These two times strangely correlate with those of Azure Load Balancing Wait Timeout .

+5
source share

Source: https://habr.com/ru/post/1264667/


All Articles