Slow Script Execution

I have written a python module for an application. It works fine, but is extremely slow. When I run the external module from a python console outside of Ignition it completes in a second or so. When I run it from a tag change script it takes about 25 seconds. Any suggestions to speed up execution?

You’ll either need to provide the script in its entirety or tell us way more about what it’s doing.

Either way, one place to start would be adding timing and logging statements to different parts of the script to see which parts are taking a long time.

Also, try with a jython console outside of Ignition.

I can’t really supply the full script. The reason for using an external module instead of Ignition scripting is to hide proprietary IP. I will try the suggestion of using a jython console to see if the added layer of java is part of the problem.

Good luck with that. If you are serious about controlling IP in Ignition you’ll write your module in Java and expose its features with registered scripting functions.

1 Like

I tried a jython console as suggested by pturmel. It still operates an order of magnitude faster than it does when called by an Ignition script. Is there something in the way Ignition calls external modules that can cause the module to execute so slow?

I will begin to add timing statements to profile the code to see where the bottlenecks are.

Also, I have attached the module.

Here is the code that calls it.

if currentValue.value:
	from CalcOffsets import calcOffsets
	if (calcOffsets() == 0):
		system.tag.write("[.]rob_riProgramComplete", True)
		system.tag.write("[.]ProgramTogle", True)

Thanks for your help with this.

Code (10.1 KB)

Based on some profiling I did this morning, the majority of the time is in the ftp file transfers. Is there a faster way to copy a file via ftp?

Consider importing and using it directly. StackOverflow also suggests Apache Commons Net, but that isn’t built into Ignition. Interesting code sample, BTW – I love ABB robots.

I am trying to use, but am not having any luck. Are there any examples around that I could look at?

Um? StackoverFlow?

Why is there so much difference (an order of magnitude) between the time required to run a module within Ignition verses running it outside of Ignition?

Answering that definitively would require substantial research, but in your case, I suspect it is thread contention due to your process blocking on I/O (yielding) for every line you read. Consider transferring entire files in one call, then splitting into lines.

That’s what I was suspecting. I have changed to using that apparently reads the entire file. Speed is improving dramatically. I am having to rewrite a few things since the data format is a little different from URLConnection as it is from FTP.

1 Like

Thanks for the help on this one. I changed to and with a couple of other optimizations the time of execution changed from about 25 seconds to about 1 second.

Also, I learned a ton about Python/Jython and interactions with Java, so all is good!