Skip to content

Commit

Permalink
Update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
brmmm3 committed Dec 11, 2019
1 parent 757b4db commit 9ba9ad4
Show file tree
Hide file tree
Showing 4 changed files with 248 additions and 142 deletions.
65 changes: 65 additions & 0 deletions examples/benchmarks/bench_echo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@

import time
import argparse
import subprocess

import echoclient


class Args:
pass


if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('--disconnect', default=False, action='store_true',
help='disconnect after every message')
args = parser.parse_args()
clientArgs = Args()
clientArgs.mpr = 1
clientArgs.num = 20000
clientArgs.times = 1
clientArgs.workers = 5
clientArgs.addr = '127.0.0.1:25000'
clientArgs.disconnect = args.disconnect
results = []
for srvArgs in ("", "--streams", "--proto",
"--uvloop", "--uvloop --streams", "--uvloop --proto",
"--pool --bufsize 4096", "--pool --bufsize 8192",
"--pool --bufsize 16384", "--pool --bufsize 32768",
"--pool --bufsize 65536", "--pool --bufsize 131072",
"--pool --bufsize 262144"):
prc = subprocess.Popen(f"python3.7 echoserver.py {srvArgs}".split())
if "--uvloop" in srvArgs:
title = "uvloop/" + srvArgs.split(" --")[1]
bufSize = ""
elif "--pool" in srvArgs:
title = "threads"
bufSize = srvArgs.split("--bufsize ")[1]
else:
title = "asyncio/" + srvArgs.lstrip("-")
bufSize = ""
print("-------")
time.sleep(0.5)
try:
for msgSize in (1000, 4096, 16384, 65536):
clientArgs.msize = msgSize
if msgSize == 1000:
size = "1000 bytes"
elif msgSize == 4096:
size = "4kB"
elif msgSize == 16384:
size = "16kB"
else:
size = "64kB"
msgSpeed, mbSpeed = echoclient.main(clientArgs)
results.append((title, bufSize, size, msgSpeed, mbSpeed))
print()
except KeyboardInterrupt:
raise
except:
import traceback
traceback.print_exc()
finally:
prc.terminate()
print("\n".join([" | ".join(result) for result in results]))
Loading

0 comments on commit 9ba9ad4

Please sign in to comment.