WebService请求被间歇性地停止,异步模式 [英] WebService request are stucked Intermitantly, async mode

查看:384
本文介绍了WebService请求被间歇性地停止,异步模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我们有一个Web服务客户端,它并行运行多个Web服务请求,默认连接限制(ServicePointManager.DefaultConnectionLimit)为10。

We have a web service client, that run the multiple web service requests in parallel, with default connection limit(ServicePointManager.DefaultConnectionLimit) which is 10.


由于在请求模式中停留的100多个请求中的随机一个或两个请求,间歇性操作无法完全成功。对于有问题的请求,在Fiddler的会话中也没有显示响应头代码或超时消息。

Intermittently the actions aren't able to completely success due to random one or two requests out of 100+ requests made stucked in requesting mode. For those request with problem also showing no response header code nor timeout message in Fiddler's session.


我们将DefaultConnectionLimit设置为1以进行故障排除,上面的情况则从未发生过。

We set the DefaultConnectionLimit to 1 for troubleshooting, above situation then never occurred.


我们的项目使用.NET Framework 4.5.2,Task.StartNew()方法来评估上述请求。通常大多数请求都能在10秒内响应,除了添加估计超时并处理它之外还有更好的方法吗?我的第二个问题是
为什么上述请求会在异步模式下间歇性地随机停留?

Our project is using .NET Framework 4.5.2, Task.StartNew() method to evaluate above requests. Generally most of the request are able to response within 10 sec, is there any better way beside adding the estimated timeout and handle it? My second question is why above request will stucked intermittently and randomly in async mode?


谢谢,

推荐答案

网络请求可能因任何原因而停顿,包括远程服务器锁定或用完连接。根据您的故障排除方案,我打赌远程服务器在处理同步请求时遇到问题。你应该联系
的实现者来获得帮助。 

Network requests can stall for any # of reasons including the remote server locks or runs out of connections. Based upon your troubleshooting scenario I'd wager the remote server is having issues with handling simultaneous requests. You should contact the implementor to get help with this. 

由于连接限制,你真的不想尝试一次启动100多个请求。您最终会在处理请求之前将请求超时。我建议您批量发送请求。例如,您可以使用

LimitedConcurrencyLevelTask​​Scheduler
将请求数限制为10,然后发送请求并等待它们全部完成。这将允许请求分批发生,并可能有助于防止您看到的问题。这个
方法的好处是你可以继续使用标准for循环,因为调度程序只会阻止添加请求,直到有空间。因此,您的代码以您希望的方式读取和工作,但调度程序仍将限制请求计数。

You don't really want to try to fire up 100+ requests at once because of the connection limit. You'll end up timing out requests potentially before they can get handled. I'd recommend that you batch send requests. You can, for example, use the LimitedConcurrencyLevelTaskScheduler to limit the # of requests to, say 10, then send your requests and wait for them to all complete. This will allow the requests to occur in batches and may help prevent the issue you're seeing. The nice thing about this approach is that you can continue to use a standard for loop because the scheduler will simply block the add request until there is room. Hence your code reads and works the way you want but the scheduler will still throttle the request count.

请注意,如果请求成功发送,那么如果请求过多则应该超时很长时间跑。如果您尚未处理此错误,则需要处理此错误。

Note that if the request is successfully sent then you should be getting a timeout if it takes too long to run. You need to be handling this error if you're not already.


这篇关于WebService请求被间歇性地停止,异步模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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