Which model of Pi need the following tweak to nod-red install?

I just found the following comment in the documentation (https://nodered.org/docs/getting-started/raspberrypi)...

"Due to the limited memory of the Raspberry Pi, you will need to start Node-RED with an additional argument to tell the underlying Node.js process to free up unused memory sooner than it would otherwise."

node-red-pi --max-old-space-size=256

I take it this was for Pi devices that have less than 1GB memory? Or is it still required, if so, is there an updated recommendation for this? I seriously doubt this issue is applicable to say a 2GB or more Pi, yes or no?

Generally I set it to half the available memory

yeah, for a 265MB to 128MB, for 512MB to 256... I see the logic. But if Pi has over 1GB, is it required or needed... would seem to not be the case.

I think node js default it to 2 or 4 gb. So unless you have that much then yes it’s needed

Yes, I found the following...

Out of the box, a 64-bit installation of node. js assumes a memory ceiling of 1.5GB per node process. If you are running your node app in a memory constrained environment, e.g. a low-cost VPS server or PaaS instance, it's necessary to inform the v8 runtime that you have a reduced memory ceiling.

https://tomspencer.dev/blog/2016/10/01/running-a-node-dot-js-app-in-a-low-memory-environment/

The reference is from 2016, but I guess it nails down the issue.

Just a foot note for anyone that in reading this thread... the current node-red install (curl url method) sets the memory size limit to 512 (see below, --max_old_space_size=512) via the unit file configuration.

# systemd service file to start Node-RED

[Unit]
Description=Node-RED graphical event wiring tool
Wants=network.target
Documentation=http://nodered.org/docs/hardware/raspberrypi.html

[Service]
Type=simple
# Run as normal pi user - change to the user name you wish to run Node-RED as
User=pi
Group=pi
WorkingDirectory=/home/pi

Nice=5
Environment="NODE_OPTIONS=--max_old_space_size=512"
# uncomment and edit next line if you need an http proxy
#Environment="HTTP_PROXY=my.httpproxy.server.address"
# uncomment the next line for a more verbose log output
#Environment="NODE_RED_OPTIONS=-v"
#ExecStart=/usr/bin/env node $NODE_OPTIONS red.js $NODE_RED_OPTIONS
ExecStart=/usr/bin/env node-red-pi $NODE_OPTIONS $NODE_RED_OPTIONS
# Use SIGINT to stop
KillSignal=SIGINT
# Auto restart on crash
Restart=on-failure
# Tag things in the log
SyslogIdentifier=Node-RED
#StandardOutput=syslog

[Install]
WantedBy=multi-user.target

This seems high for PiZero that only has 512MB total memory.

1 Like

Are you sure that is correct for a Pi Zero? I haven't used the script recently for a zero, but looking at one of mine it is set to 256 in nodered.service.

[Edit] Though I see that in fact all my systems have it at 256. Perhaps it was changed very recently. I haven't noticed any need to have it higher by the way.

Every time I install node-red, the unit (service) file defaults the memory size to 512MB. It appears to be a static setting, no modified by the installer. The PiZero only have 512MB, so that is committing everything to node-red worse case. Node.js expects about 1.5GB and needs to be informed if less than that is available. It appears that you could crash a PiZero with such a default configuration, all comes down to how many active flows are present I would suspect. Given the 512MB static assignment by the unit service configuration, this also means that newer Pi devices may be under resourced, given Pi4 for example can have 1GB to 8GB.

Sure... Below is the content of the unit file installed by default...

# cat /lib/systemd/system/nodered.service
# systemd service file to start Node-RED

[Unit]
Description=Node-RED graphical event wiring tool
Wants=network.target
Documentation=http://nodered.org/docs/hardware/raspberrypi.html

[Service]
Type=simple
# Run as normal pi user - change to the user name you wish to run Node-RED as
User=pi
Group=pi
WorkingDirectory=/home/pi

Nice=5
Environment="NODE_OPTIONS=--max_old_space_size=512"
# uncomment and edit next line if you need an http proxy
#Environment="HTTP_PROXY=my.httpproxy.server.address"
# uncomment the next line for a more verbose log output
#Environment="NODE_RED_OPTIONS=-v"
#ExecStart=/usr/bin/env node $NODE_OPTIONS red.js $NODE_RED_OPTIONS
ExecStart=/usr/bin/env node-red-pi $NODE_OPTIONS $NODE_RED_OPTIONS
# Use SIGINT to stop
KillSignal=SIGINT
# Auto restart on crash
Restart=on-failure
# Tag things in the log
SyslogIdentifier=Node-RED
#StandardOutput=syslog

[Install]
WantedBy=multi-user.target

For now, I am leaving it as is, to see what happens as I add flows. Unfortunately, my PiZero is running at about 88% memory in use. So, I suspect I will need to drop it down to 256 in the unit file at some point soon.

As I said, it seems to have changed recently and yes, I agree it should probably be reduced if running a Zero. It won't make any noticeable difference increasing it on one with larger memory unless you have a pretty large system. All mine are running fine with 256, one of which on a Pi 3B has 500 nodes. Also remember that increasing it will reduce the memory available for other stuff as I think node is liable to eventually use all the memory it is allowed even on a small set of flows. I may be wrong there though.

Right, on a Pi4 with 8GB... No Limit! LOL. Cough.

Ok... This is really weird... Odd... I have installed node-red, testing, and what not, maybe 20 times, while I have been working on a standard image to deploy to all of my Pi devices. The max old size in the unit file has been always, 512. But just now I installed node-red on a Pi that is a Pi2ModelB, which is ARM v7, 1GB RAM, and the unit file is set to 256. I am quite surprised. On a PiZero with only 512MB, the same setting is set to 512?

Here is the unit file for the most recent install...

# systemd service file to start Node-RED

[Unit]
Description=Node-RED graphical event wiring tool
Wants=network.target
Documentation=http://nodered.org/docs/hardware/raspberrypi.html

[Service]
Type=simple
# Run as normal pi user - change to the user name you wish to run Node-RED as
User=pi
Group=pi
WorkingDirectory=/home/pi

Nice=5
Environment="NODE_OPTIONS=--max_old_space_size=256"
# uncomment and edit next line if you need an http proxy
#Environment="HTTP_PROXY=my.httpproxy.server.address"
# uncomment the next line for a more verbose log output
#Environment="NODE_RED_OPTIONS=-v"
#ExecStart=/usr/bin/env node $NODE_OPTIONS red.js $NODE_RED_OPTIONS
ExecStart=/usr/bin/env node-red-pi $NODE_OPTIONS $NODE_RED_OPTIONS
# Use SIGINT to stop
KillSignal=SIGINT
# Auto restart on crash
Restart=on-failure
# Tag things in the log
SyslogIdentifier=Node-RED
#StandardOutput=syslog

[Install]
WantedBy=multi-user.target

One one of my PiZero devices...

# systemd service file to start Node-RED

[Unit]
Description=Node-RED graphical event wiring tool
Wants=network.target
Documentation=http://nodered.org/docs/hardware/raspberrypi.html

[Service]
Type=simple
# Run as normal pi user - change to the user name you wish to run Node-RED as
User=pi
Group=pi
WorkingDirectory=/home/pi

Nice=5
#Environment="NODE_OPTIONS=--max_old_space_size=512"
Environment="NODE_OPTIONS=--max_old_space_size=256"
# uncomment and edit next line if you need an http proxy
#Environment="HTTP_PROXY=my.httpproxy.server.address"
# uncomment the next line for a more verbose log output
#Environment="NODE_RED_OPTIONS=-v"
#ExecStart=/usr/bin/env node $NODE_OPTIONS red.js $NODE_RED_OPTIONS
ExecStart=/usr/bin/env node-red-pi $NODE_OPTIONS $NODE_RED_OPTIONS
# Use SIGINT to stop
KillSignal=SIGINT
# Auto restart on crash
Restart=on-failure
# Tag things in the log
SyslogIdentifier=Node-RED
#StandardOutput=syslog

[Install]
WantedBy=multi-user.target

So there is some code logic in the installation that does tweak this setting? Again, would seem that for a PiZero the setting is set too high? Just wondering here, why the delta.

we are nothing if not responsive :slight_smile: if you retry on the zero it will also set it to 256. we now detect the amount of ram and anything under 1gb we set it to 256,,, above that we set it to 512 ( so newer pi4 should get more)

1 Like

Oh yeah! I must say for the short time I have been posting to the forum... asking tons of questions, providing a few opinions, etc., the response from everyone has been wonderful. I may sound a bit cheesy or cheeky... but really, everyone has cool.