Hey Ignition community, running into an issue here. Ill post the scripts if asked to, but I'm seeing some insanely high wait times on executing these scripts (20+ seconds). mainly moving around strings, or using a OPC tag to set a memory tag true, all taking about 20 seconds to do so. Scan class is set to default (1000ms). Thanks or helping if you can.
You haven't posted the script as preformatted text, and I'm not really at a place where I can retype all of that, however, I will say two things:
- You should not be running blocking read or writes in tag value change scripts. There are good reasons for that, without getting into the details lets just say you want them to execute as quickly as possible.
- The read and write functions all take a list of tag paths. You should perform all reads/writes in a single call at the beginning of the script for reads and the end of the script for writes. That on it's own will help your performance greatly.
Also:
This:
if currentValue.value == True
is functionally equivalent to:
if currentValue.value
But the second is more pythonic.
Tag events run in a limited thread pool (three threads, by default). You must not do anything in a tag event script that takes more than a handful of milliseconds. (Like, single digit milliseconds.)
This means your tag events must not:
-
Make any database calls, except Insert/Update via the Store and Forward system.
-
Make any direct OPC reads, or any OPC tag writes, or direct OPC writes, as these block for many seconds if there are communication problems.
-
Use any system or java functions that will block on any other network activity.
-
Use any system or java functions that access large amounts of data in a filesystem.
-
Use any form of
.sleep()
or any form of busy-looping.
If you need any of the above, use a project-level Gateway Tag Change event (or multiple such) instead of event scripts attached directly to the tag.
A thread dump would be useful here.
also... when you get this moved to a project gateway script (see @pturmel
and @lrose comments), readBlocking and writeBlocking are intended to read/write multiple tags in a single pass.
Instead of using a series of readBlocking or writeBlocking statements, build your paths and values into lists (e.g.tagPaths[], tagValues[]
) then use a single readBlocking(tagPaths)
and a single writeBlocking(tagPaths,tagValues)
.
You'll see execution improvements on an order of magnitude doing that.
You should really pack all your readBlocking
calls into a single call
New to 8.1, so first time around with read/writeBlocking functions. would a standard system.tag.read/write work like in 7.9?
also I found the issue last night. I had a script running every second off a getSecond(now()) expression instead of what it was supposed to be, getDay(now()), no issues after that change.
In 7.9 there is a system.tag.readAll
and system.tag.writeAll
that accepts lists as arguments.
No, they aren’t exactly the same.
In 7.9 system.tag.write
is an asynchronous operation, where system.tag.writeBlocking
is, as the name suggests, a blocking operation.
In 8.1 if you want to write and forget, then you should use system.tag.writeAsync()
.
The functions are also intended to take a list of tag paths and they always return a list of qualified values.
There is a reason that IA went to all the trouble to rejig the functions naming and all.