#!/usr/bin/env python import sys from os.path import join,abspath,dirname path = join((abspath(dirname(__file__))), "..","..", "lib") sys.path.append(path) from thriftgen.pyload import Pyload from thriftgen.pyload.ttypes import * from thrift import Thrift from thrift.transport import TSocket from thrift.transport import TTransport from thrift.protocol import TBinaryProtocol from time import sleep, time import xmlrpclib def bench(f, *args, **kwargs): s = time() ret = [f(*args, **kwargs) for i in range(0,250)] e = time() try: print "%s: %f s" % (f._Method__name, e-s) except : print "%s: %f s" % (f.__name__, e-s) return ret server_url = "http%s://%s:%s@%s:%s/" % ( "", "user", "password", "127.0.0.1", 7227 ) proxy = xmlrpclib.ServerProxy(server_url, allow_none=True) bench(proxy.get_server_version) bench(proxy.status_server) bench(proxy.status_downloads) bench(proxy.get_queue) bench(proxy.get_collector) print try: # Make socket transport = TSocket.TSocket('localhost', 7228) # 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 = Pyload.Client(protocol) # Connect! transport.open() print "Login", client.login("User", "pyloadweb") bench(client.getServerVersion) bench(client.statusServer) bench(client.statusDownloads) bench(client.getQueue) bench(client.getCollector) print print client.getServerVersion() print client.statusServer() print client.statusDownloads() q = client.getQueue() for p in q: print client.getPackageData(p.pid) # Close! transport.close() except Thrift.TException, tx: print 'ThriftExpection: %s' % (tx.message)