This article is a mirror article of machine translation, please click here to jump to the original article.

View: 7160|Reply: 5

Docker modifies and restricts container CPU, memory, and other resources

[Copy link]
Posted on 8/6/2022 1:55:37 PM | | | |
Requirements: When creating a docker container, you can limit the maximum memory usage of the container by adding the -m parameter.

Review container memory limits

The host machine installs an 8G memory stick and creates 3 containers, of which the maximum memory of the itsvse-redis container is limited to 512M, and the remaining two containers are not restricted, as shown in the figure below:



Detailed explanation of output information format

[CONTAINER]: Displays the container's ID in a short form.
CPU %: CPU usage.
[MEM USAGE/LIMIT]: The memory currently used and the maximum memory that can be used.
[MEM %]: Displays memory usage as a percentage.
[NET I/O]: Network I/O data.
[BLOCK I/O]: Disk I/O data.
[PIDS]:P ID number.

Docker update command

The docker update command dynamically updates the container configuration. You can use this command to prevent containers from consuming too many resources from their Docker hosts. With a single command, you can set limits on a single container or multiple containers. To specify multiple containers, provide a list of container names or IDs separated by spaces.

OPTIONS Description

name
description
--blkio-weight
Blocking IO (relative weight), between 10 and 1000, 0 is disabled (default suppressed)
--cpu-period
Limit CPU CFS (Totally Fair Scheduler) duration
--cpu-quota
Limit CPU CFS (Completely Fair Scheduler) quotas
--cpu-rt-period
API 1.25+, which limits CPU real-time time to microseconds
--cpu-rt-runtime
API 1.25+, which limits CPU real-time runtime to microseconds
--cpu-shares, -c
CPU share (relative weight)
--cpus
API 1.29+, number of CPUs
--cpuset-cpus
Allowed CPU (0-3,0,1)
--cpuset-mem
Allowed MEM (0-3,0,1)
--kernel-memory
Kernel memory limits
--memory-swap
The swap limit is equal to memory plus swapping, "-1" to enable unlimited swapping
--memory-reservatio
Memory soft limit
--memory, -m
Memory limit
--pids-limit
API 1.40+, adjust container pids limits (-1 means unlimited)
--restart
Restart the policy to apply when the container exits

Documentation:The hyperlink login is visible.

Suppose you limit the php5-fpm containerMaximum memory usage 1024M (1G), the command is as follows:



(End)




Previous:HTML5 PostMessage cross-window communication
Next:[Turn] A sentence Task.Result will be locked, how else to write this code?
 Landlord| Posted on 8/6/2022 1:58:43 PM |
If you don't set the --memory-swap parameter, you may get an error:

Error response from daemon: Cannot update container ae7884f515f96cadab65668d6a44e13bb899c1e7fd411abcc88577a79d4302a3: Memory limit should be smaller than already set memoryswap limit, update the memoryswap at the same time
 Landlord| Posted on 8/6/2022 2:31:57 PM |
Linux uses lookbusy to simulate CPU usage
https://www.itsvse.com/thread-10260-1-1.html
Posted on 8/6/2022 3:52:44 PM |
Learn to learn
 Landlord| Posted on 7/1/2023 9:46:50 PM |
Runtime options for Docker memory, CPU, and GPU:The hyperlink login is visible.

--memory-swap details

--memory-swap is a modifier flag that only makes sense if --memory is also set. When a container uses up all available RAM, using swap allows the container to write excess memory requirements to disk. For applications that frequently swap memory to disk, performance suffers.

Its settings can have complex effects:

If --memory-swap is set to a positive integer, then both --memory must be set to --memory-swap. --memory-swap represents the total amount of memory and swap zones that can be used, and --memory controls the amount of memory used in non-swap zones. thereforeIf --memory="300m" and --memory-swap="1g", the container can swap space with 300m memory and 700m (1g - 300m).

If --memory-swap is set to 0, the setting is ignored and the value is considered unset.

If --memory-swap is set to the same value as --memory, and --memory is set to a positive integer, the container does not have access to swap。 See Preventing containers from using swaps.

If --memory-swap is not set and --memory is set, the container can use as much swap --memory as set (if the host container is configured with swap memory). For example, if --memory="300m" and --memory-swap are not set, the container can use a total of 600m of memory and swap space.

If --memory-swap is explicitly set to -1, the container is allowed to use an unlimited number of swaps, up to the number available on the host system.

Inside the container, tools such as free report on the available exchanges for the host instead of reporting on the exchanges available within the container. Don't rely on the output of free or similar tools to determine if an exchange exists.
 Landlord| Posted on 2/16/2024 4:07:22 AM |

If --memory-swap is not set,-- memory is set to a value,The --memory-swap default can use the same memory as --memoryFor example, if you ,-- memory-swap=1G, you can use 1G of swap space, and finally, the container can use 2G of memory (--memory 1G space + --memory-swap 1G space).

This means that when --memory is set,-- memory-swap can be understood as the total memory limit, and the swap space available is equal to the value of memory-swap minus memory.

Look at the container --memory-swap configuration with the following command:



"Memory": 536870912, // 512M=536870912/1024/1024/1024
"MemoryReservation": 0,
"MemorySwap": 1073741824, // 1G=1073741824/1024/1024/1024
"MemorySwappiness": null,

The above configuration is that the container limits the memory --memory=512M, and --memory-swap is not set.
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com