服务器主机性能分析

cpu 上下文切换 context switch

现在linux是大多基于抢占式,CPU给每个任务一定的服务时间,当时间片轮转的时候,需要把当前状态保存下来,同时加载下一个任务,这个过程叫做上下文 切换。时间片轮转的方式,使得多个任务利用一个CPU执行成为可能,但是保存现场和加载现场,也带来了性能消耗。
参考:https://blog.csdn.net/xiaomin1991222/article/details/50979728/ (cs耗时分析)

vmstat 系统层统计:

# vmstat -s
    263112896 K total memory
     30812848 K used memory
     32542284 K active memory
     28356168 K inactive memory
    188450960 K free memory
      2446104 K buffer memory
     41402992 K swap cache
            0 K total swap
            0 K used swap
            0 K free swap
     38485652 non-nice user cpu ticks
     10834280 nice user cpu ticks
     16272085 system cpu ticks
   1839677026 idle cpu ticks
        81982 IO-wait cpu ticks
            0 IRQ cpu ticks
       192726 softirq cpu ticks
            0 stolen cpu ticks
    205452070 pages paged in
   1491626456 pages paged out
            0 pages swapped in
            0 pages swapped out
    649974675 interrupts
   1206781441 CPU context switches
   1637290369 boot time
     30829843 forks

pidstat 查看特定的进程:

# pidstat | grep python
#      Time   UID       PID    %usr %system  %guest    %CPU   CPU  Command
06:17:22 PM  1000   1479571    0.77    0.02    0.00    0.79    91  python
06:17:22 PM  1000   1479590    0.78    0.02    0.00    0.80    32  python
06:17:22 PM  1000   1479656    0.75    0.02    0.00    0.76    10  python
06:17:22 PM  1000   1479661    0.78    0.02    0.00    0.79    13  python
06:17:22 PM  1000   1479669    0.79    0.02    0.00    0.81    25  python
06:17:22 PM  1000   1479676    0.75    0.02    0.00    0.76     2  python
06:17:22 PM  1000   1479685    0.81    0.02    0.00    0.82    34  python
06:17:22 PM  1000   1479695    0.75    0.02    0.00    0.76    34  python
06:17:22 PM  1000   1479703    0.83    0.02    0.00    0.85    38  python

dstat

# dstat
You did not select any stats, using -cdngy by default.
----total-cpu-usage---- -dsk/total- -net/total- ---paging-- ---system--
usr sys idl wai hiq siq| read  writ| recv  send|  in   out | int   csw
  3   1  96   0   0   0|2062k   15M|   0     0 |   0     0 |  68k  114k
 91   4   4   0   0   0|   0  1928k|  21k   58k|   0     0 |  78k  120k
 92   4   4   0   0   0|   0  1512k|  19k   60k|   0     0 |  73k  106k
 92   4   5   0   0   0|   0  2272k|  15k  831k|   0     0 |  73k  106k
 91   4   4   0   0   0|   0  1223M|  17k   74k|   0     0 |  79k  109k
 91   5   5   0   0   0|   0    15M|8584k  110k|   0     0 |  77k  112k
 90   5   5   0   0   0|  16k   14M|8236k 1463k|   0     0 |  80k  116k
 89   5   6   0   0   0|   0   124M|  38k   71k|   0     0 | 110k  112k
 90   4   6   0   0   0|   0   291M|  19k   95k|   0     0 |  89k  122k
 90   4   5   0   0   0|2608k   88M|  33k 1451k|   0     0 |  86k  120k
 89   5   6   0   0   0|8192B   98M| 950k 1000k|   0     0 |  91k  126k
 88   5   7   0   0   0|   0    89M|4715k  165k|   0     0 | 126k  129k

更多参考: https://blog.csdn.net/sinat_34789167/article/details/80986709?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522163749017816780271950106%2522%252C%2522scm%2522%253A%252220140713.130102334…%2522%257D&request_id=163749017816780271950106&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2alltop_positive~default-1-80986709.first_rank_v2_pc_rank_v29&utm_term=dstat&spm=1018.2226.3001.4187

上一篇:软件工程实践总结&个人技术博客


下一篇:冲刺随笔