1

Doesn't the fact that Node.js uses a thread-pool to queue system calls defeat its overall purpose? My understanding is that Node.js provides for purely event-based code via an event loop, however, if each event spun up is generating a thread behind the scenes anyway, then how is it any different from, say, apache, which also generates threads for blocking calls? I mean it may be more efficient if something like apache doesn't use thread pools, but other than that it seems the same? There may also be some speed differences due to the fact that JS executes faster than say php...

Francisco Aguilera
  • 3,099
  • 6
  • 31
  • 57

1 Answers1

1

There are two main reasons, you may want node:

  1. Performance

AFAIK, node leverages low-level non-blocking API wherever possible; I see thread pool as some kind of fallback which is used, when no-blocking primitive simply does not exist.

For more info, see:

When is the thread pool used?

Confusion about node.js internal asynchronous I/O mechanism

  1. No multithreading

is not just about speed. Event-loop-powered asynchronous callbacks / Promises / CSP is a way, how to write code, that 'runs tasks in parallel', but without explicit locks (and not so explicit deadlocks and race-conditions). Many of the people who tried some multithread programming tend to appreciate these semi-new paradigms.

Community
  • 1
  • 1
Tomas Kulich
  • 14,388
  • 4
  • 30
  • 35