markqvist / Reticulum

The cryptography-based networking stack for building unstoppable networks with LoRa, Packet Radio, WiFi and everything in between.
https://reticulum.network
MIT License
2k stars 124 forks source link

Building of rns package consumes too much memory in many SBC embedded systems #352

Closed wzab closed 1 year ago

wzab commented 1 year ago

I tried to install rns on an Orange Pi Zero machine (with 512 MB of RAM which should be sufficient for rns). I used armbian Linux. I installed necessary additional packages:

apt install python3-pip python3-venv  libpython3.10-dev libffi-dev  rustc cargo pkg-config gnutls-dev

After that I created the virtual environment

# python3 -m venv rns
# . rns/bin/activate

Then I tried to install the rns:

(rns) root@orangepizero:~# pip install rns
Collecting rns
  Obtaining dependency information for rns from https://files.pythonhosted.org/packages/dc/28/84c4f1899e641a9e0617c879510960811e39f2a9ad537eb10a232e7b19cc/rns-0.5.6-py3-none-any.whl.metadata
  Using cached rns-0.5.6-py3-none-any.whl.metadata (18 kB)
Collecting cryptography>=3.4.7 (from rns)
  Using cached cryptography-41.0.2.tar.gz (630 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Collecting pyserial>=3.5 (from rns)
  Using cached pyserial-3.5-py2.py3-none-any.whl (90 kB)
Collecting cffi>=1.12 (from cryptography>=3.4.7->rns)
  Using cached cffi-1.15.1-cp310-cp310-linux_armv7l.whl
Collecting pycparser (from cffi>=1.12->cryptography>=3.4.7->rns)
  Using cached pycparser-2.21-py2.py3-none-any.whl (118 kB)
Using cached rns-0.5.6-py3-none-any.whl (337 kB)
Building wheels for collected packages: cryptography
  Building wheel for cryptography (pyproject.toml) ... 

That last process consumed the whole memory and didn't finish in a few hours.

Running reticulum network nodes on low power embedded systems could be a good solution, especially to create a mesh network. However, it seems that for that a cross-compilation of rns would be necessary. It should be possible to build rns as a Buildroot, OpenWRT or Yocto package on a PC, and then install the resulting package or image on the embedded system.

wzab commented 1 year ago

I have found a viable workaround. Tracking the processes during building the rns package, I have found that the cause of the problems is running multiple rustc compilation tasks. I have limited the number of rust compilation executed in parallel by creating the /root/.cargo/config file with the following content:

[build]
jobs=1

After that, the compilation stopped failing on the lack of memory (the single rustc processes ran in a sequence occupied up to 48% of RAM). However, now another problem appears - the /tmp directory is used for intermediate compilation results and this is a ramdisk in Armbian. Therefore, now the compilation ends with:

error: could not compile `openssl-sys`

  Caused by:
    No space left on device (os error 28)
wzab commented 1 year ago

I've solved the problem of overflown /tmp directory by setting the TMPDIR variable:

mkdir /root/tmp
export TMPDIR=/root/tmp

Additionally I have added setting the TMPDIR to the /root/.cargo/config (I'm not sure if that step was necessary):

[build]
jobs=1
[env]
TMPDIR = { value = "/root/tmp", force = true }

With that, the rns package has built correctly.