Skip to content

Commit f58f7b9

Browse files
committed
TinyIPA: Precompile python code for faster load
This patch adds code into the tinyipa build process and IPA itself to allow the required python code to be PYTHONOPTIMIZE precompiled into pyo files, this speeds up IPA startup time in a nested virt by 50%. Change-Id: Ib60c420719ea52a602c1752b572d3b217c2cefc7
1 parent 7274e2e commit f58f7b9

3 files changed

Lines changed: 13 additions & 0 deletions

File tree

imagebuild/tinyipa/build_files/bootlocal.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,9 @@ if ! type "ironic-python-agent" > /dev/null ; then
1717
python /tmp/get-pip.py --no-wheel --no-index --find-links=file:///tmp/wheelhouse ironic_python_agent
1818
fi
1919

20+
export PYTHONOPTIMIZE=1
21+
2022
# Run IPA
23+
echo "Starting Ironic Python Agent:"
24+
date
2125
ironic-python-agent

imagebuild/tinyipa/finalise-tinyipa.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@ sudo cp "$WORKDIR/build_files/bootlocal.sh" "$FINALDIR/opt/."
8787

8888
# Disable ZSwap
8989
sudo sed -i '/# Main/a NOZSWAP=1' "$FINALDIR/etc/init.d/tc-config"
90+
# sudo cp $WORKDIR/build_files/tc-config $FINALDIR/etc/init.d/tc-config
91+
92+
# Precompile all python
93+
set +e
94+
$CHROOT_CMD /bin/bash -c "python -OO -m compileall /usr/local/lib/python2.7"
95+
set -e
96+
find $FINALDIR/usr/local/lib/python2.7 -name "*.py" -not -path "*ironic_python_agent/api/config.py" | sudo xargs rm
97+
find $FINALDIR/usr/local/lib/python2.7 -name "*.pyc" | sudo xargs rm
9098

9199
# Allow an extension to be added to the generated files by specifying
92100
# $BRANCH_PATH e.g. export BRANCH_PATH=master results in tinyipa-master.gz etc

ironic_python_agent/api/app.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def get_pecan_config():
3434
:returns: pecan configuration object.
3535
"""
3636
filename = config.__file__.replace('.pyc', '.py')
37+
filename = filename.replace('.pyo', '.py')
3738
return pecan.configuration.conf_from_file(filename)
3839

3940

0 commit comments

Comments
 (0)