# I/O switching performance on a Raspberry Pi 4

**URL:** <https://discourse.nodered.org/t/i-o-switching-performance-on-a-raspberry-pi-4/25486>\
**Category:** General\
**Created:** [25 April 2020 12:45 UTC](https://discourse.nodered.org/t/i-o-switching-performance-on-a-raspberry-pi-4/25486 "2020-04-25T12:45:15Z")\
**Posts on this page:** 19\
**Page:** 2

<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:** [26 April 2020 08:02 UTC](https://discourse.nodered.org/t/i-o-switching-performance-on-a-raspberry-pi-4/25486/21 "2020-04-26T08:02:57Z")

</div>

Yes, I am sure you are right, but nothing compared to the overheads of a browser running in a GUI.

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [26 April 2020 08:22 UTC](https://discourse.nodered.org/t/i-o-switching-performance-on-a-raspberry-pi-4/25486/22 "2020-04-26T08:22:15Z")

</div>

> [@dpnsw](#):
>
> even python code

You could try to let your python code do the I/O and just report rbe's (Report by Exception) via mqtt. Then you would have a "reasonable fast" I/O checking system below and a visualization on top that would be "fast enough for your eyes"

---

<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:** [26 April 2020 08:26 UTC](https://discourse.nodered.org/t/i-o-switching-performance-on-a-raspberry-pi-4/25486/23 "2020-04-26T08:26:52Z")

</div>

If I might chip in.

You could definitely cut some fat from this.

1. Lose the contrib loop node (unknown factor and unnecessary)
2. Use the faster [unsafe function](https://flows.nodered.org/node/node-red-contrib-unsafe-function) (less overhead as it doesn't use a VM)

Also, is there any reason why node-red couldn't be you first choice & if/when you need C like IO performance, you simply use a native binary to execute that part of a solution?

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [26 April 2020 08:27 UTC](https://discourse.nodered.org/t/i-o-switching-performance-on-a-raspberry-pi-4/25486/24 "2020-04-26T08:27:37Z")

</div>

I've not yet looked at the code for that node, but if it sends anything to the ui, then I would guess it is not optimised in any way to handle rapid changes. IE I would guess it tries to send every change of state, rather than only sample them. It is very easy to saturate the websocket connection to the browser.

---

<div class="post-metadata">

**Author:** ![dpnsw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dpnsw/32/20611_2.png) [@dpnsw](https://discourse.nodered.org/u/dpnsw)\
**Post date:** [26 April 2020 09:55 UTC](https://discourse.nodered.org/t/i-o-switching-performance-on-a-raspberry-pi-4/25486/25 "2020-04-26T09:55:12Z")

</div>

Hi @Colin,  
The browser is not running on the Pi. The Pi does have a GUI active but it is not being used at all, not even logged in. Node-RED is started remotely over SSH and the browser is firefox on ubuntu on machine with 12 cores & 64Gig ram that is not particularly busy.  
On the overheads situation I will try and implement suggestions from @Steve-Mcl on the unsafe function and that both of you made with respect to the contrib package and see what happens

---

<div class="post-metadata">

**Author:** ![ristomatti](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ristomatti/32/5857_2.png) [@ristomatti](https://discourse.nodered.org/u/ristomatti)\
**Post date:** [26 April 2020 10:13 UTC](https://discourse.nodered.org/t/i-o-switching-performance-on-a-raspberry-pi-4/25486/26 "2020-04-26T10:13:25Z")

</div>

I noticed node-red-node-pi-gpio uses a Python library to switch IO. I don't know what the performance implications of that are but it doesn't sound very optimized(?)

Does anyone happen to know if someone has built Node-RED nodes using [pigpio](https://github.com/fivdi/pigpio) for the switching? At least from personal experience it is very performant.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [26 April 2020 11:46 UTC](https://discourse.nodered.org/t/i-o-switching-performance-on-a-raspberry-pi-4/25486/27 "2020-04-26T11:46:22Z")

</div>

see - [https://flows.nodered.org/node/node-red-node-pi-gpiod](https://flows.nodered.org/node/node-red-node-pi-gpiod)

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [26 April 2020 11:48 UTC](https://discourse.nodered.org/t/i-o-switching-performance-on-a-raspberry-pi-4/25486/28 "2020-04-26T11:48:44Z")

</div>

the browser may not be busy - but if it is showing status at all - either debug - or blobs under the gpio nodes - then the Pi will be feeding the websocket as fast as it can.

---

<div class="post-metadata">

**Author:** ![ristomatti](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ristomatti/32/5857_2.png) [@ristomatti](https://discourse.nodered.org/u/ristomatti)\
**Post date:** [26 April 2020 12:09 UTC](https://discourse.nodered.org/t/i-o-switching-performance-on-a-raspberry-pi-4/25486/29 "2020-04-26T12:09:29Z")

</div>

> [@dceejay](#):
>
> see - [https://flows.nodered.org/node/node-red-node-pi-gpiod](https://flows.nodered.org/node/node-red-node-pi-gpiod)

Thanks but I found this already. The pigpio module I linked is a wrapper to a C library called pigpio, so it might have nothing to do with the similarly named pigpiod daemon. 🙂

---

<div class="post-metadata">

**Author:** ![dpnsw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dpnsw/32/20611_2.png) [@dpnsw](https://discourse.nodered.org/u/dpnsw)\
**Post date:** [26 April 2020 13:05 UTC](https://discourse.nodered.org/t/i-o-switching-performance-on-a-raspberry-pi-4/25486/30 "2020-04-26T13:05:25Z")

</div>

Hi @dceejay,  
I did spot that while I was coding this test up and I was concerned about load so I did deselect "show node status" under settings. Is this what you mean or are you talking about a different setting or startup configuration parameter?

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [26 April 2020 14:36 UTC](https://discourse.nodered.org/t/i-o-switching-performance-on-a-raspberry-pi-4/25486/31 "2020-04-26T14:36:10Z")

</div>

Nice - if anyone fancied "upgrading" the existing GPIO nodes to use that - that would be a great pull request contribution... (of course would need to check if existing functionality can be maintained without breaking existing users... but it does look like a good library)

---

<div class="post-metadata">

**Author:** ![ristomatti](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ristomatti/32/5857_2.png) [@ristomatti](https://discourse.nodered.org/u/ristomatti)\
**Post date:** [26 April 2020 15:10 UTC](https://discourse.nodered.org/t/i-o-switching-performance-on-a-raspberry-pi-4/25486/32 "2020-04-26T15:10:54Z")

</div>

Thanks for the tip! It could be a fun way to contribute. I'll need to look into the current implementation if it seems like something I could pull off.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [26 April 2020 15:13 UTC](https://discourse.nodered.org/t/i-o-switching-performance-on-a-raspberry-pi-4/25486/33 "2020-04-26T15:13:30Z")

</div>

@dpnsw - yes that is what I meant.  
On my Pi3 - If I just toggle the io pin as fast as i can - with no browser attached and no status etc I can do 50000 cycles in about 2.7 secs  
2020-04-26T15:12:01.324Z  
2020-04-26T15:12:04.019Z  
(but I'm well aware this is not exactly a real world situation or useable)

---

<div class="post-metadata">

**Author:** ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)\
**Post date:** [26 April 2020 17:35 UTC](https://discourse.nodered.org/t/i-o-switching-performance-on-a-raspberry-pi-4/25486/34 "2020-04-26T17:35:53Z")

</div>

> [@dceejay](#):
>
> not exactly a real world situation or useable

True, but probably more directly comparable to @dpnsw's python program than the flow he posted. 50000/2.7 = 18.5 K/sec compared to 218 K/sec is a factor of 11, not unreasonable considering the baggage that NR and node.js have to carry.

---

<div class="post-metadata">

**Author:** ![SeRiusRod](https://avatars.discourse-cdn.com/v4/letter/s/278dde/32.png) [@SeRiusRod](https://discourse.nodered.org/u/SeRiusRod)\
**Post date:** [29 April 2020 21:39 UTC](https://discourse.nodered.org/t/i-o-switching-performance-on-a-raspberry-pi-4/25486/35 "2020-04-29T21:39:08Z")

</div>

Sorry but can't understand what you are evaluating here. So you want to do some gpio work, the more efficiently possible, and you are using SBCs and high level software tools?  
There are zillion development boards, some of already with network connectivity, that could do this work way faster. They could cache readings and send to nr if measurement is what you need.

I suppose it's not the case, but here we say: (in dumb translation) A bigger donkey, walking or not.

Edit: Sorry, I wrote in response to the ops original question.

---

<div class="post-metadata">

**Author:** ![dpnsw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dpnsw/32/20611_2.png) [@dpnsw](https://discourse.nodered.org/u/dpnsw)\
**Post date:** [15 June 2020 13:12 UTC](https://discourse.nodered.org/t/i-o-switching-performance-on-a-raspberry-pi-4/25486/36 "2020-06-15T13:12:07Z")

</div>

Many thanks to everyone that responded.

Just to clarify the purpose of this is to do a simple test that can be performed on every type of platform from microcontrollers, SBC and FPGA devices using different programming languages. I am not trying for real world, I am trying to understand a performance limitation. There is no point trying to sample an ADC at 20kHz on a Pi 3 using Node-RED (many thanks @dceejay ).

The test is to change state on a digital IO pin & measure to confirm it has changed state (meaning perform both a write and read) as 1 cycle and do that as fast as possible.

I ran the equivalent test on a BeagleBone Black WiFI using Python and also C. Is this a real world test, NO. Could I have done this a different way, YES. but to me that is not the point. The point is no mater what hardware or software combination I am using I am doing the same thing. Is the limitation hardware, software or something else. To me that is no so important I am looking for orders of magnitude differences. There is a Python library for the BBB WiFi from Adafruit and that gave me performance around 10K cycles per second. The equivalent C program clocked in at almost 850K cycles per second on exactly the same unit. I was surprised at the level of difference.

Interestingly an equivalent python program on the Pi Zero is capable of 30K cycles per second and if you cross over to a multicore Pi 3B+ the number increases to 217K (on a Pi 4 it is 530K). So it could be more library than interpreter Vs compiled.

Is any of this real world, NO of course not but nowhere can I find advice that if I use Python on a BBB for DIO it is going to be 85 times slower.

Similarly I had no idea coming into this what sort of performance to expect from Node-RED on DIO and now thanks to everyone here I do.

Many thanks for that.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [15 June 2020 14:22 UTC](https://discourse.nodered.org/t/i-o-switching-performance-on-a-raspberry-pi-4/25486/37 "2020-06-15T14:22:58Z")

</div>

> [@dpnsw](#):
>
> Interestingly an equivalent python program on the Pi Zero is capable of 30K cycles per second and if you cross over to a multicore Pi 3B+ the number increases to 217K (on a Pi 4 it is 530K). So it could be more library than interpreter Vs compiled.

Hardware could also be a factor. The Pi Zero has 512M and runs at 1GHz while the pi 3 B+ has 1GB and runs at 1.4GHz and the Pi 4 has 1, 2 or 4GB and runs at 1.5GHz

---

<div class="post-metadata">

**Author:** ![dpnsw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dpnsw/32/20611_2.png) [@dpnsw](https://discourse.nodered.org/u/dpnsw)\
**Post date:** [15 June 2020 22:20 UTC](https://discourse.nodered.org/t/i-o-switching-performance-on-a-raspberry-pi-4/25486/38 "2020-06-15T22:20:19Z")

</div>

@zenofmud, the comparison was meant to be between the Pi Zero and BBB. Data on the Pi 3B+ or 4B was more informational. In fact if you look at the old Pi B it clocks in at 30K (54K if you overclock). My point is that it the 3x difference looks driver related between Pi Zero, Pi B and BBB. The hardware differences are more like 20 times when you jump from zero to Pi 3B+ with a move to multicore and 40 times when you jump to the Pi 4B.  
Also the speed difference between Python and C on the same BBB is important to note.  
On a pocket Beagle I can get 425K using C and under 1K with Node-Red

The data is just one item in a long list such as speed to deploy, maintainability, ease of use, hardware, software and driver support, size of community, target audience, etc....

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [14 August 2020 22:21 UTC](https://discourse.nodered.org/t/i-o-switching-performance-on-a-raspberry-pi-4/25486/39 "2020-08-14T22:21:09Z")

</div>

Closed on 14 August 2020 22:21 UTC

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.

[Previous page](https://discourse.nodered.org/t/i-o-switching-performance-on-a-raspberry-pi-4/25486.md?page=1)
