how to limit resource usage per LXD container

  • verifying current resource usage
lxc info $cname

  • disk limit
lxc config device set $cname root size 20GB
lxc config device $cname root 30MB
lxc config device $cname root limits.write 10MB
lxc config device $cname root 20Iops
lxc config device $cname root 10Iops
lxc config set $cname limits.disk.priority 10 # raise the priority to a maximum

you’d better use zfs or btrfs (i.e. those are also useful for RAID setup). Linux doesn’t have path-based quotas, instead most filesystems only have user and group quotas which are of little use to containers. This means that right now LXD only supports disk limits if you’re using the ZFS or btrfs storage backend.

  • CPU limit
lxc config set $cname limits.cpu 2
lxc config set $cname limits.cpu 1,3
lxc config set $cname limits.cpu 0-3,7-11
lxc profile set default limits.cpu 3
lxc profile set $pname limits.cpu 2-4
lxc config set $cname limits.cpu.allowance 10%
lxc config set $cname limits.cpu.allowance 25ms/200ms
lxc config set $cname limits.cpu.priority 0 # reduce the priority to a minimum

swap limit of LXD container
On Ubuntu 16.04, everything is enabled by default with the exception of swap memory accounting which requires you pass the “swapaccount=1” kernel boot parameter.

  • memory limit
lxc config set $cname limits.memory 256MB
lxc config set $cname limits.memory 2GB
lxc config set $cname limits.memory.swap false
lxc config set $cname limits.memory.swap.priority 0
lxc config set $cname limits.memory.enforce soft

  • network I/O limit
lxc profile device set default eth0 limits.ingress 100Mbit
lxc profile device set default eth0 limits.egress 100Mbit
lxc config set $cname 5


Leave a Reply

Your email address will not be published. Required fields are marked *