How to Limit Resources an LXD Container Can Use –

In the previous article, you will learn about LXD concepts and how to get started in case you are not familiar with the platform.

In most cases, using multiple containers on the same machine will make the smaller whole component smaller. We recommend that you limit the amount of resources that each component can use. But why? LXD container limits might be useful

If you provide a service and provide an LXD instance to each customer

The number of scenarios that can increase the number of containers is infinite. For example, this could be a large server and host each customer Web site in a separate container. Sudden traffic on your website may slow down other instances. If there is a limit, only one container will slow down and the rest will work normally.
  • Other service plans can be easily sold in similar scenarios. One customer can pay X amount of resources and the other customer can pay Y amount. And this task can be easily adjusted by using a few simple commands.
  • You can protect yourself from simple DoS (Denial of Service) attacks. When a container is bombarded, the resource usage limit is reached. Other containers are not affected.
  • There are two containers with 100% available CPU time each. However, you want to complete one task faster than others. For example, you can render your video to a project that needs tomorrow. You can allocate 90% of CPU time for the first time and 10% for the second time.
  • Of course there may be a reason. And even if you use only one container on the whole system, you may not need this container. However, if you use multiple containers, you should set almost all kinds of restrictions. An attack, bug, or other form of malfunction on one LXD instance can affect the entire system and slow down. The more containers you have, the higher the likelihood of such scenarios.

    How to set resource limits on LXD containers

    ZFS must be installed for resource control related to disk operations. If you follow the tutorial here, you are already installed. If not, follow the instructions in the tutorial to install the ZFS utility and run the command again. Selecting ZFS to Ask for Storage Backend to Use

    Memory Usage Limit

    In the following command, replace "container_name" with the actual name of the container.

    If you want to use gigabytes instead of megabytes, enter "GB" instead of "MB".

    19659011] To limit the number of CPU cores the container can use, type:

    Use the following to "pin" to a specific CPU core:

    If you do this, use only the first CPU in the container. To use the second, type 1-1.

    Another type of restriction is the amount of CPU time a container can use. 100ms

    Because this means that the container can only use 10 milliseconds out of 100 milliseconds, so the CPU core of one CPU core 10% is used.

    Disk Usage Limits

    To limit disk-related resources, you must first add the root disk device to the container. It already exists by default in the default LXD profile.

    If you specify a different name for the pool, Replace with the name of the pool.

    To limit the amount of disk space an LXD instance can use, enter:

    Finally, network entry (download) is the last step in network entry. And / or sending (uploading).

    1Mbit is 1 megabit (not megabytes). One byte contains 8 bits, and download is limited to approximately 1/8 = 0.125 Mbits / second, approximately 120 kilobytes. Therefore, to download with 1MB / s (megabytes), multiply by 8 and set the input limit to 8Mbit.

    For egress:


    This includes the most commonly used properties related to resource limits. However, there are many variables that can be set using the lxc config device set and lxc config set . You can read more about these adjustable container properties in the GitHub page of LXD.

    Is this article useful?

    Please Note: This content is provided and hosted by a 3rd party server. Sometimes these servers may include advertisements. does not host or upload this material and is not responsible for the content.

    About The Author