How to Identify and Diagnose Goroutine Leaks Using Pprof?

Mary-Kate Olsen
Release: 2024-10-26 19:54:02
Original
883 people have browsed it

How to Identify and Diagnose Goroutine Leaks Using Pprof?

How to Profile Number of Goroutines

Monitoring goroutine count can aid in detecting potential leaks. Pprof offers methods to display this information.

To view goroutine count over time, navigate to http://localhost:8888/debug/pprof/. Two relevant options are available:

goroutine (http://localhost:8888/debug/pprof/goroutine?debug=1)

This view groups goroutines that execute the same code and displays their count. For instance:

1 @ 0x42f223 0x42f2e4 0x40542f 0x404f4b 0x4a0586 0x4600a1
#   0x4a0586    gitlab.com/gitlab-org/gitlab-ci-multi-runner/commands.(*RunCommand).startWorkers+0x56   /home/me/go/src/gitlab.com/gitlab-org/gitlab-ci-multi-runner/commands/multi.go:164

1 @ 0x42f223 0x43dfd7 0x43d532 0x4a04ed 0x4600a1
#   0x4a04ed    gitlab.com/gitlab-org/gitlab-ci-multi-runner/commands.(*RunCommand).processRunners+0x45d    /home/me/go/src/gitlab.com/gitlab-org/gitlab-ci-multi-runner/commands/multi.go:147
Copy after login

full goroutine stack dump (http://localhost:8888/debug/pprof/goroutine?debug=2)

This provides a comprehensive overview of each goroutine, including its stack trace and current activity (e.g., waiting to receive from a channel). It is particularly useful for identifying leaks:

goroutine 49 [chan receive, 2 minutes]:
gitlab.com/gitlab-org/gitlab-ci-multi-runner/commands.(*RunCommand).startWorkers(0xc820103ee0, 0xc820274000, 0xc820274060, 0xc8201d65a0)
    /home/me/go/src/gitlab.com/gitlab-org/gitlab-ci-multi-runner/commands/multi.go:164 +0x56
created by gitlab.com/gitlab-org/gitlab-ci-multi-runner/commands.(*RunCommand).Run
    /home/me/go/src/gitlab.com/gitlab-org/gitlab-ci-multi-runner/commands/multi.go:294 +0x41b

goroutine 50 [select]:
gitlab.com/gitlab-org/gitlab-ci-multi-runner/commands.(*RunCommand).processRunners(0xc820103ee0, 0x0, 0xc820274060, 0xc8201d65a0)
    /home/me/go/src/gitlab.com/gitlab-org/gitlab-ci-multi-runner/commands/multi.go:147 +0x45d
created by gitlab.com/gitlab-org/gitlab-ci-multi-runner/commands.(*RunCommand).startWorkers
    /home/me/go/src/gitlab.com/gitlab-org/gitlab-ci-multi-runner/commands/multi.go:165 +0x96
Copy after login

The above is the detailed content of How to Identify and Diagnose Goroutine Leaks Using Pprof?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!