isolated-vm does not build on small machines
We switched in our project from vm2 to isolated-vm recently. This worked fine, but installation slowed down a lot and I'm experiencing some troubles getting it installed on small machines (1 Core with 256 MiB of RAM). It turns out, that the kernel kills some c++(1) processes when installing with npm install isolated-vm due to an out of memory condition. I've tried to install it with --ignore-scripts and build isolated-vm manually, which worked and led to the following results:
Building with a single thread:
$ time node-gyp rebuild --release -j max
[...]
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build', '--jobs', 1 ]
[...]
537.04 real 187.85 user 22.61 sys
But when increasing the number of threads it speed up with 2 threads and starts threshing with 3 threads:
$ JOBS=2 time node-gyp rebuild --release
[...]
256.51 real 166.68 user 10.87 sys
$ JOBS=3 time node-gyp rebuild --release
[...]
557.14 real 244.18 user 84.46 sys
Building it with more than 3 threads, did not succeeed!
Always building it manually, is not an option, because there might be other node modules, that have installation scripts which might get skipped unintentionally. What could be a solution to this? I see, that the following should be possible:
- Replace
-j 4(parallel build with 4 threads) inpackage.json's "install" script with-j max. This would automatically scale the number of threads. Unfortunately I couldn't test it on a big machines, so this might be an obstacle. - Remove the parallel
node-gypinvocation inpackage.jsoncompletely. This might slow down the installation on bigger machines, but it is possible to add theJOBS=4environment variable when installing (or addJOBS=max).
There might be other solutions, that I'm no aware of. Not only small machines, but containerized builds or cross-platform builds with qemu could benefit from this, too.
Given the options above, please remove the parallelism in the install script.
You can build on a different machine and deploy to a smaller machine?
No, this is not possible.
Oh
Jobs max sounds fine to me if you'd like submit a PR.
Thanks for merging https://github.com/laverdet/isolated-vm/pull/429. When do you plan to release it?
I'm not sure. You can npm install from github by the way.
Thanks @augjoh for finding this. I have a Rpi 3 b+ with a 4-core CPU and 1GB RAM and it freezes with -j max because node-gyp would run with 4 threads. I had to limit to 1 thread to get the build run through.
Works fine with 4.7.2