728x90
발생
# docker container run --name nginx2 -d --cpus 1 nginx
위 명령어와 같이 docker 이미지를 수행할 때 --cpus 1 과 같이 NanoCPU를 설정할 때 발생.
검토
- 커널 즉 OS에서 cfs관련된 period/quota 등의 설정이 안되어 있는 듯.
- 또는 cgroup(아직 뭔지 모름)이 mount 안되었다..
지정 예시
(출처 : https://docs.kernel.org/next/scheduler/sched-bwc.html )
- Limit a group to 1 CPU worth of runtime:
-
If period is 250ms and quota is also 250ms, the group will get 1 CPU worth of runtime every 250ms. # echo 250000 > cpu.cfs_quota_us /* quota = 250ms */ # echo 250000 > cpu.cfs_period_us /* period = 250ms */
- Limit a group to 2 CPUs worth of runtime on a multi-CPU machine
# echo 1000000 > cpu.cfs_quota_us /* quota = 1000ms */ # echo 500000 > cpu.cfs_period_us /* period = 500ms */ The larger period here allows for increased burst capacity.
- With 500ms period and 1000ms quota, the group can get 2 CPUs worth of runtime every 500ms:
- Limit a group to 20% of 1 CPU.
# echo 10000 > cpu.cfs_quota_us /* quota = 10ms */ # echo 50000 > cpu.cfs_period_us /* period = 50ms */
- With 50ms period, 10ms quota will be equivalent to 20% of 1 CPU:
- Limit a group to 40% of 1 CPU, and allow accumulate up to 20% of 1 CPU additionally, in case accumulation has been done.
# echo 20000 > cpu.cfs_quota_us /* quota = 20ms */ # echo 50000 > cpu.cfs_period_us /* period = 50ms */ # echo 10000 > cpu.cfs_burst_us /* burst = 10ms */
- With 50ms period, 20ms quota will be equivalent to 40% of 1 CPU. And 10ms burst will be equivalent to 20% of 1 CPU:
cgroups
- control groups for limiting resource usage on Linux
- memory, cpu
메모리 제약 시키기 예시
(출처 : https://sonseungha.tistory.com/537 )
cgroup 가상파일시스템을 마운트합니다.
$ sudo mkdir -p /cgroup/memory
$ sudo mount -t cgroup -o memory memory /cgroup/memory
마운트 여부 확인하기.
아래 명령어를 수행해서 결과가 표시된다면 정상적으로 마운트되었습니다.
$ mount | grep cgroup
memory on /cgroup/memory type cgroup (rw,relatime,blkio) or
$ cat /proc/mount | grep cgroup
memory /cgroup/memory cgroup rw,relatime,blkio 0 0
mount 상태 확인해보기.
linuxias@linuxias-VirtualBox:/cgroup/memory$ ls -al
total 4
dr-xr-xr-x 2 root root 0 8월 11 13:35 .
drwxr-xr-x 4 root root 4096 8월 11 15:49 ..
......
특정 프로세스의 메모리 설정하기.
$ sudo mkdir /cgroup/memory/test_process
$ sudo echo 1G > /cgroup/memory/test_process/memory.limit_in_bytes
$ cat /cgroup/memory/test_process/memory.limit_in_bytes
1073741824
cgroup에 적용하기
test process의 pid가 10001 이라고 할 때 아래와 같이 설정해 줍니다.
$ echo 10001 >> /cgroup/memory/test_process/tasks
위와 같이 설정하거나 프로세스의 이름이 test 라고 할 때
$pidof test | while read PID; do echo $PID >> /cgroup/memory/test_process/tasks; done
statistics 확인해보기
$ cat memory.stat
Setting up cgroups
- /etc/cgconfig.conf ( it is initially empty )
- /sys/fs/cgroup
- # mount -t cgroup
728x90
반응형