gpt4 book ai didi

go - 如何解释 go pprof/mutex 显示等待解锁?

转载 作者:行者123 更新时间:2023-12-03 17:03:35 25 4
gpt4 key购买 nike

我正在优化 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

代码片段是
     .          .    502:    w.mu.Lock()

. . ... some calculation

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

我不明白的是:
  • 为什么互斥量分析显示只有前 1 个有 flat时间,剩下的都是0 ?
  • 如果显示正在等待 Lock那么它可能意味着计算时间太长,但是当它显示等待 Unlock 时是什么意思? ?
  • 最佳答案

    要回答您的第二个问题,互斥锁配置文件总是在 Unlock 上显示结果。路径,并且永远不会在 Lock [1]。您的个人资料表明大多数争用发生在 w.mu .
    This document包含更多细节。
    [1] 实现细节:原因是Unlock将锁交给下一个等待的储物柜,此时争用记录在配置文件中。因此堆栈跟踪似乎在 Unlock 中。小路。

    关于go - 如何解释 go pprof/mutex 显示等待解锁?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53800407/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com