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

Performance Question

 Post Reply Post Reply Page  <12
Author
skingaby View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 23-Apr-2008
Location: United States
Posts: 146
Post Options Post Options   Quote skingaby Quote  Post ReplyReply Direct Link To This Post Topic: Performance Question
    Posted: 08-Oct-2009 at 8:21am
"I finished my nap." - Gune, Titan AE.

I worked up the code for the EntityCacheState and the tests are coming in at 6-8s load time for the 18 queries.

So far, this is the best option for priming the cache, but the main query to load the list view itself is still slow. I look forward to finding out what you guys figure out.

Here's the code that loads the cache state in an Async method:

//In the Module project, called from ViewModel.Start()
internal class ViewModelEntityInitializer
{
     public ViewModelEntityInitializer(ListViewModel viewModel)
     {
          this.ViewModel = viewModel;
     }

     public void RunInitializationQueries(Action completedAction)
     {
          this.CompletedAction = completedAction;

          var ds = new DomainModelLoaderService();
          ds.LoadModuleCompleted += new EventHandler(ds_LoadModuleCompleted);
          ds.PreLoadModuleAsync();
     }

     void ds_LoadModuleCompleted(object sender, EventArgs e)
     {
          ProcessActiveBusAssociates();
          ...
          ProcessZones();
          
          this.CompletedAction.Invoke();
     }

     private ListViewModel ViewModel { get; set; }
     private Action CompletedAction { get; set; }
}

//In the DomainModel and ClientModel projects
public class DomainModelLoaderService
{

     public void PreLoadModuleAsync()
     {
          var manager = LocalEntityManager.DefaultManager;
          ServerMethodDelegate myDelegate = new ServerMethodDelegate(PreLoadModule);
          manager.InvokeServerMethodAsync(myDelegate, PreLoadModuleAsyncCallback, null);
     }

     public void PreLoadModuleAsyncCallback(InvokeServerMethodEventArgs args)
     {
          var manager = LocalEntityManager.DefaultManager;
          //restore entitycachestate
          EntityCacheState cache = (EntityCacheState)args.Result;
          cache.Merge(manager, RestoreStrategy.Normal);

          OnLoadModuleCompleted(EventArgs.Empty);
     }

     public event EventHandler LoadModuleCompleted;

     private void OnLoadModuleCompleted(EventArgs e)
     {
          if (LoadModuleCompleted != null)
               LoadModuleCompleted(this, e);
     }

     [AllowRpc]
     public static EntityCacheState PreLoadModule(IPrincipal principal, EntityManager em, params object[] args)
     {
          var manager = LocalEntityManager.DefaultManager;
          var task = AsyncParallelTask.Create();
          task.AddAsyncQuery("BusAssociates", x => manager.BusAssociates, null);
          ...
          task.AddAsyncQuery("Zones", x => manager.Zones, null);
          
          _trigger = new AutoResetEvent(false);
          task.Execute(PreLoadModuleCompleted);
          _trigger.WaitOne();

          return manager.CacheStateManager.GetCacheState();
     }

     static AutoResetEvent _trigger;

     public static void PreLoadModuleCompleted(AsyncParallelTaskCompletedArgs args)
     {
          _trigger.Set();
     }
     
}


(My thanks to blog: http://jasondotnet.spaces.live.com/blog/cns!BD40DBF53845E64F!170.entry for how the AutoResetEvent is used.)
Back to Top
 Post Reply Post Reply Page  <12

Forum Jump Forum Permissions View Drop Down