Scala Application Memory Usage on a Raspberry Pi

My current project requires some complex software on the Raspberry Pi 3 B+, which has 1GB of RAM. For my technology stack's primary components, I've chosen Scala, OpenCV, and TensorFlow. Typically C++ or python is used with OpenCV or TensorFlow. However,

  1. C++ is low level, and I've been sorry one too many times for choosing it (I know there can be plenty of discussion there around e.g. C++14, but that's for another day).
  2. I would need a significant refresher and update on the latest C++ language standards, boost libraries, and libraries for HTTP, high-level concurrency, etc.
  3. While I've used Python, I'm no master of it, and while I could become one, I've already taken on way too many "masteries"; it's time to limit my learning in favor of more productivity, when within reason; there will always be plenty of learning to do on other fronts in technology and software development.
  4. Python isn't the quickest slitherer among languages and platforms anyway, and yes slitherer is a real word, because I just used it. (...I don't actually agree with that philosophy, but sometimes we adopt a way of thinking for immediate convenience rather than truth, don't we? An oh-so-subconscious technique to be avoided in weightier matters.)

Scala provides a high-level language and platform, concise code that can be quickly changed and maintained, and the benefits of both the functional and OO paradigms. (That's right, I'm not a functional purists, though I use OO almost solely for data objects and for organization of functions). And equally important, I'm already seasoned in its ecosystem.

However, especially in a large project, project risks must be mitigated up front, else you pay big ouchies later when you've already invested precious time and resources into a decision that won't work, or that turns out to be significantly more costly than an alternative.

This application will be using computer vision and machine learning, but potentially memory-intensive. So one of the first risks to shoot down is if a scala application, with its dependencies, would

scala app, no additional dependencies (21MB / 2.4% RAM, 5.6MB on disk):

scala app with dependencies (31MB / 3.4% RAM, 12.4MB on disk):

On my Windows desktop, the same scala app-with-no-dependencies used 862MB of RAM! That the scala app with large dependencies takes only 31MB of RAM is great news. 3.4% is a significant price, but worth the increased speed and ease of development with scala instead of C++. If I need to free up RAM e.g. for a large CNN, I can free it up other ways. Look at the other processes for example:

Xorg, the Raspbian/Debian/Linx X Windows gui process, takes 6%/54MB, so using command-line-only Linux gets rid of that. Using SSH instead of VNC during development would free up another 1.6%/11MB or so if necessary. That's about all we can eliminate from the processes though; that 30MB is very large compared to the other processes. But even with a C++ app, the majority of our application's RAM will be used by CNN(s) and image processing, both of which can be tweaked for memory usage. I don't see any need to sacrifice scala or JVM over memory usage.

The dependencies I added were: scala-library:2.11.8 akka-actor slf4j-api, slf4j-log4j commons-io commons-codec xstream joda-time com.google.code.gson org.apache.httpcomponents: 4.1

Show Comments