docker run --cpus 컨테이너 CPU 사용량 제한하기

1 개요[ | ]

docker run --cpus
  • 도커 컨테이너의 CPU를 제한하는 docker run 명령어 옵션
  • CPU 사용량을 제한할 뿐, 메모리 제한과는 달리 과부하가 있어도 컨테이너를 종료시키지는 않는다.
docker run --cpus="1.5" ...
docker run --cpus=".5" ...

2 실행예시 1: 제한없이 실행[ | ]

root@localhost:~# docker run --name stress --rm -it progrium/stress --timeout 20s --cpu 2
stress: info: [1] dispatching hogs: 2 cpu, 0 io, 0 vm, 0 hdd
stress: dbug: [1] using backoff sleep of 6000us
stress: dbug: [1] setting timeout to 20s
stress: dbug: [1] --> hogcpu worker 2 [8] forked
stress: dbug: [1] using backoff sleep of 3000us
stress: dbug: [1] setting timeout to 20s
stress: dbug: [1] --> hogcpu worker 1 [9] forked
stress: dbug: [1] <-- worker 8 signalled normally
stress: dbug: [1] <-- worker 9 signalled normally
stress: info: [1] successful run completed in 20s
root@localhost:~# docker stats --format "table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}" | tee stats.txt
NAME                CPU %               MEM USAGE / LIMIT
stress              199.17%             1.012MiB / 461.8MiB
root@localhost:~# cat stats.txt | grep stress | sort -V | tail -3
stress              199.36%             896KiB / 461.8MiB
stress              199.39%             896KiB / 461.8MiB
stress              199.39%             896KiB / 461.8MiB
--cpu 2의 부하를 주었기에 대략 200%의 CPU를 사용한다.

3 실행예시 2: 제한하고 실행[ | ]

root@localhost:~# docker run --cpus=1 --name stress --rm -it progrium/stress --timeout 20s --cpu 2
stress: info: [1] dispatching hogs: 2 cpu, 0 io, 0 vm, 0 hdd
stress: dbug: [1] using backoff sleep of 6000us
stress: dbug: [1] setting timeout to 20s
stress: dbug: [1] --> hogcpu worker 2 [11] forked
stress: dbug: [1] using backoff sleep of 3000us
stress: dbug: [1] setting timeout to 20s
stress: dbug: [1] --> hogcpu worker 1 [12] forked
stress: dbug: [1] <-- worker 11 signalled normally
stress: dbug: [1] <-- worker 12 signalled normally
stress: info: [1] successful run completed in 20s
root@localhost:~# docker stats --format "table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}" | tee stats.txt
NAME                CPU %               MEM USAGE / LIMIT
stress              199.17%             1.012MiB / 461.8MiB
root@localhost:~# cat stats.txt | grep stress | sort -V | tail -3
stress              102.55%             1.008MiB / 461.8MiB
stress              103.70%             1.008MiB / 461.8MiB
stress              103.70%             1.008MiB / 461.8MiB
--cpu 2의 부하를 주도록 했으나 --cpus=1 제한에 걸려 대략 100%의 CPU를 사용한다.

4 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}