# Tag Value Change Scripts: Are They Run Asynchronously?

**URL:** <https://forum.inductiveautomation.com/t/tag-value-change-scripts-are-they-run-asynchronously/53749>\
**Category:** Ignition\
**Tags:** ignition79, ignition81\
**Created:** [December 3, 2021, 7:12pm UTC](https://forum.inductiveautomation.com/t/tag-value-change-scripts-are-they-run-asynchronously/53749 "2021-12-03T19:12:57Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [December 3, 2021, 7:12pm UTC](https://forum.inductiveautomation.com/t/tag-value-change-scripts-are-they-run-asynchronously/53749/1 "2021-12-03T19:12:57Z")

</div>

If I have a value change script on a tag that calls a project script and the tag changes again before the last change finishes its execution, will it interrupt the first script call? Or does the tag change script get run in an asynchronous manner? Is this different between v7.9 and v8.1?

---

<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:** [December 3, 2021, 7:17pm UTC](https://forum.inductiveautomation.com/t/tag-value-change-scripts-are-they-run-asynchronously/53749/2 "2021-12-03T19:17:23Z")

</div>

> [@dkhayes117](#):
>
> will it interrupt the first script call?

No.

> [@dkhayes117](#):
>
> Is this different between v7.9 and v8.1?

No.

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [December 3, 2021, 7:20pm UTC](https://forum.inductiveautomation.com/t/tag-value-change-scripts-are-they-run-asynchronously/53749/3 "2021-12-03T19:20:11Z")

</div>

I think I might be missing some events for unknown reasons. Would you say it would be better for the script that is writing to the tags which implement the tag change script to be handled with a FIFO buffer/queue instead?

---

<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:** [December 3, 2021, 7:21pm UTC](https://forum.inductiveautomation.com/t/tag-value-change-scripts-are-they-run-asynchronously/53749/4 "2021-12-03T19:21:48Z")

</div>

Check the `missedEvents` flag to find out for sure.

Each tag can have up to 5 pending executions queued before the it “overflows” and the flag is set. You shouldn’t be missing any unless this flag is set.

---

<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:** [December 3, 2021, 7:28pm UTC](https://forum.inductiveautomation.com/t/tag-value-change-scripts-are-they-run-asynchronously/53749/5 "2021-12-03T19:28:18Z")

</div>

> [@Kevin.Herron](#):
>
> Each tag can have up to 5 pending executions queued

This seems contrary to this:

> [@Tag Change Missed Events](https://forum.inductiveautomation.com/t/tag-change-missed-events/37764/13):
>
> Another tag script performance piece that may be affecting OP is that there is a dedicated thread pool size 3 that all tag change scripts are executed on. So in addition to having a per-tag queue of size 5 that events will sit in, there’s only ever 3 tag change scripts executing at once. This is where you can really get into trouble with long running scripts (as @pturmel hinted), because if you have 3 long running scripts then nothing else is executing until at least one of them finishes.

Is it possible that if there are other tag change scripts running that you could miss one with out the flag being set? Or do I just not clearly understand how it works?

---

<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:** [December 3, 2021, 7:31pm UTC](https://forum.inductiveautomation.com/t/tag-value-change-scripts-are-they-run-asynchronously/53749/6 "2021-12-03T19:31:13Z")

</div>

I’m saying the same thing here. Let’s say your script executes, and then 10 more value changes come in real quick for that tag and it’s still executing.

The queue will have events/values 1, 2, 3, 4, and 10 and your script will execute for these 5 events/values. When it executes with `currentValue` == 10 the `missedEvents` flag will be set.

---

<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:** [December 3, 2021, 7:34pm UTC](https://forum.inductiveautomation.com/t/tag-value-change-scripts-are-they-run-asynchronously/53749/7 "2021-12-03T19:34:11Z")

</div>

Note that they are also running in a thread pool. If you have lots of events with slow execution, other tag events can be delayed.

---

<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:** [December 3, 2021, 7:34pm UTC](https://forum.inductiveautomation.com/t/tag-value-change-scripts-are-they-run-asynchronously/53749/8 "2021-12-03T19:34:32Z")

</div>

I suppose I was referring to the thread pool size of 3, sorry originally had the wrong post linked.

---

<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:** [December 3, 2021, 7:35pm UTC](https://forum.inductiveautomation.com/t/tag-value-change-scripts-are-they-run-asynchronously/53749/9 "2021-12-03T19:35:01Z")

</div>

Yes, there’s also a thread pool of size 3 that is shared between all tag event executions. This really only matters in the case you have a lot of slow to execute scripts, as @pturmel mentioned.

Sometimes it’s okay to increase this pool size, but more often it means you’ve done something wrong and should rethink your approach.

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [December 3, 2021, 7:55pm UTC](https://forum.inductiveautomation.com/t/tag-value-change-scripts-are-they-run-asynchronously/53749/10 "2021-12-03T19:55:30Z")

</div>

My tag script executes in ~100ms, is that too long?

---

<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:** [December 3, 2021, 7:56pm UTC](https://forum.inductiveautomation.com/t/tag-value-change-scripts-are-they-run-asynchronously/53749/11 "2021-12-03T19:56:43Z")

</div>

It’s not fast, but it’s only “too long” if it’s causing other tag event scripts to experience an unacceptable delay in execution. You’d need multiple scripts (3+) with lengthy executions at the same time before you started to notice.

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [December 3, 2021, 7:58pm UTC](https://forum.inductiveautomation.com/t/tag-value-change-scripts-are-they-run-asynchronously/53749/12 "2021-12-03T19:58:21Z")

</div>

I’ll look and see if I can optimize it some, monitor the missed events flag, and test it with several changes at once. I will report back, thanks.

---

<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:** [December 3, 2021, 8:23pm UTC](https://forum.inductiveautomation.com/t/tag-value-change-scripts-are-they-run-asynchronously/53749/13 "2021-12-03T20:23:12Z")

</div>

I’d consider that too long. I wouldn’t tolerate more than low single-digit millis for tag events. I would put anything longer in its own gateway tag change event, possibly with a dedicated thread.

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [December 3, 2021, 9:05pm UTC](https://forum.inductiveautomation.com/t/tag-value-change-scripts-are-they-run-asynchronously/53749/14 "2021-12-03T21:05:38Z")

</div>

What’s the difference between the tag change script on the tag versus the gateway script spot?

---

<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:** [December 3, 2021, 9:40pm UTC](https://forum.inductiveautomation.com/t/tag-value-change-scripts-are-they-run-asynchronously/53749/15 "2021-12-03T21:40:33Z")

</div>

Biggest difference is that you aren’t limited by the thread pool, each event gets it’s own thread, so 1 long running thread will not cause others to be delayed.

---

<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:** [December 3, 2021, 10:27pm UTC](https://forum.inductiveautomation.com/t/tag-value-change-scripts-are-they-run-asynchronously/53749/16 "2021-12-03T22:27:24Z")

</div>

> [@lrose](#):
>
> each event gets it’s own thread

If you choose that option. Otherwise it is a shared thread pool. I don't recall the pool quantities, but more generous than tag events. Also does not discard after 5 queued per tag.

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [December 6, 2021, 8:25pm UTC](https://forum.inductiveautomation.com/t/tag-value-change-scripts-are-they-run-asynchronously/53749/17 "2021-12-06T20:25:35Z")

</div>

I tested the tag change script and it would set the `missedEvents` flag when even just 4-5 tag writes occurred in quick succession. I changed it over to a gateway tag change event testing it up to 75 writes. It picked up every single one 🙂
