设为首页 加入收藏

TOP

MySQL 调优基础(一) CPU与进程(三)
2015-11-21 01:38:18 来源: 作者: 【 】 浏览:9
Tags:MySQL 基础 CPU 进程
?
提供的是关于内存的信息,因为Linux会尽量的来使用内存来进行缓存,所以这些信息没有多大的价值,free数值小,并不代表存在内存瓶颈;
?
第五行:
?
Swap: total, used, free ,cached
?
提供的是关于swap分区的使用情况,这些信息也没有太大的价值,因为Linux的使用内存的机制决定的。used值很大并不代表存在内存瓶颈;
?
剩下是关于每个进程使用的资源的情况,进程的各种信息,按照使用CPU的多少排序,每个字段的含义如下:
?
PID: 表示进程ID;USER: 表示运行进程的用户;PR:表示进程优先级;NI:表示进程nice值,默认为0;
?
VIRT:The ?total ?amount ?of ?virtual ?memory ?used by the task. ?It includes all code, data and shared libraries plus pages that have been swapped out. 进程占用的虚拟内存大小,包括了swap out的内存page;
?
RES: Resident size (kb)。The non-swapped physical memory a task is using. 进程使用的常驻内存大小,没有包括swap out的内存;
?
SHR:Shared Mem size (kb)。The amount of shared memory used by a task. ?It simply reflects memory that could be potentially shared
?
? ? ? ? ?with other processes. 其实应该就是使用 shmget() 系统调用分配的共享内存,可以在多个进程之间共享访问。
?
S: 表示进程处于哪种状态:R: Running; S: sleeping; T: stoped; D: interrupted; Z:zomobie;
?
%CPU: 进程占用的CPU;
?
%MEM:进程占用的内存;
?
%TIME+: 进程运行时间;
?
COMMAND: 进程运行命令;
?
读懂 top 等相关命令行的信息是进行调优的基础。其实这些命令行的输出的含义,在man top中都有是否详细的说明。只要耐心看手册就行了。
?
上面的 top 命令默认是以 进程为单位来显示的,我们也可以以线程为单位来显示: top -H
可以看到以线程为单位是,Tasks totol数量明显增加了,有92增加到了 134,因为 mysqld 是线程架构的,后台有多个后台线程。
?
如果仅仅想查看 CPU 的 load average,使用uptime命令就行了:
?
[root@localhost ~]# uptime
?15:26:59 up ?1:15, ?4 users, ?load average: 0.00, 0.02, 0.00
?
3.2 vmstat 查看CPU 信息
上面各个字段的含义:
?
?
FIELD DESCRIPTION FOR VM MODE
   Procs
       r: The number of processes waiting for run time.
       b: The number of processes in uninterruptible sleep.
   Memory
       swpd: the amount of virtual memory used.
       free: the amount of idle memory.
       buff: the amount of memory used as buffers.
       cache: the amount of memory used as cache.
       inact: the amount of inactive memory. (-a option)
       active: the amount of active memory. (-a option)
   Swap
       si: Amount of memory swapped in from disk (/s).
       so: Amount of memory swapped to disk (/s).
   IO
       bi: Blocks received from a block device (blocks/s).
       bo: Blocks sent to a block device (blocks/s).
   System
       in: The number of interrupts per second, including the clock.
       cs: The number of context switches per second.
   CPU
       These are percentages of total CPU time.
       us: Time spent running non-kernel code. (user time, including nice time)
       sy: Time spent running kernel code. (system time)
       id: Time spent idle. Prior to Linux 2.5.41, this includes IO-wait time.
       wa: Time spent waiting for IO. Prior to Linux 2.5.41, included in idle.
       st: Time stolen from a virtual machine. Prior to Linux 2.6.11, unknown.

?

和CPU相关的信息有 user time, system time, idle time, wait time, steal time;
?
另外提供了关于中断和上下文切换的信息。System 中的in,表示每秒的中断数,cs表示每秒的上下文切换数;
?
其它的字段是关于内存和磁盘的。
?
3.3 iostat 命令查看 CPU 信息
?
[root@localhost ~]# iostat
Linux 2.6.32-504.el6.i686 (localhost.localdomain)       09/30/2015      _i686_  (1 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.27    0.02    4.74    0.28    0.00   94.69

Device:            tps   Blk_read/s   Blk_wrtn/s   Blk_read   Blk_wrtn
scd0              0.01         0.08         0.00        536          0
sda               1.64        42.27         8.97     290966      61720
[root@localhost ~]# iostat -c
Linux 2.6.32-504.el6.i686 (localhost.localdomain)       09/30/2015      _i686_  (1 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.26    0.02    4.72    0.27    0.00   94.72

?

?
提供了cpu的平均使用率。
?
3.4 ps 命令查看某个进程和某个线程的 CPU 信息
?
比如我想查看 mysqld 的相关信息:
[root@localhost ~]# pidof mysqld
2412
首页 上一页 1 2 3 4 下一页 尾页 3/4/4
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇MySQL 调优基础(四) Linux 磁盘IO 下一篇卸载MySQL5.0

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: