
If there is something that web developers love, it is to know something that is better than traditional. But the traditional is such for one reason:
this shit works . Something had long disturbed me in all this hype around Node.js, but I did not have time to figure out what it was until I read the
post full of pain in the ass from Ryan Dahl, the creator of Node.js. I would forget it, like any regular whining of some ass that Unix is ​​too complicated. But, as a policeman who, assuming that something was wrong with this family in a minibus, stops him and finds fifty kilograms of heroin, it seemed to me that something was wrong with this tearful history, and perhaps, just maybe, he has no idea what he has been doing, and has been programming for many years, not controlled by anyone.
As you are reading this, you may have already understood that my guess was confirmed.
Node.js is a tumor on the programmer community, not only because it is completely insane, but also because people who use it infect other people who cannot think for themselves until, finally, every asshole I meet does not begin read sermons on the event loop.
Did you take the epoll into your heart?')
The collapse of scalability is waiting in the wings
Let's start with the worst lie: Node.js is scalable because it “never blocks”
(Radiation is good! Now in your toothpaste !) . Node.js website says:
There are almost no functions in the Node that directly perform I / O operations, so the process is never blocked. Due to the fact that nothing is blocked, less-than-experts can develop fast systems.
This statement is tempting, encouraging and completely fucking wrong.
Let's start with the definition, because your habrovsk know-it-alls, specificity is pedantry. A function call is called blocking when the execution of the calling thread is suspended until the completion of this function. As a rule, we think of input-output operations as “blocking,” for example, if you call socket.read (), the program will wait for the completion of this call, since it needs to do something with the returned data.
Here's a funny fact to you: calling any function using a processor is also blocking. This function, which calculates the Nth Fibonacci number, will block the current thread, because it uses the processor:
function fibonacci(n) {
if (n < 2)
return 1;
else
return fibonacci(n-2) + fibonacci(n-1);
}
(, . , , - ?), Node.js, :
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end(fibonacci(40));
}).listen(1337, "127.0.0.1");
:
ted@lorenz:~$ time curl http://localhost:1337/
165580141
real 0m5.676s
user 0m0.010s
sys 0m0.000s
— 5 . . , , JavaScript , ? , Node , . , , event loop:
while(1) {
ready_file_descriptor = event_library->poll();
handle_request(ready_file_descriptor);
}
, , , , , , , . , handle_request, ,
, , .
, , , node- — 10 , 5 :
ted@lorenz:~$ ab -n 10 -c 5 http://localhost:1337/
...
Requests per second: 0.17 [#/sec] (mean)
...
0.17 . . , Node , , , .
Node, , , « », «--» .
Unix, Node
- , , — , .
Unix, , . , - ,
- , .
- , . CGI, , - .
, -, , : -, — , , . , CGI-, - , . , HTTP- .
, : .
, , Node . Node ( , ) HTTP-,
, . , , http.createServer(), .
«node.js deployment» , , Nginx Node, Fugue. JavaScript HTTP-, , , «» CPU.
Node, 99- , , , Node. , , , HTTP-, - Node , , , , SSL , HTTP-. , , .
, , Node-, , , Node, .
JavaScript
, , , — JavaScript.
if (typeof my_var !== "undefined" && my_var !== null) {
// ,
}
, …
?
Node.js — , .
Update:
JavaScript-, Node.js. . , , , . , .
, , .