并行执行多个操作 [英] Execute more than one action parallely

查看:65
本文介绍了并行执行多个操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

祝你和你的家人新年快乐



我想要并行执行多个动作asp.net MVC。实际上线程池一个接一个地执行请求,并且在异步编程中我们也可以在单个请求中创建和执行多个线程。



我的要求是这样的,我做了11个异步ajax从浏览器调用我的控制器的不同的动作,每个动作平均需要3-4秒,所以要处理所有请求,它需要大约40到44秒。它发生的原因是因为浏览器异步发送的所有请求但它们在线程池中都很饿,因为线程池一个接一个地执行它们。



有没有办法强制线程池并行运行多个请求。

如果有可能那么为asp.net mvc4中的特定控制器做它会好得多。





感谢advancve ...

任何帮助都会非常感激

Hi Guys,
Wishing you and your family a very happy new Year

I want to execute multiple actions parallely asp.net MVC. Actually thread pool executes request one after another and in asynchronous programming also we can create and execute mutiple threads inside a single request.

My requirement is such taht i made 11 async ajax calls from browser to different Actions of my controller each one of them takes an average of 3-4 sec, so to process all request it is taking almost 40 to 44 sec. It is happening because all requests sent from browser async but they got starved in thread pool because thread pool executes them one after another.

Is there any way to force thread pool to run multiple requests parallely.
If it is possible then it would be much better to do it for a particular controller in asp.net mvc4.


Thanks in advancve...
Any help would be much appreciated

推荐答案

有一个如何解决这个问题。



来自浏览器的每个请求都是单独处理的,就像11个不同的客户端一样。它们通常不是同步处理的,但同时考虑到ASP.NET的设置限制。



ThreadPool中的线程不处理请求。它们由ASP.NET Worker Threads处理。它们不一样!



您将不得不稍微修改一下您的问题并列出您正在使用哪个O / S,哪个版本的Visual Studio ,您正在使用的Web服务器以及安装位置。你修改了你的web.config吗?如果是这样,你改变了什么?



接下来,查看你的代码,特别是这些调用正在使用的方法。他们使用共同资源吗?它是什么?你是否有效地使用它?
There's a little problem with how you laid this out.

Each request coming from the browser is being handled separately, like 11 different clients. They are not normally handled synchronously, but at the same time, given the restrictions on how ASP.NET is setup.

Requests are not handled by threads in the ThreadPool. They are handled by ASP.NET Worker Threads. They are not the same!

You're going to have to modify your question a bit and list which O/S you're using, which version of Visual Studio, which web server you're using and where it is installed. Did you modify your web.config? If so, what did you change?

Next, look at your code, specifically, the methods that these calls are using. Do they use a common resource? What is it? Are you using it efficiently?


你好,



在ASP.NET 4.0中,我们引入了一个概念并行编程。你可以制作使用它。它在内部管理多个线程。这里我给出了一些参考链接。看看它们并相应地改变。



1.) .NET中的并行编程

2.)使用任务并行库的异步MVC



谢谢

Sisir Patro
Hi,

In ASP.NET 4.0 one concept "Parallelprogramming is introduced. You can make use of that. It internally manages multiple threads. Here I have given some links for reference. Have a look into them and change accordingly.

1.) Parallel Programming in .NET
2.) Asynchronous MVC using the Task Parallel Library

Thanks
Sisir Patro


这篇关于并行执行多个操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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