2015-11-11 21:29:53 +00:00
|
|
|
# Copied with minimal modifications from curio
|
|
|
|
# https://github.com/dabeaz/curio
|
|
|
|
|
|
|
|
from concurrent.futures import ProcessPoolExecutor
|
|
|
|
|
2015-11-26 19:37:17 +00:00
|
|
|
import argparse
|
2015-11-11 21:29:53 +00:00
|
|
|
from socket import *
|
|
|
|
import time
|
|
|
|
import sys
|
|
|
|
|
2015-11-26 19:37:17 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument('--msize', default=1000, type=int,
|
|
|
|
help='message size in bytes')
|
|
|
|
parser.add_argument('--num', default=200000, type=int,
|
|
|
|
help='number of messages')
|
|
|
|
parser.add_argument('--times', default=1, type=int,
|
|
|
|
help='number of times to run the test')
|
|
|
|
parser.add_argument('--workers', default=3, type=int,
|
|
|
|
help='number of workers')
|
2016-02-03 23:33:39 +00:00
|
|
|
parser.add_argument('--addr', default='127.0.0.1:25000', type=str,
|
|
|
|
help='number of workers')
|
2015-11-26 19:37:17 +00:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
2016-04-01 19:35:56 +00:00
|
|
|
unix = False
|
|
|
|
if args.addr.startswith('file:'):
|
|
|
|
unix = True
|
|
|
|
addr = args.addr[5:]
|
|
|
|
else:
|
|
|
|
addr = args.addr.split(':')
|
|
|
|
addr[1] = int(addr[1])
|
|
|
|
addr = tuple(addr)
|
2016-02-03 23:33:39 +00:00
|
|
|
print('will connect to: {}'.format(addr))
|
2015-11-26 19:37:17 +00:00
|
|
|
|
|
|
|
MSGSIZE = args.msize
|
|
|
|
|
|
|
|
msg = b'x'*MSGSIZE
|
|
|
|
|
|
|
|
def run_test(n):
|
|
|
|
print('Sending', NMESSAGES, 'messages')
|
2016-04-01 19:35:56 +00:00
|
|
|
if unix:
|
|
|
|
sock = socket(AF_UNIX, SOCK_STREAM)
|
|
|
|
else:
|
|
|
|
sock = socket(AF_INET, SOCK_STREAM)
|
2016-02-03 23:33:39 +00:00
|
|
|
sock.connect(addr)
|
2015-11-26 19:37:17 +00:00
|
|
|
while n > 0:
|
|
|
|
sock.sendall(msg)
|
|
|
|
nrecv = 0
|
|
|
|
while nrecv < MSGSIZE:
|
|
|
|
resp = sock.recv(MSGSIZE)
|
|
|
|
if not resp:
|
|
|
|
raise SystemExit()
|
|
|
|
nrecv += len(resp)
|
|
|
|
n -= 1
|
|
|
|
|
|
|
|
TIMES = args.times
|
|
|
|
N = args.workers
|
|
|
|
NMESSAGES = args.num
|
|
|
|
start = time.time()
|
|
|
|
for _ in range(TIMES):
|
|
|
|
with ProcessPoolExecutor(max_workers=N) as e:
|
|
|
|
for _ in range(N):
|
|
|
|
e.submit(run_test, NMESSAGES)
|
|
|
|
end = time.time()
|
|
|
|
duration = end-start
|
|
|
|
print(NMESSAGES*N*TIMES,'in', duration)
|
|
|
|
print(NMESSAGES*N*TIMES/duration, 'requests/sec')
|