explain

锁竞争导致CPU占用过高

当多个线程争用同一把锁时,CPU会消耗在同步开销上,而不是用于实际的有效工作。

Evidence to look for

perf 在热点调用栈中显示互斥锁或自旋锁相关函数
增加线程数反而会让延迟更高
并发度提升时,单笔事务的CPU消耗上升

What it usually means

系统正在将CPU周期消耗在等待锁上,而不是执行有用的工作。并发度越高,问题越严重,不会因此变好。

What to do next

  1. 1缩小临界区范围
  2. 2减少共享状态的访问
  3. 3在热点路径上考虑使用无锁数据结构

See what's causing your CPU

cpum.ai turns CPU, process, disk, and memory signals into plain-English explanations with evidence.

Open cpum.ai

Related

锁竞争导致CPU占用过高 | cpum.ai