Repository navigation
Description
We are trying to scale an application that uses ASP.NET Identity (which is all async) and we have huge performance issues with all async work against SqlClient (we believe it has boiled down to this). We have investigated and tried many different things for a couple of weeks, and we now have very little isolated code that performs more or less equally bad all the time. The code has implementation of both sync and async calls with huge differences between them. We have read about the issues for big fields, but we see the problem on all our queries (without any big fields) and the reproduced slow calls below has no large fields.
We run in Azure with an App Service plan of P1V2 scaled to two instances and an SQL Azure Premium P1: 125 DTUs. We don't see any performance problems at all in SQL Azure. We have a VNET with a private link between the App Service and SQL Azure. We use Azure Load test to run the tests (and we can share the tests too if needed). We also get similar results when testing locally.
We use Stackify Retrace for monitoring and have enabled that through their extension.
Sync code performance when running 10 instances with 250 threads:
90%: 4,69 sek
Average: 1,417 sek
Open Connection: <0,001 sek
Select Logins: 0,002 sek
Async code performance when running 10 instances with 250 threads:
90%: 5,38 sek
Average: 2,235 sek
Open Connection: 1,624 sek
Select Logins: 0,298 sek
Sync code performance when running 45 instances with 250 threads, each thread making 10 calls after each other:
90%: 40,21 sek
Average: 17,502 sek
Open Connection: <0,001 sek
Select Logins: 0,006 sek
Async code performance when running 45 instances with 250 threads, each thread making 10 calls after each other:
90%: 80,97 sek
Average: 35,080 sek
Open Connection: 19,634 sek
Select Logins: 7,975 sek
Table script:
CREATE TABLE [security].[AspNetUserLogin](
[LoginProvider] [nvarchar] (100) NOT NULL,
[ProviderKey] [nvarchar] (100) NOT NULL,
[TenantId] [uniqueidentifier] NOT NULL,
[ProviderDisplayName] [nvarchar] (450) NULL,
[UserId] [uniqueidentifier] NOT NULL,
CONSTRAINT [PK_AspNetUserLogin] PRIMARY KEY CLUSTERED
(
[LoginProvider] ASC,
[ProviderKey] ASC,
[TenantId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [security].[AspNetUserLogin] WITH CHECK ADD CONSTRAINT [FK_AspNetUserLogin_AspNetUser_UserId] FOREIGN KEY([UserId])
REFERENCES [security].[AspNetUser] ([Id])
ON DELETE CASCADE
GO
ALTER TABLE [security].[AspNetUserLogin] CHECK CONSTRAINT [FK_AspNetUserLogin_AspNetUser_UserId]
GOData: The table is empty
ASP.NET Code (.NET 6 and Microsoft.Data.SqlClient 4.1.0 (we have tried with version 5 too). We started with a default .NET 6 template, added support for controllers and removed authorization, https redirection and exception handler.
The controller:
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Data.SqlClient;
namespace SyncAsyncPerf.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class LoadTestController : ControllerBase
{
private const string _connectionString =
"Server=tcp:ourserver.database.windows.net;Authentication=Active Directory Managed Identity;Initial Catalog=oursqldb;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;Max Pool Size=5000;Min Pool Size=100";
[HttpGet]
public IActionResult Get(Guid userId)
{
var sql = $"SELECT [LoginProvider], [ProviderKey], [ProviderDisplayName] FROM [security].[AspNetUserLogin]" +
$"WHERE [UserId] = @UserId";
using var connection = new SqlConnection(_connectionString);
using var command = connection.CreateCommand();
command.CommandText = sql;
var parameter = command.CreateParameter();
parameter.ParameterName = "@UserId";
parameter.DbType = System.Data.DbType.Guid;
parameter.Value = userId;
command.Parameters.Add(parameter);
connection.Open();
using var reader = command.ExecuteReader(System.Data.CommandBehavior.SingleResult | System.Data.CommandBehavior.CloseConnection);
var result = new List<UserLoginInfo>();
while (reader.Read())
{
result.Add(
new UserLoginInfo(reader.GetString(0), reader.GetString(1), reader.IsDBNull(2) ? null : reader.GetString(2))
);
}
return Ok(result);
}
[HttpGet("async")]
public async Task<IActionResult> GetAsync(Guid userId)
{
var sql = $"SELECT [LoginProvider], [ProviderKey], [ProviderDisplayName] FROM [security].[AspNetUserLogin]" +
$"WHERE [UserId] = @UserId";
using var connection = new SqlConnection(_connectionString);
using var command = connection.CreateCommand();
command.CommandText = sql;
var parameter = command.CreateParameter();
parameter.ParameterName = "@UserId";
parameter.DbType = System.Data.DbType.Guid;
parameter.Value = userId;
command.Parameters.Add(parameter);
await connection.OpenAsync(HttpContext.RequestAborted);
using var reader = await command.ExecuteReaderAsync(System.Data.CommandBehavior.SingleResult | System.Data.CommandBehavior.CloseConnection, HttpContext.RequestAborted);
var result = new List<UserLoginInfo>();
while (await reader.ReadAsync())
{
result.Add(
new UserLoginInfo(reader.GetString(0), reader.GetString(1), reader.IsDBNull(2) ? null : reader.GetString(2))
);
}
return Ok(result);
}
}
}Finally, some notes on the connection string. We have tried many different configurations without effecting the underlying problem. If we use defaults for connection pooling the number of errors increases rapidly, especially for async code because of connection timeouts.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsIn validation












Activity
DavoudEshtehari commentedon Mar 28, 2022
Hi @equist
Thank you for sharing here.
For the record, could you specify the OS and target framework in use?
equist commentedon Mar 28, 2022
.NET 6 on Windows. The App Service, SQL Azure and VNET are all in the same Azure region (North Europe). We see simlar problems when running locally (on a dev box) even though not with same load.
I've read those, but #1206 seemed to only happen intermitent, but we reproduce this all the time and never with acceptable results for async method.
I've also read #601, which lead us to set min pool size and to make a manual call to the service to "warm it up" before running the tests, but as shown we still have bad results.
KonnectSalon commentedon Apr 4, 2022
Having the same issue here... It's an async issue with the SQL client for large fields - Changing the nvarchar(max) to nvarchar(255) for example helped alot.
equist commentedon Apr 4, 2022
Large fields is an identified issue since earlier, but we get slow performance for small fields too.
KonnectSalon commentedon Apr 4, 2022
I removed all async db calls but can’t in the identity which is causing me issues.
Seems like sqlclient is just broken for async.
equist commentedon May 11, 2022
When switching to Linux App Service the problems disappeared. We haven't tested the downscaled example used in this issue, but the full application is scaling very well on Linux.
timothyeckert commentedon Apr 28, 2023
Chiming in with, we are seeing this issue as well and can see it reported within our APM tool. Rolling back to sync call cuts the time in half.
bedpans commentedon Nov 7, 2024
Async performance is completely unacceptable. In one particular instance changing from
ToListAsynctoToListreduced execution time from 18 minutes to 7 seconds. That is 150x speed up. This happens when we are retrieving 3 rows each one having nvarchar(max) column with 25,000,000 characters of data.TonyValenti commentedon Feb 13, 2026
Is this issue still an issue?
Looking at:
https://steven-giesel.com/blogPost/dd7ab934-c311-45e0-9a04-9a28c624b957/tolistasync-is-fast-again-in-entity-framework-kind-of
It looks like async calls might be fast.
We were thinking about migrating our sync calls to async but wanted confirmation first.
ErikEJ commentedon Feb 14, 2026
@TonyValenti still an issue , fix is behind two flags;
https://erikej.github.io/sqlclient/dotnet/performance/2025/10/20/sqlclient-performance.html
TonyValenti commentedon Feb 14, 2026
Do you think these flags might be unnecessary in .net 11? Is there an ETA for the fix?
ErikEJ commentedon Feb 14, 2026
There is no connection between SqlClient and .NET releases.
If you test the flags and provide feedback, there could be a chance that they will be turned on by default in a future release of SqlClient, I guess.
TonyValenti commentedon Feb 25, 2026
These changes are great. Please turn them on by default in an upcoming release.
paulmedynski commentedon Mar 27, 2026
AppContext switch mitigation (v7.0.0)
For the DONE token processing overhead specifically, SqlClient 7.0.0 includes a switch that forces synchronous reads in
TryProcessDone, avoiding the snapshot/replay cost for that token:Trade-off: This blocks the calling thread while reading the 12-byte DONE token, so it reduces per-call latency at the expense of thread pool scalability. It may help in scenarios where async overhead per query is the primary concern and concurrency is moderate.
For the broader async read overhead (multi-packet PLP data), there is also an experimental continuation path:
This enables resume-from-offset snapshot replay for large column reads. Both switches must be set together (the first gates the second). Set these before opening any
SqlConnection, as switch values are cached on first access. These paths are experimental — please report any issues.priyankatiwari08 commentedon Sep 17, 2026
/triage
github-actions commentedon Sep 17, 2026
🔍 Triage Summary (on-demand re-triage)
Area\AsyncAnalysis
This is a long-running, well-documented performance issue (open since March 2022, still active) showing
ExecuteReaderAsync/ReadAsyncsignificantly slower than their synchronous counterparts under load, notably forOpenAsyncand DONE-token processing overhead, even without large field values. Recent maintainer activity (comment from@paulmedynski, 2026-03-27) confirms SqlClient 7.0.0 ships two opt-in AppContext switch mitigations —Switch.Microsoft.Data.SqlClient.MakeReadAsyncBlocking(forces sync reads for the DONE token) and the pairedUseCompatibilityProcessSni/UseCompatibilityAsyncBehaviourswitches (experimental resume-from-offset snapshot replay for multi-packet PLP/large-column reads) — but these remain opt-in/experimental rather than default. Severity: P2 (known workaround exists via switches; broad community impact on async scalability, not a crash/data-corruption issue).Next Steps
MakeReadAsyncBlocking/UseCompatibilityProcessSni+UseCompatibilityAsyncBehaviouron by default in a future release once sufficient community feedback is collected.PerformanceTests/StressTeststo build a data-backed recommendation on flipping the defaults.kemsky commentedon Nov 12, 2026
@paulmedynski, I've added the last two switches yesterday, today we got the first problem:
Bug report: high CPU (~50%) sustained
Environment
dotnet-stack report -p <PID>Symptom
Evidence (from thread dump)
2 of 17 threads flagged
CPU_TIME(TIDs 0x1458, 0xC0C); all other threads idle/waitingBoth hot threads have identical stacks, deep in SqlClient TDS parsing:
TryReadPlpUnicodeCharsWithContinueis the decoder for largenvarchar(max)(PLP) columns — CPU is spent decoding big string values streamed from SQL Serverstacks.txt
Can upgrading to 7.1.1 help with that?
kemsky commentedon Nov 13, 2026
7.1.1 did not help, it stalls almost immediately, stacktrace is different:
SQL Server 2019, Web Edition