平均负载压力测试

平均负载实验

stress是Linux 系统 压力测试工具,这里我们用作异常进程模拟平均负载升高的场景。

mpstat是多核CPU性能分析工具,用来实时检查每个CPU的性能指标,以及所有CPU的平均指标。

pidstat是一个常用的进程性能分析工具,用来实时查看进程的CPU,内存,IO(磁盘吞吐量),以及上下文切换等性能指标。

场景1:状态分析

[root@qls ~]# stress --cpu 4 --timeout 600  # cpu压力测试,压4颗cpu,600毫秒之后结束

# watch -d uptime :查看负载数值,变化部分高亮显示 

# 5秒钟检测一次所有指标
[root@qls ~]# mpstat -P ALL 5
当前时间  平均和单个 用户态   优先级  内核态           硬中断  软中断    虚拟    来宾     反nice  空闲
04:43:54 PM  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
04:43:59 PM  all    1.20    0.00    0.20    0.00    0.00    0.00    0.00    0.00    0.00   99.60
04:43:59 PM    0    1.20    0.00    0.20    0.00    0.00    0.00    0.00    0.00    0.00   99.60
# 观察哪一列高,可以缩小排错范围,


# 5秒输出一组数据
[root@qls ~]# pidstat -u 5 1  # 查看引起系统负载升高的命令 (5秒输出一次,输出一次,统计一次,然后结束)

Linux 3.10.0-1062.el7.x86_64 (oldboy) 	04/22/2020 	_x86_64_	(1 CPU)

04:54:26 PM   UID       PID    %usr %system  %guest    %CPU   CPU  Command   # 这是一次输出
04:54:31 PM     0       554    1.00    0.20    0.00    0.20     0  vmtoolsd
04:54:31 PM     0     21763    1.00    0.20    0.00    0.20     0  watch

Average:      UID       PID    %usr %system  %guest    %CPU   CPU  Command   # 这是统计(平均值)
Average:        0       554    1.00    0.20    0.00    0.20     -  vmtoolsd
Average:        0     21763    1.00    0.20    0.00    0.20     -  watch

案例二:I/O密集型 # 磁盘

还是使用stress命令,但是这次模拟IO的压力
[root@zls ~]# stress --io 1 --timeout 600s

[root@zls ~]# watch -d uptime
[root@zls ~]# mpstat -P ALL 5
                  # 与cpu有关      与内核有关,与磁盘有关
22时19分32秒  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
22时19分37秒  all    2.78    0.00   97.22    0.00    0.00    0.00    0.00    0.00    0.00    0.00
22时19分37秒    0    2.78    0.00   97.22    0.00    0.00    0.00    0.00    0.00    0.00    0.00

22时19分37秒  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
22时19分42秒  all    3.01    0.00   96.99    0.00    0.00    0.00    0.00    0.00    0.00    0.00
22时19分42秒    0    3.01    0.00   96.99    0.00    0.00    0.00    0.00    0.00    0.00    0.00

[root@zls ~]# pidstat -u 5 1
Linux 3.10.0-862.el7.x86_64 (zls)   2019年07月14日     _x86_64_    (1 CPU)

22时20分59秒   UID       PID    %usr %system  %guest    %CPU   CPU  Command
22时21分04秒     0      6900    0.00    0.20    0.00    0.20     0  kworker/0:0
22时21分04秒     0     10104    2.76   83.07    0.00   85.83     0  stress
22时21分04秒     0     10105    0.00   10.63    0.00   10.63     0  kworker/u256:2


平均时间:   UID       PID    %usr %system  %guest    %CPU   CPU  Command
平均时间:     0      6900    0.00    0.20    0.00    0.20     -  kworker/0:0
平均时间:     0     10104    2.76   83.07    0.00   85.83     -  stress
平均时间:     0     10105    0.00   10.63    0.00   10.63     -  kworker/u256:2

# 平均时间

#下载新版本的包
[root@zls ~]# wget http://pagesperso-orange.fr/sebastien.godard/sysstat-11.7.3-1.x86_64.rpm

#升级到新版本
[root@zls ~]# rpm -Uvh sysstat-11.7.3-1.x86_64.rpm
准备中...                          ################################# [100%]
正在升级/安装...
   1:sysstat-11.7.3-1                 ################################# [ 50%]
正在清理/删除...
   2:sysstat-10.1.5-17.el7            ################################# [100%]
   
[root@zls ~]# pidstat -u 5 1   # 这次看每组输出的数据增加
Linux 3.10.0-862.el7.x86_64 (zls)   2019年07月14日     _x86_64_    (1 CPU)

22时24分40秒   UID       PID    %usr %system  %guest   %wait    %CPU   CPU  Command
22时24分45秒     0       281    0.00    0.20    0.00    0.40    0.20     0  xfsaild/sda3
22时24分45秒     0     10104    2.99   82.67    0.00    0.00   85.66     0  stress
22时24分45秒     0     10105    0.00    8.76    0.00   92.43    8.76     0  kworker/u256:2
22时24分45秒     0     10118    0.20    0.40    0.00    0.00    0.60     0  watch
22时24分45秒     0     10439    0.00    3.98    0.00   94.82    3.98     0  kworker/u256:3
22时24分45秒     0     11007    0.00    0.20    0.00    0.00    0.20     0  pidstat

平均时间:   UID       PID    %usr %system  %guest   %wait    %CPU   CPU  Command
平均时间:     0       281    0.00    0.20    0.00    0.40    0.20     -  xfsaild/sda3
平均时间:     0     10104    2.99   82.67    0.00    0.00   85.66     -  stress
平均时间:     0     10105    0.00    8.76    0.00   92.43    8.76     -  kworker/u256:2
平均时间:     0     10118    0.20    0.40    0.00    0.00    0.60     -  watch
平均时间:     0     10439    0.00    3.98    0.00   94.82    3.98     -  kworker/u256:3
平均时间:     0     11007    0.00    0.20    0.00    0.00    0.20     -  pidstat

# 总结:

1.平均负载高有可能是CPU密集型进程导致的
2.平均负载高并不一定代表CPU的使用率就一定高,还有可能是I/O繁忙
3.当发现负载高时,可以使用mpstat、pidstat等工具,快速定位到,负载高的原因,从而做出处理

总结:

1.平均负载高有可能是CPU密集型进程导致的
2.平均负载高并不一定代表CPU的使用率就一定高,还有可能是I/O繁忙
3.当发现负载高时,可以使用mpstat、pidstat等工具,快速定位到,负载高的原因,从而做出处理

开机启动流程

CentOS6

镜像:阿里云镜像站,官网(centos.org)

  1. 内核引导

img

2.运行init

init 在CentOS中,是系统所有进程的起点,如果进程想启动,那必须有init,如果没有init,系统中的任何进程都不会启动,那就相当于这个系统打不开...所以init才是爸爸。c7中,systemd是爸爸

img

7个运行级别:

C6 中 init 是所有进程的爸爸,

init + N 

#init 配置
vim /etc/inittab

## 关机 (-xxxxxx加不加都行)
#   0 - halt (Do NOT set initdefault to this)

## 单用户模式(只能开机的时候进入单用户模式)
#   1 - Single user mode

## 多用户模式(没有文件系统和网络)
#   2 - Multiuser, without NFS (The same as 3, if you do not have networking)

## 完整的多用户模式(命令行模式,默认模式)
#   3 - Full multiuser mode

## 没有被使用级别(没用)
#   4 - unused

## 图形化界面 (装了才可以切)
#   5 - X11

## 重启
#   6 - reboot (Do NOT set initdefault to this)
[root@oldboy ~]# cat /proc/cpuinfo 
processor       : 0
vendor_id       : AuthenticAMD
cpu family      : 23
model           : 8
model name      : AMD Ryzen 5 2600X Six-Core Processor
stepping        : 2
microcode       : 0x8008206
cpu MHz         : 3600.000
cache size      : 512 KB
physical id     : 0
siblings        : 1
core id         : 0
cpu cores       : 1       # 核心数
apicid          : 0
initial apicid  : 0
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc art rep_good nopl tsc_reliable nonstop_tsc extd_apicid aperfmperf eagerfpu pni pclmulqdq ssse3 fma cx16 sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw retpoline_amd ssbd ibpb vmmcall fsgsbase bmi1 avx2 smep bmi2 rdseed adx smap xsaveopt clzero irperf xsaveerptr arat
bogomips        : 7200.00
TLB size        : 2560 4K pages
clflush size    : 64
cache_alignment : 64
address sizes   : 42 bits physical, 48 bits virtual
power management:

 # grep 'model name' /proc/cpuinfo | wc -l
posted @ 2020-05-01 16:34  看萝卜在飘  阅读(415)  评论(1编辑  收藏  举报