并行调用服务方法 [英] Parallel Invocation of service methods

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

问题描述

我已经制作了一个消耗第三方服务方法的wcf服务方法(调用方法A,方法B,方法C),这里所有三个属于不同的服务,即serviceA,serviceB,serviceC ..



每个方法接受单个输入对象进行处理(不是输入对象列表)。但我必须处理多个对象,所以我在for循环中使用这个方法..



现在问题是,假设我有3个对象要使用methodA进行处理,2个要使用methodB进行处理的对象和5个使用methodC进行处理的对象...并考虑每个方法需要1秒来处理,然后处理所有时间所需的总时间几乎是10秒..在谷歌搜索后克服这个问题我有线程和并行LINQ。当然我对线程及其性能知之甚少,我选择远离。现在使用并行linq我发现性能提升..但仍然没有满足期望(有时它的抛出超时异常)..所以请建议我现在应该尝试什么...是否潜入线程或其他任何尝试?

解决方案

请参阅我对该问题的评论。最基本的理解是:没有奇迹这样的东西。使用线程,如果您的CPU核心数量少于请求对象的总平均数量,则吞吐量不会增加。为了进一步提高吞吐量,使用具有负载平衡服务器场。请参阅:

https://en.wikipedia.org/wiki/Server_farm [< a href =https://en.wikipedia.org/wiki/Server_farmtarget =_ blanktitle =New Window> ^ ],

https://en.wikipedia.org/wiki/Load_balancing_(computing) [ ^ ]。



- SA

i have made one wcf service Method which is consuming third party service methods(call methodA, methodB, methodC) and Here all three belongs to different services i.e. serviceA, serviceB, serviceC..

each method accepting single input object for processing (not List of input object). but i have to work on multiple objects, so i am consuming this methods in for loop..

now the problem is, suppose i have 3 objects to process with methodA, 2 objects to process with methodB and 5 objects to process with methodC.. and consider each method taking 1 sec to process then total time taken to process all is almost 10 seconds.. to overcome this problem after googling i got options like threading and parallel-linq. of course i don't have enough knowledge about threading and its performance, i choose to stay away. Now with parallel linq i found performance is up.. but still expectations are not satisfied(and sometime its throwing timeout exception).. so please advice what should i try now.. whether to dive in threading or anything other to try?

解决方案

Please see my comment to the question. The most basic thing to understand is: there is no such thing as miracle. With threading, if a number of your CPU cores is less then total average number of, say, requested objects, your throughput won't grow. For further improvement of the throughput, something like a server farm with load balancing is used. Please see:
https://en.wikipedia.org/wiki/Server_farm[^],
https://en.wikipedia.org/wiki/Load_balancing_(computing)[^].

—SA


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

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