; Date: 2011-07-08 09:36
Why? Isn't Apache+PHP good enough? The website you're reading this on is an Apache+PHP application (Drupal) in the LAMP model. The LAMP model has served us pretty well for over 10 years, but maybe it's time is ending, or maybe not. There is a heck of a lot of excitement about Node but that isn't always the right reason to adopt a new thing just because its exciting. Is there a real and practical benefit?
COMET as a justification for using Node.js? was my attempt to go over one of the reasons. COMET is a name for a web development strategy of maintaining a long running connection between each web browser and the server. The purpose is to bring even more interactivity into browsing websites with for example immediate response to requests. For example Facebook has developed COMET-like capabilities to for example pop up a notification when someone else comments on something you've commented on. It helps facebook retain you on their website, because it is letting you know immediately when there's something for you to pay attention to. It's not just Facebook, because for example Twitter notifies you of new tweets, etc.
That instant notification could be done with DHTML (AJAX) techniques but that would tend to overwhelm the server with a zillion browsers polling the server. Instead COMET has the server sending a push notification to the browser, and uses the active connection to browsers as the channel.
Where Node becomes important is that it scales extremely well in this scenario where a thread based architecture would not scale. On threaded architectures you typically have one thread per open connection and that becomes a horrible bit of nonscalability. The key is event driven asynchronous programming. The blog post goes over the details ..
What does "event driven asynchronous programming" mean? Asynchronous means that code execution doesn't follow the linear order of the text of the program. Event driven means that the execution order happens because of events arriving in the program. Program execution order is based on events rather than the sequential order of statements in the program text. The programming style requires learning a different paradigm, but it's not a programming style with no precedence. Any GUI programmer has to program in an event driven manner because that's how GUI's operate.
I think we can now begin to answer the question at the top of the article.
Why would you do it? If your web application needs more scalability especially with the "real time web" coming to the fore. The real time web (as currently implemented) is requiring more interactivity and perhaps the COMET approach is the best way to get there. Node.js seems to have been designed explicitly to handle the real time web.