缓慢的webservice问题

我在Linux机器(ubuntu)上创build一个Python webservice:

import soaplib import os from soaplib.core.service import rpc, DefinitionBase, soap from soaplib.core.model.primitive import String, Integer from soaplib.core.server import wsgi from soaplib.core.model.clazz import Array def runcmd(cmd): fout = os.popen(cmd) out = fout.read() return out class LinuxServices(DefinitionBase): @soap(String, String,_returns=Array(String)) def df(self,server, user): L = [] cmd = 'df -hP | grep "/"' output = runcmd(cmd).split('\n') for n in xrange(len(output)-1): out = output[n].split() L.append('%s;%s' % (out[5], out[4])) return L if __name__=='__main__': try: from wsgiref.simple_server import make_server soap_application = soaplib.core.Application([LinuxServices], 'tns') wsgi_application = wsgi.Application(soap_application) server = make_server('0.0.0.0', 7789, wsgi_application) server.serve_forever() except ImportError: print "Error: example server code requires Python >= 2.5" 

我基于这个例子创build它: soaplib helloworld

然后(在Windows 7上)我创build了一个Silverlight项目,我使用这个ws来获得我的linux服务器的磁盘状态:

Silverlight项目中的服务:

 public class LinuxService { [OperationContract] public List<dfItem> df() { List<dfItem> dfItems = new List<dfItem>(); WebReference.Application app = new WebReference.Application(); var result = app.df(new WebReference.df()/*...*/); foreach (var item in result.dfResult) { string[] info = item.Split(';'); dfItem dfItem = new dfItem() { MountPoint = info[0].ToString(), Usage = info[1].ToString() }; dfItems.Add(dfItem); } return dfItems; } //... } 

呼叫服务页面:

 protected override void OnNavigatedTo(NavigationEventArgs e) { LinuxServiceClient client = new LinuxServiceClient(); client.dfCompleted += new EventHandler<dfCompletedEventArgs>(client_dfCompleted); client.dfAsync(); } void client_dfCompleted(object sender, dfCompletedEventArgs e) { DG.ItemsSource = e.Result; DG.Visibility = System.Windows.Visibility.Visible; } 

我的问题是,当我导航到这个页面,需要4-8秒才能从ws(ws in LAN)获取数据。

我真的怀疑,线路带宽可以创造这个等待时间…

我的问题: 你有什么build议,我可以做些什么来加速这个?

系统信息:

  • UbuntuServer 11.04

  • Python:Python 2.7

  • Soaplib:soaplib 2.0.0-beta2


  • Windows:Windows 7 SP1

  • Silverlight:Silverlight 4

我建议使用wireshark http://www.wireshark.org/通过记录(“捕获”)设备可以看到的网络流量的副本来“侦听”通过网络发生的对话&#x3002;

当您开始捕获时,数据量看起来可能会非常大,但是如果您可以发现任何看起来像您的SOAP消息的碎片(应该很容易发现),那么您可以通过右键单击并选择'遵循TCP流'。

然后,您可以在弹出窗口中看到您编写的SOAP服务与Silverlight客户端之间的整个对话。

如果这一切看起来不错,然后关闭弹出窗口。 作为一个额外的好处,wireshark将已经筛选出的片段列表,只是在与时间戳的对话中他们发生的时间。 使用它来找出是否是客户端或服务器响应缓慢。

如果看起来没有真正的延迟,那么我会建议,要求Silverlight执行SOAP调用并实际进行网络调用之间存在相当大的延迟。

只是使用suds客户端和soaplib hello world示例的粗略基准:

 >>> def bench_soap(num): ...: start = time.time() ...: for i in range(num): ...: hello_client.service.say_hello("Dave", 5) ...: elapsed = time.time() - start ...: print "Completed %s: ops in %.2f seconds : %.1f ops/sec" % (num, elapsed, num / elapsed) ...: ...: >>> bench_soap(100) Completed 100: ops in 0.40 seconds : 247.5 ops/sec >>> bench_soap(1000) Completed 1000: ops in 3.81 seconds : 262.5 ops/sec 

我还没有看到任何“滞后”或类似的事情。 Soaplib,似乎快速和响应,所以也许是一个Silverlight的问题? 还是两者之间的某种不相容?