Ejemplo n.º 1
0
 def test_async_rpc(self):
     s = simplerpc.Server()
     class LazyMath(MathService):
         def gcd(self, a, b):
             print "server zzz..."
             time.sleep(1)
             print "server wake up"
             while True:
                 r = a % b
                 if r == 0:
                     return b
                 else:
                     a = b
                     b = r
     s.reg_svc(LazyMath())
     s.start("0.0.0.0:8848")
     c = simplerpc.Client()
     c.connect("127.0.0.1:8848")
     mp = MathProxy(c)
     n_jobs = 10
     fu_all = []
     for i in range(n_jobs):
         print "client calling..."
         fu = mp.async_gcd(124, 84)
         fu_all += fu,
     for fu in fu_all:
         print "client waiting..."
         print "error code: %d" % fu.error_code
         print "client got result:", fu.result
Ejemplo n.º 2
0
 def test_mt_rpc(self):
     s = simplerpc.Server()
     class MyMath(MathService):
         def gcd(self, a, b):
             while True:
                 r = a % b
                 if r == 0:
                     return b
                 else:
                     a = b
                     b = r
     s.reg_svc(MyMath())
     s.start("0.0.0.0:8848")
     n_th = 10
     n_jobs = 200
     start = time.time()
     class MyThread(Thread):
         def run(self):
             c = simplerpc.Client()
             c.connect("127.0.0.1:8848")
             mp = MathProxy(c)
             for i in range(n_jobs):
                 mp.sync_gcd(124, 84)
     th = []
     for i in range(n_th):
         t = MyThread()
         t.start()
         th += t,
     for t in th:
         t.join()
     end = time.time()
     print "mt: qps = %.2lf" % (1.0 * n_th * n_jobs / (end - start))
Ejemplo n.º 3
0
 def test_timedwait(self):
     class BS(BenchmarkService):
         def sleep(self, sec):
             time.sleep(sec)
     s = simplerpc.Server()
     s.reg_svc(BS())
     s.start("0.0.0.0:8848")
     c = simplerpc.Client()
     c.connect("127.0.0.1:8848")
     bp = BenchmarkProxy(c)
     fu = bp.async_sleep(2.3)
     fu.wait(1.0)
     print "done"
Ejemplo n.º 4
0
    def test_service_gen(self):
        s = simplerpc.Server()
        class MyMath(MathService):
            def gcd(self, a, b):
                while True:
                    r = a % b
                    if r == 0:
                        return b
                    else:
                        a = b
                        b = r
        s.reg_svc(MyMath())
        s.start("0.0.0.0:8848")

        c = simplerpc.Client()
        c.connect("127.0.0.1:8848")

        # raw marshal handling
        print c.sync_call(MathService.GCD, [124, 84], ["rpc::i64", "rpc::i64"], ["rpc::i64"])

        mp = MathProxy(c)
        print mp.sync_gcd(124, 84)
        print "begin 10000 sync_gcd operation"
        start = time.time()
        for i in range(10000):
            mp.sync_gcd(124, 84)
        print "done 10000 sync_gcd operation"
        end = time.time()
        print "qps = %.2lf" % (10000.0 / (end - start))

        n_async = 40000
        print "begin 100000 async_gcd operation"
        start = time.time()
        fu_list = []
        for i in range(n_async):
            fu_list += mp.async_gcd(124, 84),
        print "now waiting..."
        for fu in fu_list:
            fu.wait()
        print "done 100000 async_gcd operation"
        end = time.time()
        print "qps = %.2lf" % (n_async * 1.0 / (end - start))

        c.close()
Ejemplo n.º 5
0
def main():
    argparser = argparse.ArgumentParser(prog=sys.argv[0])
    argparser.add_argument("-c",
                           dest="client_addr",
                           help="server address (ip:port)")
    argparser.add_argument("-s",
                           dest="server_addr",
                           help="client address (ip:port)")
    opt = argparser.parse_args(sys.argv[1:])
    if opt.client_addr:
        c = simplerpc.Client()
        c.connect(opt.client_addr)
        bp = BenchmarkProxy(c)
        counter = 0
        last_time = time.time()
        while True:
            now = time.time()
            if now - last_time > 1.0:
                print "qps=%d" % (counter / (now - last_time))
                last_time = now
                counter = 0
            bp.sync_nop("")
            counter += 1

    elif opt.server_addr:
        s = simplerpc.Server()

        class MyBenchmarkService(BenchmarkService):
            def nop(self, in0):
                pass

        s.reg_svc(MyBenchmarkService())

        s.start(opt.server_addr)
        while True:
            time.sleep(1)

    else:
        argparser.print_help()