New Posts New Posts RSS Feed: ImportEntities slowness
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

ImportEntities slowness

 Post Reply Post Reply
Author
mikewishart View Drop Down
Groupie
Groupie
Avatar

Joined: 26-Feb-2010
Location: Reno, NV
Posts: 49
Post Options Post Options   Quote mikewishart Quote  Post ReplyReply Direct Link To This Post Topic: ImportEntities slowness
    Posted: 03-Jul-2010 at 11:43am
It seems like ImportEntities is very slow now.  Regardless of importing 2 entities or 2000 entities to a new EntityManager, it takes around 2 seconds...

var toManager = new DomainModelEntityManager(fromManager);
// magic happens here... build up a list of entities to copy into entityList.
Console.WriteLine("Importing " + entityList.Count() + " entities " + DateTime.Now.ToString("HH:mm:ss:ffff"));
toManager.ImportEntities(entityList, MergeStrategy.OverwriteChanges);
Console.WriteLine("Done " + DateTime.Now.ToString("HH:mm:ss:ffff"));

results:
Importing 2 entities 11:35:14:8009
Done 11:35:16:7471

Importing 2071 entities 11:35:26:7271
Done 11:35:28:9743

Any idea what I could look for that would cause this?

Thanks!

Back to Top
ting View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 27-Mar-2009
Location: San Francisco
Posts: 427
Post Options Post Options   Quote ting Quote  Post ReplyReply Direct Link To This Post Posted: 06-Jul-2010 at 8:47pm
We haven't been able to reproduce this on our end.  My import takes 0.1 second.
 
If you are loading the entities from offline storage as the first thing in an application, you could be measuring the initialization time of the Entity Framework.  Try merging twice or performing a query before the merge to see if the timing is different.
 
 
 
Back to Top
mikewishart View Drop Down
Groupie
Groupie
Avatar

Joined: 26-Feb-2010
Location: Reno, NV
Posts: 49
Post Options Post Options   Quote mikewishart Quote  Post ReplyReply Direct Link To This Post Posted: 06-Jul-2010 at 11:32pm
Not importing from offline storage, just directly from the "fromManager".  The entities in fromManager were queried for in standard ways.  I tried this anyways:

var toManager = new DomainModelEntityManager(fromManager);
var entityList = new List<Entity>();
foreach (var propertyInfo in fromManager.GetType().GetProperties())
{
  if (propertyInfo.PropertyType.BaseType == typeof(EntityQuery))
  {
    var entities = ((IEnumerable)fromManager.GetType().GetProperty(propertyInfo.Name).GetValue(fromManager, null)).Cast<Entity>().ToList();
    entityList.AddRange(entities);
  }
}
Console.WriteLine("Importing " + entityList.Count() + " entities " + DateTime.Now.ToString("HH:mm:ss:ffff"));
toManager.ImportEntities(entityList, MergeStrategy.OverwriteChanges);
Console.WriteLine("Importing 2nd time " + entityList.Count() + " entities " + DateTime.Now.ToString("HH:mm:ss:ffff"));
toManager.ImportEntities(entityList, MergeStrategy.OverwriteChanges);
Console.WriteLine("Done " + DateTime.Now.ToString("HH:mm:ss:ffff"));

Importing 2 entities 23:05:50:3062
Importing 2nd time 2 entities 23:05:52:3902
Done 23:05:53:9682

So, 2.08s first time, 1.58s second time.

Throwing in query gave the same timing results.

var toManager = new DomainModelEntityManager(fromManager);
var q = ((DomainModelEntityManager)toManager ).Customers.With(QueryStrategy.Normal);
q.ExecuteAsync(op =>
{
  var entityList = new List<Entity>();
  foreach (var propertyInfo in fromManager.GetType().GetProperties())
  {
    if (propertyInfo.PropertyType.BaseType == typeof(EntityQuery))
    {
      var entities = ((IEnumerable)from.GetType().GetProperty(propertyInfo.Name).GetValue(from, null)).Cast<Entity>().ToList();
      entityList.AddRange(entities);
    }
  }
  Console.WriteLine("Importing " + entityList.Count() + " entities " + DateTime.Now.ToString("HH:mm:ss:ffff"));
  toManager.ImportEntities(entityList, MergeStrategy.OverwriteChanges);
  Console.WriteLine("Importing 2nd time " + entityList.Count() + " entities " + DateTime.Now.ToString("HH:mm:ss:ffff"));
  toManager.ImportEntities(entityList, MergeStrategy.OverwriteChanges);
  Console.WriteLine("Done " + DateTime.Now.ToString("HH:mm:ss:ffff"));
});

Importing 2 entities 23:29:41:5530
Importing 2nd time 2 entities 23:29:43:4812
Done 23:29:45:0553

Back to Top
ting View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 27-Mar-2009
Location: San Francisco
Posts: 427
Post Options Post Options   Quote ting Quote  Post ReplyReply Direct Link To This Post Posted: 07-Jul-2010 at 7:37pm
Wow, that's not the code I was expecting.  However, that shouldn't affect the timing on the second import.  Do you have a small solution that you can send over to support so that we can look for anything that stands out?
Back to Top
mikewishart View Drop Down
Groupie
Groupie
Avatar

Joined: 26-Feb-2010
Location: Reno, NV
Posts: 49
Post Options Post Options   Quote mikewishart Quote  Post ReplyReply Direct Link To This Post Posted: 08-Jul-2010 at 10:15am
Thanks.  I have submitted the solution on ticket #7159
Back to Top
ting View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 27-Mar-2009
Location: San Francisco
Posts: 427
Post Options Post Options   Quote ting Quote  Post ReplyReply Direct Link To This Post Posted: 08-Jul-2010 at 7:47pm
We got it.  Thanks!
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down