가이드 제목은 [도구명] [내용]-하기 형태(ex Bitbucket Cloud 저장소 생성하기)로 입력한다.
이 문서는 Docker CPU, Memory 리소스 제한 및 부하 테스트 내용을 공유하기 위해 작성되었다.
가이드에 사용되는 도구 정보를 입력한다.
|
첨부한 이미지 너비는 800px 을 넘기지 않는다.
Docker Compose에서 실행되는 컨테이너의 CPU 사용률과 메모리 사용률 테스트
docker-compose 버전이 1.X 일 경우 해당 부분 지원하지 않음 #docker-compose 버전 확인 |
sudo rm /usr/local/bin/docker-compose # curl + grep VERSION=$(curl --silent https://api.github.com/repos/docker/compose/releases/latest | grep -Po '"tag_name": "\K.*\d') # curl + jq VERSION=$(curl --silent https://api.github.com/repos/docker/compose/releases/latest | jq .name -r) DESTINATION=/usr/local/bin/docker-compose sudo curl -L https://github.com/docker/compose/releases/download/${VERSION}/docker-compose-$(uname -s)-$(uname -m) -o $DESTINATION sudo chmod 755 $DESTINATION |
services: service_name: ... deploy: resources: limits: cpus: '0.5' # half a CPU memory: 256M # 256 MB of RAM reservations: cpus: '0.25' # a quarter of a CPU memory: 128M # 128 MB of RAM |
docker-compose -f do-limits.yml up -d |
docker stats [OPTIONS] [CONTAINER...] |
#접속 docker exec -it [Name 및 Container ID] /bin/bash #종료 exit #OS 버전 확인 후 필요한 패키지 설치 cat /etc/*-release apt-get update && apt-get -y install vim && apt-get -y install stress |
#vi cpu_stress.sh #chmod 777 cpu_stress.sh #!/bin/bash # Function to check if a number is prime is_prime() { local number=$1 for ((i=2; i<=$((number/2)); i++)); do if [ $((number%i)) -eq 0 ]; then return 1 fi done return 0 } # Infinite loop to calculate prime numbers while true; do for ((i=2; i<=100000; i++)); do if is_prime $i; then echo $i fi done done |
#vi mem_stress.sh #chmod 777 mem_stress.sh #!/bin/bash # Run the memory stress test loop while true do #head -c ${memory}k </dev/zero> /dev/null </dev/zero head -c 512m | tail #</dev/zero head | tail #(</dev/zero head -c 512m) <(sleep 300) | tail done |
#CPU 부하 stress --cpu 2 --timeout 20s #Memory 부하 stress --verbose --vm 1 --vm-bytes 512M --timeout 20s |
version: "3" services: web1: container_name: test_1 image: nginx #command: sh -c "apt update&&apt-get install vim -y&&apt-get install stress -y&&stress --verbose --vm 1 --vm-bytes 512M" entrypoint: sh -c "apt update&&apt-get install vim -y&&apt-get install stress -y&&stress --verbose --vm 1 --vm-bytes 512M" ports: - "8083:8080" deploy: resources: limits: cpus: '1' # half a CPU memory: 256M # 256 MB of RAM reservations: cpus: '0.5' # a quarter of a CPU memory: 256M # 128 MB of RAM db: image: postgres:12 container_name: postgres12 environment: POSTGRES_USER: sonar POSTGRES_PASSWORD: sonar deploy: resources: limits: cpus: '1.5' # half a CPU memory: 1024M # 256 MB of RAM reservations: cpus: '0.6' # a quarter of a CPU memory: 256M # 128 MB of RAM web3: container_name: test_3 image: nginx ports: - "8082:8080" deploy: resources: limits: cpus: '1.5' # half a CPU memory: 1024M # 256 MB of RAM reservations: cpus: '0.6' # a quarter of a CPU memory: 256M # 128 MB of RAM |
stress --cpu 2 --timeout 20s
stress --verbose --vm 1 --vm-bytes 512M
stress --verbose --vm 1 --vm-bytes 512M
docker-compose 버전 upgrade
memory script
stress 명령어