-
Notifications
You must be signed in to change notification settings - Fork 0
/
client-benchmark.py
60 lines (41 loc) · 1.41 KB
/
client-benchmark.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
49
50
51
52
53
54
55
56
57
58
"""
Test the server
"""
import concurrent.futures
import sys, logging
import argparse
import multiprocessing
import time
from protocol import Client, CommandError
globalclient = Client()
class Process(multiprocessing.Process):
def __init__(self):
super(Process, self).__init__()
def run(self):
globalclient.set('foo', 'bar')
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO, format='%(asctime)s [%(levelname)s] %(message)s')
parser = argparse.ArgumentParser()
parser.add_argument("-t", help="commands to test")
parser.add_argument("-r", help="key space")
parser.add_argument("-n", help='repeat', default=50)
args = parser.parse_args()
p = Process()
p.start()
p.join()
logging.info("Start")
starttime = time.time()
logging.info("Start parallel threadpool executor:")
with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor:
f = [executor.submit(globalclient.set, f"foo{i}", "bar") for i in range(int(args.n))]
executor.shutdown(wait=True)
# logging.info("Start the old way in serial:")
# for i in range(int(args.n)):
# globalclient.set("foo", "bar") #2.3 for 10,000 set request.
globalclient.close()
endtime = time.time()
logging.info("Done!")
print(f"""======SET====
{args.n} requests completed in {endtime-starttime} seconds
50 parallel clients
""")