File: ssh-roundtrip.py

package info (click to toggle)
python-mitogen 0.3.0~rc1-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 3,240 kB
  • sloc: python: 19,899; sh: 91; perl: 19; ansic: 18; makefile: 13
file content (36 lines) | stat: -rw-r--r-- 645 bytes parent folder | download
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
"""
Measure latency of SSH RPC.
"""

import sys
import time

import mitogen
import mitogen.core
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 = mitogen.core.now()
    end = mitogen.core.now() + 5.0
    i = 0
    while mitogen.core.now() < end:
        f.call(do_nothing)
        i += 1
        t1 = mitogen.core.now()

    print('++', float(1e3 * (t1 - t0) / (1.0+i)), 'ms')