# Julia for Real-Time processing on embedded platforms

**URL:** <https://discourse.julialang.org/t/julia-for-real-time-processing-on-embedded-platforms/95925>\
**Category:** General Usage\
**Created:** [March 11, 2023, 5:16pm UTC](https://discourse.julialang.org/t/julia-for-real-time-processing-on-embedded-platforms/95925 "2023-03-11T17:16:22Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![jpreisig](https://avatars.discourse-cdn.com/v4/letter/j/ed8c4c/32.png) [@jpreisig](https://discourse.julialang.org/u/jpreisig)\
**Post date:** [March 11, 2023, 5:16pm UTC](https://discourse.julialang.org/t/julia-for-real-time-processing-on-embedded-platforms/95925/1 "2023-03-11T17:16:23Z")

</div>

I have seen a lot of older (order 2019) posts about Julia not being suitable for real-time implementations on embedded platforms. Wondering about the current state of thinking on this. I realize the embedded means different things to different people and scale is important. For me, I am talking about small SBCs running Ubuntu Linux and having order 4 of RAM and 32 GB of non-volatile storage. We do mostly signal detection and analysis applications.

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [March 11, 2023, 6:30pm UTC](https://discourse.julialang.org/t/julia-for-real-time-processing-on-embedded-platforms/95925/2 "2023-03-11T18:30:45Z")

</div>

I don’t remember if this was about embedded platforms, but might be interesting to you:

[![](https://global.discourse-cdn.com/julialang/original/3X/f/9/f93e75bb85fe20d31573f9f4d235979cd89777f1.jpeg "Towards Using Julia for Real-Time applications in ASML | Francesco Fucci | JuliaCon 2022") ](https://www.youtube.com/watch?v=EafTuyy7apY)

---

<div class="post-metadata">

**Author:** ![jar1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jar1](https://discourse.julialang.org/u/jar1)\
**Post date:** [March 11, 2023, 6:37pm UTC](https://discourse.julialang.org/t/julia-for-real-time-processing-on-embedded-platforms/95925/3 "2023-03-11T18:37:34Z")

</div>

This has a big computer but a small time budget.

[![](https://global.discourse-cdn.com/julialang/original/3X/0/b/0b71256d516593ad3b81147b0fb018d0cc526872.jpeg "JuliaRobotics: Making robots walk with Julia | Robin Deits") ](https://www.youtube.com/watch?v=dmWQtI3DFFo)

---

<div class="post-metadata">

**Author:** ![rehmi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rehmi/32/16972_2.png) [@rehmi](https://discourse.julialang.org/u/rehmi)\
**Post date:** [March 11, 2023, 7:33pm UTC](https://discourse.julialang.org/t/julia-for-real-time-processing-on-embedded-platforms/95925/4 "2023-03-11T19:33:30Z")

</div>

I recently started working on such platforms (4 GB RAM, 4 ARM cores @ 1.5 GHz) when the new object-code caching feature became available in Julia 1.9. This new feature has made a huge difference in usability on all platforms, but on these small systems it exposes other shortcomings (e.g. limited memory, I/O bandwidth) that hinder interactivity.

A quick and surprisingly good fix for this is to move the main filesystem to a fast device, e.g., a USB 3.0 drive that can sustain \>200 MB/s. Thanks to this one change, I can now spend a good part of my day remotely developing on a Raspberry Pi or one of its Rockchip-based clones (Libre, Khadas, etc) running Julia via Visual Studio Code. Yes, even with the Language Server. No, I do not have the patience of a saint.

Also, Julia 1.9 offers a new command line option (`--heap-size-hint`) to keep you out of the swap/thrash zone when precompiling a large project or building a system image. I usually set this to take half of the physical memory, leaving the rest for system processes and the kernel’s block cache.

Hope this helps,  
Rehmi

---

<div class="post-metadata">

**Author:** ![TheCedarPrince](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thecedarprince/32/17323_2.png) [@TheCedarPrince](https://discourse.julialang.org/u/TheCedarPrince)\
**Post date:** [March 11, 2023, 10:55pm UTC](https://discourse.julialang.org/t/julia-for-real-time-processing-on-embedded-platforms/95925/5 "2023-03-11T22:55:45Z")

</div>

Hey @rehmi , this is really interesting (and welcome to the community! 👋 )! To not derail this discussion, would you be able to share more about your set-up and experiences in another Discourse post? I know for a fact several folks would be interested in this notion of running Julia on resource constrained machines – myself included. Thanks!

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [March 11, 2023, 11:22pm UTC](https://discourse.julialang.org/t/julia-for-real-time-processing-on-embedded-platforms/95925/6 "2023-03-11T23:22:58Z")

</div>

Important: Enable zram if you have less than 8 GB RAM, in particular if you want to build a custom system image. [How to Configure ZRAM on Your Ubuntu Computer - Make Tech Easier](https://www.maketecheasier.com/configure-zram-ubuntu/)

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [March 11, 2023, 11:29pm UTC](https://discourse.julialang.org/t/julia-for-real-time-processing-on-embedded-platforms/95925/7 "2023-03-11T23:29:57Z")

</div>

The question is, what do you mean with realtime, and what is the frequency of your control loop. If you need hard realtime you cannot allow any memory allocations. A control loop of 20 Hz that allows a jitter of 5ms might also be possible in the presence of memory allocations.

---

<div class="post-metadata">

**Author:** ![jar1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jar1](https://discourse.julialang.org/u/jar1)\
**Post date:** [March 11, 2023, 11:36pm UTC](https://discourse.julialang.org/t/julia-for-real-time-processing-on-embedded-platforms/95925/8 "2023-03-11T23:36:37Z")

</div>

> <https://github.com/JuliaLang/julia/issues/34248>
>
> When implementing real-time applications (robotics control, streaming audio-sign…al processing, software-defined radio, etc.) in Julia, the unpredictable timing of heap allocation and garbage collection is a significant hazard. Developers who want to use Julia for such applications have to ensure that all required heap memory allocations happen in advance, and not inside time-critical loops. What would help enormously with learning and practicing such allocation-free time-critical programming is a macro that turns allocations into errors. The main purposes of such a macro would be:
> \* Developers can get compile-time feedback on whether they have succeeded in implementing algorithms in a way that cannot trigger allocations and garbage collection
> \* Users of existing allocation-free methods can see in the source code a compiler-enforced promise that this method will not cause allocations
> 
> This feature suggestion was originally made by @rdeits at the end of his wonderful JuliaCon 2018 talk “JuliaRobotics: Making robots walk with Julia”
> https://youtu.be/dmWQtI3DFFo?t=2263
> (also mentioning @tkoolen ) in response to my question of what tools he could envisage to make allocation-free real-time programming easier in Julia:
> https://youtu.be/dmWQtI3DFFo?t=2160
> @JeffBezanson then asked “Would it be enough for the turn-allocation-into-error feature to be lexically scoped”, and after the speaker agreed, promised “OK, you got it!” (followed by audience applause):
> https://youtu.be/dmWQtI3DFFo?t=2330
> 
> What is the status of this feature?

---

<div class="post-metadata">

**Author:** ![jpreisig](https://avatars.discourse-cdn.com/v4/letter/j/ed8c4c/32.png) [@jpreisig](https://discourse.julialang.org/u/jpreisig)\
**Post date:** [March 14, 2023, 1:43pm UTC](https://discourse.julialang.org/t/julia-for-real-time-processing-on-embedded-platforms/95925/9 "2023-03-14T13:43:03Z")

</div>

Thanks for the welcome and for all the comments, suggestions and insights. To give a little context, I would classify our real-time processing as soft real time (i.e., signal processing where we grab signals out of a buffer and our processing needs to keep-up in order to not loose samples) as opposed to hard real time (for example, a control loop where delays or imprecise timing can cause failure of or instability in the control loop). We deploy small underwater systems. Our current prototyping platform is the Khadas VIM3 Pro although we are probably going to migrate to a platform that uses one of the NXP iMX8 family of processors.

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [March 14, 2023, 1:55pm UTC](https://discourse.julialang.org/t/julia-for-real-time-processing-on-embedded-platforms/95925/10 "2023-03-14T13:55:30Z")

</div>

For soft real-time have a look at [KiteControllers.jl/autopilot.jl at main · aenarete/KiteControllers.jl · GitHub](https://github.com/aenarete/KiteControllers.jl/blob/main/examples/autopilot.jl) …

Key points:

- do `GC.gc()` before your control loop starts
- do something like:

```julia
        if t_sim < 0.3*dt
            t_gc_tot += @elapsed GC.gc(false)
        end

```

at each larger time step. This means, do a partial garbage collection if you have at least 30% of the time step left.

- measure the execution time of each time step and count how often you violate your constraint.

For my usecase I am happy if I violate the contraint less than 1% of the time, of course less than 0.1% would be even better…

If you have multiple cores, try to pin your real-time loop to a core that is NOT used by the OS for system IO… This helped a lot when we were implementing a flight controller for a drone on a Rasperry Pi 3…

And of course run your real-time code with real time priority (if using Linux)… But not with the highest priority possible, that might starve some OS threads…

---

<div class="post-metadata">

**Author:** ![Larbino1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/larbino1/32/37831_2.png) [@Larbino1](https://discourse.julialang.org/u/Larbino1)\
**Post date:** [June 11, 2024, 3:35pm UTC](https://discourse.julialang.org/t/julia-for-real-time-processing-on-embedded-platforms/95925/11 "2024-06-11T15:35:08Z")

</div>

This is fantastic advice, I have just a quick question

What do you mean about pinning to a non-IO core? Can you link me to an explanation or example?

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [June 11, 2024, 3:58pm UTC](https://discourse.julialang.org/t/julia-for-real-time-processing-on-embedded-platforms/95925/12 "2024-06-11T15:58:48Z")

</div>

> [@Larbino1](#):
>
> What do you mean about pinning to a non-IO core?

You can try (and read the documentation of) [GitHub - carstenbauer/ThreadPinning.jl: Readily pin Julia threads to CPU processors](https://github.com/carstenbauer/ThreadPinning.jl) But that only works on Linux.

---

<div class="post-metadata">

**Author:** ![Larbino1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/larbino1/32/37831_2.png) [@Larbino1](https://discourse.julialang.org/u/Larbino1)\
**Post date:** [June 11, 2024, 4:10pm UTC](https://discourse.julialang.org/t/julia-for-real-time-processing-on-embedded-platforms/95925/13 "2024-06-11T16:10:46Z")

</div>

Good news: I’m already on a realtime linux install so it’s applicable. Thank you!

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [June 11, 2024, 4:15pm UTC](https://discourse.julialang.org/t/julia-for-real-time-processing-on-embedded-platforms/95925/14 "2024-06-11T16:15:52Z")

</div>

I don’t know anything about your code, but if you are not using heavy Julia libraries, then [GitHub - MasonProtter/Bumper.jl: Bring Your Own Stack](https://github.com/MasonProtter/Bumper.jl) might help to avoid using the GC.
