多线程的Web应用程序 [英] multi threading a web application

查看:147
本文介绍了多线程的Web应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有些时候,最好多线程应用程序许多情况下,但 什么时候最好多线程一个.NET Web应用程序?

I know there are many cases when it's best to multi thread an application but when is it best to multi thread a .net web Application?

推荐答案

Web应用程序是几乎可以肯定已经多的托管环境(IIS等)螺纹。如果你的网页是CPU绑定(并且想使用多个内核),那么可以说是多线程是一个坏主意,因为当你的系统在负载情况下,你已经在使用它们。

A web application is almost certainly already multi threaded by the hosting environment (IIS etc). If your page is CPU-bound (and want to use multiple cores), then arguably multiple threads is a bad idea, as when your system is under load you are already using them.

当时它的可能的帮助,当你IO约束;例如,你有一个网页需要去跟3个外部网络服务,跟一个数据库,并写入一个文件(所有不相关)。可以(最好使用内置的异步操作,以最大限度地完成端口使用率)做那些在不同线程上平行,以减少总的处理时间。 - 所有不影响本地CPU过于多(此处的实延迟是在网络上)

The time it might help is when you are IO bound; for example, you have a web-page that needs to talk to 3 external web-services, talk to a database, and write a file (all unrelated). You can do those in parallel on different threads (ideally using the inbuilt async operations, to maximise completion-port usage) to reduce the overall processing time - all without impacting local CPU overly much (here the real delay is on the network).

当然,在这种情况下,您还可能通过简单地排队在Web应用程序中的工作,有一个单独的服务出队并处理它们做的更好 - 但你不能提供给调用者立即作出反应(他们' ð需要稍后再检查以确认完成等)。

Of course, in such cases you might also do better by simply queuing the work in the web application, and having a separate service dequeue and process them - but then you can't provide an immediate response to the caller (they'd need to check back later to verify completion etc).

这篇关于多线程的Web应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆