Is Scala suitable for IoT?

I am starting new side project using Raspberry Pi to collect video record and the temperature sensor :grin: to the cloud server, implement ML and display on frontend. But I am not sure that Scala + jvm is suitable for running on Raspberry Pi or not, I mean in terms of performance and reliability.

Does anyone have implemented the similar IoT project using Scala? Any thought or suggestion on this?

Thanks in advance everyone!

I’ve been hacking on ev3dev - which is a lot less than a Raspberry Pi. It works pretty well, with two big caveats:

  • Starting the JVM is several minutes. It’s like waiting for Santa. I think that’s due mostly the very slow microSD card file system.
  • The usual Java libraries assume an abundance of computation is available, and the traditional layers are costly performance-wise. Be ready to analyze and rewrite core bits of code.

I haven’t found a good fix for the first problem. The second was just archeology work to remove the strata that didn’t add anything I needed. Raspberry PI should go much better.

1 Like

A few years ago, I experimented with scala on the pi, and it fell unfortunately short for my requirements, which require fairly accurate timing between pulses on pins, which unfortunately became unreliable due to GC pauses.

This has probably all vastly improved, but if you need accurate timing of things on a millisecond scale, the JVM on a pi is not your friend.

If you don’t, you’re probably fine.

1 Like

Thanks!

Oh, if the application need to be accurate, guess I need to change to the language w/o gc then.

Thanks!

The big follow-on question is: How sensitive are you to the GC stalls? If you can write scala code that rarely GCs - or only GCs when you tell it - then it will be very well behaved. Two cores vastly eases the GC burden.

If you really care about timing then you’ll want to look into real-time operating systems, and even those will have some jitter. There are lots of shades of grey in between the extremes.

Is Scala Native an option here? I know it has a GC, but it sounds like the GC is actually optional.

This portends two possibilities:

  • Forgo using the GC altogether, also forgoing quite a bit of standard library help.
  • Minimise use of everything which would create GC pressure(s)
1 Like

We use Scala on JVM for IoT. Whether it’s suitable for you will probably depend on the actual use case, like other people have said. But in my experience a Pi is more than powerful enough. We use Pis to develop on when the much more limited devices we use in production are too slow for a pleasant development turnaround.

1 Like

There have been experiments with Scala Native on IoT devices. I believe that Shadaj played around with it a few years ago. The Scala Native project has matured quite a bit since then so it is probably worth looking into.

1 Like