-
Notifications
You must be signed in to change notification settings - Fork 5
/
bench.py
54 lines (45 loc) · 1.24 KB
/
bench.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
#! /bin/env python
import time
from threading import Thread
from gevent.pool import Pool
import gevent.monkey
gevent.monkey.patch_all()
import cubi.proxy as proxy
import cubi.logger as logger
request_time = 15
concurrent_num = 1024
def basic_test(endpoint, i):
prx = proxy.Proxy(endpoint)
for _ in range(request_time):
try:
data = {'msg': time.time()}
r = prx.request('echo', data)
except Exception:
import traceback
print traceback.format_exc()
def stress_test(endp):
if True:
pool = Pool(128)
for i in range(concurrent_num):
pool.spawn(basic_test, endp, i)
else:
threads = []
for i in range(concurrent_num):
t = Thread(target=basic_test, args=(endp, i))
t.start()
threads.append(t)
for t in threads:
t.join()
def start_test(endp):
print 'start test for', endp
basic_test(endp, 0)
print 'basic test ok'
t1 = time.time();
stress_test(endp)
print concurrent_num * request_time / (time.time() - t1)
print 'stress test ok'
if __name__ == '__main__':
# logger.enable_debug_log()
endp = "echo@tcp::2014"
# basic_test(endp, 1)
start_test(endp)