I would like to ensure that the available heap size (my NodeJS app can use) always has been set to the max.
To my understanding it should not any longer be necessary to set the "--max_old_space_size" when you run NodeJS 10 and up...?
No matter where I run my node app - and I check the heap size it is between 35MB - 40MB. My laptop has 32GB of memory and my small AWS instance has 1GB - but both seem to allocate and use the same small heap size (old_space of 37MB/37072896 (of 1GB) and 35MB/35270656(of 32GB))?
I have tried to use and set "--max_old_space_size=1000000" - but it doesn't seems to have any effect?
const v8 = require('v8');
console.log(v8.getHeapSpaceStatistics());
1.AWS INSTANCE WITH 1GB MEMORY:
[
{
space_name: 'read_only_space',
space_size: 262144,
space_used_size: 32296,
space_available_size: 229576,
physical_space_size: 262144
},
{
space_name: 'new_space',
space_size: 8388608,
space_used_size: 1995376,
space_available_size: 2194576,
physical_space_size: 8388608
},
{
space_name: 'old_space',
space_size: 37072896,
space_used_size: 35261192,
space_available_size: 1746800,
physical_space_size: 37072896
},
{
space_name: 'code_space',
space_size: 425984,
space_used_size: 296192,
space_available_size: 70048,
physical_space_size: 425984
},
{
space_name: 'map_space',
space_size: 1576960,
space_used_size: 1272080,
space_available_size: 300656,
physical_space_size: 1576960
},
{
space_name: 'large_object_space',
space_size: 1720320,
space_used_size: 1700944,
space_available_size: 0,
physical_space_size: 1720320
},
{
space_name: 'code_large_object_space',
space_size: 49152,
space_used_size: 3552,
space_available_size: 0,
physical_space_size: 49152
},
{
space_name: 'new_large_object_space',
space_size: 0,
space_used_size: 0,
space_available_size: 4189952,
physical_space_size: 0
}
]
2.MY LAPTOP WITH 32GB MEMORY:
[
{
space_name: 'read_only_space',
space_size: 262144,
space_used_size: 33040,
space_available_size: 0,
physical_space_size: 262144
},
{
space_name: 'new_space',
space_size: 33554432,
space_used_size: 16417832,
space_available_size: 340952,
physical_space_size: 33554432
},
{
space_name: 'old_space',
space_size: 35270656,
space_used_size: 35127408,
space_available_size: 50416,
physical_space_size: 35270656
},
{
space_name: 'code_space',
space_size: 692224,
space_used_size: 451296,
space_available_size: 14304,
physical_space_size: 692224
},
{
space_name: 'map_space',
space_size: 1839104,
space_used_size: 1817840,
space_available_size: 0,
physical_space_size: 1839104
},
{
space_name: 'large_object_space',
space_size: 3067904,
space_used_size: 3045496,
space_available_size: 0,
physical_space_size: 3067904
},
{
space_name: 'code_large_object_space',
space_size: 49152,
space_used_size: 2784,
space_available_size: 0,
physical_space_size: 49152
},
{
space_name: 'new_large_object_space',
space_size: 1523712,
space_used_size: 1515104,
space_available_size: 15243680,
physical_space_size: 1523712
}
]
My experience:
I realized that Node actually increment the heap-size automatically (and that it is actually working as expected). So unless the heap-size fills up all your memory - you are all good.
I also realized that I had a memory leak (my node app open way to many web socket connections - instead of resetting the existing one). I found this via running the Node app via PM2 - it has as build-in "active handlers" counter which just increased and increased.