New Posts New Posts RSS Feed: Query Performance
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Query Performance

 Post Reply Post Reply
Author
Vonzkie View Drop Down
Senior Member
Senior Member
Avatar

Joined: 01-Aug-2011
Location: PH
Posts: 133
Post Options Post Options   Quote Vonzkie Quote  Post ReplyReply Direct Link To This Post Topic: Query Performance
    Posted: 03-Aug-2011 at 6:36pm
Hi,

Using the NorthwindIB database, I inserted 50k records in Order Table.

When I used the native SQL Adapter, it only took me a second to fetch the data.

SqlDataAdapter
adap = new SqlDataAdapter("SELECT TOP 50000 * FROM dbo.[Order]", @"Data Source=IVON\SQL2008R2;Initial Catalog=NorthwindIB;Integrated Security=SSPI;");

DataSet
dt = new DataSet();

adap.Fill(dt);

But when I execute this query using Devforce:
 
          NorthwindIBEntities _context = new NorthwindIBEntities();
  var orderquery = _context.Orders.Select(p => p).OrderBy(p => p.OrderID).Skip(0).Take(50000);
           _context.ExecuteQueryAsync(orderquery, p =>
            {
                if (!p.HasError)
                {
                    // My code here..
                }
            }, null);

It took me 30 seconds to finish the async query..

Why is this so? Am I missing some configuration or performance tips?
Another, when I use the SQL Profiler to get the SQL query provided by Entity Framework and execute it in the Management Studio, it also took me a second to finish it.

Your help is highly appreciated. :)

Thanks,
Von 
Back to Top
Vonzkie View Drop Down
Senior Member
Senior Member
Avatar

Joined: 01-Aug-2011
Location: PH
Posts: 133
Post Options Post Options   Quote Vonzkie Quote  Post ReplyReply Direct Link To This Post Posted: 03-Aug-2011 at 7:16pm
Hi,

Another thing is that, when I used the native Entity Framework it only took me a second to load
50k records.

            NorthwindIBEntities context = new NorthwindIBEntities();

            var query = context.Orders.Take(50000);

            List<Order> orders = query.ToList<Order>();

I rewrite my Devforce query to this one and it took me 7 seconds to load it, faster than my first approach but still far behind the performance of native EF4 and this query is not async:
            
            NorthwindIBEntities _context = new NorthwindIBEntities();

    IEntityQuery<Order> orderquery = _context.Orders.Take(50000);

            List<Order> orders = orderquery.ToList<Order>();
    

Kindly give me some guide on how to accomplish same performance as the native EF4 because we are very particular with the performance because we are not only dealing with thousands of records but millions.

Thanks,
Von
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 05-Aug-2011 at 3:36pm
Hi Von,
 
When you tested using DevForce, were you doing in 2-tier or n-tier?
 
Silvio.
Back to Top
Vonzkie View Drop Down
Senior Member
Senior Member
Avatar

Joined: 01-Aug-2011
Location: PH
Posts: 133
Post Options Post Options   Quote Vonzkie Quote  Post ReplyReply Direct Link To This Post Posted: 06-Aug-2011 at 8:17am
Hi,

I tested it in a 2-tier environment by setting the isDistributed property to false.

Thanks,
Von
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 09-Aug-2011 at 3:19pm
Hi Vonzkie,
Entity Framework is slightly faster than DevForce considering DevForce has some overhead over EF and is optmized for n-tier.
 
A few suggestions:
 
1) Try turning Query Inversion off:
 
orderquery.QueryStrategy = new QueryStrategy(context.DefaultQueryStrategy.FetchStrategy, context.DefaultQueryStrategy.MergeStrategy, QueryInversionMode.Off);
You can find more information about query inversion in the DevForce Resource Center.
 
2) You could also try querying a reasonable number the entities, i.e. 50, after async querying for everything
3) As a last resource, you could always user SqlDataReader to populate a POCO. You can store POCOs in the EntityManager's cache and query them. You can find additional information about POCOs in our DevForce Resource Center. There is nothing wrong with falling back to SqlDataReader occasionally, using it in a few places for hot spot performance improvements.
 
Silvio.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down