Gergő Horváth
Gergő Horváth

Reputation: 3705

What those nodeJS options mean

I'm renting a 96 core, 360gb ram linux VM from GCP. My function is generating 100.000.000 combinations (array of items), and each gets passed into a fairly heavy function. I'm running numberOfCores - 1 workers to divide the task into equal parts.

The instance is throwing different errors with different option values, but the common in all of them is: JavaScript heap out of memory.

I've had some playaround with those:

--max-old-space-size, --max-semi-space-size

The first option is the most popular, and as I see solves the problem most of the cases, but not in mine.

I'm trying to research all my possible options to solve this problem (as I can't believe 96 cores, and 360gb ram isn't enough), and I found some:

For worker:

For node (excluding the already mentioned ones):

They aren't too well documented, and I would like to understand what each mean to solve my out of memory problem, and set them to maximize the hardware resource usage without crashing it.

Upvotes: 1

Views: 929

Answers (1)

TimDog
TimDog

Reputation: 8928

For what it's worth, I was having the same trouble with OOM errors on a linux box with 256gb of memory, and no tweaks of any of those values worked for me. Based on this discussion, what ended up solving the worker_thread OOM errors for me was tweaking these limits:

sysctl -w kernel.threads-max=4194303
sysctl -w vm.max_map_count=8388606
sysctl -w kernel.pid_max=4194303

And to persist them across reboot:

vi /etc/sysctl.conf
kernel.threads-max = 4194303
vm.max_map_count = 8388606
kernel.pid_max = 4194303

After stopping and restarting the main node process once those were applied, I did not see the OOMs.

Another interesting thing I found - the max-old-space-size param that you set when starting node is inherited by all the worker_threads and you don't need to issue that same amount using the resourceLimits. maxOldGenerationSizeMb -- so I don't think you need to launch the 'master' script with a huge amount and then set the worker_threads to a smaller amount; I think you can just launch the master script with the same values you intend on giving to the worker_thread

Finally, FWIW, I was not able to set the max threads to more than the CPU core count with this configuration. I'm using threadsjs and a ThreadPool, not spawning the workers directly though.

Upvotes: 1

Related Questions