In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly shows you "Docker how to achieve Memory resource restrictions", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "Docker how to achieve Memory resource restrictions" this article.
One: brief introduction
Docker uses cgroup to control the resource quota used by the container, including CPU, memory and disk, which basically covers the common resource quota and usage control.
Cgroup, the abbreviation of Control Groups, is a mechanism provided by Linux kernel to limit, record and isolate the physical resources used by process groups (such as cpu, memory, disk IO, etc.). It is used to control process resources by LXC, docker and many other projects. Cgroup the Linux kernel function that manages arbitrary processes in groups. Cgroup itself is the infrastructure that provides the function and interface for packetized management of processes. Specific resource management functions such as Imax O or memory allocation control are realized through this function. These specific resource management functions are called cgroup subsystems and are implemented by the following subsystems:
Blkio: sets the input and output control that limits each block device. For example: disk, CD, usb and so on.
Cpu: use the scheduler to provide cpu access to cgroup tasks.
Cpuacct: generate cpu resource reports for cgroup tasks.
Cpuset: if it is a multi-core cpu, this subsystem allocates separate cpu and memory for the cgroup task.
Devices: allow or deny cgroup task access to the device.
Freezer: pauses and resumes cgroup tasks.
Memory: set memory limits for each cgroup and generate memory resource reports.
Net_cls: Mark each network packet for cgroup convenience.
Ns: namespace subsystem.
Perf_event: added the ability to monitor and trace each group, that is, to monitor all threads belonging to a particular group and threads running on a particular CPU.
At present, docker only uses some of these subsystems to control the quota and use of resources.
Second: memory resource control
Like the CPU control, docker also provides several parameters to control the container's memory usage quota, which can control various memory aspects such as the swap size of the container, the amount of available memory, and so on. The main parameters are as follows:
1.--memory: sets the maximum memory limit used by the container. The default unit is byte, and you can use strings with units such as K, G, M, etc.
2.Mel-memory-reservation: enable flexible memory sharing, which allows the container to use memory as much as possible when the host has sufficient resources. When memory competition or low memory is detected, the container's memory is forced to be reduced to the memory size specified by memory-reservation. Officially, when this option is not set, some containers may take up a lot of memory for a long time, resulting in a loss of performance.
3.--memory-swap: equal to the sum of memory and swap partition size. A setting of-1 indicates that the size of the swap partition is infinite. The default unit is byte, and you can use strings with units such as K, G, M, etc. If the setting value of-memory-swap is less than the value of-memory, the default value is used, which is twice the value of-memory-swap.
4.-- memory-swappiness: controls the process's tendency to swap physical memory to swap partitions, with a default factor of 60. The smaller the coefficient, the more likely you are to use physical memory. Values range from 0 to 100. A value of 100 means to use swap partitions as far as possible, and a value of 0 means to disable the container swap feature (unlike the host, which is set to 0 does not guarantee that swap will not be used).
By default, the container can use all the free memory on the host.
Three: give an example
Docker run-ti-rm-name mytest-memory 128m centos:latest / bin/bash
Docker stats
Four: IO resource control
Compared with the quota control of CPU and memory, docker's control of disk IO is relatively immature, and most of them must be used with host devices. It mainly includes the following parameters:
-device-read-bps: limit the read speed (bytes per second) on this device, which can be kb, mb, or gb.
-device-read-iops: limits the read speed of a specified device by reading IO per second.
-device-write-bps: limit the write speed on this device (bytes per second), which can be kb, mb, or gb.
-device-write-iops: limits the write speed of a specified device by writing IO times per second.
-blkio-weight: the weighting value of the container's default disk IO. Valid values range from 10 to 100.
-blkio-weight-device: IO weighted control for specific devices. Its format is DEVICE_NAME:WEIGHT
The above is all the content of the article "how Docker achieves Memory resource restrictions". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.