我正在运行一个简单的Thrift服务器(http://thrift.apache.org/),作为Python(服务器)和Haskell(客户机)之间的跨语言平台。唯一需要发送的数据结构是一个3元组的double,因此服务器/客户端的实现也非常简单-只需遵循教程就足够了。在
然而,它真的,真的很慢!每次服务器响应的响应时间大约为0.5s,而我需要的响应时间大约为0.1s或更低。在
有人对如何加快速度有什么想法吗?您可以在下面看到我的简单服务器实现:1 import sys
2
3 from vision import Vision
4 from vision.ttypes import *
5
6 from thrift.transport import TSocket
7 from thrift.transport import TTransport
8 from thrift.protocol import TBinaryProtocol
9 from thrift.protocol.TBinaryProtocol import TBinaryProtocolAccelerated
10 from thrift.server import TServer
11
12 class VisionHandler:
13 def observe(self):
14 ret = Position()
15 ret.x,ret.y,ret.z = (1,2,3)
16 return ret
17
18 ret = Position()
20 handler = VisionHandler()
21 processor = Vision.Processor(handler)
22 transport = TSocket.TServerSocket(port=9090)
23 tfactory = TTransport.TBufferedTransportFactory()
24 pfactory = TBinaryProtocol.TBinaryProtocolFactory()
25
26 server = TServer.TSimpleServer(processor, transport, tfactory, pfactory)
27
28 print 'Starting the vision server...'
29 server.serve()
30 print 'done.'
客户机只需通过运行
^{pr2}$
然后呢res
据我所知,这一切都很标准!为什么这么慢??在
谢谢!在