Snap performance and troubleshooting issues

Hi,

I have filed a bug against snapd but it seems it would be more appropriate to discuss the problem here, first.

I have built a new snap (bsrally) based on another one (fcbtest). Both snaps are slow in their execution, compared to the same software (rally + rally-openstack plugin + tempest verifier) running on a virtual env.

nagiososc@juju-b6ff74-29:~$ time bsrally.rally --config-file /home/nagiososc/rally.conf verify list-verifiers
+--------------------------------------+-----------------+---------+-----------+---------------------+---------------------+-----------+-------------+-------------+--------+
| UUID | Name | Type | Platform | Created at | Updated at | Status | Version | System-wide | Active |
+--------------------------------------+-----------------+---------+-----------+---------------------+---------------------+-----------+-------------+-------------+--------+
| 045ffc5e-e915-4f13-a30c-2ca43745ae81 | tempestverifier | tempest | openstack | 2019-09-18T14:41:51 | 2019-09-18T14:41:55 | installed | tags/21.0.0 | True | :-) |
+--------------------------------------+-----------------+---------+-----------+---------------------+---------------------+-----------+-------------+-------------+--------+

real 0m20.989s
user 0m8.801s
sys 0m0.843s

The difference with the virtual environment (no snap) is:

(rally) nagiososc@juju-b6ff74-23:~$ time rally verify list-verifiers
+--------------------------------------+-----------------+---------+-----------+---------------------+---------------------+-----------+---------+-------------+--------+
| UUID | Name | Type | Platform | Created at | Updated at | Status | Version | System-wide | Active |
+--------------------------------------+-----------------+---------+-----------+---------------------+---------------------+-----------+---------+-------------+--------+
| 47cbeeb6-e1e5-4e35-bf34-b8aa883ebadc | tempestverifier | tempest | openstack | 2019-09-17T14:35:46 | 2019-09-17T14:36:22 | installed | 21.0.0 | False | :-) |
+--------------------------------------+-----------------+---------+-----------+---------------------+---------------------+-----------+---------+-------------+--------+

real 0m4.781s
user 0m3.599s
sys 0m0.628s

On the other hand, I’ve been suggested to use snap run --trace-exec or snap run --strace=--raw, but they both fail due to permission issues (snap runs on a privileges and nested lxd container, with apparmor enforced).

What could I do to track the reason behind such slowness in execution?

Thank you.

Snippet from snap run:

$ sudo snap run --strace=--raw bsrally.rally --config-file /home/nagiososc/rally.conf verify list-verifiers
execve("/snap/snapd/4605/usr/lib/snapd/snap-confine", ["/snap/snapd/4605/usr/lib/snapd/s"..., "--base", "core18", "snap.bsrally.rally", "/usr/lib/snapd/snap-exec", "bsrally.rally", "--config-file", "/home/nagiososc/rally.conf", "verify", "list-verifiers"], 0x7ffff897ce00 /* 38 vars */) = -1 EACCES (Permission denied)
fstat(2, {st_mode=S_IFIFO|0600, st_size=0, ...}) = 0
write(2, "/usr/bin/strace: exec: Permissio"..., 41/usr/bin/strace: exec: Permission denied
) = 41
getpid() = 2574
exit_group(1) = ?
+++ exited with 1 +++
error: exit status 1

Given that this appears to be a Python project, one difference is the presence of bytecode for your Python modules (i.e. .pyc files). They would be generated on first run for the non-snapped version of the application, but can’t be written for the snapped version as it is distributed as a read-only file system.

One thing to investigate would be to compile and include the bytecode as part of the snap build process. This could be done with an appropriate invocation of python3 -m compileall in an override-build section from your snapcraft.yaml.

There may be further differences that explain the perf difference, but this would be a good place to start.

2 Likes