21

I've been reading about the C10K Problem, and of particular note is the part that refers to asynchronous server I/O. http://www.kegel.com/c10k.html#aio

I believe this pretty much summarises what Node.js does on the server, by allowing threads to process user requests whilst relying on I/O interrupts (events) to notify threads of jobs that are completed, rather than have the thread be responsible for the full CPU job. The thread can get on with other things (non-blocking), and be notified of when a job is done (e.g. a file is found or a video is compressed).

This subsequently means that a thread is more 'available' to sockets and therefore to users on the server.

Then I found this: http://teddziuba.com/2011/10/straight-talk-on-event-loops.html

The writer here claims that although the event driven framework (interrupted threading), may free up threads, it doesn't actually reduce the amount of work a CPU has to do! The rationale here is that if, say, a user requests to compress a video they uploaded, the CPU still has to actually do this job, and will be blocking while it does it (for simplicity's sake, lets forget about parallelism here - unless you know better!).

I'm a straightforward coder, not a server admin or anything like that. I'm just interested to know: is Node.js a gift from the gods of 'cloud computing' or is it all hot air, and won't actually save companies time and/or money by improving scalability?

Many thanks.

5
  • 12
    Firstly ted is a troll, secondly node.js is meant for IO-bound applications not CPU-bound applications. What you want is a combination of the two. Anything CPU-bound goes into a new thread/process. Anything IO-bound goes in a event loop.
    – Raynos
    Commented Oct 25, 2011 at 16:41
  • 1
    +! That guy is definitely a troll. Commented Oct 25, 2011 at 17:42
  • It depends with what you compare - if you still use Apache (for some reason) - then Node is gift from gods, but if you compare it to Nginx - improvements are much less drastic, and Node is even slower. (ten times slower, 2ms vs 20ms to generate a responce, BUT in our tests, Nginx was giving 504 under moderately heavy load, and Node was giving normal responses).
    – c69
    Commented Oct 25, 2011 at 18:09
  • Now you mention it guys, the troll guy is clearly a troll. @c69 that's good info, thanks a lot.
    – Alex
    Commented Oct 25, 2011 at 21:02
  • Your "straight talk on event loops" link no longer works. Commented May 26, 2016 at 19:10

3 Answers 3

20

Of course any CPU bound work is going to utilize the CPU. It's going to block the CPU in whatever language or framework you write it in.

Node.js is great for when you have I/O bound work, not CPU bound. I wouldn't do heavy lifting in Node, though it can be done. Node.js solves real problems, not fictional or imagined ones like fibonacci number servers. It's not “hot air”.

3
  • Just checking some benchmarks and indeed it does seem way faster at serving pages: zgadzaj.com/… .. I guess this is what I was after...
    – Alex
    Commented Oct 25, 2011 at 14:48
  • 3
    @AlexW: Good point about those benchmarks is that you're essentially serving static content. See my Millions of Hits a Day piece. Spinning up the PHP interpreter for that is waste. Look at something like node-static for serving file directories.
    – Josh K
    Commented Oct 25, 2011 at 15:55
  • @AlexW, Just to remind that zgadzaj.com/… uses node.js 0.1.103, which is old now !! Commented Oct 30, 2011 at 10:06
4

While the C10K paper is somewhat out of date with regards to implementation details, event-based concurrency (the reactor model) is still in some ways superior to preemptive scheduling. For example, a preemptive scheduling model may schedule threads while they are IO blocked. This allows node (and other tools like Ruby's Event Machine and Python's Twisted) to better use available cycles by spending more time doing real work and less time blocking.

-1

Multithreading still boosts the performance. The original explanation is idiotic as it does not consider existence of multiple cores. The moment you have more than one core, threads are no more threads. They are hyperthreads. Any thread intensive application is going to benefit from it more than a single threaded application.

3
  • 2
    This doesn't really explain the Node.JS fervor though. The primary benefit of Node.JS is its ability to quickly handle and dispatch multiple requests from a single thread, not to effectively handle heavy background workloads, which your answer doesn't address. Commented May 26, 2016 at 19:08
  • The primary benefit of node.js is to have a single language for front and backend. All these other claims are just fluff to make it seem more important. Commented May 26, 2016 at 20:14
  • 2
    @whatsisname single threaded concurrency is a huge benefit, much larger than having a single language in my opinion.
    – pllee
    Commented May 26, 2016 at 20:22

Not the answer you're looking for? Browse other questions tagged or ask your own question.