# Slow On change script

**URL:** <https://forum.inductiveautomation.com/t/slow-on-change-script/77824>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [August 14, 2023, 7:01pm UTC](https://forum.inductiveautomation.com/t/slow-on-change-script/77824 "2023-08-14T19:01:35Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![ecujak](https://avatars.discourse-cdn.com/v4/letter/e/839c29/32.png) [@ecujak](https://forum.inductiveautomation.com/u/ecujak)\
**Post date:** [August 14, 2023, 7:01pm UTC](https://forum.inductiveautomation.com/t/slow-on-change-script/77824/1 "2023-08-14T19:01:35Z")

</div>

I am only recording changes about every 800 milliseconds.

I have a DINT tag on a Logix controller that should be updating every cycle for 1-3 seconds. I am expecting thousands of changes. The on change script logs this tag value and three other tags at the time of the event.  
Tag group:  
I have tried Sub and Polling. Sampling of 1ms

Tag:  
Deadband is Absolute.  
Auto and Discrete.  
Sample mode of On Change and Tag Group....

nothing is improving.

The PLC cycle time is about 1.2 ms.

Why is sampling so slow?

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [August 14, 2023, 7:06pm UTC](https://forum.inductiveautomation.com/t/slow-on-change-script/77824/2 "2023-08-14T19:06:11Z")

</div>

> [@ecujak](#):
>
> I am only recording changes about every 800 milliseconds

That's pretty fast actually.

> [@ecujak](#):
>
> The on change script logs this tag value and three other tags at the time of the event.

Can you show this script? Is this a `valueChange` script on the tag, or a `tagChange` script on the gateway?

Are you using IA's Logix Driver?

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [August 14, 2023, 7:11pm UTC](https://forum.inductiveautomation.com/t/slow-on-change-script/77824/3 "2023-08-14T19:11:45Z")

</div>

> I am only recording changes about every 800 milliseconds.

Do you mean that tag historian is updating every 800 ms?

> I have a DINT tag on a Logix controller that should be updating every cycle for 1-3 seconds. I am expecting thousands of changes.

You say below that your PLC scan time is 1.2 ms. You are trying to log **one tag** and hoping to catch every scan for 3 s?

> The ~~on change~~ **onChange** script logs this tag value and three other tags at the time of the event.

Is this a gateway event script? Can you show the code?

> I have tried Sub and Polling. Sampling of 1 ms.

What is the network path between the gateway and the PLC? Are they on the same subnet?

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [August 14, 2023, 7:14pm UTC](https://forum.inductiveautomation.com/t/slow-on-change-script/77824/4 "2023-08-14T19:14:14Z")

</div>

You can't poll a PLC that fast.

Realistically, you need to accumulate changes into a buffer/array and then poll that buffer and process it at a much slower rate.

Look at your device diagnostics. Usually best case response time from the PLC is something like 5ms per request.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [August 14, 2023, 7:16pm UTC](https://forum.inductiveautomation.com/t/slow-on-change-script/77824/5 "2023-08-14T19:16:22Z")

</div>

> [@ecujak](#):
>
> I am expecting thousands of changes.

PLC Cycle time has no bearing on the answer. What rate is the subscription for the OPC tag in Ignition (typically set via the rate in the tag group)? Ignition is not even going to **try** to get samples faster than that.

If you set the poll rate (interval, really) to a very small number, it will actually run at the fastest pace the PLC's request-response comms processor can handle (aka "Class 3" comms). Typical response times for the latest processors (L8x family) with a light load is mid-single-digit milliseconds. With much load, low tens of milliseconds.

If you really need to capture events that occur hundreds per second, you will certainly need a ring buffer in the PLC to hold them so an external client (like Ignition) can bulk read from the buffer. Or switch to class 1 communications (aka I/O packets). Or both. [(Cough...)](https://inductiveautomation.com/moduleshowcase/module/automation-professionals-llc-ethernetip-class-1-communications)

---

<div class="post-metadata">

**Author:** ![ecujak](https://avatars.discourse-cdn.com/v4/letter/e/839c29/32.png) [@ecujak](https://forum.inductiveautomation.com/u/ecujak)\
**Post date:** [August 15, 2023, 9:06pm UTC](https://forum.inductiveautomation.com/t/slow-on-change-script/77824/6 "2023-08-15T21:06:25Z")

</div>

Irose, this was a valueChange script on the tag. We are using the IA Logix Driver.

It is a simple insert to an SQL database for two DINT tags and a DateTime tag.

---

<div class="post-metadata">

**Author:** ![ecujak](https://avatars.discourse-cdn.com/v4/letter/e/839c29/32.png) [@ecujak](https://forum.inductiveautomation.com/u/ecujak)\
**Post date:** [August 15, 2023, 9:08pm UTC](https://forum.inductiveautomation.com/t/slow-on-change-script/77824/7 "2023-08-15T21:08:02Z")

</div>

I would like to get more than 5 of the several thousand scans....

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [August 15, 2023, 9:10pm UTC](https://forum.inductiveautomation.com/t/slow-on-change-script/77824/8 "2023-08-15T21:10:41Z")

</div>

> [@ecujak](#):
>
> get more than 5 of the several thousand scans

Did you go look at the settings described? Did you go look at the driver diagnostics?

Getting thousands of values per second is **non-trivial** for request-response drivers. Your desire is utterly unreasonable for "out-of-the-box" operation.

---

<div class="post-metadata">

**Author:** ![ecujak](https://avatars.discourse-cdn.com/v4/letter/e/839c29/32.png) [@ecujak](https://forum.inductiveautomation.com/u/ecujak)\
**Post date:** [August 15, 2023, 9:12pm UTC](https://forum.inductiveautomation.com/t/slow-on-change-script/77824/9 "2023-08-15T21:12:06Z")

</div>

Thank you all. I would like to log every 20ms. I didn't know what type of polling limits to expect. I didn't know what setup I should used to get the best response time.

---

<div class="post-metadata">

**Author:** ![ecujak](https://avatars.discourse-cdn.com/v4/letter/e/839c29/32.png) [@ecujak](https://forum.inductiveautomation.com/u/ecujak)\
**Post date:** [August 15, 2023, 9:14pm UTC](https://forum.inductiveautomation.com/t/slow-on-change-script/77824/10 "2023-08-15T21:14:11Z")

</div>

> [@Transistor](#):
>
> What is the network path between the gateway and the PLC? Are they on the same subnet?

They are on the same subnet on the same switch.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [August 15, 2023, 9:15pm UTC](https://forum.inductiveautomation.com/t/slow-on-change-script/77824/11 "2023-08-15T21:15:10Z")

</div>

> [@ecujak](#):
>
> I would like to log every 20ms.

You need a ring buffer in your PLC to hold several seconds worth of your (multi-value) samples. Include a precision timestamp with each sample to place in the DB. You need some rather tricky code in a fast tag change event in Ignition to slurp up the new values in the ring when your index register changes. You need to use multi-row inserts to your DB so that its own round-trip response time doesn't hold you back.

---

<div class="post-metadata">

**Author:** ![ecujak](https://avatars.discourse-cdn.com/v4/letter/e/839c29/32.png) [@ecujak](https://forum.inductiveautomation.com/u/ecujak)\
**Post date:** [August 15, 2023, 9:18pm UTC](https://forum.inductiveautomation.com/t/slow-on-change-script/77824/12 "2023-08-15T21:18:07Z")

</div>

Again thank you for your help. This is always the most helpful and responsive product forum that I have ever experienced. Another reason I always recommend this product. Take care ...
