473,320 Members | 1,868 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,320 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.

Nov 17 '05 #1
4 1934
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.

Nov 17 '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.
Nov 17 '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.
Nov 17 '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
Nov 17 '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: 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...
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
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: archana | last post by:
Hi all, I am having one web application in which i want to create new appdomain for loading dll dynamically. So my question is how will i do this? I read that aspnet_wp.exe has one appdomain...
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
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.