Understanding node.js

I started reading node.js. I have a few questions:

  • Is node better than multithreading because it saves us from worrying about deadlocks and reducing the overhead of threads, or are there other factors? node uses internal threads, so we can’t say that it saves the overhead of threads, it is just managed internally.

  • Why do we say that node is not suitable for multi-core processors? It creates threads internally, so it should receive the benefits of multi-core processors. Why are we saying that this is bad for processor intensive applications? We can always create new processes for tasks requiring intensive CPU utilization.

  • Are there only callback functions sent as threads, or are there other cases?

  • Non-blocking I / O can also be achieved using threads. The main thread can always be ready for new requests. So what is the use?

+5
source share
1 answer
  • Right.

  • Node.js performs scaling using cores, through child processes , clusters , among other things.

  • Callbacks are just a common convention that developers use to implement asynchronous methods. There are no technical reasons why you should enable them. You could, for example, use all your async methods using promises.

  • All node can be executed using threads, but when using Node.js asynchronous I / O, there is less code / overhead than with multi-threaded code. For example, you do not need to instantiate thread or runnable every time you would in Java .

0
source

All Articles