| 1 |
""" |
| 2 |
Measure latency of SSH RPC. |
| 3 |
""" |
| 4 |
|
| 5 |
import getpass |
| 6 |
|
| 7 |
import mitogen.core |
| 8 |
import mitogen.utils |
| 9 |
import ansible_mitogen.affinity |
| 10 |
|
| 11 |
mitogen.utils.setup_gil() |
| 12 |
ansible_mitogen.affinity.policy.assign_worker() |
| 13 |
|
| 14 |
|
| 15 |
def do_nothing(): |
| 16 |
pass |
| 17 |
|
| 18 |
@mitogen.main() |
| 19 |
def main(router): |
| 20 |
import optparse |
| 21 |
parser = optparse.OptionParser(description=__doc__) |
| 22 |
parser.add_option( |
| 23 |
'-p', '--python', metavar='CMD', default='python3', |
| 24 |
help='Remote python path (default %default)') |
| 25 |
parser.add_option( |
| 26 |
'-u', '--user', metavar='S', default=getpass.getuser(), |
| 27 |
help='Remote username (default %default)') |
| 28 |
parser.add_option('--debug', action='store_true') |
| 29 |
opts, args = parser.parse_args() |
| 30 |
|
| 31 |
f = router.ssh( |
| 32 |
hostname=args[0], python_path=opts.python, username=opts.user, |
| 33 |
debug=opts.debug, |
| 34 |
) |
| 35 |
f.call(do_nothing) |
| 36 |
t0 = mitogen.core.now() |
| 37 |
end = mitogen.core.now() + 5.0 |
| 38 |
i = 0 |
| 39 |
while mitogen.core.now() < end: |
| 40 |
f.call(do_nothing) |
| 41 |
i += 1 |
| 42 |
|
| 43 |
t1 = mitogen.core.now() |
| 44 |
iterations = i + 1 |
| 45 |
mean = (t1 - t0) / iterations |
| 46 |
print('++ iterations %d, mean %.03f ms' % (iterations, 1e3 * mean)) |