Entity framework takes 6 seconds to bring back a single record

I

Ilyas

Hi all

I have created a new ado.net entity data model using VS2008 for the
northwind db. I added all tables in the northwind db

I then attempted to run the following code in NUnit (2.4.7):

NorthwindEntities nw = new NorthwindEntities();
var x= nw.Region.First();

This took 6 seconds, which I thought was a bit long.

Here is the sql that was executed:

SELECT TOP (1)
[c].[RegionID] AS [RegionID],
[c].[RegionDescription] AS [RegionDescription]
FROM [dbo].[Region] AS [c]

Now sql server takes a fraction of a second, to execute this simplt
sql, and interestingly enough when I use Sql Profiler, I notice that
the command doesnt actually come to sql server until the 6 seconds are
almost over. So my question is what is happening inside the EF that is
taking 6 seconds to send to command to sql server?

Any advice, pointers would be very appreciated

My machine is Vista SP1, 2GB ram, 2.2GHZ, also .net 3.5 sp1 is present.
 
J

jacerhea

Is it taking 6 seconds inside an aspx page or just in the unit test?

I could see the EF taking a bit to initialize the first time. Do
repeated requests in the same test take the same amount of time?
 
I

Ilyas

Is it taking 6 seconds inside an aspx page or just in the unit test?

I could see the EF taking a bit to initialize the first time.  Do
repeated requests in the same test take the same amount of time?

I havent tried it inside an aspx page. Its just inside a a test nunit
method

The delay seems to be only the first time the code NorthwindEntities
nw = new NorthwindEntities(); is executed

This is still pretty poor performance, I mean whats going on inside it
for 6 seconds?
 
F

Frans Bouma [C# MVP]

Ilyas said:
I havent tried it inside an aspx page. Its just inside a a test nunit
method

The delay seems to be only the first time the code NorthwindEntities
nw = new NorthwindEntities(); is executed

This is still pretty poor performance, I mean whats going on inside it
for 6 seconds?

It's processing the meta-data and creates pre-compiled views. So it
can handle subsequential queries more efficiently. The bigger the
project the longer the startup time.

FB

--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
 
I

Ilyas

        It's processing the meta-data and creates pre-compiled views. So  it
can handle subsequential queries more efficiently. The bigger the
project the longer the startup time.

                FB

--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website:http://www.llblgen.com
My .NET blog:http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------

So how would one avoid this delay, or reduce it in anyway....

Also 6 seconds seems quite a long time, and this is just against the
northwind database. Real business applications will have much more
complex structure too, as so this delay will be increased...
 
J

Jeroen Mostert

Ilyas said:
So how would one avoid this delay, or reduce it in anyway....
I'm guessing not, other than petitioning the team for better startup
performance. I think those 6 seconds can be shaved down a bit, and of course
a precompilation tool is a distinct possibility (there currently isn't one,
as far as I'm aware).
Also 6 seconds seems quite a long time, and this is just against the
northwind database. Real business applications will have much more
complex structure too, as so this delay will be increased...

Real business applications will be processing thousands of requests over a
long period of time, from equally long-running processes. Startup time is
all but insignificant in those scenarios (contrary to those of desktop
applications).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top