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
This commit is contained in:
Sam Betts 2016-05-05 19:25:57 +01:00
parent 7274e2ee81
commit f58f7b9a07
3 changed files with 13 additions and 0 deletions

View File

@ -17,5 +17,9 @@ if ! type "ironic-python-agent" > /dev/null ; then
python /tmp/get-pip.py --no-wheel --no-index --find-links=file:///tmp/wheelhouse ironic_python_agent
fi
export PYTHONOPTIMIZE=1
# Run IPA
echo "Starting Ironic Python Agent:"
date
ironic-python-agent

View File

@ -87,6 +87,14 @@ sudo cp "$WORKDIR/build_files/bootlocal.sh" "$FINALDIR/opt/."
# Disable ZSwap
sudo sed -i '/# Main/a NOZSWAP=1' "$FINALDIR/etc/init.d/tc-config"
# sudo cp $WORKDIR/build_files/tc-config $FINALDIR/etc/init.d/tc-config
# Precompile all python
set +e
$CHROOT_CMD /bin/bash -c "python -OO -m compileall /usr/local/lib/python2.7"
set -e
find $FINALDIR/usr/local/lib/python2.7 -name "*.py" -not -path "*ironic_python_agent/api/config.py" | sudo xargs rm
find $FINALDIR/usr/local/lib/python2.7 -name "*.pyc" | sudo xargs rm
# Allow an extension to be added to the generated files by specifying
# $BRANCH_PATH e.g. export BRANCH_PATH=master results in tinyipa-master.gz etc

View File

@ -34,6 +34,7 @@ def get_pecan_config():
:returns: pecan configuration object.
"""
filename = config.__file__.replace('.pyc', '.py')
filename = filename.replace('.pyo', '.py')
return pecan.configuration.conf_from_file(filename)