The question is: what is the main advantage of asynchronous servers (Node.js Python Tornado), frameworks (Python Twisted) etc. in front of a bunch of asynchronous server + any programming language (or, as it is written in the header PHP). That is, we get that nginx collects requests from users and PHP oproblem them in turn. In the asynchronous server in a single point in time is processed as many requests as there are sarkerov and PHP/nginx likewise.
Briefly, an error has crept in here:
In the asynchronous server in a single point in time is processed as many requests as there are workerb
Imagine that you have comes to the server a request associated with fetching data from database.
He fulfills, say, for 150 MS, of which 130 is to work with the database.
In the case of PHP you have vorker will be blocked these 150 MS for processing other requests.
In the case of the asynchronous server, while request 1 is waiting for data from DB for 130 MS, will be able to accept and begin processing other requests. Suppose that we have a single PHP worker. In this case, such requests as in the example, it can handle seven pieces per second.
Asynchronous same, for example, arrive 20 queries. It will handle every interaction with the database, for example for 10 MS, fly 20 database queries, will be, for example, for 500 MS, and the server generates response. And it's all practically simultaneously. A total of less than a second we will process the 20 queries.
You can, of course, increase the pool of FastCGI, but the overhead in processing the request, each worker will be disproportionately higher than the asynchronous server.
Read it here - http://habrahabr.ru/post/128772/
The short version is that the asynchronous model is not better or worse. She has her own scope. For example, to run heavy math inside NodeJS server - the death of everything and everyone. But heavy queries to the database from PHP is quite a chipper will run on the server (well, as for them it is possible).
Or a good example from nginx-ovogo pearl queries in mysql-database to do (Yes, he can). Then he, too, begins the extremely disgusting work)
That is, the asynchronous model (at least in the area of web servers/applications) is good only when all the queries you have quickly and spend. Something like this.
(well, as usual - comments are not less valuable than the article).
Quite a narrow place to put a stake in the entire system.
Partially asynchronous system better than the system without async.
But worse than the fully asynchronous.
The creation and support of a variety of processes and threads for synchronous processing - the operation is not cheap, even if they are in a wait state. In practice, this looks like a mad increase LoadAverage.
Async allows you to keep a fixed number of worker processes (ideally, one process per processor core). The process to create it is not necessary to switch almost not necessary in bitcoin I have a scheme to handle thousands of concurrent connections with cpu load less than 1%.
All servers are designed for large loads are asynchronous. That is, the processing of new incoming connections happening before I finish work current connections.
Advantage ready asynchronous servers that they are ready. You can just write an asynchronous server in php (socket + select), but is not so efficient as in python and especially in node.js where this functionality comes out of the box.
The standard case of the application node.js/Python and twisted any other implementations of processing or raw tcp connections (e.g. push notification), or keep-alive for the same purpose. In the processing of your http requests profit is not so big. In any case, between php and python. node.js will be faster, but it will eat a little more.
The question is: what is the main advantage of asynchronous servers ... in front of a bunch of asynchronous server + any language
in front of a bunch of asynchronous server + any other language is not entirely clear what You mean. Asynchronous server or not, is one thing, but asynchronous or no access to the data from JAPANESE is quite another. I'm sure You are more interested in the second.
The beauty, the complexity and challenges in the asynchronous approach arise for the same reason. The result of the request comes immediately, but asynchronously. This gives a huge reduction in response time of the program if it uses the result of several independent IO operations. In all other cases, the synchronous approach is easier, at the same time the response is delivered. (IO is a file, external api, etc )
Nodejs has one significant drawback - it has a single implementation. This heavy calculations on it much inferior to the performance of PHP on multiprocessor/nuclear systems. (this case is easily bypassed workername and so forth, but that's another fault)
erlang, java and several other languages do not have the above problems.
Nodejs over PHP has 2 important advantages:
1. the node can store data, timers, handles, etc between requests. This is much more effective than the various caching mechanisms in PHP.
2. the gcd is not wasted time loading of code.
>>In an async server in a single point in time is processed as many requests as there are sarkerov and PHP/nginx likewise.
Not true, neither in the first nor in the second case. In the asynchronous server has only one thread which handles any number of requests in nginx - exactly the same. About PHP is a different story, but each request needs at least a thread or process.