为什么只有ASP.NET有异步编程模型?

时间:2021-12-02 19:30:38

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.

我使用ASP.NET。恕我直言,ASP.NET中的异步编程支持很漂亮。也就是说,我们可以使用BeginXXXX / EndXXXX配对方法来提高资源密集型任务的可伸缩性。

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 occupied 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.

例如,一个操作需要从数据库获取大量数据并在响应网页上呈现它。如果我们将此操作同步。处理此请求的线程将占用整个页面生命周期。由于线程是有限的资源,因此以异步方式使用I / O编程操作总是更好。也就是说,ASP.NET将分配线程以使用回调函数调用BeginXXXX方法。线程调用BeginXXXX立即返回,并可以安排处理其他请求。作业完成后,将触发回调函数,ASP.NET将调用EndXXXX以获取实际响应。

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.

这种异步编程模型可以充分利用线程资源。即使ThreadPool有限,它实际上可以处理更多的请求。但是,如果我们以同步方式编程,并且每个请求都需要冗长的I / O,则并发请求不会超过线程池的大小。

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.

最近,我有机会探索其他Web开发解决方案,如PHP和Ruby on Rails。令我惊讶的是,这些解决方案没有异步编程模型的对应物。每个请求由整个生命周期中的一个线程或进程处理。也就是说,线程或进程在发送最后一位响应之前被占用。

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.

有一些类似于异步的东西(http://netevil.org/blog/2005/may/guru-multiplexing),但基线是请求总是有一个线程或进程占用。这不像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?

所以,我想知道:为什么这些流行的Web解决方案不具备像ASP.NET这样的异步编程模型?为什么只有ASP.NET演变为使用异步方法?

Is it because PHP and Ruby-on-Rails mostly deployed in Linux? And Linux doesn't suffer process/thread performance penalty like Microsoft Windows?

是因为PHP和Ruby-on-Rails主要部署在Linux中? Linux不像微软Windows那样遭受进程/线程性能损失吗?

Or, is there actually asynchronous solution for PHP and Ruby-on-Rails that I haven't find?

或者,实际上我找不到PHP和Ruby-on-Rails的异步解决方案吗?

Thanks.

谢谢。

1 个解决方案

#1


4  

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.

诸如PHP和Ruby之类的系统被设计为非常独立于平台,而ASP.NET则深深地集成到Windows平台中。此外,PHP更像是旧式ASP,具有线性,从头到尾的流程。

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.

完整的ASP.NET样式异步页面不仅需要线程,还需要使用本机异步I / O来发挥其最大影响。异步I / O是特定于操作系统的功能。异步页面还依赖于页面生命周期的概念,这是线性流式的诅咒。如果没有页面生命周期,将异步调用的结果与页面的其余部分集成起来会变得更加困难。

Just my two cents, YMMV.

只是我的两分钱,YMMV。

#1


4  

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.

诸如PHP和Ruby之类的系统被设计为非常独立于平台,而ASP.NET则深深地集成到Windows平台中。此外,PHP更像是旧式ASP,具有线性,从头到尾的流程。

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.

完整的ASP.NET样式异步页面不仅需要线程,还需要使用本机异步I / O来发挥其最大影响。异步I / O是特定于操作系统的功能。异步页面还依赖于页面生命周期的概念,这是线性流式的诅咒。如果没有页面生命周期,将异步调用的结果与页面的其余部分集成起来会变得更加困难。

Just my two cents, YMMV.

只是我的两分钱,YMMV。