2017-02-23 7 views
0

私はPyroを使って非常に単純なクライアント/サーバアプリケーションを実装しました。 Pyro tips&tricksはこれに対して助言していますが、サーバーを使用してクライアントに画像を送信しています(圧縮されていない配列が正確です)。ネットワークを経由する必要はなく、すべてがlocalhostにとどまっているので、問題はありません。何が起こるのは、クライアントがサーバーよりも1桁も遅いということです。その理由は何ですか?ここでパイロ通信は同じホストで極端に遅い

コード:

サーバー:

import numpy as np 
import time 
import Pyro.core 

class DataProd(Pyro.core.ObjBase): 
    def __init__(self, batch_size): 
     print 'Loading data into memory' 
     self.all_imgs = np.load('data.npy') 
     Pyro.core.ObjBase.__init__(self) 

    def get_batch(self, batch_size=32, flip=False): 

     print 'getting 1 batch from PYRO' 
     s = time.time() 
     #process the images 
     print time.time()-s 
     return images 


def main(): 
    Pyro.core.initServer() 
    daemon=Pyro.core.Daemon() 
    uri=daemon.connect(DataProd(32),'dataprod') 
    print "The daemon runs on port:",daemon.port 
    print "The object's uri is:",uri 
    print "Starting request loop" 
    daemon.requestLoop() 

if __name__ == '__main__': 
    main() 

とクライアント:

import Pyro.core 
import time 

data = Pyro.core.getProxyForURI("PYROLOC://localhost:7766/dataprod") 
while True: 
    s = time.time() 
    im = data.get_batch(32) 
    print time.time()-s 

サーバー版画:

getting 1 batch from PYRO 
0.526908874512 
getting 1 batch from PYRO 
0.51292014122 
getting 1 batch from PYRO 
0.523808956146 
getting 1 batch from PYRO 
0.536481142044 
getting 1 batch from PYRO 
0.518028974533 

とクライアント:

4.93717813492 
4.05996489525 
3.40680289268 
3.79327297211 
3.99453115463 

2つの間に1桁の大きさの違いがあるのはなぜですか?クライアントはイメージを要求する以外に何もしません。

ありがとう!

+0

サーバーコードにエラーがあります。 "画像"はget_batchで定義されていません –

+0

クライアントコードの処理と関係がないため、すべての処理コードを削除して読みやすくしているからです。 – powder

答えて

1

知覚された減速がクライアントのどこで正確に発生するかをプロファイルしましたか?

大規模なデータのデシリアライズが原因であると思われます。これをお読みくださいhttps://pythonhosted.org/Pyro4/tipstricks.html#pyro-and-numpy

+0

問題の解決方法を教えてください? –

関連する問題