Pyro를 사용하여 매우 간단한 클라이언트/서버 응용 프로그램을 구현했습니다. Pyro tips&tricks에서 이에 대한 조언을하는 동안 서버를 사용하여 클라이언트에 이미지를 보내고 있습니다 (정확한 압축되지 않은 배열). 네트워크를 통과 할 필요는 없으며 모든 것이 localhost에 있기 때문에 문제가 발생하지 않습니다. 클라이언트가 서버보다 1 배 더 느린 이유는 무엇입니까? 여기Pyro 통신이 동일한 호스트에서 매우 느립니다.
코드 :
서버 :
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
왜 둘 사이에 큰 차가 있습니까? 클라이언트는 이미지를 요청하는 것 외에는 아무것도하지 않습니다 ..
고마워요!
서버 코드에 오류가 있습니다. "이미지"는 get_batch에 정의되어 있지 않음 –
클라이언트 - 서버의 성능과 관련이 없기 때문에 모든 처리 코드를 제거하여 읽기 쉽도록 만들었 기 때문에 그 이유가 있습니다 – powder