locked
Code First context warm-up time much greater than Database First context warm-up time. RRS feed

  • General discussion

  • VS2012, .NET 4.5, Entity Framework 6 RC1 and an AdventureWorks2012 database.

    I created one project and added a Database First (EDMX) model generated against the AdventureWorks2012 database. In a second project I used the EF Powertools Reverse Engineer Code First function to create the model against the same database. Much to my surprise I found that the time if takes for the context objects to "warm-up" in the two projects was not even close to the same. In over a dozen tests I found that the context object for Code First consistently took over twice as long to warm-up as the one created by the Database First generation (on my machine ~6 seconds compared with ~12 seconds). I'm not at all sure how to explain this difference but it is very disconcerting.

    Has anyone else looked at this before or does anyone have a good explanation as to why this would be?

    • Changed type Fred Bao Monday, October 21, 2013 8:24 AM It is an open thread
    Friday, September 27, 2013 5:17 PM

All replies

  • Hello,

    I do a test with the same environment as yours, however, it seemed that both of then only took less than 2 seconds.

    Below is my test code:

      Console.WriteLine(DateTime.Now.ToLocalTime());
    
                using (AdventureWorks2012Entities db = new AdventureWorks2012Entities())
    
                {
    
                    Console.WriteLine(DateTime.Now.ToLocalTime());
    
                }
    
                Console.ReadLine();
    

    I am not sure if it is that you have written to “warm-up” the dbcontext.

    So could please share your “warm-up” code so that we can do some analysis on this issue.

    Regards.


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Monday, September 30, 2013 7:05 AM
  • The context object in your example above won't have gone through warm up because you didn't actually query anything using it. I've found repeatedly that simple instantiation of a context does not cause a warm-up hit. That doesn't occur until at least the first query. Here's what I used:

    using (var context = new AdventureWorks2012Context())
    {
        var c = context.Departmentss.FirstOrDefault();
    }
    

    After performing the above warm-up I then loop through a simple query a number of times to get an average time. The query I use is as follows:

    using (var context = new AdventureWorks2012Context())
    {
        var custs = context.Customers.ToList();
    }
    

    I have now also tested this same method using Code First and Database First using both EF5 and EF6. Here's the hard results I've found. Of course the actual numbers will differ depending on the machine used but I doubt the trends will. I've now done this same testing against 3 separate databases with similar resulting trends.

    EF5 Code First: Warm-up time 7.3 s, average query time 3.9 s

    EF6 Code First: Warm-up time 17 s, average query time 6.7 s

    EF6 Database First: Warm-up time 9.2 s, average query time 7.2 s

    EF5 Database First: Warm-up time 2.8 s, average query time 3.9 s

    Monday, September 30, 2013 3:22 PM
  • Hi Dane R. Vinson,

    Yes, after using the warm-up way as yours, the time takes longer than before and it is strange.

    And It seems that some members of the entity framework team are dealing with it.

    So if they have result, I think they will feedback as soon as possible.

    Regards.


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Wednesday, October 2, 2013 10:10 AM