Skip to content
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

EF Core5.0 Slow queries #24194

Closed
hwl962589950 opened this issue Feb 19, 2021 · 6 comments
Closed

EF Core5.0 Slow queries #24194

hwl962589950 opened this issue Feb 19, 2021 · 6 comments

Comments

@hwl962589950
Copy link

Include your code

In the asynchronous method ToListAsync, when the field VCHAR is too long, the query is slow. When the asynchronization is eliminated and the ToList method is used, the query field is base64 of image transcoding, but I use the log to check, the database query part only takes 2ms. The actual mapping asynchronization is about 20S, and the non-asynchronization requires about 2S

Code

            Stopwatch stopwatch = new Stopwatch();
            Console.WriteLine($"ToList Time Start");
            stopwatch.Start();
            var test1 = dbContext.CourseTree.ToList();
            stopwatch.Stop();
	    Console.WriteLine($"ToList Time {stopwatch.ElapsedMilliseconds}ms End");

            Console.WriteLine($"ToListAsync Time Start");
            stopwatch.Restart();
            var test2 = await dbContext.CourseTree.ToListAsync();
            stopwatch.Stop();
            Console.WriteLine($"ToListAsync Time {stopwatch.ElapsedMilliseconds}ms End");

Log

ToList Time Start
info: 2021-02-19 11:19:35.263 RelationalEventId.CommandExecuted[20101] (Microsoft.EntityFrameworkCore.Database.Command)
      Executed DbCommand (3ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
      SELECT [c].[Id], [c].[CourseId], [c].[CourseTreeMainBoby], [c].[CourseTreeMainType], [c].[CreationTime], [c].[Name], [c].[OrderByIndex], [c].[ParentId], [c].[TreePath]
      FROM [CourseTree] AS [c]
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
      Executed DbCommand (3ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
      SELECT [c].[Id], [c].[CourseId], [c].[CourseTreeMainBoby], [c].[CourseTreeMainType], [c].[CreationTime], [c].[Name], [c].[OrderByIndex], [c].[ParentId], [c].[TreePath]
      FROM [CourseTree] AS [c]
ToList Time 93ms End
ToListAsync Time Start
info: 2021-02-19 11:19:35.353 RelationalEventId.CommandExecuted[20101] (Microsoft.EntityFrameworkCore.Database.Command)
      Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
      SELECT [c].[Id], [c].[CourseId], [c].[CourseTreeMainBoby], [c].[CourseTreeMainType], [c].[CreationTime], [c].[Name], [c].[OrderByIndex], [c].[ParentId], [c].[TreePath]
      FROM [CourseTree] AS [c]
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
      Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
      SELECT [c].[Id], [c].[CourseId], [c].[CourseTreeMainBoby], [c].[CourseTreeMainType], [c].[CreationTime], [c].[Name], [c].[OrderByIndex], [c].[ParentId], [c].[TreePath]
      FROM [CourseTree] AS [c]
ToListAsync Time 26799ms End

EF Core version:
Database provider: (e.g. Microsoft.EntityFrameworkCore.SqlServer)
Target framework: (e.g. .NET 5.0)
Operating system:
IDE: (e.g. Visual Studio 2019 16.3)

@anranruye
Copy link

See #23900. For this scenario, don't use Async methods.

@hwl962589950
Copy link
Author

See #23900. For this scenario, don't use Async methods.

OK, it's greater than 1MB

@hwl962589950
Copy link
Author

hwl962589950 commented Feb 19, 2021 via email

@roji
Copy link
Member

roji commented Feb 19, 2021

Duplicate of dotnet/SqlClient#593

@roji roji marked this as a duplicate of dotnet/SqlClient#593 Feb 19, 2021
@roji
Copy link
Member

roji commented Feb 19, 2021

This is unfortunately a SqlClient issue that is out of EF 's control... You can indeed use the sync API as a workaround until that's fixed.

@hwl962589950
Copy link
Author

This is unfortunately a SqlClient issue that is out of EF 's control... You can indeed use the sync API as a workaround until that's fixed.

All right. Got the question

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants