node-memory-behaviour icon indicating copy to clipboard operation
node-memory-behaviour copied to clipboard

Interesting tests, though I cannot replicate use of swap

Open tommedema opened this issue 8 years ago • 2 comments

I am doing an experimental test where I am running a big data regression in memory on a machine with relatively low RAM (32gb) but with a huge swap SSD (300gb).

Of course this is perhaps not a good idea; but I would like to give it a try and see actual benchmarks.

The problem is that node doesn't seem to be able to use swap, even though swapon -s confirms that 300gb of swap is available. I've run node as per your recommendation:

node --expose-gc --max_semi_space_size=4480 --max_old_space_size=286720 --max_executable_size=143360 src/main.js

The system has enough physical and virtual RAM: screen shot 2017-03-01 at 19 40 51

I created a simple memtest.js script to see if node will start using swap:

const targetBytes = 500 * 1024 * 1024 * 1024; // 500gb
const arrLength = Math.pow(2, 32) - 1;
const arrLength2 = 20000;

let arr = new Array(arrLength);
for (var i = 0, il = arrLength; i < il; i++) {
  let arr2 = new Array(arrLength2);
  for (var i2 = 0, il2 = arrLength2; i2 < il2; i2++) {
    arr2[i2] = Math.random();
  }
  arr[i] = arr2;
  if (i % 100 === 0) {
    console.log(process.memoryUsage().heapUsed / 1024 / 1024);
  }
}

The result is:

screen shot 2017-03-01 at 19 42 57

Initially it seems to go well. But then at this point it will hit the physical RAM amount and for some reason throw an out of memory exception:

screen shot 2017-03-01 at 20 27 51 screen shot 2017-03-01 at 19 40 40

Your tests specifically test for virtual memory. Do you have any clue as to why it still throws an OOM at the physical memory limit? Why doesn't it start to use more swap?

tommedema avatar Mar 02 '17 09:03 tommedema

Same for Google Compute Engine (Debian). It exits at about 28GB. This machine had 6GB physical RAM and 250GB virtual RAM.

screen shot 2017-03-05 at 19 31 52

Is there something in node that causes this to happen at about 30GB RAM usage, no matter the amount of SWAP remaining?

tommedema avatar Mar 05 '17 11:03 tommedema

Note that on the same machine the same test but run with PHP works just fine (using 70GB+ without issues).

tommedema avatar Mar 05 '17 12:03 tommedema