Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pprof should be initialized only once per process #502

Merged
merged 2 commits into from
Jan 11, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions common/service/config/pprof.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ package config
import (
"fmt"
"net/http"
"sync/atomic"
// DO NOT REMOVE THE LINE BELOW
_ "net/http/pprof"

Expand All @@ -37,6 +38,15 @@ type (
}
)

const (
pprofNotInitialized int32 = 0
pprofInitialized int32 = 1
)

// the pprof should only be initialized once per process
// otherwise, the caller / worker will experience weird issue
var pprofStatus = pprofNotInitialized

// NewInitializer create a new instance of PProf Initializer
func (cfg *PProf) NewInitializer(logger bark.Logger) *PProfInitializerImpl {
return &PProfInitializerImpl{
Expand All @@ -53,10 +63,11 @@ func (initializer *PProfInitializerImpl) Start() error {
return nil
}

go func() {
initializer.Logger.Info("PProf listen on %d", port)
http.ListenAndServe(fmt.Sprintf("localhost:%d", port), nil)
}()

if atomic.CompareAndSwapInt32(&pprofStatus, pprofNotInitialized, pprofInitialized) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the situation where Start can be called multiple times?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

./cadence start, i.e. local run

go func() {
initializer.Logger.Infof("PProf listen on %d", port)
http.ListenAndServe(fmt.Sprintf("localhost:%d", port), nil)
}()
}
return nil
}