node.js Is VB6 - Does node.js Suck? Javascript is incredibly ugly. Why would anyone extend it to a full server-side language?
Node.js is single-threaded only. You use non-blocking calls and callback functions. In these days of multicore servers, why would anyone design a language to be only single-threaded? Plus, it’s a PITA to manage all those callback functions and debug.
With Apache, a new thread/process is spawned for each request. The PHP code then runs in that thread. The database calls are blocking calls; the thread sleeps until the call returns. If one thread is waiting for the database, that thread cedes the CPU via UNIX multitasking, and the other threads work.
The drawback is that spawning a thread/process is CPU expensive. (Actually, doesn’t Apache keep a pool of idle threads, only spawning new ones when necessary? If that is true, then the node.js criticism is completely wrong. Node.js’ “single thread model” is based on a criticism of Apache that’s outright false.)
However, unless your website is super-popular, it doesn’t make a difference. I doubt I’ll ever get enough traffic to push the limits of my Linode, even without any WordPress caching extensions.
With node.js, it’s only one thread. Instead of spawning a new thread, you have non-blocking database calls. Then, there’s a callback function when the database call returns. Internally, node.js processes all the callbacks, in order.
There’s another language that uses non-blocking calls and callback functions. It’s VB6 (Microsoft Visual Basic 6). My preliminary analysis of node.js is that it uses advanced VB6-like technology.
Node.js does have a lot of built-in libraries. If you want a basic node.js http server, you just include the http library, listen, and handle the request.
If you want to set up Apache/LAMP, that’s a full day of work. If you write an http server in C++, that’s a lot of code. With node.js’ libraries, you can get a basic http server running quickly.
Do you see the fallacy?
Yes, it’s nice that node.js gets a basic http server running quickly, via nice libraries. However, you still have to write the code for your application.
Clueless people get obsessed with languages and frameworks. No matter what language and framework you use, you have to write your application code. If you use a fancy framework, then you have to write framework-compliant code in addition to your program’s code. With node.js, you’re fiddling around with callback functions and manually managing timing, instead of letting Apache and the OS do it for you.
I wonder if a clueless person prefers to install and run node.js, rather than set up a full LAMP installation? It’s a lot more work to properly install and configure LAMP, than to install node.js and run that.
I suspect that the founders hired a parasite/psychopath to build their product. He’s focusing on hype instead of content, and picked the latest trend, node.js. However, unless I meet their CTO, I don’t know if he’s sane or a psychopath. Given that the non-technical co-founders were intelligent, I’m pretty sure they hired a psychopath.
The “beauty” of node.js is that it only spawns one thread that does everything. However, what if your website is super-popular? What happens once one thread isn’t enough? Then you have to add code to juggle requests between threads and servers. Now, all the advantages of node.js are flushed down the toilet, once one thread can’t handle everything. With Apache, I can upgrade from a 4-core server to an 8-core server and get double the power. You can’t do that with node.js, unless you write code to handle it, which defeats the benefit of using node.js in the first place. Yes, I can write my own thread pooling algorithm, but why not use Apache, which was already super-tuned by others? If I’m balancing my load among several servers, I can directly configure Apache to do that for me. With node.js, wouldn’t I have to manually add all the code for that? (There are some libraries planned but not finished, to address some of my concerns. However, they probably will eliminate any advantages of node.js in the first place.)
Node.js seems like exactly the opposite of the language I’d write. In these days of multi-cores, you need a language that handles multiple cores/threads/processes well. Node.js will only use one core, no matter what you do, unless you spawn multiple node.js instances.