可以做些什么来加速同步 WCF 调用? [英] What can be done to speed up synchronous WCF calls?

查看:50
本文介绍了可以做些什么来加速同步 WCF 调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对来自 Silverlight 应用程序内的同步 WCF 调用的性能测量表明,我可以在本地主机连接上进行 7 次调用/秒,这非常慢.这可以加快速度,还是正常?

My performance measurements of synchronous WCF calls from within a Silverlight application showed I can make 7 calls/s on a localhost connection, which is very slow. Can this be speeded up, or is this normal?

这是我的测试代码:

const UInt32 nrCalls = 100;
ICalculator calculator = new CalculatorClient(); // took over from the MSDN calculator example
for (double i = 0; i < nrCalls; ++i)
{
    var call = calculator.BeginSubtract(i + 1, 1, null, null);
    call.AsyncWaitHandle.WaitOne();
    double result = calculator.EndSubtract(call);
}

备注:

  • CPU 负载几乎为 0%.显然,WCF 模块正在等待某些东西.
  • 我在 Firefox 3.6 和 Internet Explorer 7 上对此进行了测试.
  • 我使用的是 Silverlight v3.0
  • 为了进行比较:我曾经用 C++ 编写过一个 IPC 库,类似的测试产生了 4000 次调用/秒.那是没有 HTTP 数据包包装器,但我不希望这会减慢速度.只是每秒 7 次调用是如此之慢.
  • CPU load is almost 0%. Apparently, the WCF module is waiting for something.
  • I tested this both on Firefox 3.6 and Internet Explorer 7.
  • I'm using Silverlight v3.0
  • For comparison: I've once written an IPC library in C++ and a similar test yielded some 4000 calls/s. That was without the HTTP packet wrapper, but I don't expect that to slow things down much. It's just that 7 calls/s is so incredibly slow.

更新:我已将客户端从 Silverlight 移植到 .NET,这解决了性能问题.在该测试中,同步调用以 140 次调用/秒(而不是 7 次调用/秒)进行,异步调用以 200 次调用/秒(而不是 16 次调用/秒)进行.显然,缓慢是 Silverlight 平台所固有的.我必须学会忍受它.

Update: I've ported the client side from Silverlight to .NET, and this solved the performance problem. In that test, synchronous calls are made at 140 calls/s (instead of 7 calls/s), and asynchronous calls at 200 calls/s (instead of 16 calls/s). Apparently, the slowness is inherent to the Silverlight platform. I'll have to learn to live with it.

推荐答案

不多.您遇到了进行 100 个 http 调用的问题,这需要时间.女士们不要每次都生成一个新客户端来破坏它......所以,对不起.

Not a lot. You run the problem of making 100 http calls, that just takes time. You arelady do not blow it by generating a new client every time.... so, sorry.

总的来说,这是一个不好的例子(或者:一个好的例子,展示了不好的做法).服务应该始终是粗粒度的,以避免调用开销.一般来说,服务应该在它所做的事情上有一些权重".

In general, this is a bad example (or: a good one showing bad practice). Services should always be coarse grained to avoid the call overhead. A service should have some "weight" in what it does, generally.

一个计算器可以接受一系列运算,例如,因此可以一次发送所有 100 个计算.

A calculator may accept an array of operations, so all 100 calculations can be sent at once, for example.

在设计自己的界面时请记住这一点.

Keep that in mind when when designing your own interfaces.

这篇关于可以做些什么来加速同步 WCF 调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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