我創建的Linux機器上的一個Python web服務(Ubuntu的):慢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"
我創造了它在此基礎上例如:soaplib helloworld
然後(在Windows 7)我創建了一個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秒鐘就可以(在LAN WS)從WS數據。
我真懷疑線路帶寬可以創建此等待時間......
我的問題: 你有什麼建議,我能做些什麼來加速這個?
系統信息:
UbuntuServer 11.04
的Python:Python 2.7版
Soaplib:soaplib 2.0.0-β2
-
組
的Windows:Windows 7的SP1
的Silverlight:Silverlight 4的
如果您告訴我們您正在使用哪種Python和soaplib版本,這將有所幫助,因爲這是無效的2.7/0.8.1。編寫一個簡單的Python soap客戶端以查看它是否是導致延遲的Silverlight或Python也是有用的(我懷疑Silverlight(因爲我總是懷疑Silverlight))。 – msw 2011-06-02 10:45:17
添加了關於python的信息,...我將嘗試編寫一個簡單的Python肥皂客戶端.. – Wolfy 2011-06-02 11:03:41
我測試了ws,就像在helloworld示例中一樣...首先運行慢,然後快速運行...任何想法? – Wolfy 2011-06-02 11:10:59