New Posts New Posts RSS Feed: 7-8 Seconds to Instance an EntityManager - BOS Performance
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

7-8 Seconds to Instance an EntityManager - BOS Performance

 Post Reply Post Reply
Author
yafei View Drop Down
Newbie
Newbie


Joined: 25-Aug-2010
Location: los Angeles
Posts: 21
Post Options Post Options   Quote yafei Quote  Post ReplyReply Direct Link To This Post Topic: 7-8 Seconds to Instance an EntityManager - BOS Performance
    Posted: 27-Aug-2010 at 4:37pm

Is it normal to have an overhead of 7-8 seconds to initialize an instance of EntityManger in client side ?

I have created a BOS prototype with a WPF window client. The Domain model has an entity with total 17 properties which are mapping to a SQL table. The db columns are very small, either nchar(10) or datatime, or int. I set a Stopwatch to monitor the timing and find that it takes 7-8 seconds to just create an instance of the EntityManager and 2 seconds to load total 4000 records. This would add to total 9-10 seconds. 

The BOS is hosted on a Window Service in a win2008 server machine using http. I don’t use any customized serviceModel. I compare if I use it, it creates the same result.

Client is a WPF window load the total records (17 columns/properties) and the data are displaying in a DataGrid.
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: 27-Aug-2010 at 4:49pm

There are three big operations on startup:

1)  IIS startup time
2)  Entity Framework schema initialization
3)  DevForce probing (via Microsoft's MEF - Managed Extensibility Framework)
 
There's not much you can do about 1 and 2, but if you have a lot of assemblies, the MEF probing can take a while (a few seconds or more).  Most often this occurs because it is probing third party assemblies (especially 3rd party UI components) that have a lot of types.  The debuglog.xml shows how much time it spent probing and gives you a message about how to control it.
 
If that is indeed taking the time, you can write code like this that will specify what to probe and speed up the process quite a bit:
 
using IdeaBlade.Core.Composition;
 
CompositionHost.SearchPatterns.Clear();
CompositionHost.SearchPatterns.Add("DomainModel.dll");  //  Add whatever assemblies you need probed
 
Back to Top
yafei View Drop Down
Newbie
Newbie


Joined: 25-Aug-2010
Location: los Angeles
Posts: 21
Post Options Post Options   Quote yafei Quote  Post ReplyReply Direct Link To This Post Posted: 27-Aug-2010 at 5:20pm
Thank for your reply.
 

Put the code into my WPF win client, the initializing of EntityManager decreases by 2 seconds to 5 seconds. Is there any way I can change the proding in BOS side ? I don’t have any other dlls except DomainModel.dll.

 
 
I also attach the output of my WPF client debugging here for your reference:

'WpfApplication1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.

'WpfApplication1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities\10.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.

'WpfApplication1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.

'WpfApplication1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.

'WpfApplication1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.

'WpfApplication1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities.Sync\10.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.Sync.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.

'WpfApplication1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime\10.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Debugger.Runtime.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.

'WpfApplication1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\ WpfApplication1\bin\Debug\WpfApplication1.vshost.exe', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.

'WpfApplication1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.

'WpfApplication1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.

'WpfApplication1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.

'WpfApplication1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml.Linq\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.Linq.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.

'WpfApplication1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xaml\v4.0_4.0.0.0__b77a5c561934e089\System.Xaml.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.

The thread 'vshost.NotifyLoad' (0x1824) has exited with code 0 (0x0).

The thread '<No Name>' (0x1198) has exited with code 0 (0x0).

The thread '<No Name>' (0x184c) has exited with code 0 (0x0).

The thread 'vshost.LoadReference' (0xcc0) has exited with code 0 (0x0).

'WpfApplication1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\WpfApplication1\bin\Debug\WpfApplication1.exe', Symbols loaded.

'WpfApplication1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\PresentationFramework\v4.0_4.0.0.0__31bf3856ad364e35\PresentationFramework.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.

'WpfApplication1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\WindowsBase\v4.0_4.0.0.0__31bf3856ad364e35\WindowsBase.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.

'WpfApplication1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\PresentationCore\v4.0_4.0.0.0__31bf3856ad364e35\PresentationCore.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.

'WpfApplication1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.

Step into: Stepping over non-user code 'WpfApplication1.App.App'

Step into: Stepping over non-user code 'WpfApplication1.App.InitializeComponent'

'WpfApplication1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\PresentationFramework.Classic\v4.0_4.0.0.0__31bf3856ad364e35\PresentationFramework.Classic.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.

'WpfApplication1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\IdeaBlade.Core\v4.0_6.0.4.0__287b5094865421c0\IdeaBlade.Core.dll'

'WpfApplication1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\WpfApplication1\bin\Debug\DomainModel.dll', Symbols loaded.

'WpfApplication1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\IdeaBlade.EntityModel\v4.0_6.0.4.0__287b5094865421c0\IdeaBlade.EntityModel.dll'

'WpfApplication1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\IdeaBlade.Validation\v4.0_6.0.4.0__287b5094865421c0\IdeaBlade.Validation.dll'

'WpfApplication1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel\v4.0_4.0.0.0__b77a5c561934e089\System.ServiceModel.dll'

'WpfApplication1.vshost.exe' (Managed (v4.0.30319)): Loaded 'rzkazxnc'

'WpfApplication1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ComponentModel.Composition\v4.0_4.0.0.0__b77a5c561934e089\System.ComponentModel.Composition.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.

'WpfApplication1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\IdeaBlade.Linq\v4.0_6.0.4.0__287b5094865421c0\IdeaBlade.Linq.dll'

'WpfApplication1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\System.Transactions\v4.0_4.0.0.0__b77a5c561934e089\System.Transactions.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.

'WpfApplication1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.Serialization\v4.0_4.0.0.0__b77a5c561934e089\System.Runtime.Serialization.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.

'WpfApplication1.vshost.exe' (Managed (v4.0.30319)): Loaded 'Anonymously Hosted DynamicMethods Assembly'

'WpfApplication1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\IdeaBlade.EntityModel.Edm\v4.0_6.0.4.0__287b5094865421c0\IdeaBlade.EntityModel.Edm.dll'

'WpfApplication1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Data.Entity\v4.0_4.0.0.0__b77a5c561934e089\System.Data.Entity.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.

'WpfApplication1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\IdeaBlade.EntityModel.Web\v4.0_6.0.4.0__287b5094865421c0\IdeaBlade.EntityModel.Web.dll'

'WpfApplication1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\System.Web\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Web.dll'

'WpfApplication1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\IdeaBlade.EntityModel.Server\v4.0_6.0.4.0__287b5094865421c0\IdeaBlade.EntityModel.Server.dll'

'WpfApplication1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel.Activation\v4.0_4.0.0.0__31bf3856ad364e35\System.ServiceModel.Activation.dll'

'WpfApplication1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ComponentModel.DataAnnotations\v4.0_4.0.0.0__31bf3856ad364e35\System.ComponentModel.DataAnnotations.dll'

'WpfApplication1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Management\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Management.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.

The thread '<No Name>' (0x14b8) has exited with code 0 (0x0).

'WpfApplication1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\SMDiagnostics\v4.0_4.0.0.0__b77a5c561934e089\SMDiagnostics.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.

'WpfApplication1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.DurableInstancing\v4.0_4.0.0.0__31bf3856ad364e35\System.Runtime.DurableInstancing.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.

'WpfApplication1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.IdentityModel\v4.0_4.0.0.0__b77a5c561934e089\System.IdentityModel.dll'

'WpfApplication1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.WorkflowServices\v4.0_4.0.0.0__31bf3856ad364e35\System.WorkflowServices.dll'

'WpfApplication1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel.Web\v4.0_4.0.0.0__31bf3856ad364e35\System.ServiceModel.Web.dll'

'WpfApplication1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel.Discovery\v4.0_4.0.0.0__31bf3856ad364e35\System.ServiceModel.Discovery.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.

'WpfApplication1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel.Activities\v4.0_4.0.0.0__31bf3856ad364e35\System.ServiceModel.Activities.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.

'WpfApplication1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel.Routing\v4.0_4.0.0.0__31bf3856ad364e35\System.ServiceModel.Routing.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.

'WpfApplication1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.VisualStudio.Diagnostics.ServiceModelSink\v4.0_4.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Diagnostics.ServiceModelSink.dll'

'WpfApplication1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel.Channels\v4.0_4.0.0.0__31bf3856ad364e35\System.ServiceModel.Channels.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.

The thread '<No Name>' (0x524) has exited with code 0 (0x0).

 

 

 

Back to Top
BringerOD View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 27-Aug-2010
Location: USA
Posts: 35
Post Options Post Options   Quote BringerOD Quote  Post ReplyReply Direct Link To This Post Posted: 30-Aug-2010 at 11:50am
Is there a way to cache the results and put them in the application as a resource file?
Back to Top
yafei View Drop Down
Newbie
Newbie


Joined: 25-Aug-2010
Location: los Angeles
Posts: 21
Post Options Post Options   Quote yafei Quote  Post ReplyReply Direct Link To This Post Posted: 30-Aug-2010 at 11:54am
I use Entity Manager to cache the data in client side. However, I'm talking about the performance of the first time loading.
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: 30-Aug-2010 at 7:15pm
yafei - On the server-side you can add the calls to the CompositionHost to the Global.asax file.
 
BringerOD - We cache the probing while the application is running, but always reprobe again on startup.  If you use the CompositionHost to limit the assemblies, it is very fast.  It's typically the large 3rd party UI assemblies where probing takes longer.
 
 
Back to Top
BringerOD View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 27-Aug-2010
Location: USA
Posts: 35
Post Options Post Options   Quote BringerOD Quote  Post ReplyReply Direct Link To This Post Posted: 30-Aug-2010 at 9:30pm
ting,
 
This did not work!
 
There was no difference in the time it took to instantiate the Entity Manager. 

CompositionHost.SearchPatterns.Clear();

CompositionHost.SearchPatterns.Add("Prime.DataAccess.dll");
Back to Top
yafei View Drop Down
Newbie
Newbie


Joined: 25-Aug-2010
Location: los Angeles
Posts: 21
Post Options Post Options   Quote yafei Quote  Post ReplyReply Direct Link To This Post Posted: 31-Aug-2010 at 10:36am

There is an impact on my performance. It used to take 7 seconds to instantiate the Entity Manager. Now it takes 5 seconds after I use the CompositionHost.

My question for server side is where I can put these code in if I host it as Windin Service. I have no Global.asax.
Back to Top
BringerOD View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 27-Aug-2010
Location: USA
Posts: 35
Post Options Post Options   Quote BringerOD Quote  Post ReplyReply Direct Link To This Post Posted: 31-Aug-2010 at 10:39am
"If you use the CompositionHost to limit the assemblies, it is very fast."
 
I guess I am commenting on ting's comment of very fast.  7 seconds to 5 seconds?
 
Still the same for me.
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: 31-Aug-2010 at 1:49pm

Probing is just one part of the initialization.  The debuglog records how long it took, so check there for timing.

Entity Framework schema initialization will take a second or two, and if this is the first time the server is being used after starting up, or if the server has been idle for a while (20 min) IIS will take time to spin up the service again.
 
Can you guys measure how long it takes to create a new EntityManager after another one has been created (which should remove IIS, probing, & application overhead)?
 
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: 31-Aug-2010 at 2:00pm

yafei - For the Windows Service, you can try subclassing EntityServiceApplication and overriding OnServiceStartup().  However, your EntityServiceApplication subclass is found using probing, so this may not actually help.  Server-side probing is usually less of an issue because you don't tend to have the large 3rd party UI assemblies there (and because server startup should be infrequent in deployment scenarios).  You might want to check the server-side debuglog to see if this is a problem first.

 


Edited by ting - 31-Aug-2010 at 2:00pm
Back to Top
yafei View Drop Down
Newbie
Newbie


Joined: 25-Aug-2010
Location: los Angeles
Posts: 21
Post Options Post Options   Quote yafei Quote  Post ReplyReply Direct Link To This Post Posted: 31-Aug-2010 at 3:50pm
my testing the performance of creating is first EntityManager 5 seconds and second EntityManager 0.5 second.
Back to Top
BringerOD View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 27-Aug-2010
Location: USA
Posts: 35
Post Options Post Options   Quote BringerOD Quote  Post ReplyReply Direct Link To This Post Posted: 31-Aug-2010 at 4:29pm
After deploying the solution.  There was a good speed improvement.  I did not time it.
 
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down