Question

In our server we are loading a third-party assembly which creates its own resources like memory and threads. We need to create multiple instance of this third-party plug-in and as number of instances increases memory and threads for our server hits the limit.

One way is to load this plug-ins in different exes, which frees up server resources. This will work as each process will get benefit of its own resource pool.

The question is, if we use AppDomain and isolate the plug-in, will it give the advantage similar to hosting it in different process with respect to resource availability.

Thanks, M...

Was it helpful?

Solution

AppDomain does not enjoy a new 'resource space' provided by the OS. For example, the available memory space is not enlarged when creating a new AppDomain which could be a limitation on 32bit systems. For the same reason, an error which causes the process to die (like out of memory) will cause all AppDomains in process to die together, and so are uncatched exceptions. That's absolutely wrong when using Processes.

However .NET do deal with AppDomain as foreign units. For example garbage collection is performed for each AppDomain by its own thus one GC thread of an AppDomain will not disturb different AppDomain. It may affect the CPU time resource that AppDomains consume by lowering dependencies between AppDomains (although I've never tried to check how much it affects).

From your questions it sounds like process is the preferred solution as you want a different resource pool for each plugin, but the answer depends on what exactly resource types are you talking about.

OTHER TIPS

My experience is that processes are more flexible and stable than AppDomains. There are some fatal limitations of AppDomains compared to processes:

  1. If threads are created in the AppDomain, the host has no idea about the new threads
  2. If threads are created in the AppDomain and an unhandled exception is thrown in the new threads, the whole process will be killed (which is disaster when hosting 3rd party components)
  3. An AppDomain cannot be unloaded properly if it contains unmanaged code
  4. Even if the AppDomain only contains managed code, you may still not be able to unload it or abort the thread (e.g. dead loop in finally block), while a process can be easily killed
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top