Run nodejs script with 100% cpu

I’d like to run my nodejs script with 100% cpu usage. How can I achieve this?

I want to do some calculations really fast and I think with more cpu usage it will run faster.

It is stuck at 15% cpu usage.

>Solution :

Javascript is single threaded, it can only run in a single core of your processor.

Your JS process currently uses 100% of a core, hence, 15% (1/6) of your total computational power.

You need to do parallel computations with cluster module to use all your processor power.

This can be very tricky to do efficiently because you will need a common memory between processes to avoid useless computations.

If you want to do it, the easiest way is to have the primary process giving await numbers to workers to compute.

Leave a Reply