Interface parameters

In swarm clusters, a single CPU core is equivalent to 100 CPUs. The unit of memory is MB.

Orchestration templates

In orchestration templates, you can use the cpu_shares and mem_limit labels to set CPU limit and memory limit.

CPU limit

A single CPU core is equivalent to 100 CPUs. If your machine is configured with 4 cores, the total number of available CPU resources is 400. In orchestration templates, you can use the cpu_shares label to specify CPU limit. cpu_shares: 50 indicates 0.5 core.

Memory limit

You can use the mem_limit label to restrict memory usage. The unit is the byte and the minimum memory is 4 MB. If you set the memory limit and a container applies for a memory that exceeds the limit, the container is stopped because of OOM.

The following orchestration template demonstrates how to restrict CPU and memory.

n1:

expose:

-443/tcp

-80/tcp

image:'nginx:latest'

cpu_shares:50#0.5 core

mem_limit:536870912#512 MB

labels:

aliyun.scale:'1'

restart: always

volumes:

-/var/cache/nginx

Resource scheduling

To ensure that containers can obtain sufficient specified resources, such as 0.5 CPU core and 512 MB of memory in the preceding example, Container Service reserves resources for containers. For example, a 4-core machine can schedule up to eight cpu_shares=50 containers.

If you create containers without specifying the cpu_shares and mem_limit labels, Container Service does not reserve resources for such containers by default.