Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Seemingly infinite stack trace in EF 4.0 and poor query performance under load

On a large EF 4.0 model (700+ entities), we are getting poor performance on System.Data.Objects.ObjectContext.CreateObjectSet(string). The call to this is triggered by a query like context.Users.FirstOrDefault(u => u.userId = 100).

The query performs well in general, but under load the query does not do well. We are running a 20 concurrent user load against a page that uses this query. The application for this page is under profiling mode i.e. we are using Visual Studio 2010 performance profiler while running this small load test. The profiler is using the "Sampling" mode.

The application is built with ASP.NET 4.0 / ASP.NET MVC 3.0 and is hosted on IIS 7.5 on a Windows 7 server when the load test is being run.

The profiling report shows a call stack that seems "infinite" i.e. there are a lot of calls to the below lines over and over.

System.Data.Mapping.DefaultObjectMappingItemCollection.LoadObjectMapping
    System.Data.Mapping.DefaultObjectMappingItemCollection.LoadAssociationTypeMapping
        System.Data.Mapping.DefaultObjectMappingItemCollection.LoadObjectMapping
            System.Data.Mapping.DefaultObjectMappingItemCollection.LoadAssociationTypeMapping

What could be the cause for poor performance and such infinite looking call stacks?

like image 405
Dhwanil Shah Avatar asked Aug 08 '11 05:08

Dhwanil Shah


1 Answers

Another thing to try is the excellent Entity Framework Profiler - has saved us many headaches in debugging performance issues like these - gives you a lot more than SQL Profiler and you can see what queries/objects are created per ObjectContext and method/source line, etc - http://efprof.com/

like image 69
AVH Avatar answered Nov 05 '22 01:11

AVH