码迷,mamicode.com
首页 > 其他好文 > 详细

docker ---stress压力工具的镜像

时间:2018-05-23 02:23:39      阅读:1045      评论:0      收藏:0      [点我收藏+]

标签:virt   failed   1.0   nts   status   sse   ati   one   bytes   

标签:压力测试   docker   

1、下载一个stress压力工具的镜像

[root@docker ~]# docker pull joedval/stress
Pulling repository joedval/stress
7eb627cb08a2: Download complete 
b0082ba983ef: Download complete 
109b72e23ca5: Download complete 
a1a076997d57: Download complete 
Status: Downloaded newer image for joedval/stress:latest

2、随机生成一个以“joedval/stress”镜像为基础的容器,设定权级为512

[root@docker ~]# docker run -it --rm -c 512 joedval/stress --cpu 1
stress: info: [1] dispatching hogs: 1 cpu, 0 io, 0 vm, 0 hdd
可以看到cpu占用为99.6%,接近100%
[root@docker ~]# top
top - 15:19:07 up  1:04,  3 users,  load average: 1.62, 1.03, 0.43
Tasks: 158 total,   2 running, 156 sleeping,   0 stopped,   0 zombie
Cpu(s): 99.3%us,  0.3%sy,  0.0%ni,  0.0%id,  0.0%wa,  0.3%hi,  0.0%si,  0.0%st
Mem:   3910160k total,  1289624k used,  2620536k free,    96856k buffers
Swap:  4194300k total,        0k used,  4194300k free,   914440k cached
   PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                              
  4144 root      20   0  7208  120   28 R 99.6  0.0   2:58.09 stress                                                                                
  4403 root      20   0 15032 1252  924 R  0.3  0.0   0:00.32 top                                                                                   
     1 root      20   0 19356 1532 1228 S  0.0  0.0   0:01.55 init                                                                                  
     2 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kthreadd                                                                              
     3 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 migration/0                                                                           
     4 root      20   0     0    0    0 S  0.0  0.0   0:00.03 ksoftirqd/0                                                                           
     5 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 stopper/0                                                                             
     6 root      RT   0     0    0    0 S  0.0  0.0   0:00.02 watchdog/0                                                                            
     7 root      20   0     0    0    0 S  0.0  0.0   0:01.62 events/0                                                                              
     8 root      20   0     0    0    0 S  0.0  0.0   0:00.00 events/0                                                                              
     9 root      20   0     0    0    0 S  0.0  0.0   0:00.00 events_long/0                                                                         
    10 root      20   0     0    0    0 S  0.0  0.0   0:00.00 events_power_ef                                                                       
    11 root      20   0     0    0    0 S  0.0  0.0   0:00.00 cgroup                                                                                
    12 root      20   0     0    0    0 S  0.0  0.0   0:00.00 khelper                                                                               
    13 root      20   0     0    0    0 S  0.0  0.0   0:00.03 netns                                                                                 
    14 root      20   0     0    0    0 S  0.0  0.0   0:00.00 async/mgr                                                                             
    15 root      20   0     0    0    0 S  0.0  0.0   0:00.00 pm                                                                                    
    16 root      20   0     0    0    0 S  0.0  0.0   0:00.02 sync_supers                                                                           
    17 root      20   0     0    0    0 S  0.0  0.0   0:00.01 bdi-default

3、继续生成一个容器

root@docker ~]# docker run -it --rm -c 512 joedval/stress --cpu 1
stress: info: [1] dispatching hogs: 1 cpu, 0 io, 0 vm, 0 hdd
[root@docker ~]# top
top - 15:20:48 up  1:05,  3 users,  load average: 1.55, 1.13, 0.52
Tasks: 164 total,   3 running, 161 sleeping,   0 stopped,   0 zombie
Cpu(s): 99.0%us,  0.7%sy,  0.0%ni,  0.0%id,  0.0%wa,  0.3%hi,  0.0%si,  0.0%st
Mem:   3910160k total,  1298324k used,  2611836k free,    97924k buffers
Swap:  4194300k total,        0k used,  4194300k free,   917480k cached
   PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                              
  4772 root      20   0  7208  124   28 R 49.9  0.0   0:16.12 stress                                                                                
  4144 root      20   0  7208  120   28 R 49.5  0.0   4:22.39 stress                                                                                
     1 root      20   0 19356 1532 1228 S  0.0  0.0   0:01.55 init                                                                                  
     2 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kthreadd                                                                              
     3 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 migration/0                                                                           
     4 root      20   0     0    0    0 S  0.0  0.0   0:00.03 ksoftirqd/0                                                                           
     5 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 stopper/0                                                                             
     6 root      RT   0     0    0    0 S  0.0  0.0   0:00.02 watchdog/0                                                                            
     7 root      20   0     0    0    0 S  0.0  0.0   0:01.66 events/0                                                                              
     8 root      20   0     0    0    0 S  0.0  0.0   0:00.00 events/0                                                                              
     9 root      20   0     0    0    0 S  0.0  0.0   0:00.00 events_long/0                                                                         
    10 root      20   0     0    0    0 S  0.0  0.0   0:00.00 events_power_ef                                                                       
    11 root      20   0     0    0    0 S  0.0  0.0   0:00.00 cgroup                                                                                
    12 root      20   0     0    0    0 S  0.0  0.0   0:00.00 khelper                                                                               
    13 root      20   0     0    0    0 S  0.0  0.0   0:00.03 netns                                                                                 
    14 root      20   0     0    0    0 S  0.0  0.0   0:00.00 async/mgr                                                                             
    15 root      20   0     0    0    0 S  0.0  0.0   0:00.00 pm                                                                                    
    16 root      20   0     0    0    0 S  0.0  0.0   0:00.02 sync_supers                                                                           
    17 root      20   0     0    0    0 S  0.0  0.0   0:00.01 bdi-default        
然后,可以发现存在两个stress的进程,各占用49.5%
我们再次添加一个容器,并修改下stress权限为1024
[root@docker ~]# top
top - 15:22:13 up  1:07,  4 users,  load average: 2.53, 1.50, 0.70
Tasks: 171 total,   4 running, 167 sleeping,   0 stopped,   0 zombie
Cpu(s): 99.3%us,  0.3%sy,  0.0%ni,  0.0%id,  0.0%wa,  0.3%hi,  0.0%si,  0.0%st
Mem:   3910160k total,  1318152k used,  2592008k free,    99008k buffers
Swap:  4194300k total,        0k used,  4194300k free,   921024k cached
   PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                              
  4992 root      20   0  7208  120   28 R 49.5  0.0   0:09.79 stress                                                                                
  4144 root      20   0  7208  120   28 R 24.9  0.0   4:59.56 stress                                                                                
  4772 root      20   0  7208  124   28 R 24.6  0.0   0:53.28 stress                                                                                
     1 root      20   0 19356 1532 1228 S  0.0  0.0   0:01.55 init                                                                                  
     2 root      20   0     0    0    0 S  0.0  0.0   0:00.01 kthreadd                                                                              
     3 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 migration/0                                                                           
     4 root      20   0     0    0    0 S  0.0  0.0   0:00.03 ksoftirqd/0                                                                           
     5 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 stopper/0                                                                             
     6 root      RT   0     0    0    0 S  0.0  0.0   0:00.02 watchdog/0                                                                            
     7 root      20   0     0    0    0 S  0.0  0.0   0:01.69 events/0                                                                              
     8 root      20   0     0    0    0 S  0.0  0.0   0:00.00 events/0                                                                              
     9 root      20   0     0    0    0 S  0.0  0.0   0:00.00 events_long/0                                                                         
    10 root      20   0     0    0    0 S  0.0  0.0   0:00.00 events_power_ef                                                                       
    11 root      20   0     0    0    0 S  0.0  0.0   0:00.00 cgroup                                                                                
    12 root      20   0     0    0    0 S  0.0  0.0   0:00.00 khelper                                                                               
    13 root      20   0     0    0    0 S  0.0  0.0   0:00.03 netns                                                                                 
    14 root      20   0     0    0    0 S  0.0  0.0   0:00.00 async/mgr                                                                             
    15 root      20   0     0    0    0 S  0.0  0.0   0:00.00 pm                                                                                    
    16 root      20   0     0    0    0 S  0.0  0.0   0:00.02 sync_supers

4、查看容器信息:

[root@docker ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES
fcc6cb7b064c        joedval/stress      "stress --cpu 1"    29 seconds ago      Up 28 seconds                                   drunk_rosalind      
7c195fe2e038        joedval/stress      "stress --cpu 1"    2 minutes ago       Up 2 minutes                                    loving_galileo      
9b19fbca489b        joedval/stress      "stress --cpu 1"    7 minutes ago       Up 7 minutes                                    furious_rosalind

 

5、测试内存:

[root@docker ~]# docker run -it --rm -m 128m joedval/stress --vm 1 --vm-bytes 120m --vm-hang 0
stress: info: [1] dispatching hogs: 0 cpu, 0 io, 1 vm, 0 hdd
[root@docker ~]# docker ps -l
CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS              PORTS               NAMES
9841ee711d7f        joedval/stress      "stress --vm 1 --vm-   8 seconds ago       Up 6 seconds                            boring_jones       
[root@docker ~]# docker run -it --rm -m 128m joedval/stress --vm 1 --vm-bytes 512m --vm-hang 0
stress: info: [1] dispatching hogs: 0 cpu, 0 io, 1 vm, 0 hdd
stress: FAIL: [1] (415) <-- worker 5 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 3s
[root@docker ~]# docker run -it --rm -m 128m joedval/stress --vm 1 --vm-bytes 255m --vm-hang 0
stress: info: [1] dispatching hogs: 0 cpu, 0 io, 1 vm, 0 hdd
[root@docker ~]# docker run -it --rm -m 128m joedval/stress --vm 1 --vm-bytes 256m --vm-hang 0
stress: info: [1] dispatching hogs: 0 cpu, 0 io, 1 vm, 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 2s
说明:不能超过预设值的两倍(比如上面案例中256m是128m,所以自动退出了)

docker ---stress压力工具的镜像

标签:virt   failed   1.0   nts   status   sse   ati   one   bytes   

原文地址:https://www.cnblogs.com/jiaohenghao/p/9074662.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!