4 ms·
So let's say you write a web app in Rails or Django. Of course all sorts of magic happens behind the scenes, but ultimately the whole thing boils down to a func
by asolove 16y ago
So let's say you write a web app in Rails or Django. Of course all sorts of magic happens behind the scenes, but ultimately the whole thing boils down to a function, ( def handle_request(request) { return ... } ); which is given the request and returns a response. If you have to wait for something (the database or whatever) that function will have to sit around waiting for it (e.g. "blocking") before returning the answer.
In Node.js, despite however much magic of a framework you have, it utlimately boils down to a function that gets a request and a response proxy ( function process_request(request, response) { } ). The function can do whatever it wants with this response object, by sending data right away, stashing it somewhere to be picked up later, having it send data in response to an event in the future, whatever. Then the function returns, and gets out of the way, and other stuff runs. But the response object is still sitting around, and whenever you tell it to do something, you can send some (or all) of a response back.
- callmeed 16y agoThis helps a lot (I've been wondering the same thing about node). But if you're not waiting for database calls (or whatever) before you respond, what is it useful for? I'm still a bit confused—some type of example and comparison (say with Rails) would help
- aaronblohowiak 16y agoMost web servers are bottlenecked on Io and memory. Assuming the bottleneck is that your app servers are starved for more data ( as opposed to trying to push out too much data to clients,) then a big part of your request cycle is waiting. Waiting for db, waiting for memcache, waiting for web service, waiting for disk to return some file, etc. The other thing is that your app servers will gobble ram. This is less true with copy on write, but ruby implementations and rails are usually very memory hungry. Node is not. Node is more like rack than rails, so it isn't fair to compare the two.
- superk 16y agoWhat he said... I'll also add, that it's written for Javascript should not be understated - not only is it one of the most widely used and accessible languages around, but I'd wager no other platform has the amount of competitive development that Javascript does - right now - with a slew of engines that improve in performance by magnitudes year after year. I don't know why Ryan didn't just call it Node. I think most people are thrown off by the .js.