Skip to content

Commit

Permalink
Problem: Execution test hanging. Python runtime slow
Browse files Browse the repository at this point in the history
It's a problem surfaced by another

The visible problem was that the new exection test were hanging, inside the runtime, during the import at the line
 from aleph.sdk.chains.remote import RemoteAccount

after some more investigative work, it was pin pointed to an inner import of eth_utils module (specifically eth_utils.network )

Second problem that made the first visible: in the runtime the pre-compiled bytecode, created during runtime creation in create_disk_image.sh was not used, which made the import of module slower. This surfaced the first problem. The cause of that second problem was that the init1.py code which run the user caude was not launched with the same optimization level as the pre-compiled bytecode and thus recompiled everything. (this is specified in the init1.py #! sheebang on the first line)

Solution: Compile the bytecode with the same optimisation level (-o 2 )
as during run

We haven't found out yet why the eth_utils.network import hang when it
is not precompiler. But this fix the test hanging issue
  • Loading branch information
olethanh committed Apr 10, 2024
1 parent 64af5a1 commit f0922f2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 5 additions & 2 deletions runtimes/aleph-debian-11-python/create_disk_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ pip3 install 'fastapi~=0.103.1'
echo "Pip installing aleph-client"
pip3 install 'aleph-sdk-python==0.7.0'
# Compile all Python bytecode
python3 -m compileall -f /usr/local/lib/python3.9
# Compile Python code to bytecode for faster execution
# -o2 is needed to compile with optimization level 2 which is what we launch init1.py (`python -OO`)
# otherwise they are not used
python3 -m compileall -o 2 -f /usr/local/lib/python3.9
echo "PubkeyAuthentication yes" >> /etc/ssh/sshd_config
echo "PasswordAuthentication no" >> /etc/ssh/sshd_config
Expand Down
6 changes: 4 additions & 2 deletions runtimes/aleph-debian-12-python/create_disk_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ mkdir -p /opt/aleph/libs
pip3 install --target /opt/aleph/libs 'aleph-sdk-python==0.9.0' 'fastapi~=0.109.2'
# Compile Python code to bytecode for faster execution
python3 -m compileall -f /usr/local/lib/python3.11
python3 -m compileall -f /opt/aleph/libs
# -o2 is needed to compile with optimization level 2 which is what we launch init1.py (`python -OO`)
# otherwise they are not used
python3 -m compileall -o 2 -f /usr/local/lib/python3.11
python3 -m compileall -o 2 -f /opt/aleph/libs
echo "PubkeyAuthentication yes" >> /etc/ssh/sshd_config
echo "PasswordAuthentication no" >> /etc/ssh/sshd_config
Expand Down

0 comments on commit f0922f2

Please sign in to comment.