Docker container cpu usage
Docker practices-resource isolation and throttling
D
ocker stats cpu usage
Building Stress Mirrors
[Root@controller ~]# cd/home/shangwu/tools/[root@controller tools]# cd dockerfile/[Root@controller dockerfile]# mkdir Stress [Root@controller dockerfile]# cd stress/[Root@controller stress]# vim dockerfile [Root@controller stress]# cat Doc Kerfile from CentOS ADD epel-7.repo/etc/yum.repos.d/run yum install-y stress && yum Clean all entrypoint ["str ESS "] [Root@controller stress]# [Root@controller stress]# wget Http://mirrors.aliyun.com/repo/epel-7.repo [root@contr Oller stress]# Docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SI
Docker check cpu usage
ZE centos latest 72a210db1424 hours ago 192.5 MB [Root@controller stress]#
[Root@controller stress]# Docker build-t stress.
Docker cpu
[Root@controller stress]# Docker images REPOSITORY TAG IMAGE ID CREATED
Docker container cpu
VIRTUAL SIZE stress latest a458db7db05b seconds ago212.1 MB CentOS latest 72a210db1424 hours ago 192.5 MB Lemonbar/centos6-ssh
Latest b78c71c001db 2 years ago 296.9 MB [Root@controller stress]#
D
ocker run cpu
Viewing the docker Run command help output
[Root@controller stress]# Docker run--help -C,--cpu-shares=0 CPU shares (relative weight)
--cpuset-cpus= CPUs in which to allow execution (0-3, 0,1)
-M,--memory= memory limit
To start a container: docker cpu usage
[Root@linux-node1 stress]# Docker run -it--rm--cpuset-cpus=0 stress--cpu 1
stress:info: [1] dispatching hogs : 1 CPU, 0 io, 0 vm, 0 HDD
view usage CPU in another window
[Root@controller ~]# top top-19:21:25 up 18:12, 3 users, load average:0.22, 0.05, 0.02 tasks:244 Total, 2 running, 242 sleeping, 0 stopped, 0 zombie Cpu (s): 12.5%us, 0.0%sy, 0.0%ni, 87.5%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 3917020k Total, 3267980k used, 649040k free, 81992k buffers swap:4095996k total, 0k used, 4095996k free
, 2872996k cached PID USER PR NI VIRT RES SHR S%cpu%MEM time+ COMMAND
15386 Root 0 7204 R 100.0 0.0 0:15.85 Stress Root 0 0 0 0 S 0.3 0.0 0:08.21 Eve NTS/1 1 Root 0 19232 1376 1108 S 0.0 0.0 0:03.27 Init 2 root 20 0 0 0 0 S 0.0 0.0 0:00.22 Kthreadd
again, open a window:
[Root@controller ~]# Docker run -it--rm--cpuset-cpus=0-c 1 Stress--cpu
switch to another window to view CPU usage
[Root@controller ~]# top top-19:23:58 up 18:15, 3 users, load average:1.09, 0.45, 0.17 tasks:251 Total, 3 running, 248 sleeping, 0 stopped, 0 zombie Cpu (s): 12.5%us, 0.0%sy, 0.0%ni, 87.5%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 3917020k Total, 3280344k used, 636676k free, 82764k buffers swap:4095996k total, 0k used, 4095996k free
, 2876432k cached PID USER PR NI VIRT RES SHR S%cpu%MEM time+ COMMAND
15386 Root 0 7204 R 66.5 0.0 2:45.48 Stress 15489 Root 0 7204 124 R 33.2 0.0 0:03.80 str ESS 1 Root 0 19232 1376 1108 S 0.0 0.0 0:03.27 Init 2 root 20 0 0 0 0 S 0.0 0.0 0:00.22 Kthreadd
Note the command
Docker run -it--rm stress--cpu 1
Docker run -it--rm--cpuset-cpus=0 stress--cpu 1
--cpuset-cpus back with CPU The total number, specified for the Docker container, and how many CPUs the--CPU is running, can only be 1, 2, 3, 4 ... N and so on
-C can specify the proportion of CPU;
--cpuset can bind CPU;
Memory
Overview
Docker provides the parameter-m,--memory= "" to limit the amount of memory used by the container.
Condition 1-NormalAllow containers to use a maximum memory limit of 128M:
[Root@controller ~]# Docker run-it--rm-m 128m stress--vm 1--vm-bytes 128M--vm-hang 0
stress:info: [1] Dispatchi ng hogs:0 CPU, 0 IO, 1 VMS, 0 HDD
Condition 2-Normal
[Root@controller ~]# Docker run-it--rm-m 128m stress--vm 1--vm-bytes 200M--vm-hang 0
stress:info: [1] Dispatchi ng hogs:0 CPU, 0 IO, 1 VMS, 0 HDD
Case 3-Exception
[Root@controller ~]# Docker run-it--rm-m 128m stress--vm 1--vm-bytes 260M--vm-hang 0
stress:info: [1] Dispatchi ng hogs:0 CPU, 0 IO, 1 VMS, 0 HDD
stress:fail: [1] (415) <--worker 6 got signal 9
stress:warn: [1] (417) Now Reaping child worker Processes
Stress:fail: [1] (421) Kill error:no Such process
stress:fail: [1] (451) failed Run completed in 4s
Description
1) You can see that the container was killed because of the out of memory.
IO (Reference)
# docker run-it--rm Dbyin/tlinux:1.2/bin/bash
bash-4.1# Time $ (dd If=/dev/zero of=f1.txt bs=1024 count=500000 & & Sync)
500000+0 Records in
500000+0 records
out 512000000 bytes (MB) copied, 1.28334 s, 399 MB/s
Real 0m12.091s
user 0m0.056s
sys 0m1.237s
can see, write 512M data, share 12s, average 42m/s.
Limit IO bandwidth to 10m/s:
# echo "253:1 10485760" >/cgroup/blkio/docker/$CONTAINER _id/blkio.throttle.write_bps_ Device
bash-4.1# Time $ (dd If=/dev/zero of=f1.txt bs=1024 count=500000 && sync)
500000+0 Records in< C15/>500000+0 Records
out 512000000 bytes (MB) copied, 1.41813 s, 361 MB/s
real 0m50.348s
user< c20/>0m0.071s
sys 0m1.473s