-
Notifications
You must be signed in to change notification settings - Fork 319
Description
Every time you create a new instance of SqlConnection, if the connection string's RetryCount is equal to 1 (which is the default value) SqlClient will attempt to subtly replace it with 5 if it determines that the host is azure synapse on demand endpoint.
SqlClient/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnection.cs
Lines 423 to 429 in 6d2473d
| _connectRetryCount = connString.ConnectRetryCount; | |
| // For Azure Synapse ondemand connections, set _connectRetryCount to 5 instead of 1 to greatly improve recovery | |
| // success rate. Note: Synapse should be detected first as it could be detected as a regular Azure SQL DB endpoint. | |
| if (_connectRetryCount == 1 && ADP.IsAzureSynapseOnDemandEndpoint(connString.DataSource)) | |
| { | |
| _connectRetryCount = 5; | |
| } |
The problem is that to determine that SqlClient concats prefix -ondemand with a collection of specific endpoints and then checks whether the host contains any endpoint. With 5 endpoints, that's 5 string allocations per each instance of SqlConnection, which in a simple benchmark results in about 40% of total allocations.
SqlClient/src/Microsoft.Data.SqlClient/src/Microsoft/Data/Common/AdapterUtil.cs
Lines 821 to 832 in 6d2473d
| // check if servername ends with any endpoints | |
| for (int index = 0; index < s_azureSqlServerEndpoints.Length; index++) | |
| { | |
| string endpoint = string.IsNullOrEmpty(prefix) ? s_azureSqlServerEndpoints[index] : prefix + s_azureSqlServerEndpoints[index]; | |
| if (length > endpoint.Length) | |
| { | |
| if (string.Compare(dataSource, length - endpoint.Length, endpoint, 0, endpoint.Length, StringComparison.OrdinalIgnoreCase) == 0) | |
| { | |
| return true; | |
| } | |
| } | |
| } |
Maybe it's better to instantiate them once just like it's done for azure sql server endpoints?
