- 1、本文档共15页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
性能测试分析之CPU篇
目录
Linux系统结构简介
用户态CPU消耗分析
内核态CPU消耗分析
硬中断软中断
Load average剖析
Linux系统结构
Linux系统结构
几种CPU消耗
Us%
user cpu time (or) % CPU time spent in user space
Sy%
system cpu time (or) % CPU time spent in kernel space
Ni%
user nice cpu time (or) % CPU time spent on low priority processes
Id%
idle cpu time (or) % CPU time spent idle
Wa%
io wait cpu time (or) % CPU time spent in wait (on disk)
Hi%
hardware irq (or) % CPU time spent servicing/handling hardware interrupts
Si%
software irq (or) % CPU time spent servicing/handling software interrupts
St%
steal time - - % CPU time in involuntary wait by virtual cpu while hypervisor is servicing another processor (or) % CPU time stolen from a virtual machine
CPU调度
用户态CPU
例1:程序cpu usr%瓶颈问题定位。
模拟程序TestMap
主线程:死循环阻塞
线程1: sleep
线程2 : 循环map find操作
执行命令:top –H –p 7152
用户态CPU
执行命令:pstack 7152
分析过程:
通过top –H –p XX 发现线程7153占用cpu特别高
通过pstack 发现线程7153在做map查询操作,大量的红黑树查找操作。
用户态CPU
例2:程序cpu usr%瓶颈问题定位。(如果线程cpu消耗比较均衡)
执行:perf top -p 7152 -e cycles:u
参考案例:VTDU因CPU消耗过高回滚
内核态CPU
例3:定位sy%消耗过高问题
执行:perf top -p xxxx -e cycles:k
内核态CPU
上下文切换(只会发生在内核态)
当前执行任务时间片用完,cpu正常调度下一个任务。
I/O阻塞
抢占锁资源,用户代码挂起(sleep),等待条件变量
硬中断软中断
例4:程序问题造成大量的上下文切换
执行:TestCsw程序
开启100个线程,每个线程usleep(1*1000)
硬中断软中断
网卡中断为例:
频繁的数据包收发会耗尽cpu时间
多核cpu,如何做中断负载均衡?
多队列网卡: 只需配置每个队列的cpu亲和性,smp_affinity。
单队列网卡: 先通过RPS模拟出多队列再最cpu亲和性。
RPS:根据数据包源地址、目的地址和源端口做hash,来选择不同cpu。
RFS: RPS负载均衡的优化。
Load average剖析
load average???
System load averages is the average number of processes that are either in a runable or uninterruptable state. ?A process in a runnable state is either using the CPU or waiting to use the CPU. ?A ?process ?in??uninterruptable state is waiting for some I/O access,??eg??waiting for disk. ?The averages are taken over the three time intervals. ?Load averages are not normalized for the number of CPUs in a system, so a load??average of 1 means a single CPU system is loaded all the time while on a 4 CPU system it means it was idle 75% of the time.??
进程状态
Load average剖析
例5:TASK_UNINTERRUPTIB
文档评论(0)