【问题标题】:How to interpret go pprof/mutex showing waiting on Unlock?如何解释 go pprof/mutex 显示等待解锁?
【发布时间】:2018-12-16 07:52:27
【问题描述】:

我正在优化 Go 程序的性能。在查看互斥量分析时,我得到了

> go tool pprof -seconds 30 -ignore .*Shopify.*  http://HOST/debug/pprof/mutex
(pprof) top 20
Active filters:
ignore=.*Shopify.*
Showing nodes accounting for 3.08mins, 91.03% of 3.39mins total
Dropped 82 nodes (cum <= 0.02mins)
    flat  flat%   sum%        cum   cum%
3.08mins 91.03% 91.03%   3.08mins 91.03%  sync.(*Mutex).Unlock
       0     0% 91.03%   0.06mins  1.75%  ....func2
       0     0% 91.03%   0.06mins  1.75%  ....func3

代码sn-p是

     .          .    502:    w.mu.Lock()

     .          .    ... some calculation

     .   5.02mins    510:    w.mu.Unlock()
     .          .    511:
     .          .    512:    return nil
     .          .    513:}

我不明白的是:

  • 为什么互斥量分析显示只有前 1 个有 flat 时间,其余的都是 0
  • 如果显示在Lock 上等待,则可能意味着计算时间过长,但在Unlock 上显示等待是什么意思?

【问题讨论】:

    标签: go pprof


    【解决方案1】:

    为了回答您的第二个问题,互斥锁配置文件始终在 Unlock 路径上显示结果,而从不在 Lock [1] 上显示结果。您的个人资料表明大多数争用发生在w.mu

    This document 包含更多细节。

    [1] 实现细节:原因是Unlock 将锁交给了下一个等待的locker,并且此时争用记录在配置文件中。因此,堆栈跟踪似乎位于 Unlock 路径中。

    【讨论】:

      猜你喜欢
      • 2015-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多