并行 Foreach 网络服务调用 [英] Parallel Foreach webservice call

查看:36
本文介绍了并行 Foreach 网络服务调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们已经实现了需要处理传入批次的应用程序.例如,必须将特定对象类型的一组请求发送到特定的 Web 服务以进行处理

We have implemented application wherein we need to process incoming batch. for example a set of Request of certain object type has to be sent to particular webservice to have it processed

我们已经实现了以下代码片段来做到这一点.如果有任何陷阱,需要您的帮助/指导

We have implemented following snippet to do so. need your help / guidance if there wouldbe any pitfalls on same

var options = new ParallelOptions { MaxDegreeOfParallelism = 10 };

Parallel.ForEach(request, options, currentRequest =>
{
    ProcessedRequest processedRequest = null;
    try
    {
        currentRequest.DBSave = true;

        processedRequest = CommunicateToService(currentRequest);

    }
    catch (Exception ex)
    {

        ExceptionManager.HandleException(ex);
    }
});

在 CommunicateToservice 方法中,我们将调用服务并传递请求并获取响应对象并将大约 10 -15 个表保存到 MS SQL DB.整个方法用 AggregateException 包裹.

Inside CommunicateToservice method we will be calling the service and pass the request and get the response object and save to MS SQL DB around 10 -15 tables. The whole method is wrapped with AggregateException.

需要关于如何确定 MaxDegreeOfParallelism 值的输入.

Need inputs on How the MaxDegreeOfParallelism value can be decided.

推荐答案

对于 IO 绑定的工作,没有简单的指导方针.您不知道最佳吞吐量的要点是什么.测试不同的值并测量哪个值最快.

For IO-bound work there is no easy guideline. You don't know what the point of optimal throughput is. Test different values and measure which one is the fastest.

您可能不应该将 DOP 设置得太高,因为这可能会使远程服务过载.

You probably should not set the DOP too high because that might overload the remote service.

这篇关于并行 Foreach 网络服务调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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