You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The company I work for have a old legacy system that stores data into our MSSQL database. When our server written in DotNet full framework have to find data in the database using EF6 it performance terribly. One of our customers servers are freezing up to 20 minutes and it seems to be because of the garbage collector cannot clean up fast enough. Further more the performance between FindAsync and Find are huge, and is clear that only FindAsync are having this performance issue.
To make this issue easier to understand, I have managed to reproduce the performance issues and somewhat the memory issue in a dummy project by using binary data.
(Extra note, the issue can be found both in EF6 and EF Core)
Steps to reproduce
The code below can be ran simply by adding connection to a MSSQL database.
usingSystem;usingSystem.Data.Entity;usingSystem.Diagnostics;usingSystem.Linq;usingSystem.Threading.Tasks;namespacePerfEFIssueFramework{publicclassItem{publicintId{get;set;}publicbyte[]Data{get;set;}}publicclassItemContext:DbContext{publicDbSet<Item>Items{get;set;}publicItemContext():base(@"Data Source=localhost;Initial Catalog=ItemDb;Integrated Security=False;User ID=user;Password=pw"){}}internalclassProgram{privatestaticasyncTaskMain(string[]args){Console.WriteLine("Ready to consume a lot of memory with EF.");using(vardb=newItemContext()){db.Database.CreateIfNotExists();//insert dummy recordif(db.Items.ToArray().Length==0){db.Items.Add(newItem{Data=newbyte[20*1024*1024]});db.Items.Add(newItem{Data=newbyte[40*1024*1024]});db.Items.Add(newItem{Data=newbyte[60*1024*1024]});db.Items.Add(newItem{Data=newbyte[80*1024*1024]});db.Items.Add(newItem{Data=newbyte[100*1024*1024]});awaitdb.SaveChangesAsync();}}// Findfor(inti=1;i<6;i++){// Find sync - No performance issuesusing(vardb=newItemContext()){varstopwatch=Stopwatch.StartNew();Console.WriteLine("Find sync method doesn't have performance and memory issue");varitem=db.Items.Find(i);Console.WriteLine($"Record with id '{item.Id}' was fetched in {stopwatch.ElapsedMilliseconds}ms. Press any key to read again...");}// Find async - performance issuesusing(vardb=newItemContext()){varstopwatch=Stopwatch.StartNew();Console.WriteLine("Reproduce FindAsync performance and memory issue:");varitem=awaitdb.Items.FindAsync(i);Console.WriteLine($"Record with id '{item.Id}' was fetched in {stopwatch.ElapsedMilliseconds}ms. Press any key to read again...");}}using(vardb=newItemContext()){db.Database.Delete();}}}}
ID 1 = 20mb
ID 2 = 40mb
ID 3 = 60mb
ID 4 = 80mb
ID 5 = 100mb Performance issue
What we can clearly see is that find without running the async method, it takes between 150 to 350ms, but async are taking between 13000ms to 280000ms
Memory
With 2 mb binary data Find uses about 52 mb
With 2 mb binary data FindAsync uses about 96 mb
With 20 mb binary data Find uses about 63 mb
With 20 mb binary data FindAsync uses about 432 mb
Further technical details
EF version: 6.4.4
Database Provider: EntityFramework.SqlServer
Operating system: Windows 10 - 1909 (Build 18363.836)
IDE: Visual Studio 2019 - 16.4.1
The text was updated successfully, but these errors were encountered:
This issue has been closed because EF6 is no longer being actively developed. We are instead focusing on stability of the codebase, which means we will only make changes to address security issues. See the repo README for more information.
The company I work for have a old legacy system that stores data into our MSSQL database. When our server written in DotNet full framework have to find data in the database using EF6 it performance terribly. One of our customers servers are freezing up to 20 minutes and it seems to be because of the garbage collector cannot clean up fast enough. Further more the performance between FindAsync and Find are huge, and is clear that only FindAsync are having this performance issue.
To make this issue easier to understand, I have managed to reproduce the performance issues and somewhat the memory issue in a dummy project by using binary data.
(Extra note, the issue can be found both in EF6 and EF Core)
Steps to reproduce
The code below can be ran simply by adding connection to a MSSQL database.
ID 1 = 20mb
ID 2 = 40mb
ID 3 = 60mb
ID 4 = 80mb
ID 5 = 100mb
Performance issue
What we can clearly see is that find without running the async method, it takes between 150 to 350ms, but async are taking between 13000ms to 280000ms
Memory
With 2 mb binary data Find uses about 52 mb
With 2 mb binary data FindAsync uses about 96 mb
With 20 mb binary data Find uses about 63 mb
With 20 mb binary data FindAsync uses about 432 mb
Further technical details
EF version: 6.4.4
Database Provider: EntityFramework.SqlServer
Operating system: Windows 10 - 1909 (Build 18363.836)
IDE: Visual Studio 2019 - 16.4.1
The text was updated successfully, but these errors were encountered: