linux线程内存占用率测试

linux内核下开一个while(1)死循环线程,top命令观察内存占用率

Mem: 605060K used, 1428360K free, 0K shrd, 0K buff, 150044K cached
CPU:  0.0% usr 25.4% sys  0.0% nic 74.4% idle  0.0% io  0.0% irq  0.0% sirq
Load average: 10.70 9.02 7.85 6/119 5261
  PID  PPID USER     STAT   VSZ %MEM CPU %CPU COMMAND
 4997     2 root     RW       0  0.0   0  0.6 [indxd]
    9     2 root     SW       0  0.0   2  0.0 [rcu_sched]
 4989     2 root     DW       0  0.0   2  0.0 [ge_sw_d]
 5164     1 root     S    1124m 56.4   2  0.0 ./a_server
 5146     1 root     S     852m 42.8   0  0.0 drvBaMc
 5076     1 root     S     7720  0.3   2  0.0 /usr/local/WebServer/apache/bin/ht
 5082  5076 root     S     7720  0.3   1  0.0 /usr/local/WebServer/apache/bin/ht
 5083  5076 root     S     7720  0.3   2  0.0 /usr/local/WebServer/apache/bin/ht
 5084  5076 root     S     7720  0.3   3  0.0 /usr/local/WebServer/apache/bin/ht
 5085  5076 root     S     7720  0.3   1  0.0 /usr/local/WebServer/apache/bin/ht
 5086  5076 root     S     7720  0.3   1  0.0 /usr/local/WebServer/apache/bin/ht
 1586     1 root     S     5800  0.2   3  0.0 tftpserver -l var/log/tftp.log
 5080  5078 root     S     4964  0.2   0  0.0 /usr/local/WebServer/apache/bin/ro
 5081  5079 root     S     4964  0.2   3  0.0 /usr/local/WebServer/apache/bin/ro
 5092     1 root     S     4912  0.2   2  0.0 /usr/local/bin/adaemon /usr/local/
 1355     1 root     S     4704  0.2   0  0.0 telnetd
 1587     1 root     S     4104  0.2   2  0.0 -/bin/sh
 2182  1355 root     S     4104  0.2   3  0.0 -sh
 5127  1587 root     R     4100  0.2   0  0.0 top
 1341     1 root     S     4040  0.2   2  0.0 klogd -c 8

linux内核下开一个msleep(2000)延时2000ms循环线程,top命令观察内存占用率

###msleep(2000)
Mem: 521512K used, 1511908K free, 0K shrd, 0K buff, 77788K cached
CPU:  0.0% usr  0.9% sys  0.0% nic 99.1% idle  0.0% io  0.0% irq  0.0% sirq
Load average: 7.68 4.49 1.88 1/99 2349
  PID  PPID USER     STAT   VSZ %MEM CPU %CPU COMMAND
 2215     2 root     DW       0  0.0   1  0.5 [indxd]
 2320     2 root     DW       0  0.0   0  0.1 [set-speed-disp]
 2233     1 root     S     852m 42.8   2  0.0 drvBaMc
 1098     2 root     SW       0  0.0   0  0.0 [kworker/0:1]
 2207     2 root     DW       0  0.0   2  0.0 [ge_sw_d]
 1733     2 root     SW       0  0.0   3  0.0 [kworker/u8:2]
 2294     1 root     S     7720  0.3   2  0.0 /usr/local/WebServer/apache/bin/ht
 2300  2294 root     S     7720  0.3   0  0.0 /usr/local/WebServer/apache/bin/ht
 2301  2294 root     S     7720  0.3   2  0.0 /usr/local/WebServer/apache/bin/ht
 2302  2294 root     S     7720  0.3   3  0.0 /usr/local/WebServer/apache/bin/ht
 2303  2294 root     S     7720  0.3   0  0.0 /usr/local/WebServer/apache/bin/ht
 2304  2294 root     S     7720  0.3   0  0.0 /usr/local/WebServer/apache/bin/ht
 1586     1 root     S     5800  0.2   2  0.0 tftpserver -l var/log/tftp.log
 2298  2296 root     S     4964  0.2   1  0.0 /usr/local/WebServer/apache/bin/ro
 2299  2297 root     S     4964  0.2   3  0.0 /usr/local/WebServer/apache/bin/ro
 2310     1 root     S     4912  0.2   1  0.0 /usr/local/bin/adaemon /usr/local/
 1355     1 root     S     4704  0.2   0  0.0 telnetd
 1587     1 root     S     4104  0.2   3  0.0 -/bin/sh
 1613  1355 root     S     4104  0.2   2  0.0 -sh
 2343  1587 root     R     4100  0.2   0  0.0 top


linux内核下开一个msleep(1)延时2000ms循环线程,top命令观察内存占用率

###msleep(1)
Mem: 521556K used, 1511864K free, 0K shrd, 0K buff, 77660K cached
CPU:  0.1% usr  3.4% sys  0.0% nic 96.4% idle  0.0% io  0.0% irq  0.0% sirq
Load average: 7.54 3.66 1.43 1/99 2023
  PID  PPID USER     STAT   VSZ %MEM CPU %CPU COMMAND
 1993     2 root     DW       0  0.0   0  2.7 [set-speed-disp]
 1888     2 root     DW       0  0.0   2  0.4 [indxd]
 1098     2 root     SW       0  0.0   0  0.1 [kworker/0:1]
    9     2 root     SW       0  0.0   0  0.1 [rcu_sched]
 1996  1587 root     R     4100  0.2   0  0.0 top
 1880     2 root     DW       0  0.0   1  0.0 [ge_sw_d]
 1906     1 root     S     852m 42.8   2  0.0 drvBaMc
 1967     1 root     S     7720  0.3   3  0.0 /usr/local/WebServer/apache/bin/ht
 1973  1967 root     S     7720  0.3   1  0.0 /usr/local/WebServer/apache/bin/ht
 1974  1967 root     S     7720  0.3   3  0.0 /usr/local/WebServer/apache/bin/ht
 1975  1967 root     S     7720  0.3   0  0.0 /usr/local/WebServer/apache/bin/ht
 1976  1967 root     S     7720  0.3   1  0.0 /usr/local/WebServer/apache/bin/ht
 1977  1967 root     S     7720  0.3   1  0.0 /usr/local/WebServer/apache/bin/ht
 1586     1 root     S     5800  0.2   2  0.0 tftpserver -l var/log/tftp.log
 1971  1969 root     S     4964  0.2   2  0.0 /usr/local/WebServer/apache/bin/ro
 1972  1970 root     S     4964  0.2   0  0.0 /usr/local/WebServer/apache/bin/ro
 1983     1 root     S     4912  0.2   2  0.0 /usr/local/bin/adaemon /usr/local/
 1355     1 root     S     4704  0.2   0  0.0 telnetd
 1587     1 root     S     4104  0.2   3  0.0 -/bin/sh
 1613  1355 root     S     4104  0.2   1  0.0 -sh

结论:1、不延时,死循环下,CPU占用率满,内存占用多了82MB,高速缓存使用量几乎翻倍,多了70MB

            2、 随着延时时间缩短,CPU占用率增加,内存占用率有所下降,但不明显,高速缓存使用量有所下降,但不明显

展开阅读全文

没有更多推荐了,返回首页