forked from ikegami-yukino/mprpc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark_zerorpc.py
48 lines (32 loc) · 868 Bytes
/
benchmark_zerorpc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# -*- coding: utf-8 -*-
from __future__ import print_function
import time
import multiprocessing
import sys
NUM_CALLS = 10000
def run_sum_server():
import zerorpc
class SumServer(object):
def sum(self, x, y):
return x + y
server = zerorpc.Server(SumServer())
server.bind("tcp://127.0.0.1:6000")
server.run()
def call():
import zerorpc
client = zerorpc.Client()
client.connect("tcp://127.0.0.1:6000")
start = time.time()
if sys.version_info < (3,):
range = xrange
else:
import builtins
range = builtins.range
[client.sum(1, 2) for _ in range(NUM_CALLS)]
print('call: %d qps' % (NUM_CALLS / (time.time() - start)))
if __name__ == '__main__':
p = multiprocessing.Process(target=run_sum_server)
p.start()
time.sleep(1)
call()
p.terminate()