使用Parallel.ForEach当远程系统prevent过载() [英] Prevent overload on remote system when using Parallel.ForEach()

查看:179
本文介绍了使用Parallel.ForEach当远程系统prevent过载()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们已经建立了这个应用程序,需要有一定的计算,一台远程机器(实际上是一个MATLAB服务器)上进行。我们使用Web服务连接到MATLAB的服务器,并执行计算。

We've built this app that needs to have some calculations done on a remote machine (actually a MatLab server). We're using web services to connect to the MatLab server and perform the calculations.

为了加快速度,我们已经使用Parallel.ForEach(),以便有多个服务调用会在同一时间。如果我们是非常保守的设置最大DOP @ 4什么的,一切工作正常,良好。 但是,如果我们让框架决定对DOP它会催生它强制远程机器上它的膝盖和超时这么多线程开始发生(> 10分钟)。

In order to speed things up, we've used Parallel.ForEach() in order to have multiple service calls going at the same time. If we're very conservative in setting max DOP @ 4 or something, everything works fine and well. However, if we let the framework decide on the DOP it will spawn so many threads that it force the remote machine on its knees and timeouts start occurring ( > 10 minutes ).

我们怎样才能解决这个问题呢?我很想能够做的是使用的响应时间扼杀了电话。如果响应时间小于30秒,不断增加的线程,只要它是在30秒内,使用较少。有什么建议?

How can we solve this issue? What I would LOVE to be able to do is use the response time to throttle the calls. If response time is less than 30 sec, keep adding threads, as soon as it's over 30 sec, use less. Any suggestions?

N.B。相关于这个问题的回应: http://stackoverflow.com/a/20192692/896697

N.B. Related to the response in this question: http://stackoverflow.com/a/20192692/896697

推荐答案

简单的方法是调整的并发请求,硬code,最好的号码,你这样做,到目前为止,但也有一些更好的选择如果你愿意花心思。

Simplest way would be to tune for the best number of concurrent requests and hardcode that as you have done so far, however there are some nicer options if you are willing to put in some effort.

您可以从Parallel.ForEach移动href="http://msdn.microsoft.com/en-us/library/3dasc8as.aspx" rel="nofollow">使用一个线程池。这样的东西是从远程服务器返回的您可以手动或以编程方式调整可用线程的数量。减少/增加可用线程的数量事情慢下来/加速,或者即使需要杀死他们。

You could move from a Parallel.ForEach to using a thread pool. That way as things come back from the remote server you can either manually or programatically tune the number of available threads. reducing/increasing the number of available threads as things slow down/speed up, or even kill them if needed.

您也可以做到上面的使用任务这是在做并行/异步的东西,在.NET中的新方式。

You could also do a variant of the above using Tasks which are the newer way of doing parallel/async stuff in .net.

另一种选择是用一个定时器和/或工作模式,计划作业每隔x毫秒,然后可以节流/放松的结果从服务器返回。最简单的方法就可以开始将使用Quartz.Net

Another option would be to use a timers and/or jobs model to schedule jobs every x milliseconds, which could then be throttled/relaxed as results returned from the server. The easiest way to get started would be using Quartz.Net.

这篇关于使用Parallel.ForEach当远程系统prevent过载()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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