473,395 Members | 1,936 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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.processTasks.Length; i++)
{
try
{
// Create a suitable name for the AppDomain
string[] taskArgs = this.processTasks[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.CreateDomain(appDomainName);

try
{
// Execute the assembly in the AppDomain
Trace.WriteLine(String.Format("Executing assembly '{0}' on AppDomain
'{1}'", taskArgs[0], appDomain.FriendlyName));
appDomain.ExecuteAssembly(taskArgs[0],
AppDomain.CurrentDomain.Evidence, taskArgs);
}
catch (Exception e)
{
// Log any errors
Trace.WriteLine(e.ToString(), EVENT_SOURCE);
EventLog.WriteEntry(EVENT_SOURCE, e.ToString(),
EventLogEntryType.Error);
}
finally
{
// Unload the AppDomain
Trace.WriteLine(String.Format("Unloading AppDomain '{0}'",
appDomain.FriendlyName));
AppDomain.Unload(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.Unload().

Any info very greatefully received!!

Many thanks,

Chris.

Sep 8 '05 #1
4 2320
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.processTasks.Length; i++)
{
try
{
// Create a suitable name for the AppDomain
string[] taskArgs = this.processTasks[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.CreateDomain(appDomainName);

try
{
// Execute the assembly in the AppDomain
Trace.WriteLine(String.Format("Executing assembly '{0}' on AppDomain
'{1}'", taskArgs[0], appDomain.FriendlyName));
appDomain.ExecuteAssembly(taskArgs[0],
AppDomain.CurrentDomain.Evidence, taskArgs);
}
catch (Exception e)
{
// Log any errors
Trace.WriteLine(e.ToString(), EVENT_SOURCE);
EventLog.WriteEntry(EVENT_SOURCE, e.ToString(),
EventLogEntryType.Error);
}
finally
{
// Unload the AppDomain
Trace.WriteLine(String.Format("Unloading AppDomain '{0}'",
appDomain.FriendlyName));
AppDomain.Unload(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.Unload().

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*********@bigfoot.com> wrote in message
news:Og**************@TK2MSFTNGP11.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.CreateDomain(appDomainName); appDomain.ExecuteAssembly(taskArgs[0],
AppDomain.CurrentDomain.Evidence, taskArgs); AppDomain.Unload(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.Unload().


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.CurrentDomain.GetAssemblies(). 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
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...
4
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
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...
3
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...
0
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...
1
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...
1
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,...
4
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...
31
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
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...

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.