设为首页 加入收藏

TOP

MySQL 调优基础(一) CPU与进程(二)
2015-11-21 01:38:18 来源: 作者: 【 】 浏览:1
Tags:MySQL 基础 CPU 进程
tain signals (for example SIGINT, SIGSTOP) is in this state. The process is waiting to be
?
? ? ?resumed by a signal such as SIGCONT.
?
3)TASK_INTERRUPTIBLE: In this state, the process is suspended and waits for a certain condition to be satisfied. If a process is in
?
? ? ?TASK_INTERRUPTIBLE state and it receives a signal to stop, the process state is changed and operation will be interrupted. A typical
?
? ? ?example of a TASK_INTERRUPTIBLE process is a process waiting for keyboard interrupt.
?
4)TASK_UNINTERRUPTIBLE: Similar to TASK_INTERRUPTIBLE. While a process in TASK_INTERRUPTIBLE state can be interrupted,?
?
? ? ?sending a signal does nothing to the process in TASK_UNINTERRUPTIBLE state. A typical example of a TASK_UNINTERRUPTIBLE
?
? ? ?process is a process waiting for disk I/O operation.
?
5)TASK_ZOMBIE: After a process exits with exit() system call, its parent should know of the termination. In TASK_ZOMBIE state, a
?
? ? ?process is waiting for its parent to be notified to release all the data structure.
?
除了 TASK_RUNNING 中的进程可能在运行之外,其它状态的进程都没有在运行。但是其实 TASK_UNINTERRUPTIBLE 比较特殊,它其实可以看做是在运行的,因为他是在等待磁盘操作完成,所以其实从系统的角度,而不是从进程的角度而言,其实系统是在为进程运行的。这也就是为什么 load average 中的数值,是包括了 TASK_RUNNING 和 TASK_UNINTERRUPTIBLE 两种状态的进程的平均值。
?
进程如何使用内存:
?
进程的运行,必须申请和使用内存,最重要的包括堆和栈:
进程使用的内存,可以用 pmap, ps 等待命令行来查看。在后面会有站么的内存调优文章介绍。
?
CPU 调度:
?
前面介绍了CPU的调度涉及到进程的优先级和nice level. Linux中进程的调度算法是 O(1)的,所以进程数量的多少不会影响进程调度的效率。
?
进程的调度涉及到两个优先级数组(优先级队列):active, expired 。CPU按照优先级调度 active 队列中的进程,队列中所有进程调度完成之后,交换active队列和expired队列,继续调度。
?
NUMA架构的CPU在调度时,一般不会垮node节点进行调度,除非一个node节点CPU超载了并且请求进行负载均衡。因为垮node节点CPU调度影响性能。
?
3. Linux 如何度量 CPU?
?
1)CPU utilization:最直观最重要的就是CPU的使用率。如果长期超过80%,则表明CPU遇到了瓶颈;
?
2)User time: 用户进程使用的CPU;该数值越高越好,表明越多的CPU用在了用户实际的工作上
?
3)System time: 内核使用的CPU,包括了硬中断、软中断使用的CPU;该数值越低越好,太高表明在网络和驱动层遇到瓶颈;
?
4)Waiting: CPU花在等待IO操作上的时间;该数值很高,表明IO子系统遇到瓶颈;
?
5)Idel time: CPU空闲的时间;
?
6)Load average: the average of the sum of TASK_RUNNING and TASK_UNINTERRUPTIBLE processes. If processes that request CPU time are blocked (which means that the CPU has no time to process them), the load average will increase. On the other hand, if each?
process gets immediate access to CPU time and there are no CPU cycles lost, the load will decrease.
?
7)Context Switch: 上下文切换;
?
如何检测CPU:
?
检测CPU使用情况最好的工具是 top 命令:
?
3.1 top 命令 查看CPU 信息
要调优,那么就必须读懂 很多 命令行工具的输出。上面的top命令包括了很多的信息:
?
第一行:
?
top - 14:35:55 up 25 min, 4 users, ? load average: 0.10, 0.07, 0.14
?
分别表示的是:当前系统时间;up 25 min表示已经系统已经运行25分钟; 4 users:表示系统中有4个登录用户;
?
load average: 分别表示最近 1 分钟, 5 分钟, 15分钟 CPU的负载的平均值。
?
(load average: the average of the sum of TASK_RUNNING and TASK_UNINTERRUPTIBLE processes);
?
这一行最重要的就是 load average
?
第二行:
?
Tasks: 92 total, ?1 running, 91 sleeping , 0 stopped, 0 zombie
?
分别表示系统中的进程数:总共92个进程, 1个在运行,91个在sleep,0个stopped, 0个僵尸;
?
第三行:
?
Cpu(s): 0.0%us, ?1.7 %sy, 0.0%ni, 97.7%id, 0.0%wa, 0.3%hi, 0.3%si, 0.0%st
?
这一行提供了关于CPU使用率的最重要的信息,分别表示 users time, system time, nice time, idle time, wait time, hard interrupte time, soft interrupted time, steal time; 其中最终要的是:users time, system time, wait time ,idle time 等等。nice time 表示用于调准进程nice level所花的时间。
?
第四行:
?
Mem: ?total, used ,free, buffers
首页 上一页 1 2 3 4 下一页 尾页 2/4/4
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇MySQL 调优基础(四) Linux 磁盘IO 下一篇卸载MySQL5.0

评论

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