0

Nodejs is said to use only one process to handle requests and then those function using I/O will do asynchronously, which will improve the efficiency of web server. However, those process to handle I/O doesn't count? Compared with traditional web server, like Apache, which use multithread to handle requests where every request in one thread, Is the cost(request + I/O) reduced?

qqibrow
  • 2,942
  • 1
  • 24
  • 40
  • Not really a programming question.. – Duncan_m Nov 01 '12 at 01:59
  • are you serious? if you don't know the inner mechanism of some language, how can you program well? – qqibrow Nov 01 '12 at 04:03
  • possible duplicate of [how node.js server is better than thread based server](http://stackoverflow.com/questions/3759683/how-node-js-server-is-better-than-thread-based-server) – slebetman Nov 01 '12 at 11:44

1 Answers1

0

Yes, node.js only needs one thread (which is an even more restrictive than requiring one process, depending on operating system). And yes, this does impact on your programming requirements:

-- your programs must never block!

There are quite a few resources you can refer to, as to why node.js is so fast, e.g.:

http://www.manning.com/cantelon/NjsiA_meap_ch01.pdf

http://nodejs.org/about/

node.js saves on the threading penalty imposed by context switching, that other servers require (see Slebetman). We built our own such server in 2004 in C++, because of high performance requirements, when your server has to open and close a lot of connections, this approach really saves a lot of resources.

I think what you are missing in your question is that node.js hands off operations that take a long time to the O/S and is called back with the answer. The O/S is fully multi-process. So node.js only NEEDS one thread for its control, but I/O is controlled by O/S processes.

node.js can however spawn additional processes, in which you can run parallel programs.

Ron Wertlen
  • 830
  • 10
  • 24
  • 1
    That's not really correct. See my previous answer to this question: http://stackoverflow.com/questions/3759683/how-node-js-server-is-better-than-thread-based-server/3759991#3759991 – slebetman Nov 01 '12 at 11:44
  • made answer more precise now. hth. I already +1'ed your other post, thanks. – Ron Wertlen Nov 01 '12 at 13:27