From 12569ad70a9f97a99bfd5ec81153f3cb122ea6a9 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Sun, 10 Mar 2019 21:26:32 +0000 Subject: [PATCH] tests/bench: import ssh-roundtrip.py. --- tests/bench/ssh-roundtrip.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/bench/ssh-roundtrip.py diff --git a/tests/bench/ssh-roundtrip.py b/tests/bench/ssh-roundtrip.py new file mode 100644 index 00000000..8745505d --- /dev/null +++ b/tests/bench/ssh-roundtrip.py @@ -0,0 +1,35 @@ +""" +Measure latency of SSH RPC. +""" + +import sys +import time + +import mitogen +import mitogen.utils +import ansible_mitogen.affinity + +mitogen.utils.setup_gil() +ansible_mitogen.affinity.policy.assign_worker() + +try: + xrange +except NameError: + xrange = range + +def do_nothing(): + pass + +@mitogen.main() +def main(router): + f = router.ssh(hostname=sys.argv[1]) + f.call(do_nothing) + t0 = time.time() + end = time.time() + 5.0 + i = 0 + while time.time() < end: + f.call(do_nothing) + i += 1 + t1 = time.time() + + print('++', float(1e3 * (t1 - t0) / (1.0+i)), 'ms')