Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to continuously measure EF performance?

I have a huge application that uses Entity Framework 4. It's WCF on the server (hosted inside Windows service) and WPF on the client.
Some of it's parts are slow, and I wonder if it's due to the fact that database access is slow.
I would like to continuously measure performance of that code, e.g. log every query's execution time (preferrably including EF's own stuff like materialization) somewhere to analyze later. How do I do that?
Tools like EFProf (because even if they can measure time it took db server to execute particular query, how do I run them for a week?) and Glimpse (it doesn't support Windows service and WPF) won't do in my case.
I considered making my own SqlConnection subclass, but my version only accepts EntityConnection in ObjectContext ctor, and EntityConnection is marked as sealed. And this option will only allow to measure raw sql queries execution time, not EF's code.
The only options I see now are: 1) to update to EF 6 and write SqlConnection subclass (this won't measure EF's own code) 2) update to later versions and use something like EF hooks library
And of course, it's not in a book (just looked at Mastering Enity Framework) - because most of us only need to work with a library, not know how quick it is (sarcasm).

like image 753
chester89 Avatar asked Nov 08 '22 10:11

chester89


1 Answers

There are all sorts of optimizations being made, both in the linq expression caching and what SQL server chooses to cache, the only way is to measure your performance speed and memory consumption

for your case, I think Microsoft has provided a simple way through "Measuring Entity Framework Performance using ETW"

Also, You can get some of this info through SQL profiler, it's just a lot more work.

like image 76
MohamedHamza Avatar answered Nov 15 '22 07:11

MohamedHamza