开发者

Slow webservice problem

I create a Python webservice on Linux machine (ubuntu):

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"

I created it based on this example: soaplib helloworld

Then (on Windows 7) I created a Silverlight project, where I use this ws to get disk status on my linux server:

Service in Silverlight project:

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;
    }
    //...
}

Calling service on page:

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

My problem is that when I navigate to this page, it takes 4-8 seconds to get data from ws (ws in LAN).

I really doubt that line bandwidth can create this wait time...

My question: Do you have any suggestions what can I do to speed up this?

System Info:

  • UbuntuServer 11.04

  • Python: Python 2.7

  • Soaplib: soaplib 2.0.0-beta2


  • Windows: Windows 7 sp1

  • Silverlight: Silverlight 4


I'd recommend using wireshark http://www.wireshark.org/ to 'listen' in on the conversation that is occurring over the network by recording ('capturing') copies of the network traffic that the device can see.

When you start a capture, the amount of data can seem overwhelming, but if you can spot any fragments that look like your SOAP message (should be easy to spot), then you can swiftly filter to just that conversation by right-clicking and selecting 'Follow TCP Stream'.

You can then see the entire conversation between the SOAP service you've written and the silverlight client in a pop-up window.

If that all looks fine, then close the popup window. As an added bonus, wireshark will have filtered out the list of fragments to just those in the conversation with timestamps as to when they happened. Use this to find out whether it's client or server that is being slow to respond.

If there appears to be no real delay, then I would suggest that there is a considerable lag between asking Silverlight to do a SOAP call and it actually making the network call.


Just a cursory benchmark using the suds client and the soaplib hello world example:

>>> 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

I've not seen any "lag" or anything like that on my end. Soaplib, seems fast and responsive, so perhaps a Silverlight issue? Or some sort of incompatibility between the two?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜