Flow with 10 MQTT "IN Node".. is better use just one "IN node" and split via "function node"?

Dear All,
Hi, I have an old Raspberry Pi 3 running Raspbian Debian 11 Bullseye.
I have installed Node-Red with the Mosquitto MQTT broker to receive signals from temperature/humidity sensors and current probes for home automation.

The Node-Red Flow has about 10 "MQTT IN NODE" nodes, one for each sensor. Each sensor with Tasmota Firmware, every 5 minute send MQTT data to Raspi Mosquitto..

I wonder if this is the correct solution or if, to save resources and processing power/Robustness and reliability of the Flow, I should use a single "MQTT IN NODE" to read all MQTT inlet message and, from its output, use a "function" node to split and send the received signal to one of the 10 outputs of the function node I think I need, to send the data to the following process nodes, depending on which sensor was read.
What do you think about this?
Thanks in advance!

Hi @lumanga

I don't use MQTT (much)
But I would subscribe to a base topic (with a wildcard) in 1 MQTT In Node.
then use a switch node (not a function node) - to split out from there based on the top level topic

Better folk around here then I for MQTT, but that is my approach

Small example - of what I do

1 Like

It makes little difference they would still be using the same configuration node / connection, You should use which ever method you prefer.

1 Like

These are fairly low numbers.
So, overall I don't think that 10 MQTT nodes and a flow or 1 MQTT followed by a switch (no need to use a function) and then the flow makes a significant difference performance wise.

What is the most readable option for you ?
If you come back in one year as you add/remove one sensor which option you will find easier to amend ?

So, avoid the function, as there is probably no effective need.
Then, 1 MQTT Nodes and a switch with 10 options, or 10 MQTT Nodes is, I think, a matter of taste.

Personally, I'd go for 10 MQTT Nodes and I would give them a "good" name. Eg. the sensor of that subscription.

The choice will not make any measurable difference to any of those factors. Use the KISS principle (keep it simple, stupid). Do whichever you think is the simpler (but use a Switch not a function node if you go that way). Personally, I use individual mqtt nodes.

Exactly as @colin says above, the difference is minimal.

However, consider this.

if your broker is producing 10000 messages per second & you subscribe to a wildcard to filter ALL except 10 messages, your code is processing 9990 useless messages every second.

In short, "it depends"

If all 10 events occur at the same time than I would recommend using a single IN-Node.

However, if these 10 events occur independently than you should have individual IN-Node.

Example: my home lights are controlled over MQTT (Zigbee) and I have an IN-Node for each Light (even for all sensors over MQTT)

As it’s nodejs they run on an event loop so can never occur at exactly the same time. So yes do whichever you find makes most sense to you to understand when you come back to it in 6 months time.