-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Performance issue when querying varbinary(MAX), varchar(MAX), nvarchar(MAX) or XML with Async #18221
Comments
This would be covered by #885 |
On a hunch, I recreated a benchmark for reading large values with SqlClient, on async/sync and with CommandBehavior=Default/SequentialAccess. Results are different from the (very useful) stackoverflow reported above:
I suspect a significant behavior difference between the .NET Framework version of System.Data.SqlClient used in the SO benchmark back in 2015, to the MS.Data.SqlClient being used on .NET Core today. I've opened dotnet/SqlClient#245 to track this, the full benchmark and results are available there. So as things stand, it looks like having EF Core pass CommandBehavior.SequentialAccess wouldn't help in any way. However, it definitely seems like the right thing to do, and once the odd SqlClient behavior is corrected it could provide a significant boost. As the ability to pass SequentialAccess is already covered by #885, I don't think there's anything else to do here, so we should close it. One last note: CommandBehavior.Sequential makes sense for large values. On SQL Server the provider can reasonably "guess" that a property will contain large values based on its store type: VARCHAR(MAX) would probably be a good candidate, whereas VARCHAR(255) obviously would not be. This doesn't necessarily hold for other providers: in PostgreSQL users are encouraged to just use the TEXT store type for all strings, regardless of length, so it would probably be a bad idea to always access it with SequentialAccess. Maybe an additional user hint makes sense here. |
Closing this as duplicate of #885 for the EF part; the SqlClient part is tracked by dotnet/SqlClient#245 |
@tibitoth did you ever find a solution to this issue? It looks like everyone shrugs and says, can't be fixed easily. I ran into this issue yesterday where a table hit a breaking point and essentially killed out app. Is there a workaround? |
@rogerfar use the non Async API? |
@rogerfar the problem really is in the SqlClient provider - I'd advise upvoting the issue there to help them prioritize it more. |
@rogerfar Sadly we have to keep in mind this large fields and use sync APIs when this involves in a query. I did not run the benchmark with .NET 5 or .NET 6 but I will and file a new issue if it is still an issue. |
@rogerfar I found a workaround. First see #24290. The missing part is making a wrapper for DbDataReader which caches the most recently accessed value, in order not to get an exception when EF Core reads primary keys twice. With the suggested interceptor and the DbDataReader wrapper it worked, reaching the same performance as sync methods for my use cases. |
This is still a major issue. I have been troubleshooting spikes in CPU and slow SQL statements only to come to this thread. GetClaimsAsync in Microsoft.AspNetCore.Identity calls SQL that has a table of nvarchar(max) for claims and values. Changing the table to nvarchar(255) seem to resolve the issue. This issue is having a knock on affect to other libraries :( |
Any news on this? We are still waiting for this to be fixed :( |
@SokoFromNZ and others, this has nothing to do with EF Core; this issue tracking the problem is dotnet/SqlClient#593. |
EF SequentialAccess perfomance issue is #885 (according to @ajcvickers comment), pls upvote 885 |
Description
I would like to resurrect the following EF6 issue: dotnet/ef6#88 because it's still present in EF Core 2.2 and 3.0 also.
Related SO question and answer: https://stackoverflow.com/questions/28543293/entity-framework-async-operation-takes-ten-times-as-long-to-complete
This is a huge issue, we cannot use
ToList
as a workaround because this requires impossible checks at development time.Steps to reproduce
I have created a small repro codebase and benchmarks.
Benckmarks
Further technical details
EF Core version: 2.2, 3.0
Database provider: (e.g. Microsoft.EntityFrameworkCore.SqlServer)
Target framework: (e.g. .NET Core 3.0, .NET Core 2.2)
Operating system: Windows 10.
IDE: (e.g. Visual Studio 2019 16.3)
The text was updated successfully, but these errors were encountered: