by baublet · 8mo ago · 0 comments
e.g., this certainly helps when the event loop is blocked, but so could FFI calls to another language for the CPU bound work. I’d only reach for a new Node thread if these didn’t pan out, because there’s usually a LOT that goes into spinning up a new node process in a container (isolating the data, making sure any bundlers and transpilers are working, making sure the worker doesn’t pull in all the app code, etc.).
Side car processes aren’t free, either. Now your processes are contending for the same pool of resources and can’t share anything, which IME means more likelihood of memory issues, esp if there isn’t anything limiting the workers your app can spawn.
Still, good article! Love seeing the ways people tackle CPU bound work loads in an otherwise I/O bound Node app.
Worker threads can be more convenient than FFI, as you don't need to compile anything, you can reuse the main application's functions, etc.
I make my comment to note tho that in many envs it’s easier to scale out than account for all the extra complications of multiple processes in a single container.
5 years ago I never would have given this comment a second thought.
Now I read it and have to wonder: when does the price of ram start showing up in the butchers bill from your cloud provider?
But the prices have gotten stupid: https://pcpartpicker.com/trends/price/memory/
https://appleinsider.com/articles/26/02/27/the-global-ram-an...
It's an SDK that runs in users' apps. So userland code blocks the event loop, preventing outgoing heartbeats from the SDK