Parallel Foreach webservice call

强颜欢笑 提交于 2019-12-24 19:29:59

问题


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);
    }
});

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.

Need inputs on How the MaxDegreeOfParallelism value can be decided.


回答1:


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.

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



来源:https://stackoverflow.com/questions/20192561/parallel-foreach-webservice-call

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!