# Is tag.readBlocking function reading from memory or PLC OPC?

**URL:** <https://forum.inductiveautomation.com/t/is-tag-readblocking-function-reading-from-memory-or-plc-opc/94328>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [August 8, 2024, 6:01am UTC](https://forum.inductiveautomation.com/t/is-tag-readblocking-function-reading-from-memory-or-plc-opc/94328 "2024-08-08T06:01:12Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hui\_Xia](https://avatars.discourse-cdn.com/v4/letter/h/ee7513/32.png) [@Hui\_Xia](https://forum.inductiveautomation.com/u/Hui_Xia)\
**Post date:** [August 8, 2024, 6:01am UTC](https://forum.inductiveautomation.com/t/is-tag-readblocking-function-reading-from-memory-or-plc-opc/94328/1 "2024-08-08T06:01:13Z")

</div>

I connect a simens PLC 1500 by OPC.  
I try to use readblcoking(tagPaths) , but sometimes it cost too much time (more than 1 sec ).  
I want to check this function is reading tags from PLC direct or ignition read all tags from PLC and store to memory , this function read tags from memory.

---

<div class="post-metadata">

**Author:** ![Benjamin\_Furlani](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/benjamin_furlani/32/66084_2.png) [@Benjamin\_Furlani](https://forum.inductiveautomation.com/u/Benjamin_Furlani)\
**Post date:** [August 8, 2024, 10:44am UTC](https://forum.inductiveautomation.com/t/is-tag-readblocking-function-reading-from-memory-or-plc-opc/94328/2 "2024-08-08T10:44:52Z")

</div>

I believe when running anything against tags on a provider such as [default] it is reading from Ignitions tag store.

ReadBlocking will return you a PyList of QualifiedValues from what it currently has in memory for that provider.

In terms of it taking "More than 1 second" I am unsure what your use case is, but the result of the readBlocking function depends somewhat on Gateway Memory/CPU allocation as well as the number of tags you are actually trying to read. Keep in mind too, if you are reading say 100 tags, and then running a process of looping, sorting, etc on them that will also take time.

I recommend if you are having a specific issue other than speed of your gateway returning the results of your readBlocking call you should add to this post what those issues may be, or make another post with a different topic heading to get more assistance.

---

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [August 8, 2024, 11:51am UTC](https://forum.inductiveautomation.com/t/is-tag-readblocking-function-reading-from-memory-or-plc-opc/94328/3 "2024-08-08T11:51:39Z")

</div>

system.tag.readBlocking reads the QualifiedValue from the Ignition tag database. See the manual: [system.tag.readBlocking | Ignition User Manual](https://docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions/system-tag/system-tag-readBlocking)

If you want the actual live value from the PLC, you will need to use the system.opc.readValues function. See the manual: [system.opc.readValues | Ignition User Manual](https://docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions/system-opc/system-opc-readValues)

As @Benjamin_Furlani noted, the response time for either is going to be extremely sensitive to gateway load, where the function is called etc... If you are calling the function in a client scope environment, that call has to make a round trip to the gateway with then also involves network latency etc...

Note... that the readBlocking is a **thread blocking** call. So if used on a button on a client screen, then the screen will freeze while that read is happening. You can mitigate that by using either system.tag.readAsync, or a combination of system.util.invokeAsync and system.util.invokeLater together to mitigate that freeze aspect.

---

<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 8, 2024, 12:00pm UTC](https://forum.inductiveautomation.com/t/is-tag-readblocking-function-reading-from-memory-or-plc-opc/94328/4 "2024-08-08T12:00:48Z")

</div>

> [@Hui\_Xia](#):
>
> I try to use readblcoking(tagPaths) , but sometimes it cost too much time (more than 1 sec ).

I have read hundreds of tags in milliseconds. Show the code that is taking too much time, there may be other reasons the execution time is taking so long.

---

<div class="post-metadata">

**Author:** ![Hui\_Xia](https://avatars.discourse-cdn.com/v4/letter/h/ee7513/32.png) [@Hui\_Xia](https://forum.inductiveautomation.com/u/Hui_Xia)\
**Post date:** [August 9, 2024, 1:13am UTC](https://forum.inductiveautomation.com/t/is-tag-readblocking-function-reading-from-memory-or-plc-opc/94328/5 "2024-08-09T01:13:05Z")

</div>

I try to use readasync function but it also cause a long delay time , I reduce the max processor state of compute to 99% that will cause the cpu run at 2.4Ghz， if I modify the max processor state to 100% , the script execute low than 1 second .  
The code like this  
self.view.custom.instance = utils.getTagPathAsDict(tagPath)

The function getTagPathAsDict will read all of tags from tagPath by readblocking .  
The count of tags in tagPath is 79.  
This code may execute 21 or 28 times per second.  
If the CPU run at 2.4GHz, the time of execute will get longer and longer (1sec,2sec,and more).  
The scripts execute in one core of CPU or all of cores of CPU?

Because the project is just one of my project ,if I use all project with this code ,it will execute more than 200 times per second , it will cause more problems.

---

<div class="post-metadata">

**Author:** ![Hui\_Xia](https://avatars.discourse-cdn.com/v4/letter/h/ee7513/32.png) [@Hui\_Xia](https://forum.inductiveautomation.com/u/Hui_Xia)\
**Post date:** [August 9, 2024, 1:14am UTC](https://forum.inductiveautomation.com/t/is-tag-readblocking-function-reading-from-memory-or-plc-opc/94328/6 "2024-08-09T01:14:03Z")

</div>

self.view.custom.instance = utils.getTagPathAsDict(tagPath)

The function getTagPathAsDict will read all of tags from tagPath by readblocking .  
The count of tags in tagPath is 79.  
This code may execute 21 or 28 times per second.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [August 9, 2024, 2:02am UTC](https://forum.inductiveautomation.com/t/is-tag-readblocking-function-reading-from-memory-or-plc-opc/94328/7 "2024-08-09T02:02:59Z")

</div>

Post the actual function definition you're calling in the project script.

---

<div class="post-metadata">

**Author:** ![Hui\_Xia](https://avatars.discourse-cdn.com/v4/letter/h/ee7513/32.png) [@Hui\_Xia](https://forum.inductiveautomation.com/u/Hui_Xia)\
**Post date:** [August 9, 2024, 5:09am UTC](https://forum.inductiveautomation.com/t/is-tag-readblocking-function-reading-from-memory-or-plc-opc/94328/8 "2024-08-09T05:09:34Z")

</div>

```python
import system.tag as Tag
def getTagPathAsDict(tagPath_):
    """
    :param tagPath_:
    :return:
    """
    dict_ = {}
    tags = Tag.browse(tagPath_)
    for tag in tags:
        keyName = tag['fullPath'].split('/')[-1]
        if str(tag['tagType']) != 'Folder':          
            dict_[keyName] = Tag.readBlocking([tag["fullPath"]])[0].value
        else:
            #name =getTagPathAsDict(str(element['fullPath']) + "/info/name")
            dict_[keyName] = getTagPathAsDict(tag["fullPath"])
    return dict_

```

I write a sample code for it ,it's different with really code ,but the cost time operator is the same.  
If several read the same tags in the same time ,will it cause spend more time or not?

---

<div class="post-metadata">

**Author:** ![Hui\_Xia](https://avatars.discourse-cdn.com/v4/letter/h/ee7513/32.png) [@Hui\_Xia](https://forum.inductiveautomation.com/u/Hui_Xia)\
**Post date:** [August 9, 2024, 5:47am UTC](https://forum.inductiveautomation.com/t/is-tag-readblocking-function-reading-from-memory-or-plc-opc/94328/9 "2024-08-09T05:47:14Z")

</div>

I tested the function , read all of the tagPath's tag to dict is faster than system.tag.readBlocking([tagPath])

```python
sumList = []
for i in range(100):
	start_ = time.time()
	x= system.tag.readBlocking([tagPath])
	end_ =time.time()
	sumList.append(end_-start_)
print(sum(sumList)/len(sumList))	
sumList = []
for i in range(100):
	start_ = time.time()
	x= utils.getTagPathAsDict(tagPath)
	end_ =time.time()
	sumList.append(end_-start_)
print(sum(sumList)/len(sumList))

```

output is:  
readBlocking cost 0.159990000725s  
read all of children tag one by one to dict cost 0.0268899989128s

Could you tell me the reason of different cost time .

---

<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 9, 2024, 12:09pm UTC](https://forum.inductiveautomation.com/t/is-tag-readblocking-function-reading-from-memory-or-plc-opc/94328/10 "2024-08-09T12:09:52Z")

</div>

> [@Hui\_Xia](#):
>
> readBlocking cost 0.159990000725s  
> read all of children tag one by one to dict cost 0.0268899989128s

What is TagPath, because I have never, in 8 years found this to be true.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [August 9, 2024, 4:20pm UTC](https://forum.inductiveautomation.com/t/is-tag-readblocking-function-reading-from-memory-or-plc-opc/94328/11 "2024-08-09T16:20:02Z")

</div>

There's literally no way _browsing_ and reading many tags in sequence _recursively_ is faster than an individual tag read.

What your sample script there is doing is _catastrophic_ for performance, and probably explains your issues in one.

What are you _actually doing_ that lead you to this script, that completely ignores the benefits of a tag hierarchy and instead reads every single tag underneath a path in one go? What are you doing with this massive result dictionary, especially every ~35 milliseconds? (A rate that will basically never be consistently achievable even with a simple flat read, because of garbage collection stalls in Ignition).

The scripting practices here _don't make sense_, and it's likely you've engineered yourself into a corner that's going to take significant effort to crawl out of.

---

<div class="post-metadata">

**Author:** ![Hui\_Xia](https://avatars.discourse-cdn.com/v4/letter/h/ee7513/32.png) [@Hui\_Xia](https://forum.inductiveautomation.com/u/Hui_Xia)\
**Post date:** [August 12, 2024, 9:44am UTC](https://forum.inductiveautomation.com/t/is-tag-readblocking-function-reading-from-memory-or-plc-opc/94328/13 "2024-08-12T09:44:43Z")

</div>

Thank you , I will try to do more test in that ,from my side I just want to use the bind to an custom parameter, use read tag per second is not an good solution .  
Could you tell as the opc tags update time or update strategy?I have some tags in plc is changed very fast like current( LT#time type) , if I bind these tags to parameter ,could it cause some issues?

---

<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 12, 2024, 11:35am UTC](https://forum.inductiveautomation.com/t/is-tag-readblocking-function-reading-from-memory-or-plc-opc/94328/14 "2024-08-12T11:35:46Z")

</div>

> [@Hui\_Xia](#):
>
> I have some tags in plc is changed very fast like current( LT#time type)

Ignition is going to poll the PLC at a pace set in Ignition's tag group. It will only notice changes that often, no matter how quickly the signal changes in the PLC. If there is no change from one poll to the next, Ignition will avoid updating bindings with the unchanged value.

Polling a PLC very fast is **difficult** to achieve with ordinary protocols.

---

<div class="post-metadata">

**Author:** ![Hui\_Xia](https://avatars.discourse-cdn.com/v4/letter/h/ee7513/32.png) [@Hui\_Xia](https://forum.inductiveautomation.com/u/Hui_Xia)\
**Post date:** [August 13, 2024, 4:55am UTC](https://forum.inductiveautomation.com/t/is-tag-readblocking-function-reading-from-memory-or-plc-opc/94328/15 "2024-08-13T04:55:37Z")

</div>

I got it , Thank you very much .
