Nerves is a Real-Time Embedded System and Can Be Optimized for RTC
Jumping to the good stuff, the conclusion is that Nerves provides enough real-time performance within its minimal firmware that it’s suitable for real-time embedded devices. He found this by running benchmarks on a variety of hardware platforms and by comparing Nerves to other embedded operating systems like Raspberry Pi OS and Ubuntu MATE.
What’s even cooler is that he took these findings one step further and investigated whether we can improve Nerves’ real-time performance by configuring our system. It turns out the answer is yes.
Disabling Minor Garbage Collection
First, he found disabling minor garbage collection (GC) can improve real-time performance for applications that consume lots of local data. Since garbage collection automatically manages memory, scaling it back reduces overhead and increases consistency.
Second, Erlang also allows us to set process scheduling according to four priority levels: low, normal, high, and max. Basically, higher priority processes get more attention than lower ones. Dr. Takase found that setting high priority was good for real-time performance.
Third, we can also optimize in cpufreq, which manages the CPU’s clock speed. Specifically, some processors include Dynamic Voltage and Frequency Scaling (DVFS) that lets them automatically switch between different clock speeds, depending on IO and power consumption requirements.
However, since this scaling requires overhead, setting a fixed frequency is desirable for real-time performance. Setting the clock speed to maximum is best for performance—so long as you don’t mind the resulting BBQ—and powersave mode is still better for real-time performance than DVFS, even though it’s the lowest cpufreq.
Exploring the Linux Kernel
The last place Dr. Takase tried to optimize was in the Linux kernel itself. Since Nerves is highly customizable, he bumped the kernel version up from v4.19 to v5.4 and applied a PREEMPT_RT patch, which enables hard real-time features at the operating system level. Unfortunately, he couldn’t find any noticeable effect, but he did speculate that this could be useful for severe processes with high CPU loads and lots of concurrent IOs.
Nerves, Real-Time Performance, and the Future of IoT
The results are in, and Dr. Takase puts it best:
“Nerves is a now, young, cool, and real-time framework!”
Note that ‘now’(ナウ) is Japanese slang for cutting-edge. We couldn’t agree more.
While Nerves isn’t hard real-time, it’s good enough for all but the most time-sensitive applications. When we package that together with its small firmware, customizability, and all its other awesome features, we’re confident that Nerves will grow into the #1 choice for IoT development.
Specifically focusing on its real-time capabilities, we can expect to see Nerves’ stock go up for Industrial IoT (IIoT) applications, early warning alert systems, and even medical science applications, such as MRI scans and radiation therapy. Just like we rely on our own nervous system to interact with the world around us in real-time, our IoT devices can count on their Nerves.
Excited to learn more? Take the next step and check out our Nerves development services.