Why only ASP.NET have asynchronous programming model?
I works with ASP.NET. IMHO, the asynchronous programming support in ASP.NET is beautiful. That is, we can have BeginXXXX/EndXXXX pair method to improve scalability for resource intensive task.
For example, one operation needs to get huge data from database and render it on response web page. If we have this operation synchronous. The thread handing this request will be occ开发者_StackOverflow中文版upied for the whole page life cycle. Since threads are limited resource, it is always better to program operation with I/O in asynchronous way. That is, ASP.NET will allocate thread to invoke BeginXXXX method with a callback function. The thread invokes BeginXXXX returns immediately and can be arranged to handle other requests. When the job is done, the callback function is triggered and ASP.NET will invoke EndXXXX to get the actually response.
This asynchronous programming model can fully takes advantage of threading resources. Even though there is limit of ThreadPool, it can actually handle much more requests. However, if we program in synchronous way, and each request needs lengthy I/O, the concurrent requests would not exceed size of thread pool.
Recently, I have chance to explore other web development solution such as PHP and Ruby on Rails. To my surprise, these solutions doesn't have counterpart of asynchronous programming model. Each request is handled by one thread or process for the whole life cycle. That is, the thread or process is occupied before the last bit of response is sent.
There is something similar to asynchronously(http://netevil.org/blog/2005/may/guru-multiplexing), but the baseline is that there is always one thread or process occupied for the request. This is not like ASP.NET.
So, I am wondering: why doesn't these popular web solution have asynchronous programming model like ASP.NET? Why only ASP.NET evolves to use asynchronous approach?
Is it because PHP and Ruby-on-Rails mostly deployed in Linux? And Linux doesn't suffer process/thread performance penalty like Microsoft Windows?
Or, is there actually asynchronous solution for PHP and Ruby-on-Rails that I haven't find?
Thanks.
I don't have a definitive answer to your question, but I can make an educated guess.
Systems such as PHP and Ruby are designed to be very platform-independent, whereas ASP.NET is deeply integrated into the Windows platform. In addition, PHP is more like old-style ASP, with a linear, start-to-finish flow.
Full ASP.NET-style async pages require not only threads, but native async I/O to be used to their maximum impact. Async I/O is an OS-specific capability. Async pages also rely on the concept of a page life cycle, which is anathema to the linear flow style. Without a page life cycle, it becomes much more difficult to integrate the results of the async calls with the rest of your page.
Just my two cents, YMMV.
精彩评论