Skip to content

Reduce IsAzureSynapseOnDemandEndpoint allocations #3363

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
vonzshik opened this issue May 20, 2025 · 4 comments · May be fixed by #3364
Open

Reduce IsAzureSynapseOnDemandEndpoint allocations #3363

vonzshik opened this issue May 20, 2025 · 4 comments · May be fixed by #3364
Assignees
Labels
Triage Done ✔️ Issues that are triaged by dev team and are in investigation.

Comments

@vonzshik
Copy link

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.

_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.

// 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;
}
}
}

Image

Maybe it's better to instantiate them once just like it's done for azure sql server endpoints?

@vonzshik
Copy link
Author

@ErikEJ more like making a copy of s_azureSqlServerEndpoints with each endpoint having ONDEMAND_PREFIX prepended and passing a specific array to IsEndpoint instead of allocating a string per each.

SqlClient-azure-synapse-check.patch

@ErikEJ
Copy link
Contributor

ErikEJ commented May 20, 2025

@vonzshik Got it!

@ErikEJ
Copy link
Contributor

ErikEJ commented May 20, 2025

@vonzshik Planning to do a PR?

@vonzshik
Copy link
Author

Not really, so go on ahead.

ErikEJ added a commit to ErikEJ/SqlClient that referenced this issue May 20, 2025
@ErikEJ ErikEJ linked a pull request May 20, 2025 that will close this issue
@cheenamalhotra cheenamalhotra added the Triage Needed 🆕 For new issues, not triaged yet. label May 20, 2025
@cheenamalhotra cheenamalhotra added Triage Done ✔️ Issues that are triaged by dev team and are in investigation. and removed Triage Needed 🆕 For new issues, not triaged yet. labels May 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Triage Done ✔️ Issues that are triaged by dev team and are in investigation.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants