File: fork_roundtrip.py

package info (click to toggle)
python-mitogen 0.3.39-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 6,732 kB
  • sloc: python: 24,733; sh: 198; makefile: 74; perl: 19; ansic: 18
file content (34 lines) | stat: -rw-r--r-- 877 bytes parent folder | download | duplicates (2)
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
"""
Measure latency of local RPC.
"""

import mitogen.core
import mitogen.utils
import ansible_mitogen.affinity

mitogen.utils.setup_gil()
ansible_mitogen.affinity.policy.assign_worker()


def do_nothing():
    pass

@mitogen.main()
def main(router):
    import optparse
    parser = optparse.OptionParser(description=__doc__)
    parser.add_option(
        '-i', '--iterations', type=int, metavar='N', default=20000,
        help='Number of iterations (default %default)')
    parser.add_option('--debug', action='store_true')
    opts, args = parser.parse_args()

    f = router.fork(debug=opts.debug)
    f.call(do_nothing)
    t0 = mitogen.core.now()
    for x in mitogen.core.range(opts.iterations):
        f.call(do_nothing)

    t1 = mitogen.core.now()
    mean = (t1 - t0) / opts.iterations
    print('++ iterations %d, mean %.03f us' % (opts.iterations, 1e6 * mean))