Setting limits for services


In general Docker services will consume resources and spawn containers as needed, but you may want to explicitly limit a particularly resource-hungry services, or to set minimum or maximum limits for the number of containers a service may use.

Limiting CPU and RAM usage

By default, Docker services will use as much CPU and memory as they require. You may wish to set a hard limit on memory, or the relative CPU shares used by a service.

This can be accomplished in Maestro by adding the constraints/resources directive to your service’s service.yml.

CPU limits

The default number of CPU shares given to a service is 1024. This is a relative number - if the service of container A has 1024 CPU shares, and the service of container B has 512 CPU shares, and both containers attempt to use 100% of the CPU, then container B will receive half of the total CPU time. This only applies when CPU-intensive tasks are running, as if one container is idle then the others can use the remaining CPU time.

RAM limits

The memory limit will apply to RAM usage and SWAP usage. A valid entry is a positive number, followed by one of, "K", "M", or "G", with the minimum being "4M". (You can also use the power-of-two equivalents like Gi, Mi, Ki if you prefer.)

For example:

                memory: "100M"
                cpu: 512

Limiting the number of containers

You can also limit the number of containers that a service may use. You can set both minimum and maximum limits for each service. For example:

            min_count: 2
            max_count: 7

This would ensure that the service would always have at least 2 containers, but that it would never have more than 7.

Removing existing constraints

If you have added constraints to your Maestro application in the past and now need to remove them, you will need to explicitly recreate your services (and the containers that embody them) via the Dashboard.

To recreate your services without constraints:

  1. Remove the constraints/resources directive from your configuration file(s) and ensure you’ve saved them.
  2. In the Cloud 66 Dashboard navigate to the application in question.
  3. Click on the name of the service in question under App Services
  4. Click the Recreate Service button to the right of the Containers list. This will recreate your containers and remove the constraints on that service.

Recreate service button