IMD SolutionComputing LibraryShop main store

Troubleshooting

High CPU and memory with Node-RED containers on Balena Engine

Edge computing and IIoT Published 7 min read

Short answer

High CPU and memory on a controller running Node-RED under Balena Engine trace first to container state, not flows: repeated installs leave unused containers and OCI images that a Type 1 or Type 2 reset does not delete. Inventory everything the engine holds, prune only the unused artifacts, then baseline the load with flows stopped and OPC UA polling inactive.

On this page
  1. What the failure looks like
  2. Why empty flows still cost memory and CPU
  3. Inventory everything the engine holds
  4. Remove only what is unused
  5. Baseline the load in three states
  6. Why a CPU or memory cap is not the fix
  7. The decision for each case
  8. Questions asked

High CPU on both cores with memory nearly exhausted on a controller running Node-RED under Balena Engine traces first to leftover container state, not to Node-RED itself. Every install attempt can leave a stopped container and an unused OCI image on the controller, and a Type 1 or Type 2 reset deletes neither. Inventory every container and image, remove only what is unused, restart the single instance the application needs, then baseline the load with flows stopped and OPC UA polling inactive. Work in that order: it removes the documented accumulation before any tuning of a runtime that may be perfectly healthy.

What the failure looks like #

Four observations define the failure:

  • Both CPU cores load to saturation, to the point the controller stops.
  • Memory usage sits above 90%.
  • Deploying empty flows changes nothing.
  • The controller also serves OPC UA data to a client over the network.

Each observation narrows the cause. Empty flows rule out flow complexity as the driver. The OPC UA client is a second consumer to hold constant during testing: a suspect to measure, not a proven cause. The reset history matters most — containers and OCI images are not deleted by a Type 1 or a Type 2 reset, so a controller that was reset between install attempts is not a clean controller.

Documentation and tools for this controller class use both designations, AXC2152 and AXC F 2152; confirm the exact designation on the device before applying model-specific steps.

The layout itself is not the fault. Running Node-RED next to the PLC runtime is a supported pattern, covered in Running Python and Node-RED beside PLC code on an edge PC; what the pattern leaves behind is the fault.

Why empty flows still cost memory and CPU #

A Node-RED container is a complete runtime whether or not a single node executes. On top of the runtime, an instance that polls the controller over OPC UA holds a client session with its subscriptions. The cost per instance is runtime plus session; flows only add to it.

The accumulation mechanism is the documented part. Engineers running several containers on one AXC F 2152 report CPU load climbing as the container count grows, with disk space as the first casualty — and neither a Type 1 nor a Type 2 reset removes containers or images. Three install attempts and two resets can still leave three containers and three images in storage. If a leftover instance is running rather than stopped, it costs a full second runtime and a second OPC UA session, live, which is how memory lands in the reported band with the flow editor empty.

Inventory everything the engine holds #

Balena Engine is Docker-compatible and its command reference uses the Docker command names; the removal examples in the PLCnext Docker_GettingStarted repository use the same set. Work through the inventory in this order:

  • List every container, stopped ones included: docker ps -a. Note each container's name, image and status.
  • List the image store: docker images. Several entries under one image name with different creation dates are the repeated install attempts.
  • Watch live per-container usage with docker stats; one screen separates a running leftover instance from a stopped one.
  • Check free storage on the controller. Accumulated images surface here first.

The pattern to find: three or more Node-RED containers from repeated attempts, images duplicated under one name, and at least one instance still running. One intended deployment with three instances in the list means the substrate of the problem is found; the baseline test below proves whether it is the driver.

Remove only what is unused #

Prune in a maintenance window: a mistyped name removes whatever that container was serving.

  1. Export the current flows from the live Node-RED instance, credentials included, before removing anything.
  2. Remove each confirmed unused container by name with docker rm, using the container name or ID from the inventory.
  3. Clear the untagged leftovers with docker image prune; this removes dangling images only, not images a container still references.
  4. If unused images remain, docker system prune removes unused images, containers and networks in one pass, as Docker's pruning guide describes it. Run it only after the step 2 inventory is confirmed, because it deletes stopped containers too.
  5. Restart the one Node-RED container the application needs and confirm docker ps lists only the instances you named.

Baseline the load in three states #

Hold the container set and the configuration constant and record both CPU cores and memory in three states:

  • State A: Node-RED stopped.
  • State B: Node-RED running, flows empty, OPC UA client nodes disabled.
  • State C: OPC UA polling active, flows still empty.

The deltas decide:

  • Numbers fall after the prune and stay flat through B and C: accumulation was driving the load. Keep the prune in the install and update procedure from now on.
  • The jump appears only between B and C: the data path is the driver. Cut the polling rate or the monitored-item count before touching Node-RED again.
  • State B alone pins the cores: a single clean Node-RED runtime does not fit this controller. Take the three-state measurements and the install procedure you used to whoever maintains that procedure.

Exclude one more pattern before blaming OPC UA: a CPU trace that spikes on a fixed cadence points at the container healthcheck, not the data path — Stop Node-RED Docker healthcheck CPU spikes on an edge PC is that fault, with its own fix.

A worked memory budget #

The arithmetic that reproduces the reported failure is short. The figures are illustrative, not specifications of any controller: read the per-instance values from docker stats and the controller's memory readout and substitute your own.

Item Example value
Controller RAM 1 GB (1024 MB)
One Node-RED instance, empty flows 150 MB
Its OPC UA client session 40 MB
Engine and supervisor overhead 120 MB
Control runtime and operating system 250 MB

Three leftover instances, each runtime plus session, cost 3 × (150 MB + 40 MB) = 570 MB. Add the engine and the control side: 570 MB + 120 MB + 250 MB = 940 MB. Against 1024 MB of RAM that is 940 ÷ 1024 = 92%, which is the reported band above 90%. After the prune, one required instance gives 190 MB + 120 MB + 250 MB = 560 MB, and 560 ÷ 1024 = 55%. Two lines of arithmetic turn an unexplained 92% into a container count, and docker ps -a is what counts the containers.

Why a CPU or memory cap is not the fix #

The desktop Docker instinct — hand the instance less of the machine — fails here twice. A cap does not remove work: throttled CPU backs the same load up, and a memory limit tight enough to matter ends with the engine killing the container mid-flow instead of a slow controller. Whether this controller's Balena Engine build exposes CPU and memory allocation flags at all is not established by the available documentation, so verify that in the controller's engine reference before building anything on it. Prune first; a cap is a last resort for a workload you have measured and decided to keep.

The decision for each case #

  • Load falls after the prune and stays flat through states B and C: accumulation was the cause. Keep the prune in every install and update, and re-check the image list after each release update.
  • State B on the cleaned controller still pins both cores or pushes memory back above 90%: one clean Node-RED runtime does not fit the controller. Move the stack. Starting Node-RED and Mosquitto MQTT in OCI Containers walks through that layout on a dedicated edge host. When the choice is a new box rather than an existing server, a fanless industrial mini PC sized for the data stack leaves the controller its real-time job.
  • The jump appears only between states B and C: the OPC UA data path is the cost. Trim the polling rate and the monitored items first; the relocated stack removes that polling load from the controller entirely.

Questions asked

What is the difference between docker image prune with and without the all flag?

Without a flag, docker image prune removes only dangling images: untagged layers left behind by an upgrade or a failed install. With the -a flag, it removes every image no container references, which is what builds up after several install attempts on a controller. The balena engine command reference documents both forms. Run the plain form first, list what remains, and use the all form only after you have confirmed no stopped container still needs an older image.

Do my Node-RED flows survive when I remove an unused container?

Only what lives outside the container survives. A container's writable layer is deleted with the container, so flows that exist only inside a leftover instance disappear with it. Before pruning anything, open the editor on the live instance, export the flows, and copy the credentials with them. Then keep exactly one reference copy of the flows you intend to run and remove the rest.

Can I cap the container's CPU or memory instead of pruning?

A cap treats the symptom. Throttled CPU leaves the same work backing up in the event loop, and a tight memory limit ends with the engine killing the container instead of a controller that stops. A cap also does nothing about disk pressure from old images. Remove the unused containers and images first; if one healthy instance with empty flows still saturates the controller, the workload does not belong on that controller.

Why does memory stay high even though the flows are empty?

Empty flows remove application logic, not runtimes. Every Node-RED instance runs its own full runtime, and an instance polling the controller over OPC UA holds a client session on top. Run the engine's per-container statistics view and sum the Node-RED rows: if the sum plus the control runtime comes close to total memory, the instance count is the answer, and the prune removes it.

How do I keep the containers and images from piling up again?

Prune when you change things, not on hope: after every successful install or release update, run the image prune, then confirm the container list shows only the instances you named. Users have reported that the Balena supervisor does not prune dangling images on its own after release updates, so the manual prune is the reliable step. Also note that putting the device into local mode and leaving it restores images and containers on exit, which can quietly undo your cleanup.

Keep reading

  • Troubleshooting

    Stop Node-RED Docker healthcheck CPU spikes on an edge PC

    The official Node-RED Docker image ships a Docker HEALTHCHECK whose probe command boots a full second Node.js runtime inside the container to make one loopback HTTP request. On a controller-class CPU shared with a PLC runtime, that boot is the roughly 45% spike in htop. Disable the probe or swap it for a shell test in the compose file; the restart policy still recovers crashes.

    Edge computing and IIoT

  • How-to

    Rebooting the host PC from Node-RED running in a container

    Write a request file from Node-RED into a single bind-mounted directory; a host-side systemd path unit consumes it and runs one fixed reboot command. The container never holds a password, a shell, or the Docker socket — the worst a compromised container can do is force one reboot. Enable the units, test from the host first, then prove the reboot with uptime arithmetic.

    Edge computing and IIoT

  • How-to

    Run Python and Node-RED beside PLC code on an edge PC

    Keep the IEC 61131-3 program in the controller runtime and run Python and Node-RED as separate Docker containers on the same edge PC. Exchange data over one MQTT interface with a fixed publish period, and declare data stale after three missed periods. One container per workload, and nothing from Python or Node-RED inside the control project.

    Edge computing and IIoT