我正在使用以下剧本调整ansible剧本的性能
---
# simplespeedtest.yml
- hosts: localhost
connection: local
gather_facts: false
tasks:
- command: echo 1
- command: echo 2
- command: echo 30
我使用tasts\U profile模块测试了playbook的运行时间和playbook中的每个任务,结果如下:
# time $ANSIBLE_HOME/bin/ansible-playbook -i hosts simplespeed_localhost.yml
PLAY [localhost] ********************************************************************************
TASK [command] ********************************************************************************
Thursday 11 January 2018 15:29:45 +0800 (0:00:00.091) 0:00:00.091 ******
changed: [localhost]
TASK [command] ********************************************************************************
Thursday 11 January 2018 15:29:45 +0800 (0:00:00.316) 0:00:00.407 ******
changed: [localhost]
TASK [command] ********************************************************************************
Thursday 11 January 2018 15:29:46 +0800 (0:00:00.205) 0:00:00.613 ******
changed: [localhost]
PLAY RECAP ********************************************************************************
localhost : ok=3 changed=3 unreachable=0 failed=0
Thursday 11 January 2018 15:29:46 +0800 (0:00:00.187) 0:00:00.800 ******
===============================================================================
command ---------------------------------- 0.32s
command ----------------------------------- 0.21s
command ----------------------------------- 0.19s
Playbook run took 0 days, 0 hours, 0 minutes, 0 seconds
real 0m1.894s
user 0m1.652s
sys 0m0.220s
执行任务的总时间是0.72s,但执行剧本的总时间是1.894s,这比任务的总时间要大,我想知道如何减少这个时间。通过运行以下命令:
time python -m cProfile -o test1.out -s time $ANSIBLE_HOME/bin/ansible-playbook -i hosts simplespeed_localhost.yml
我得到了python cprofile文件
ncalls tottime percall cumtime percall filename:lineno(function)
633 0.673 0.001 0.673 0.001 {time.sleep}
34730 0.072 0.000 0.076 0.000 /usr/local/lib/python2.7/dist-packages/yaml/reader.py:99(forward)
3597 0.069 0.000 0.213 0.000 /usr/local/lib/python2.7/dist-packages/yaml/scanner.py:1272(scan_plain)
63467 0.058 0.000 0.128 0.000 /usr/local/lib/python2.7/dist-packages/yaml/scanner.py:142(need_more_tokens)
38543 0.051 0.000 0.585 0.000 /usr/local/lib/python2.7/dist-packages/yaml/scanner.py:113(check_token)
66812 0.046 0.000 0.055 0.000 /usr/local/lib/python2.7/dist-packages/yaml/scanner.py:276(stale_possible_simple_keys)
153 0.042 0.000 0.093 0.001 /usr/lib/python2.7/ConfigParser.py:464(_read)
46 0.040 0.001 0.040 0.001 {compile}
162917 0.039 0.000 0.040 0.000 /usr/local/lib/python2.7/dist-packages/yaml/reader.py:87(peek)
22624 0.032 0.000 0.032 0.000 /usr/local/lib/python2.7/dist-packages/yaml/error.py:6(__init__)
4981 0.031 0.000 0.150 0.000 /usr/local/lib/python2.7/dist-packages/yaml/parser.py:273(parse_node)
967/207 0.030 0.000 0.089 0.000 /usr/lib/python2.7/sre_parse.py:379(_parse)
7649 0.028 0.000 0.428 0.000 /usr/local/lib/python2.7/dist-packages/yaml/scanner.py:153(fetch_more_tokens)
101 0.026 0.000 0.026 0.000 {method 'read' of 'file' objects}
22624 0.026 0.000 0.058 0.000 /usr/local/lib/python2.7/dist-packages/yaml/reader.py:114(get_mark)
100506 0.025 0.000 0.029 0.000 {isinstance}
{time.sleep}time的调用是0.673s,我想知道ansible的哪个进程将调用{time.sleep},以及如何减少它
ps:
我从中的ansible源代码中得到了3个位置调用{time.sleep}/lib/ansible/executor/task\u executor。py并更改arg,但似乎不起作用