IMD SolutionComputing LibraryShop main store

Troubleshooting

Scaling Node-RED from 20 to 1000 Modbus tags into SQL Server

Edge computing and IIoT Published 8 min read By IMD Solution engineering team

Short answer

Yes: 1,000 Modbus tags at a one-minute interval is 16.7 values per second and fits Node-RED writing to SQL Server, provided reads are grouped per device and each poll-plus-insert cycle finishes well inside the logging window. The budget below puts a grouped design at about 3.5 seconds per cycle and a per-tag design at 51 seconds, which ten device timeouts push past the deadline.

On this page
  1. The load in numbers
  2. The 60-second cycle budget
  3. Group the reads and pace the queue
  4. Prove the payload path before the SQL node
  5. Batch the inserts into one statement per cycle
  6. When the cycle misses the window
  7. Questions asked

Yes, 1,000 Modbus tags at a one-minute logging interval works with Node-RED writing to SQL Server. The workload is 16.7 values per second, and the cycle budget below shows a flow that groups its reads finishing every poll-plus-insert cycle in about 3.5 seconds. What breaks these projects at scale is rarely CPU: it is per-tag polling that turns 50 requests into 1,000, and a SQL statement written against a payload path the Modbus message never carried. This article sizes the load, works the budget for both polling designs, and gives the node-by-node procedure that separates a Modbus fault from a mapping fault from a database fault.

The load in numbers #

Write the workload as a rate first: 50 devices × 20 tags = 1,000 values per one-minute cycle, and 1,000 ÷ 60 = 16.7 values per second. That is the average storage rate the database must absorb; it is not a Modbus request rate, because the number of requests depends entirely on how the reads are grouped.

Grouping is where the design is decided. The Modbus application protocol specification (V1.1b3, function code 03, Read Holding Registers) caps one request at 125 registers. Twenty contiguous registers per device therefore cost one request per device: 50 requests per cycle. Read those same 20 registers one at a time and the identical data costs 1,000 requests per cycle — twenty times the traffic and queue length, which no processor upgrade buys back.

The 60-second cycle budget #

The logging interval is a deadline. Every poll of every device plus the database write must finish inside the 60-second window; whatever remains is the margin that absorbs retries, timeouts and node processing. Treat the following round trip as an example — 50 ms per Modbus request on a plant LAN — and substitute your own measured figure.

Grouped polling, one read per device: 50 requests × 0.05 s = 2.5 s of polling. Add a batched insert of all 1,000 rows at about 1 s (an example figure; measure it on your server) and the cycle lands at 3.5 s, roughly 6 percent of the window, with 56 s of margin. Decision: this design holds at 1,000 tags, and the margin absorbs a slow or briefly offline device.

Per-tag polling: 1,000 requests × 0.05 s = 50 s, plus the same 1 s insert, puts the cycle at 51 s — 85 percent of the window. A device that is offline burns a full request timeout every cycle; at a 1 s timeout, nine timed-out reads land exactly on the deadline and ten push the cycle past 60 s, so rows arrive late and cycles begin to overlap. Decision: reject per-tag polling at this scale before you run it.

Polling design Requests per cycle Poll span at the example round trip Cycle total Decision
One grouped read per device 50 2.5 s about 3.5 s with the insert Holds, 56 s margin
One read per tag 1,000 50 s about 51 s with the insert Fails: nine timeouts reach the deadline

Check your own numbers the same way: timestamp poll start, poll end and insert done, and keep the measured cycle under half the window.

Group the reads and pace the queue #

Grouping is a flow change, not a checkbox. Map each device's 20 registers as one contiguous block where the device allows it and read the whole block with one Read Holding Registers request; where a device splits its tags, one request per block still beats one per tag. The standard pattern for polling dozens of Modbus TCP devices with Node-RED is exactly this pair: batch the reads, and drive them through a sequencer or queue that releases one request at a time, so the cycle steps through the device list instead of firing everything at once — one open connection per device, no overlapping cycles.

The same queueing discipline that carries polling 100 Modbus TCP slave IDs from Node-RED without saturating the CPU is what makes a 50-device poll routine. Without it, a slow device at the front of the list delays every device behind it.

Fix the addressing while you are in the node configuration. A point written 40001 in a drawing is documentation shorthand for holding-register space, not a value to type into the address field: enter the offset the node expects and confirm it against the values the debug node returns. In the reported project, registers noted as 40001 and 40002 would not reach SQL until that mapping was corrected.

Prove the payload path before the SQL node #

A Modbus read node and a SQL node cannot be wired together directly and expected to build a query. Something between them must map the message into the statement's fields, and skipping that step is how a project passes at 20 tags and collapses at 1,000.

In the reported flow, the INSERT reached for the message through the wrong object and the result came back as modbus.msg.payload:undefined — a path naming a property the Modbus message never had. The fix is not guessing another index; it is reading the message you actually receive.

Work the faults from this list:

  • SQL node returns or stores undefined — the query path names a property absent from the message — inspect the real payload with a debug node before editing the statement.
  • Debug shows no values at all — the Modbus read itself is unproven — test the read node alone and check the register offset and data type before reconnecting SQL.
  • Flow runs clean but no row appears — insert, column mapping, connection or value typing is wrong — run an inject-to-SQL test with known values and check the table directly.
  • Rows arrive but late, and cycle time grows — polling or database work overruns the window — timestamp each stage at full scale and watch the queue drain.

Then expand in this order:

  1. Bypass the SQL node and connect a debug node directly to the Modbus read output. Trigger one read and expand the message: note whether msg.payload is an array or an object and where the register values sit.
  2. Copy the payload path exactly as the debug pane shows it. If it is an array, take each register's index from the observed response, never from the point-list order you assumed.
  3. Insert a function or split node between Modbus and SQL that maps each value to a named column and carries the device ID and the read timestamp with it; mapping a Modbus payload into named database fields is the same job as mapping Modbus TCP payloads into InfluxDB fields in Node-RED, and the same debug-first method applies.
  4. Prove the database separately: an inject node straight into the SQL node with a one-row INSERT of known values, then check the row in the table.
  5. Pass one known register value through the whole chain and verify the row's value and timestamp.
  6. Scale one device, then several, then the full set; each cycle's row count must equal the tag count and every timestamp must land inside its interval. Time the complete cycle over at least five repeats before calling it production-ready.

Batch the inserts into one statement per cycle #

Per-value writes are the second quiet killer. Checking a connection out of a pool and running a single-row INSERT 1,000 times per minute spends nearly all its time on connection and statement overhead, which is what the reported flow was doing register by register. Build one multi-row INSERT per cycle instead — all 1,000 rows in a single statement, or five chunks of 200 rows inside one transaction so a failed chunk can retry without duplicating rows. The chunk sizes are examples; the gain comes from statement count, not the split.

Keep the connection pool small. The reported flow held its pool at five connections, which is fine for one batch per cycle and useless for per-value writes, which queue behind each other. A larger pool does not speed up a single batched INSERT.

Stamp every row with its read time, taken from one clock used by both polling and inserts. If the rows later feed interval averages in a historian, they are correct only when the query groups by the exact interval boundary — the timestamp grouping requirement described in how interval averages require timestamp grouping.

When the cycle misses the window #

Measure before blaming anything: poll span, write span and remaining margin are the three numbers that decide. If the grouped design still overruns, work down this order — a dead device burning its full timeout every cycle (remove it from rotation and log its absence), network retries, then host CPU.

If the host itself is the constraint — cycle time climbing with tag count while CPU sits near 100 percent — the polling box is what to size up, not the flow; a fanless industrial mini PC with more cores takes the same Node-RED flow without rework. And if the plan grows past roughly 1,000 tags, drops below a one-minute interval, or needs data buffered while the network to SQL Server is down, that is the point where a dedicated historian platform earns its keep: Ignition, for example, provides store-and-forward buffering that a bare SQL insert node lacks. Decide from the measured budget, not the tag count.

Questions asked

How many Modbus TCP devices can one Node-RED flow poll?

There is no fixed device count; the limit is cycle time. At the example 50 ms round trip, one grouped read per device spends 0.05 s per device, so polling alone would not reach the 60-second deadline until about 1,200 devices, and well before that socket counts, memory and device timeouts become the real constraints. Size by measuring the cycle at your actual device count and keep the total under half the window.

Why does my SQL Server column hold undefined instead of the register value?

The query is reaching for a property the Modbus message does not carry. The reported flow built its INSERT around the wrong object and got modbus.msg.payload:undefined back. Disable the SQL node, put a debug node on the Modbus read output, expand msg.payload and copy the path exactly as shown; if the payload is an array, take each index from the observed response, then rebuild the INSERT and verify one known value end to end.

Does it matter where the SQL Server runs?

Only through the write span. An on-premise server on the same plant LAN adds little to a batched insert; a cloud database adds a network round trip to every cycle's write and can consume the margin the budget leaves. Running the database on the polling host itself removes that network leg entirely, at the cost of handling backup, retention and access on the box. Measure the write span either way before deciding.

What changes if the logging interval drops below one minute?

The window shrinks while the poll span barely moves: at a 30-second interval the required rate doubles, at 12 seconds it is five times higher. The grouped design's 3.5-second cycle takes 35 percent of a 10-second window and stays viable; the per-tag design's 51-second span cannot fit at all. Re-run the budget with the new interval before adding tags, and keep the measured cycle under half the window.

Keep reading

  • How-to

    Polling 100 Modbus TCP slave IDs from Node-RED without 100% CPU

    Drive one Modbus request per message with a rate-limited split node and keep one to four requests in flight per endpoint: a 5-second scan of 100 slave IDs is only 20 reads per second. Flush SQL Server inserts in batches of 50 to 200 rows through one persistent connection, off the polling path. The 100% CPU comes from a scan loop, overlapping scans or a retry backlog, not from the request rate.

    Edge computing and IIoT

  • How-to

    Log production data from a panel PC to SQL Server

    Run Node-RED on the panel PC, read the production values straight from the controller, and insert one row per event into SQL Server with the mssql-plus node. Keep the panel's CSV-plus-FTP file relay only as a fallback, block duplicates with a last-record check and a unique key, and expect about 86,400 rows, roughly 8.6 MB, per day at one record per second.

    Edge computing and IIoT

  • How-to

    Connect Node-RED on ctrlX CORE to a MySQL server

    Send the SQL as msg.topic to a node-red-node-mysql node: create the table once as an administrator, prove one INSERT and SELECT from Inject nodes, then route Read Datalayer values into a multi-row insert. Grant the runtime account only SELECT and INSERT on db1, match its host part to the client address the server reports, and keep a local snap's data directory on external media.

    Edge computing and IIoT

Retrieve manually inserted historian values into InTouch tags