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

Report GCP profiles from zoekt-git-index #816

Merged
merged 3 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions cmd/zoekt-git-index/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"runtime/pprof"
"strings"

"github.com/sourcegraph/zoekt"
"github.com/sourcegraph/zoekt/internal/profiler"
"go.uber.org/automaxprocs/maxprocs"

"github.com/sourcegraph/zoekt/cmd"
Expand Down Expand Up @@ -70,6 +72,7 @@ func run() int {
}
*repoCacheDir = dir
}

opts := cmd.OptionsFromFlags()
opts.IsDelta = *isDelta
opts.DocumentRanksPath = *offlineRanking
Expand Down Expand Up @@ -107,6 +110,7 @@ func run() int {
opts.LanguageMap[m[0]] = ctags.StringToParser(m[1])
}

profiler.InitLightweight("zoekt-git-index", zoekt.Version)
Copy link
Member

Choose a reason for hiding this comment

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

What's the reasoning for having a separate profiler config? Is mutex profiling polluting zoekt-git-index and that's not the case for webserver or indexserver?

Copy link
Member

Choose a reason for hiding this comment

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

Agreed, interesting in why we need a lighterweight indexing config here. Given this will only trigger for slower runs of zoekt-git-index, more info seems useful?

Copy link
Member Author

@jtibshirani jtibshirani Sep 9, 2024

Choose a reason for hiding this comment

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

The thing I found concerning was AllocForceGC: true. If I'm understanding correctly, it means that enabling profiling could significantly impact memory usage (lower peak usage due to more frequent GCs). So you could have weird things like "we switched off the GCP profiler and now memory usage is much higher."

However, it looks like we do this all over the place, including sg/sg, and I haven't heard of a problem. I'm probably just scarred from my Java days where WAY more stuff is on the heap and GC behavior is very core to memory usage.

I'll remove InitLightweight!

exitStatus := 0
for dir, name := range gitRepos {
opts.RepositoryDescription.Name = name
Expand Down
2 changes: 1 addition & 1 deletion cmd/zoekt-sourcegraph-indexserver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1277,7 +1277,7 @@ func startServer(conf rootConfig) error {
return err
}

profiler.Init("zoekt-sourcegraph-indexserver", zoekt.Version, conf.blockProfileRate)
profiler.Init("zoekt-sourcegraph-indexserver", zoekt.Version)
setCompoundShardCounter(s.IndexDir)

if conf.listen != "" {
Expand Down
2 changes: 1 addition & 1 deletion cmd/zoekt-webserver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func main() {
liblog := sglog.Init(resource)
defer liblog.Sync()
tracer.Init(resource)
profiler.Init("zoekt-webserver", zoekt.Version, -1)
profiler.Init("zoekt-webserver", zoekt.Version)

if *logDir != "" {
if fi, err := os.Lstat(*logDir); err != nil || !fi.IsDir() {
Expand Down
16 changes: 15 additions & 1 deletion internal/profiler/profiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

// Init starts the supported profilers IFF the environment variable is set.
func Init(svcName, version string, blockProfileRate int) {
func Init(svcName, version string) {
jtibshirani marked this conversation as resolved.
Show resolved Hide resolved
if os.Getenv("GOOGLE_CLOUD_PROFILER_ENABLED") != "" {
err := profiler.Start(profiler.Config{
Service: svcName,
Expand All @@ -21,3 +21,17 @@ func Init(svcName, version string, blockProfileRate int) {
}
}
}

// InitLightweight starts the supported profilers IFF the environment variable is set.
// Compared to Init, it disables mutex profiling and forced GC to reduce its overhead.
jtibshirani marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

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

I actually don't know why we do AllocForceGC given the default is off. I wonder if it has a measurable impact on our perf. I suspect not. Then it makes sense. Why don't we use it for zoekt-git-index then?

func InitLightweight(svcName, version string) {
if os.Getenv("GOOGLE_CLOUD_PROFILER_ENABLED") != "" {
err := profiler.Start(profiler.Config{
Service: svcName,
ServiceVersion: version,
})
if err != nil {
log.Printf("could not initialize profiler: %s", err.Error())
}
}
}
Loading