4 ms·
> Does that mean that node apps shouldn’t do any computation on data, just move bytes between a file and a network socket? If I need my program to think, I wrot
by throwitaway1123 3y ago
> Does that mean that node apps shouldn’t do any computation on data, just move bytes between a file and a network socket? If I need my program to think, I wrote it wrong or in the wrong language?
This is a very uncharitable interpretation of Node's primary use case. I think it would be more accurate to say don't use Node if all of the following apply:
- Your task is CPU bound rather than IO bound (e.g. you're not waiting to insert or retrieve data from the database).
- Your task is highly parallel (some computations are sequential and linear).
You can't use worker threads because:
- You have too much data to bear the cost of message passing via the structured clone algorithm.
- You can't share memory and avoid structured cloning because your data can't be represented using an array buffer.
This is a far cry from the claim that Node can't handle problems that require "thinking". When you're on the JIT compiler's happy path Node can think pretty quickly actually. In practice, many high volume web servers are handling enough requests that there's more than enough jobs for each Node process to have exclusivity over its jobs, and you don't need to share work between processes. Each process or worker thread can be largely independent. Not every task is going to fall within those boundaries, but that's ok, Node doesn't have to fulfill every use case.