Skip to content

Comment on Node.js worker threads are problematic, but they work great for us

Comments

It’s not weird that you can’t share state between totally different processes except by passing in args.

And you can make it thread-like if you prefer by creating a “load balancer” setup to begin with to keep them CPU bound.

    require('os').cpus().length
Spawn a process for each CPU, bind data you need, and it can feel like multithreading from your perspective.

More here https://github.com/bennyschmidt/simple-node-multiprocess

I love the simplicity of Node.js that each process or child process can have its own CPU core with essentially no context switching (assuming you have enough CPU cores).

Most other ways are just hiding the context switching costs and complicating monitoring IMO.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.