lundi 1 décembre 2014

What could cause slowness when calling methods from a separate app domain?


Vote count:

0




I setup an AppDomain for my IronPython to run in:



var appDomainSetup = new AppDomainSetup { ApplicationBase = sandboxPath };
var sandbox = AppDomain.CreateDomain("Sandbox", evidence, appDomainSetup, permissionSet);


When sandboxPath is set to my exe directory, calls made by the scripts are "fast." When sandboxPath is set to a folder containing all necessary dlls (basically classes for scripts to call into and relevant IronPython dlls) the scripts' calls are "slow." It is important to note these calls are crossing from my main AppDomain into my sandbox AppDomain. This issue brought up a number of questions due to my lack of understanding of how IronPython works and my searching has led me in a few circles. My main question is how and when does IronPython load assemblies and how would having it using a separate directory as its base decrease performance?:


Do the assemblies get loaded on AppDomain construction? Where can I read how the AppDomain goes about loading assemblies and the assembly loader?



  • This article mentions setting the ApplicationBase property determines "where the assembly loader begins probing for assemblies to load into a new application domain."


When I call Python.CreateEngine with a new AppDomain what is exactly happening?



  • I see that it creates a script runtime. If I preload the assemblies perhaps the performance hit will go away? Or does setting the base already preload the assemblies in the base directory?


Finally, say I have some class TypeA in Types.dll that can be shared across AppDomains and some dictionary class in which I have a bunch of TypeAs stored. These TypeAs are set from the C# side of things (as part of a Main.proj). This storage class has a proxy a scope value class so it can be accessed by the IronPython scripts (this scope value is in Sandbox.proj). With the separate directory setup above, I actually have two Types.dll, one in my exe directory and one in my sandbox directory. The C# project is built to reference the one in the exe directory while I assume IronPython is referencing the one in its ApplicationBase directory. Why isn't that a problem? Is that a potential issue here? I know this is easily fixable but I don't understand why it works. Summing it up: I have two identical dlls loaded into two separate AppDomains which communicate with each other by passing a class in those dlls around but it's not really the same class.


Dependencies:



Main.proj -> Types.dll // to set the TypeAs read from a file or network
Sandbox.proj -> Types.dll // to read in the scripts


Folder structure:



bin/Main.exe
bin/Types.dll
bin/Sandbox/Sandbox.dll
bin/Sandbox/Types.dll


Any help and comments are welcome.



asked 47 secs ago







What could cause slowness when calling methods from a separate app domain?

Aucun commentaire:

Enregistrer un commentaire