| 1 |
""" |
| 2 |
Measure latency of local RPC. |
| 3 |
""" |
| 4 |
|
| 5 |
import mitogen.core |
| 6 |
import mitogen.utils |
| 7 |
import ansible_mitogen.affinity |
| 8 |
|
| 9 |
mitogen.utils.setup_gil() |
| 10 |
ansible_mitogen.affinity.policy.assign_worker() |
| 11 |
|
| 12 |
|
| 13 |
def do_nothing(): |
| 14 |
pass |
| 15 |
|
| 16 |
@mitogen.main() |
| 17 |
def main(router): |
| 18 |
import optparse |
| 19 |
parser = optparse.OptionParser(description=__doc__) |
| 20 |
parser.add_option( |
| 21 |
'-i', '--iterations', type=int, metavar='N', default=20000, |
| 22 |
help='Number of iterations (default %default)') |
| 23 |
parser.add_option('--debug', action='store_true') |
| 24 |
opts, args = parser.parse_args() |
| 25 |
|
| 26 |
f = router.fork(debug=opts.debug) |
| 27 |
f.call(do_nothing) |
| 28 |
t0 = mitogen.core.now() |
| 29 |
for x in mitogen.core.range(opts.iterations): |
| 30 |
f.call(do_nothing) |
| 31 |
|
| 32 |
t1 = mitogen.core.now() |
| 33 |
mean = (t1 - t0) / opts.iterations |
| 34 |
print('++ iterations %d, mean %.03f us' % (opts.iterations, 1e6 * mean)) |