multi threading a web application

前端 未结 5 1760
无人共我
无人共我 2021-02-08 04:13

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?

5条回答
  •  滥情空心
    2021-02-08 04:59

    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.

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

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

提交回复
热议问题