2

I have a very strange problem, I have a c# application (quite complex) that among other things calls an Ironpython script that exchanges some data with the C# code. The IronPython script do a set of calculations and mainly it passes from around 30 rules checking the input data and collects the results of each, which returns as the results set. This script is called repeatedly every 20 sec for about 60 times before the whole process ends. The result is that the CPU load increases continuously up to 100% and stays there until the end of the process.

Now, when the script is called either from visual studio as an IronPython project or run as a python script from command prompt (ipy), even as a python script (not IronPython) using Anaconda and cPython and for all of the above with a call repetition like the process, it runs normally without any problem no CPU load more that some spikes that do not go higher than 50% .

When I try to analyze the whole application with visual studio I get something like this IronPython.Runtime.FunctionCode+<>c__DisplayClass19_0.b__0 which appears to have like 500K samples(inclusive, exclusive) and consumes something like the 90% of the CPU load.

I understand that my problem is a bit specific and my question a bit generic but is too complicated to share something more. So, apologies if somebody feels that the picture is not complete ... I accept it, it is not!

What I would like to ask the community is if somebody else has phased a similar problem (similar pattern) and managed to check a few things and maybe resolve the problem or even workaround it.

For those who may wonder, we have already restructured and checked the IronPython code to avoid unnecessary calls or repetitive (endless) loops, etc. Also, even when the CPU is loaded to 100% the script returns the correct results and does not show any issues in operation.

Finally we have tested all know and documented ways to call the IronPython script from within c# (dynamic object, compiled, plain py script and assembly dll), all of them had the same (more or less) CPU performance issue.

My feeling is that it is an issue with how .Net calls IronPython scripts from within C# .

Many thanks in advance for reading my question and even more for your answers.

Regards, IK

  • What kind of classes and patterns are involved? How do you host the ironpython environment? Is there a chance that some kind of handler/dictionary/... keeps lots of stuff around/alive/in memory? Could it happen that you add the rules to something on each execution and they are actually executed several times? – Simon Opelt May 31 '17 at 10:42
  • Hi thanks for your comment. – user8091075 Jun 01 '17 at 10:48
  • Hi thanks for your comment. In the IronPython script the logic is simple many different set of parameters that are checked for a set of around 30 rules, eg. for rule No1, if from set#1 the param#23 is greater than param#34 from set#2 bla bla ... then rule_1_mark is 8 and rule_1_message is Hello World, etc. Yes we are using a lot of dictionaries but memory is not an issue is kept normal but cpu load is a problem. Quite true but how to figure out if something remains, all function calls seem to end normally ... – user8091075 Jun 01 '17 at 11:09
  • Don't really got your question about IronPython env. let me clarify a bit, version is 2.7.7, I create an engine from C# using its classes and then load the script (py), scope, py object instantiation using invoke and then using that and the engine I am invoking functions. The way to access as I understand that is pretty standard how to call ironpython from c#, is'n it? Please advise on that if you can, I am interested. – user8091075 Jun 01 '17 at 11:09
  • It is curios that the python script is taking 100% of the CPU. In case you are not running a multi threaded application, and assuming that you are not using a single core processor, this seems more like a problem of environment (IDE/Debugger, .Net...) that is taking your processor up. You could try to run the same application if you did not tried by now in the Release mode, without the debugger attached. – meJustAndrew Jun 02 '17 at 13:41
  • In order to reply to the comments of others, please use @ and their name, so they get notified by your comment, as I have seen you have tried to reply to @SimonOpelt – meJustAndrew Jun 02 '17 at 13:42

0 Answers0