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

Viewed 522

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?

1 Answers
Related