undefined

mpstat

sysstat 包含了常用的Linux 性能分析工具,用来监控和分析系统的性能。
mpstat 是一个常见的多核CPU性能分析工具,用来实时查看每个CPU的性能指标,以及所有CPU的平均指标
工具使用:

1
2
3
4
5
[root@localhost ~]# mpstat -h
Usage: mpstat [ options ] [ <interval> [ <count> ] ]
Options are:
[ -A ] [ -u ] [ -V ] [ -I { SUM | CPU | SCPU | ALL } ]
[ -P { <cpu> [,...] | ON | ALL } ]
  • -P {cpu | ALL} 表示监控那个 CPU,cpu 在[0, cpu个数-1] 中取值;或者 ALL 监控所有CPU
查看更多

undefined

Linux性能调优之CPU篇

针对于线上问题的快速定位以及程序的性能发现调优,主要通过CPU、内存、IO、网络四个方向去分析。本文针对CPU相关的指标罗列常用的工具以及排查问题的思路。
本人对Linux了解尚浅,如有错误,可指出共同学习。

一、平均负载

1. uptime命令

1
2
root@9-134-239-95:~# uptime
22:52:30 up 265 days, 12:54, 1 user, load average: 0.03, 0.06, 0.05

命令返回:

  • 22:52:30 表示当前时间
查看更多

undefined

pidstat

在 sysstat 包中,pidstat 用于监控进程占用系统资源的情况。注意:pidstat 监控的是进程的指标,如果要看线程,加上 -t 选项
工具使用:

1
2
3
4
5
6
[root@localhost ~]# pidstat -help
Usage: pidstat [ options ] [ <interval> [ <count> ] ]
Options are:
[ -d ] [ -h ] [ -I ] [ -l ] [ -r ] [ -s ] [ -t ] [ -U [ <username> ] ] [ -u ]
[ -V ] [ -w ] [ -C <command> ] [ -p { <pid> [,...] | SELF | ALL } ]
[ -T { TASK | CHILD | ALL } ]
  • -u 默认的参数,显示各个进程的CPU使用情况
查看更多

undefined

stress 压力测试工具

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
[root@localhost ~]# stress 
`stress' imposes certain types of compute stress on your system

Usage: stress [OPTION [ARG]] ...
-?, --help show this help statement
--version show version statement
-v, --verbose be verbose
-q, --quiet be quiet
-n, --dry-run show what would have been done
-t, --timeout N timeout after N seconds
--backoff N wait factor of N microseconds before work starts
-c, --cpu N spawn N workers spinning on sqrt()
-i, --io N spawn N workers spinning on sync()
-m, --vm N spawn N workers spinning on malloc()/free()
--vm-bytes B malloc B bytes per vm worker (default is 256MB)
--vm-stride B touch a byte every B bytes (default is 4096)
--vm-hang N sleep N secs before free (default none, 0 is inf)
--vm-keep redirty memory instead of freeing and reallocating
-d, --hdd N spawn N workers spinning on write()/unlink()
--hdd-bytes B write B bytes per hdd worker (default is 1GB)

Example: stress --cpu 8 --io 4 --vm 2 --vm-bytes 128M --timeout 10s

Note: Numbers may be suffixed with s,m,h,d,y (time) or B,K,M,G (size).
  • -t, –timeout N 指定运行N秒后结束
    • –backoff N 等待N微妙后开始运行
查看更多

undefined

vmstat

当系统所需的内存超过实际的物理内存,内核会释放某些进程占用但未使用的部分或所有物理内存,将这部分资料存储在磁盘上直到进程下一次调用,并将释放出的内存提供给有需要的进程使用。

vmstat (Virtual Memory)命令的含义为显示虚拟内存状态,可以报告关于进程、内存、IO 等系统整体运行状态

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
➜  [/tmp] vmstat -h

Usage:
vmstat [options] [delay [count]]

Options:
-a, --active active/inactive memory
-f, --forks number of forks since boot
-m, --slabs slabinfo
-n, --one-header do not redisplay header
-s, --stats event counter statistics
-d, --disk disk statistics
-D, --disk-sum summarize disk statistics
-p, --partition <dev> partition specific statistics
-S, --unit <char> define display unit
-w, --wide wide output
-t, --timestamp show timestamp

-h, --help display this help and exit
-V, --version output version information and exit

查看更多