isolated-vm icon indicating copy to clipboard operation
isolated-vm copied to clipboard

isolated-vm does not build on small machines

Open augjoh opened this issue 2 years ago • 7 comments

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) in package.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-gyp invocation in package.json completely. This might slow down the installation on bigger machines, but it is possible to add the JOBS=4 environment variable when installing (or add JOBS=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.

augjoh avatar Nov 24 '23 06:11 augjoh

You can build on a different machine and deploy to a smaller machine?

laverdet avatar Nov 24 '23 21:11 laverdet

No, this is not possible.

augjoh avatar Nov 24 '23 22:11 augjoh

Oh

laverdet avatar Nov 25 '23 00:11 laverdet

Jobs max sounds fine to me if you'd like submit a PR.

laverdet avatar Nov 25 '23 00:11 laverdet

Thanks for merging https://github.com/laverdet/isolated-vm/pull/429. When do you plan to release it?

augjoh avatar Dec 08 '23 05:12 augjoh

I'm not sure. You can npm install from github by the way.

laverdet avatar Dec 08 '23 17:12 laverdet

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.

jairoxyz avatar Dec 29 '23 19:12 jairoxyz

Works fine with 4.7.2

augjoh avatar Jan 30 '24 18:01 augjoh