def ping(): transport = TSocket.TSocket('127.0.0.1', 9099) tranport = TTransport.TFramedTransport(transport) protocol = TBinaryProtocol.TBinaryProtocol(tranport) client = Echo.Client(protocol) tranport.open() client.ping() tranport.close() print("ping ...")
def echo(s): transport = TSocket.TSocket('127.0.0.1', 9090) tranport = TTransport.TFramedTransport(transport) protocol = TBinaryProtocol.TBinaryProtocol(tranport) client = Echo.Client(protocol) tranport.open() s = client.echo(s) tranport.close() return s
def create_client(): # Make socket transport = TSocket.TSocket('localhost', 9090) # Buffering is critical. Raw sockets are very slow transport = TTransport.TBufferedTransport(transport) # Wrap in a protocol protocol = TBinaryProtocol.TBinaryProtocol(transport) # Create a client to use the protocol encoder client = Echo.Client(protocol) return (client, transport)
import timeit import gevent if __name__ == '__main__': # Make socket transport = TSocket.TSocket('localhost', 9090) # Buffering is critical. Raw sockets are very slow transport = TTransport.TBufferedTransport(transport) # Wrap in a protocol protocol = TBinaryProtocol.TBinaryProtocol(transport) # Create a client to use the protocol encoder client = Echo.Client(protocol) def worker(): try: client.noop() except: print 'worker failed' # Connect! transport.open() for n in [1000, 10000, 100000]: client.reset() for _ in xrange(n): gevent.spawn(worker)