# Optimizing Switch Nodes / OPCUA

**URL:** <https://discourse.nodered.org/t/optimizing-switch-nodes-opcua/46524>\
**Category:** General\
**Created:** [31 May 2021 20:34 UTC](https://discourse.nodered.org/t/optimizing-switch-nodes-opcua/46524 "2021-05-31T20:34:45Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![psalibe](https://avatars.discourse-cdn.com/v4/letter/p/e9c0ed/32.png) [@psalibe](https://discourse.nodered.org/u/psalibe)\
**Post date:** [31 May 2021 20:34 UTC](https://discourse.nodered.org/t/optimizing-switch-nodes-opcua/46524/1 "2021-05-31T20:34:45Z")

</div>

I have a general question about the capabilities of the switch node. For example, in the screenshot attached, I am sending just about all of my OPC info through one READ node that then goes to a switch node, and using browseName I separate them and send them where they need to go. Is this too many for the switch node to handle? Would it be better to split it up into 2 equally sized ones? Every once in a while it seems like there is a delay (which is why I split some off into the top READ node) Just wasn't sure if it was approaching the limits of its capability

![Screen Shot 2021-05-31 at 4.30.20 PM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/6/06368ef0d2e6830dcdbf727164c5fe31162372b1.png)

Thanks

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [31 May 2021 21:12 UTC](https://discourse.nodered.org/t/optimizing-switch-nodes-opcua/46524/2 "2021-05-31T21:12:30Z")

</div>

You forgot the screenshot 🙂

---

<div class="post-metadata">

**Author:** ![psalibe](https://avatars.discourse-cdn.com/v4/letter/p/e9c0ed/32.png) [@psalibe](https://discourse.nodered.org/u/psalibe)\
**Post date:** [31 May 2021 21:14 UTC](https://discourse.nodered.org/t/optimizing-switch-nodes-opcua/46524/3 "2021-05-31T21:14:43Z")

</div>

Haha thank you for pointing that out!! 🤣

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [31 May 2021 21:22 UTC](https://discourse.nodered.org/t/optimizing-switch-nodes-opcua/46524/4 "2021-05-31T21:22:52Z")

</div>

There's something different about your image - it doesn't expand when you click it - can you try just pasting the image in please

(Did you shrink it before posting or something - if you did - paste the original full image instead)

---

<div class="post-metadata">

**Author:** ![psalibe](https://avatars.discourse-cdn.com/v4/letter/p/e9c0ed/32.png) [@psalibe](https://discourse.nodered.org/u/psalibe)\
**Post date:** [31 May 2021 21:25 UTC](https://discourse.nodered.org/t/optimizing-switch-nodes-opcua/46524/5 "2021-05-31T21:25:02Z")

</div>

![Screen Shot 2021-05-31 at 4.30.20 PM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/6/06368ef0d2e6830dcdbf727164c5fe31162372b1.png)

---

<div class="post-metadata">

**Author:** ![tree-frog](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tree-frog/32/89303_2.png) [@tree-frog](https://discourse.nodered.org/u/tree-frog)\
**Post date:** [1 June 2021 00:14 UTC](https://discourse.nodered.org/t/optimizing-switch-nodes-opcua/46524/6 "2021-06-01T00:14:59Z")

</div>

When using a switch or this approach, the results depend on the iteration when it got to the result that then broke out to the output. The LAST iteration takes the longest to find, thus delay. The first, the less time, the fastest. You will need to find a method to eliminate the time taken to search through the "switch". Or, you will need to find a means to eliminate the variance in the time it takes to find the first vs. the last possible choice.

---

<div class="post-metadata">

**Author:** ![psalibe](https://avatars.discourse-cdn.com/v4/letter/p/e9c0ed/32.png) [@psalibe](https://discourse.nodered.org/u/psalibe)\
**Post date:** [9 June 2021 14:26 UTC](https://discourse.nodered.org/t/optimizing-switch-nodes-opcua/46524/7 "2021-06-09T14:26:23Z")

</div>

Do you have any suggestions on a more efficient way to do this?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [9 June 2021 14:49 UTC](https://discourse.nodered.org/t/optimizing-switch-nodes-opcua/46524/8 "2021-06-09T14:49:41Z")

</div>

Can you export just the switch node and share it here, so we can see what you are doing there? In case you don't know how to do that see this post for more details - [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506)

---

<div class="post-metadata">

**Author:** ![psalibe](https://avatars.discourse-cdn.com/v4/letter/p/e9c0ed/32.png) [@psalibe](https://discourse.nodered.org/u/psalibe)\
**Post date:** [9 June 2021 15:09 UTC](https://discourse.nodered.org/t/optimizing-switch-nodes-opcua/46524/9 "2021-06-09T15:09:46Z")

</div>

```auto
[{"id":"33f668dd.52c13","type":"switch","z":"d86d2f0f.3aa6e","g":"9563f4d9.722bf","name":"","property":"browseName","propertyType":"msg","rules":[{"t":"cont","v":"DIG LOAD CELL NORMALIZED","vt":"str"},{"t":"cont","v":"DIG WEIGHT NET","vt":"str"},{"t":"cont","v":"DIG WEIGHT FINAL","vt":"str"},{"t":"cont","v":"DIG WEIGHT TARE OFFSET","vt":"str"},{"t":"cont","v":"DIG TANK PERCENT FULL","vt":"str"},{"t":"cont","v":"UNLOCK DIG DOOR REQ","vt":"str"},{"t":"cont","v":"DIG TEMP FINAL","vt":"str"},{"t":"cont","v":"DIG WEIGHT AVERAGE","vt":"str"},{"t":"cont","v":"AUTO MODE","vt":"str"},{"t":"cont","v":"HEARTBEAT TO HMI","vt":"str"},{"t":"cont","v":"BOIL LOAD CELL NORMALIZED","vt":"str"},{"t":"cont","v":"BOIL WEIGHT NET","vt":"str"},{"t":"cont","v":"BOIL WEIGHT FINAL","vt":"str"},{"t":"cont","v":"BOIL WEIGHT TARE OFFSET","vt":"str"},{"t":"cont","v":"BOIL WEIGHT AVERAGE","vt":"str"},{"t":"cont","v":"POWER ON COMPLETE","vt":"str"},{"t":"cont","v":"DIG MOTOR SPEED","vt":"str"},{"t":"cont","v":"ECO MODE","vt":"str"},{"t":"cont","v":"MANUAL MODE","vt":"str"},{"t":"cont","v":"CLEANOUT MODE","vt":"str"},{"t":"cont","v":"STANDBY MODE","vt":"str"},{"t":"cont","v":"JAM COUNT","vt":"str"},{"t":"cont","v":"DIG MIXER RECIPE","vt":"str"},{"t":"cont","v":"BIO DOSE COMPLETE","vt":"str"},{"t":"cont","v":"FAULTED CODE","vt":"str"},{"t":"cont","v":"DIG FAULTED","vt":"str"},{"t":"cont","v":"BOIL FAULTED","vt":"str"},{"t":"cont","v":"MAIN FAULTED","vt":"str"},{"t":"cont","v":"BOIL WT MIN SETPOINT","vt":"str"},{"t":"cont","v":"BOIL WT MAX SETPOINT","vt":"str"},{"t":"cont","v":"BOIL WT FULL SETPOINT","vt":"str"},{"t":"cont","v":"BOIL WT EMPTY SETPOINT","vt":"str"},{"t":"cont","v":"DIG WT MIN SETPOINT","vt":"str"},{"t":"cont","v":"DIG WT MAX SETPOINT","vt":"str"},{"t":"cont","v":"DIG WT FULL SETPOINT","vt":"str"},{"t":"cont","v":"DIG WT EMPTY SETPOINT","vt":"str"},{"t":"cont","v":"DIG PUMP","vt":"str"},{"t":"cont","v":"TOTAL KW","vt":"str"},{"t":"cont","v":"BOIL PROGRAM STATUS","vt":"str"},{"t":"cont","v":"DIG PROGRAM STATUS","vt":"str"},{"t":"cont","v":"DIG TEMP MAX SP","vt":"str"},{"t":"cont","v":"DIG TEMP MIN SP","vt":"str"},{"t":"cont","v":"BAND MAX TEMP SP","vt":"str"},{"t":"cont","v":"BOIL TEMP STANDBY SP","vt":"str"},{"t":"cont","v":"BOIL TEMP MAX SP","vt":"str"},{"t":"cont","v":"BOIL TEMP MIN SP","vt":"str"},{"t":"cont","v":"DIG TEMP SCALED","vt":"str"},{"t":"cont","v":"DIG TEMP SETPOINT","vt":"str"},{"t":"cont","v":"DIG TEMP FINAL","vt":"str"},{"t":"cont","v":"DIG TEMP OFFSET","vt":"str"},{"t":"cont","v":"BAND TEMP FINAL","vt":"str"},{"t":"cont","v":"TANK TEMP OFFSET","vt":"str"},{"t":"cont","v":"TANK TEMP SCALED","vt":"str"},{"t":"cont","v":"BOIL TANK TEMP FINAL","vt":"str"},{"t":"cont","v":"CHANGE RESIDUAL WARNING","vt":"str"},{"t":"cont","v":"DOSE BIO WARNING","vt":"str"},{"t":"cont","v":"RESIDUAL BIN CONNECTED","vt":"str"},{"t":"cont","v":"CURING OFF","vt":"str"},{"t":"cont","v":"DIG OFF","vt":"str"},{"t":"cont","v":"RESIDUAL WEIGHT","vt":"str"},{"t":"cont","v":"DIG TANK FULL","vt":"str"},{"t":"cont","v":"CURE COOK REQ","vt":"str"}],"checkall":"true","repair":false,"outputs":62,"x":3415,"y":1520,"wires":[["fcadbd07.4a7c98"],["6a14566b.3cf9f8"],["1f972176.cb3d7f"],["691acb9e.34cff4"],["1616ff07.dd5a51","2f9d9560.505282"],["90659be8.65c4d8"],["a416ec9a.7d3068","56b8b88d.e90e08"],["8e42680d.b74348","f70dfc98.f7e5e8","b0adc049.ae98a"],["b81d2b67.510d","f79d2711.2163f"],["e3db4d.3fe80cb","37a4d4ee.4f412c"],["b3d997e2.756d98"],["11eb2292.43a5fd"],["6e18bcd9.4e836c"],["84075c1d.7255c8"],["44938c37.d73fac","c242e9f3.0613f8"],[],["420098ab.eafdc8"],["1fb2c4e6.058b7b","d279a90f.92f08"],["2154cb45.f310ec","a6b518b3.90ba48"],["31946a17.eb4726","5d2a9543.c21efc"],["cc2de4ea.14a23","1571c334.8fdcb5"],["f42a0c90.4d597"],["1fd4eb83.94d2e4","fe2fb154.8257b","1f6ae296.b544dd"],["c0d174c.19a2088"],["754f1058.4c2ea8"],["dccf489d.ada498"],["7d1d848f.9cdcec"],["2598ffed.b39d7"],["8de99747.f968d"],["ad9b8039.acc968"],["28c60f8d.eba1a8"],["38171ebb.9e0c7a"],["aa4c0bfe.b131a"],["a7ea4aaa.d5c9b8"],["fd875b0c.c8b108"],["afc80a0b.d03e5"],["795631f3.1f3918"],[],["470b648c.7657fc","5fbddd05.892fc4","a64dbee6.580e5"],["bb9f3294.756fd8","a52fe14.828d6a","fdef4eae.46535"],["e8da7963.786ee8"],["1fef1277.b2c316"],["685fc766.75e3b"],["9889a203.069d98"],["7957cbb3.3190f4"],["e02c85a2.0f75c8"],[],[],[],[],["4cba71fe.8a4948","2382c5ed.fe20ca","da61b1d0.24e31"],[],[],["a7c8574c.d4f46","4286cdd6.e533c4","591a45d7.abd9a4"],["79f05da8.0855a4"],["2cff5198.d9f816"],["35de24c6.66fb94","26120c1f.396354"],["a2a38139.70327"],["e7e4cb9c.ae084"],["f2ee87e8.bed4a8","857f8307.86355"],["ae8fc088.b4629"],["b71bcaa3.dd7a7"]],"outputLabels":["DIG LOAD CELL NORMALIZED","DIG WEIGHT NET","DIG WEIGHT FINAL","DIG WEIGHT TARE OFFSET","DIG TANK PERCENT FULL","UNLOCK DIG DOOR REQ","DIG TANK TEMP FINAL","DIG WEIGHT AVERAGE","AUTO MODE","HEARTBEAT TO HMI","BOIL LOAD CELL NORMALIZED","BOIL WEIGHT NET","BOIL WEIGHT FINAL","BOIL WEIGHT TARE OFFSET","BOIL WEIGHT AVERAGE","POWER ON COMPLETE","DIG MOTOR SPEED","ECO MODE","MANUAL MODE","CLEANOUT MODE","STANDBY MODE","JAM COUNT","DIG MIXER RECIPE","BIO DOSE COMPLETE","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",null],"l":false}]

```

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [9 June 2021 19:10 UTC](https://discourse.nodered.org/t/optimizing-switch-nodes-opcua/46524/10 "2021-06-09T19:10:56Z")

</div>

It would probably be a little more efficient to check for equals rather than contains as If you use contains and the search string is short then it has to look for it anywhere in the string, not just at the start.

However, if you are seeing a delay that is noticeable to the human brain then I don't believe it is in that node. Even on a Pi Zero that is only going to take a fraction of a second (probably very small fraction).

---

<div class="post-metadata">

**Author:** ![psalibe](https://avatars.discourse-cdn.com/v4/letter/p/e9c0ed/32.png) [@psalibe](https://discourse.nodered.org/u/psalibe)\
**Post date:** [9 June 2021 19:23 UTC](https://discourse.nodered.org/t/optimizing-switch-nodes-opcua/46524/11 "2021-06-09T19:23:59Z")

</div>

So in that case do you think the delay is on the OPCUA side? We use node-red-contrib-opcua READ/WRITE nodes to write data to the OPC and read data coming from it...In this case, the switch node is only used for the READ

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [9 June 2021 19:34 UTC](https://discourse.nodered.org/t/optimizing-switch-nodes-opcua/46524/12 "2021-06-09T19:34:32Z")

</div>

I have no idea. How long a delay are you seeing?

---

<div class="post-metadata">

**Author:** ![psalibe](https://avatars.discourse-cdn.com/v4/letter/p/e9c0ed/32.png) [@psalibe](https://discourse.nodered.org/u/psalibe)\
**Post date:** [10 June 2021 18:15 UTC](https://discourse.nodered.org/t/optimizing-switch-nodes-opcua/46524/13 "2021-06-10T18:15:32Z")

</div>

Sometimes nothing at all, sometimes up to about 8-10 seconds... Have yet to find a pattern

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [10 June 2021 18:49 UTC](https://discourse.nodered.org/t/optimizing-switch-nodes-opcua/46524/14 "2021-06-10T18:49:04Z")

</div>

If it is that long then add some debug nodes and you should be able to work out where the delay is from the timestamps on the debug. If necessary configure them to output to the console so you can go back and analyse then later.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [10 June 2021 18:59 UTC](https://discourse.nodered.org/t/optimizing-switch-nodes-opcua/46524/15 "2021-06-10T18:59:53Z")

</div>

This [flow-timer](https://flows.nodered.org/flow/63f29373e826a9fd4943d679d43e725f) subflow node might help - place as many pairs as you need then check in context for timings.

---

<div class="post-metadata">

**Author:** ![tree-frog](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tree-frog/32/89303_2.png) [@tree-frog](https://discourse.nodered.org/u/tree-frog)\
**Post date:** [11 June 2021 12:40 UTC](https://discourse.nodered.org/t/optimizing-switch-nodes-opcua/46524/16 "2021-06-11T12:40:24Z")

</div>

You should check the source of your OPC-UA Server. If it is remote, then you may have latency on your network or a system that is just slow.  
Can you describe your system such that we can determine where to look for latency issues.

For instance:

- PLC,
- What software is your OPC Server?
- OPC Server side OS,
- Kind of resources the Sever side OS has,
- OPC Server configuration, scan rates etc...
- How many clients are connected at any point in time? Number of Served tags?
- OPC Client Side OS, Kind of resources the Client side OS has...
- Any correlation to the delays and any particular data with the delay. (are some value always late, others always early?)

With OPC it is not uncommon to have up to 3 seconds delay, depending on conditions. OPC-UA may be the same depending on your server. In your case this seems to be exacerbated by other factors.

---

<div class="post-metadata">

**Author:** ![psalibe](https://avatars.discourse-cdn.com/v4/letter/p/e9c0ed/32.png) [@psalibe](https://discourse.nodered.org/u/psalibe)\
**Post date:** [11 June 2021 13:25 UTC](https://discourse.nodered.org/t/optimizing-switch-nodes-opcua/46524/17 "2021-06-11T13:25:48Z")

</div>

Thanks for the responses...I just did a little test with the debug node and it writes "true" on the time that it should (When i hit the button) but I just sometimes get no response for some time..

PLC is a Siemens S7-1200. It uses an OPC UA server. I am not entirely sure about the Server side OS or the resources... I believe we are using Basic256Sha256 and I believe our scan rate is 100ms. In Node-Red I have two Read Client nodes and one Write Client node, and there are about 235 tags but not all writing/reading at the same time... We are using node-red-contrib-opcua nodes for this but am running on a Raspberry Pi (ComfilePi 10.2")

No patterns in particular, but as I said above i did a little test and it writes "true" to the tag at least in the debug panel on time. It does seem like there is a more likely chance of a delay if nothing has been hit in a while. I wonder if it could be slow uptake on the PLC side? Only other thing to report is that we are sending data not only to the dashboard but to a Ubidots cloud service, and sometimes, despite being connected to the internet, some values don't get sent at the rate they should. This is why I asked about the switch node but its sounding more and more like its the PLC/OPC.

---

<div class="post-metadata">

**Author:** ![tree-frog](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tree-frog/32/89303_2.png) [@tree-frog](https://discourse.nodered.org/u/tree-frog)\
**Post date:** [11 June 2021 17:04 UTC](https://discourse.nodered.org/t/optimizing-switch-nodes-opcua/46524/18 "2021-06-11T17:04:14Z")

</div>

I am interested in how the OPC server is configured and installed. Also, how you are getting the data. You are doing subscriptions vs. Asynchronous Reads?

Do you have a subscription Node? to the tags you want to monitor or force Reads by message or inject?

That OPC Server is that on the PLC? or is it installed on a PC in the network loop somewhere?

---

<div class="post-metadata">

**Author:** ![psalibe](https://avatars.discourse-cdn.com/v4/letter/p/e9c0ed/32.png) [@psalibe](https://discourse.nodered.org/u/psalibe)\
**Post date:** [11 June 2021 20:12 UTC](https://discourse.nodered.org/t/optimizing-switch-nodes-opcua/46524/19 "2021-06-11T20:12:59Z")

</div>

The OPC Server I believe is just on the PLC by default. Siemens S7-1200 comes with the OPC UA server. We are doing subscriptions, yes. There is a client node that either reads or writes that is configured with opc.tcp://ipaddress:4840. Then there are item nodes of the same package (node-red-contrib-opcua) that enter the ns and i numbers for the specific tag. Some are being read periodically with injects and others that get written get written on an event like a button push for example.

---

<div class="post-metadata">

**Author:** ![mikakaraila](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mikakaraila/32/37496_2.png) [@mikakaraila](https://discourse.nodered.org/u/mikakaraila)\
**Post date:** [16 June 2021 11:16 UTC](https://discourse.nodered.org/t/optimizing-switch-nodes-opcua/46524/20 "2021-06-16T11:16:39Z")

</div>

It can be that server will publish new value every 1000ms even sampling rate is 100ms.  
Then if you read something what is inject interval?  
Case can be that server will have reads on queue... do you use registerNode?  
It will help server to keep variable ready for cyclic reading.

[Next page](https://discourse.nodered.org/t/optimizing-switch-nodes-opcua/46524.md?page=2)
