Do we have any declarative way of limiting percentage of resources to use in a snap or in a snap app?. A friend of mine likes a feature in docker that allows him to limit the % of cpu used by a container. Is it worthwhile having a declarative way in snapcraft.yaml to have this feature (perhaps it might be implemented using cgroups…) ?
We do not have such a feature in the YAML. Once snapcraft starts building in containers by default it’s something we could conceivably have, but you can achieve the same results today by running snapcraft from within lxc, and using its resource control features.
I don’t think it would be appropriate for a developer or packager to define resources used on your system by her snap. I think if resource limitation is to be included in snapd then it should be controlled by the user of the snap not the builder of it.
To answer @rmescandon, this isn’t available in snapd today. I agree with @lucyllewy in terms of default operation because even with well-intentioned limits it is very difficult to setup something that is useful on every system since snaps can run on embedded all the way up to huge server systems.
Today snapd doesn’t do anything with resource control in the manner described, but it could (and yes, it would need to be done with cgroups). Perhaps it would be done via ‘snap run’ which should approximate what docker is doing. Perhaps it would be configurable via a new 'snap ’ or influenced by the gadget snap. AIUI, resource controls are planned in the longer term, but what it would look like and how it operates needs design.