Peformance questions on Entity Framework 4.0
We are about to use EF 4.0 version, I did some perf. test and compared with EF 3.5 version, I found something interesting.
Test methodology: I have developed a simple ASP.NET website which is having a button and Gridview control, clicking on the Button I populate the grid. I have copied the code of populating the Data grid:
private void BindData()
{
using (NorthwindEntities context = new NorthwindEntities())
{
DataGrid.DataSource = context.Categories;
DataGrid.DataBind();
}
}
I ran Load-test on this web page, the test pattern is like this -- Initial user count = 30, Increment user count by 10 in every 10 second, Max user count = 250, [ I ran this test for 5 minutes ]. I ran this test for the website which is using EF 3.5 version and also the website which is using EF 4.0, the observations are interesting...
Total number of request (web request sent by the Test agent) processed within 5 minutes is always more in EF 3.5 version (though the delta is very less).
The CLR contention rate is very high in EF 4.0 version website (compare to the 3.5 EF version website), just curious to know whether more Locking included in EF 4.0.
Also it would be good to know:
Is there any performance enhancement done in EF 4.0 version?
I was wondering whether any guidance from EF team on how to use EF with web app context (especially how to use the
ObjectContext
, whether to share a singleton ObjectContext开发者_如何学运维 among the web sessions or let every session have its ownObjectContext
, or let every request create and destroy theObjectContext
(as I have done in my perf. test).
Yes there are performance enhancements done in EF4. You will probably not see them in simple query you executed:
SELECT * FROM dbo.Categories
But once you will start to use EF in real world scenarios you will find EF4 better and faster. Even if EF4 is little bit slower in some scenarios you will still want to use EF4 because of much complex feature set, POCO support etc.
Life time of ObjectContext
should be short. In web application it is best to use one ObjectContext
instance per request.
EFv1 is dead. Unless you must use .NET 3.5 don't use EFv1.
精彩评论