473,587 Members | 2,316 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

AppDomain creation gets increasingly expensive

Hi,

I'm currently writing a scheduling service which starts a number DotNet
executables, each within a new AppDomain, every ten seconds.

The guts of the code is as follows:

// For each executable in the list of tasks
for (int i = 0; i < this.processTas ks.Length; i++)
{
try
{
// Create a suitable name for the AppDomain
string[] taskArgs = this.processTas ks[i].Trim().Split(' ');
string appDomainName = String.Format(" Task {0}", i);

// Create a new AppDomain for the task
Trace.WriteLine (String.Format( "Creating AppDomain '{0}'",
appDomainName)) ;
AppDomain appDomain = AppDomain.Creat eDomain(appDoma inName);

try
{
// Execute the assembly in the AppDomain
Trace.WriteLine (String.Format( "Executing assembly '{0}' on AppDomain
'{1}'", taskArgs[0], appDomain.Frien dlyName));
appDomain.Execu teAssembly(task Args[0],
AppDomain.Curre ntDomain.Eviden ce, taskArgs);
}
catch (Exception e)
{
// Log any errors
Trace.WriteLine (e.ToString(), EVENT_SOURCE);
EventLog.WriteE ntry(EVENT_SOUR CE, e.ToString(),
EventLogEntryTy pe.Error);
}
finally
{
// Unload the AppDomain
Trace.WriteLine (String.Format( "Unloading AppDomain '{0}'",
appDomain.Frien dlyName));
AppDomain.Unloa d(appDomain);
}
}
catch (Exception e)
{
// Log any errors that may be thrown in the finally block above

At the moment, because I have six executables in the processTasks array, 6
new AppDomains are created and destroyed on every pass.

As time has gone on (the schedule process has been running for several
days), the time taken to create/destroy an AppDomain has gone from 1s to
about 12s, and the memory usage of the process has crept steadily upwards.

Should I be creating and destroying AppDomains with this rapidity, or are
they simply not designed for this use? Or am I not getting rid of them
properly with the simple AppDomain.Unloa d().

Any info very greatefully received!!

Many thanks,

Chris.

Sep 8 '05 #1
4 2344
If you are starting the same apps every 10 seconds, consider making them
services that run their business every 10 seconds instead. This will be much
less overhead on the system.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*************** ************
Think Outside the Box!
*************** ************
"Chris Lacey" wrote:
Hi,

I'm currently writing a scheduling service which starts a number DotNet
executables, each within a new AppDomain, every ten seconds.

The guts of the code is as follows:

// For each executable in the list of tasks
for (int i = 0; i < this.processTas ks.Length; i++)
{
try
{
// Create a suitable name for the AppDomain
string[] taskArgs = this.processTas ks[i].Trim().Split(' ');
string appDomainName = String.Format(" Task {0}", i);

// Create a new AppDomain for the task
Trace.WriteLine (String.Format( "Creating AppDomain '{0}'",
appDomainName)) ;
AppDomain appDomain = AppDomain.Creat eDomain(appDoma inName);

try
{
// Execute the assembly in the AppDomain
Trace.WriteLine (String.Format( "Executing assembly '{0}' on AppDomain
'{1}'", taskArgs[0], appDomain.Frien dlyName));
appDomain.Execu teAssembly(task Args[0],
AppDomain.Curre ntDomain.Eviden ce, taskArgs);
}
catch (Exception e)
{
// Log any errors
Trace.WriteLine (e.ToString(), EVENT_SOURCE);
EventLog.WriteE ntry(EVENT_SOUR CE, e.ToString(),
EventLogEntryTy pe.Error);
}
finally
{
// Unload the AppDomain
Trace.WriteLine (String.Format( "Unloading AppDomain '{0}'",
appDomain.Frien dlyName));
AppDomain.Unloa d(appDomain);
}
}
catch (Exception e)
{
// Log any errors that may be thrown in the finally block above

At the moment, because I have six executables in the processTasks array, 6
new AppDomains are created and destroyed on every pass.

As time has gone on (the schedule process has been running for several
days), the time taken to create/destroy an AppDomain has gone from 1s to
about 12s, and the memory usage of the process has crept steadily upwards.

Should I be creating and destroying AppDomains with this rapidity, or are
they simply not designed for this use? Or am I not getting rid of them
properly with the simple AppDomain.Unloa d().

Any info very greatefully received!!

Many thanks,

Chris.

Sep 8 '05 #2
Thanks, Gregory.

The single service that schedules all of the other applications is required
because the list of executables is determined by the end user (in a
configuration file). We also need to be sure that these run sequentially,
and not in parallel.

AppDomains seem like the right thing to use here - and I can cope with a
small (consistent!) delay in creating and destroying them - but the
increasing memory usage and creation time seems to imply they are not
"fully" destroyed.

Any ideas?

Thanks in advance,

Chris.
Sep 8 '05 #3

"Chris Lacey" <ch*********@bi gfoot.com> wrote in message
news:Og******** ******@TK2MSFTN GP11.phx.gbl...
Thanks, Gregory.

The single service that schedules all of the other applications is
required because the list of executables is determined by the end user (in
a configuration file). We also need to be sure that these run
sequentially, and not in parallel.

AppDomains seem like the right thing to use here - and I can cope with a
small (consistent!) delay in creating and destroying them - but the
increasing memory usage and creation time seems to imply they are not
"fully" destroyed.

Any ideas?

Thanks in advance,

Chris.

If I get you right you load six AD, every 10 seconds, that makes 24 * 60 *
36 = 51840 AD/Day, this is quite a lot if you consider the possibility that
some types might leak through the AD boundaries and as such wont be unloaded
when the secondary AD unloads.
I'm also not clear on why you load an .exe assembly in an application
domain, why not simply start the .exe as a separate process? If this is not
possible (which I doubt), I would suggest you to recycle the process every
now and then, say once a day.
Willy.
Sep 8 '05 #4
Chris Lacey wrote:
The guts of the code is as follows: AppDomain appDomain = AppDomain.Creat eDomain(appDoma inName); appDomain.Execu teAssembly(task Args[0],
AppDomain.Curre ntDomain.Eviden ce, taskArgs); AppDomain.Unloa d(appDomain); As time has gone on (the schedule process has been running for several
days), the time taken to create/destroy an AppDomain has gone from 1s to
about 12s, and the memory usage of the process has crept steadily upwards.

Should I be creating and destroying AppDomains with this rapidity, or are
they simply not designed for this use? Or am I not getting rid of them
properly with the simple AppDomain.Unloa d().


The guts look fine, and Unload IS what you should be doing. My guess
is that you stripped something seemingly innocuous, and that's what's
causing these increasing create/destroy times.

One trick I have found very useful for debugging app domains is to
watch the assemblies loaded into the default appdomain -
AppDomain.Curre ntDomain.GetAss emblies(). Buggy app domain code often
'leaks' assemblies into the main domain.

--

www.midnightbeach.com
Sep 8 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
6192
by: Daylor | last post by:
in win32 process , when u create new process,u have new main thread. i know,appDomain r logical procces,that exists in 1 win32 process. the q: is there way to create second appDomain (the first 1 is the defualt appDomain) with his new ("main") thread ? if not ,what is the easy and clear way to create new thread on the new appDomain ?
4
15978
by: benben | last post by:
What is exactly the difference b/w an AppDomain and a Process, they seem to me very much the same -- boundary for an execution context with protected resources. ben
4
1945
by: Chris Lacey | last post by:
Hi, I'm currently writing a scheduling service which starts a number DotNet executables, each within a new AppDomain, every ten seconds. The guts of the code is as follows: // For each executable in the list of tasks for (int i = 0; i < this.processTasks.Length; i++) {
3
2380
by: hB | last post by:
Hi. Error = "The configuration system can only be set once. Configuration system is already set" Exception Details: System.InvalidOperationExcepti­on: The configuration system can only be set once. Configuration system is already set
0
1127
by: Chris van de Steeg | last post by:
In iis6 there is this feature to recycle your appdomain at certain tresholds, great. But I recently ran into strange problems when my appdomain was recycled. When my application starts, it loops through all the assemblies it gets from System.AppDomain.CurrentDomain.GetAssemblies(). This works great when the application starts for the first...
1
2485
by: José Joye | last post by:
I'm currently trying to load an instance of a given class within a secondary appDomain and access it from within my main AppDomain. Everything is fine and working if the class in the second AppDomain catches any potential exception. However, if I throw an error within a method that is implemented in the object running in the 2nd AppDomain,...
1
4280
by: Bill Woodruff | last post by:
Visual Studio 2005, .NET FrameWork 2.0, C#, WinForms Application Hi, I've read the recent posts by and to 'Thunderbird' (and learned a lot, thanks, from the usual masters Skeet and Paladino, and others) which involve AppDomains in a remoting scenario, but I think the issue I am working with .... while related ... is sufficiently different...
4
5333
by: illegal.prime | last post by:
Hi all, I'm getting unexpected results when trying to preload assemblies into an AppDomain I'm creating. Upon creation of the AppDomain - I attach an AssemblyResolve to both my current AppDomain and the new AppDomain I create. I copy all the assemblies/dlls into a new directory and then try loading them all into the new AppDomain using the...
31
3395
by: Tom P. | last post by:
I am doing quite a bit of custom painting and it means I have to create a lot of brushes (think one for every file system object in a directory) per paint. How expensive is this? Should I find a way to create the brushes once, store them in an member variable, and use them when I need them? Or is creating brushes a throw-away process that...
0
8205
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8339
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7967
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8220
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6619
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5712
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5392
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3872
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1185
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.