Random data, and Entity Framework performance ...
Posted: Wed Jan 04, 2017 1:02 pm
Hi guys,
I have come across some interesting stuff lately, while doing my LINQ and EF6 research.
One thing that I will share (here) with you is that we can get a HUGE different in the performance of an Entity (framework 6) application, depending on how we go about saving our changes to the Entity objects in our .NET code (at runtime).
As part of my eNote development(and session material preparation) I was coding my test app to randomly create Orders for Customers (data 'seeding') - I set a limit of five thousand new orders. Each Order has a bunch of OrderLine entities. About 18 thousand in total.
The performance test was to see what different exists in overall data creation time, between saving each Order separately, or waiting to save all 5005 when everything was done and finished.
Check the following attached image to see lines 223 (best result) and line 214 (by far the worst result). Times were 21 seconds compared to 263 seconds - just the placement of the 'SaveChanges' was the only difference :-
I have a feeling that when web articles talk about EF6 being slow in some respects, the authors need to take into account more than just simple comparisons.
Nick has more experience in such matters and may help us to understand performance issues, and when we may need to save changes ASAP. Obviously, 5004 more 'SaveChanges' operations have been carried out the 'slow' way. That is as compared to only one for the whole set of new Orders.
The handling of the Random values generation (here) is my first working attempt, but I now have a much better and 'smarter' solution which I will share in my next post from here.
STATIC classes can be most helpful, not just STATIC methods.
Regards,
Phil.
Wales, UK.
I have come across some interesting stuff lately, while doing my LINQ and EF6 research.
One thing that I will share (here) with you is that we can get a HUGE different in the performance of an Entity (framework 6) application, depending on how we go about saving our changes to the Entity objects in our .NET code (at runtime).
As part of my eNote development(and session material preparation) I was coding my test app to randomly create Orders for Customers (data 'seeding') - I set a limit of five thousand new orders. Each Order has a bunch of OrderLine entities. About 18 thousand in total.
The performance test was to see what different exists in overall data creation time, between saving each Order separately, or waiting to save all 5005 when everything was done and finished.
Check the following attached image to see lines 223 (best result) and line 214 (by far the worst result). Times were 21 seconds compared to 263 seconds - just the placement of the 'SaveChanges' was the only difference :-
I have a feeling that when web articles talk about EF6 being slow in some respects, the authors need to take into account more than just simple comparisons.
Nick has more experience in such matters and may help us to understand performance issues, and when we may need to save changes ASAP. Obviously, 5004 more 'SaveChanges' operations have been carried out the 'slow' way. That is as compared to only one for the whole set of new Orders.
The handling of the Random values generation (here) is my first working attempt, but I now have a much better and 'smarter' solution which I will share in my next post from here.
STATIC classes can be most helpful, not just STATIC methods.
Regards,
Phil.
Wales, UK.