This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
технология_cgroup [2024/04/28 18:21] val [cgroup v2] |
технология_cgroup [2024/12/11 10:58] (current) val [cgroup v2] |
||
---|---|---|---|
Line 2: | Line 2: | ||
* [[https://habrahabr.ru/company/selectel/blog/303190/|Механизмы контейнеризации: cgroups]] (сокращение от control groups, контрольные группы) | * [[https://habrahabr.ru/company/selectel/blog/303190/|Механизмы контейнеризации: cgroups]] (сокращение от control groups, контрольные группы) | ||
- | * [[https://blogs.rdoproject.org/7761/hands-on-linux-sandbox-with-namespaces-and-cgroups|Hands on Linux sandbox with namespaces and cgroups]] | + | * [[https://habr.com/ru/companies/redhatrussia/articles/423051/|Борьба за ресурсы, часть 1: Основы Cgroups]] |
===== cgroup v2 ===== | ===== cgroup v2 ===== | ||
+ | |||
+ | * [[https://pavlokhmel.com/cgroup-v2-limit-memory-and-cpu-usage-for-all-users-on-linux.html|Cgroups v2 - limit memory and CPU usage for all users on Linux]] | ||
+ | |||
<code> | <code> | ||
+ | # ###systemd-run --scope -p MemoryMax=1M vim | ||
+ | |||
+ | # lssubsys -a | ||
+ | |||
# systemd-cgls | # systemd-cgls | ||
/apache2 | /apache2 | ||
Line 11: | Line 18: | ||
# cat /sys/fs/cgroup/system.slice/apache2.service/memory.high | # cat /sys/fs/cgroup/system.slice/apache2.service/memory.high | ||
- | # echo 500 > /sys/fs/cgroup/system.slice/apache2.service/memory.high | + | # echo 2000000 > /sys/fs/cgroup/system.slice/apache2.service/memory.high |
- | # curl 127.0.0.1 | + | # time curl 127.0.0.1 |
- | # systemctl stop apache2.service | + | # systemctl edit --force --full my.slice |
+ | </code><code> | ||
+ | [Unit] | ||
+ | Description=My Slice | ||
+ | Before=slices.target | ||
- | # source /etc/apache2/envvars | + | [Slice] |
+ | MemoryAccounting=true | ||
+ | MemoryLimit=64M | ||
+ | MemoryHigh=64M | ||
+ | CPUAccounting=true | ||
+ | CPUQuota=5% | ||
+ | TasksMax=4096 | ||
+ | </code><code> | ||
+ | # systemctl edit apache2.service | ||
+ | </code><code> | ||
+ | [Service] | ||
+ | Slice=my.slice | ||
+ | </code><code> | ||
+ | # systemctl daemon-reload | ||
- | # /usr/sbin/apache2 -k start | + | # systemctl restart apache2.service |
# systemd-cgls | # systemd-cgls | ||
/apache2 | /apache2 | ||
- | # find /sys/fs/cgroup/ | grep session-NN | + | # cat /sys/fs/cgroup/my.slice/memory.high |
+ | |||
+ | # cat /sys/fs/cgroup/my.slice/cpu.max | ||
</code> | </code> | ||
===== cgroup v1 (Debian10/Ubuntu20) ===== | ===== cgroup v1 (Debian10/Ubuntu20) ===== |