调优的目的是突破性能瓶颈性能监测的目的是测试瓶颈在哪里不同的硬件, 不同的系统, 不同的应用, 优化的重点 / 参数 / 方法都是不一样的
对于 mysql 而言, 调优也要从这三方面入手: 硬件 / 系统 / mysql 应用
1 硬件基础
1.1 cpu-NUMA 架构
在 NUMA 出现之前, cpu 的所有 core 共享一个北桥来访问内存 cpu 向多核多 socket 发展之后, 总线争用问题就变得很突出, 北桥的响应时间变长所以北桥中的内存控制器被拆分, 出现了 NUMA 架构 (non-uniform memory access 非统一型内存访问) 架构
NUMA 相关概念: node 是一个逻辑概念, 对应服务器上物理的 socket
NUMA 基本理解: 一个 node 中有多个 core, 多个 core 共用一个内存控制器 core 访问 local memery 速度较快 node 之间通过互联模块, 可以使 core 访问 remote memery, 但是速度较慢如果一台四路服务器, 就有 4 个 node,core 可以访问的 remote memery 有三个, 访问速度与节点距离有关, 称为 node distance
1.2 进程
进程运行在 cpu 上, 是硬件资源分配的对象
进程的生命周期和调用: 父进程 fork 子进程, 子进程执行代码然后返回信息给父进程, 父进程回收相关资源
进程优先级: 进程调度涉及优先级(nice level), 范围是 19~-20, 值越小, nice 越大, 默认为 0 如果调高 nice 值, 进程被调度的频率就会下降, 对 cpu 的争抢就会减少
context switch 和中断:: 一个进程原在 cpu 中运行, 现被中断, 进程被刷到内存中另一个进程切换到 cpu 中运行
1.3 linux 下的 cpu 调度
user time: 用户空间的 cpu 时间(未使用 nice 调度)
system time: 系统内核程序的 cpu 时间
nice time: 用户空间中经过 nice 调度的 cpu 时间
idel time: 空闲 cpu 时间
wait time:cpu 运行时在等磁盘 io 的时间
1.4 Load average: the average of the sum of TASK_RUNNING(running or in the running queue) and TASK_UNINTERRUPTIBLE(不被中断, 等待 io 完成) 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.
来源: http://www.bubuko.com/infodetail-2535002.html