c# - Scripting.Dictionary Performance Suffers In Multiple Processes -
to illustrate problem, compile c# project reference microsoft scripting runtime, , code below. run single instance of resulting executable. on 12 core machine, read loop consistently takes 180ms. starting instance of executable slows down, approximately 100ms per additional executable.
any ideas what's going on? , solutions other switching different dictionary implementation?
using system; using system.collections.generic; using system.linq; using system.text; namespace consoleapplication4 { class program { static void main(string[] args) { system.diagnostics.stopwatch stp = new system.diagnostics.stopwatch(); var dict = (scripting.idictionary)(new scripting.dictionary()); stp.start(); (int = 1; < 1000; ++i) { object s = i.tostring(); dict.add(ref s, ref s); } console.writeline("after add {0}", stp.elapsedmilliseconds); object q = null; (int j = 0; j < 1000; ++j) { long old = stp.elapsedmilliseconds; (int = 1; < 10000; ++i) { q = null; object s = i.tostring() object; q = dict.get_item(ref s); } long newval = stp.elapsedmilliseconds; console.writeline("after retrieve {0}", newval - old); } } } }
eric, you'll pleased hear problem not specific scripting.dictionary, rather apartment threading model. 1 can read performance impact of mixed threading models on msdn, surprise (to me) out-of-process impact.
i able create own com object single method, outlined below, replacing scripting.dictionary calls in above example. can switch between 'apartment' , 'both' threading models in test.rgs file, rebuild, , confirm cross-process impact resolved in mta-enabled object.
moreover, attaching debugger , pausing process, using procexp (from microsoft sysinternals), 1 can see call stack heading off kernel, assume there single queue being managed com marshalling, causing bottle-neck across different processes.
even worse, slowdown occurs when marshalling calls different objects, observable running 1 application calling scripting.dictionary, few others calling donothing(), , watching of them slowing down.
for our purposes, use alternative dictionary implementation (although possible change scripting.dictionary threading model, seems unwise).
i suppose there still question outstanding inter-process impact of com marshalling. recommendation must try avoid apartment threading in multi-process environment unless has better answer...?
creating test com object
- create new project in visual studio, using c++ atl template (i'm using vs 2008).
- select server type dll.
- right-click project, add class... -> atl simple object.
- give short name, e.g. "test", ensure apartment threading selected.
- from class view, right-click interface (itest), , add method...
- name method, e.g. "donothing", , leave default options.
- check method implementation empty, , build.
one can add com reference test application , call donothing() method.
Comments
Post a Comment