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

Set Go Max procs in a better location #2147

Merged
merged 4 commits into from
Apr 2, 2015
Merged
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
14 changes: 10 additions & 4 deletions cmd/influxd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ func main() {
commit = "unknown"
}

// Set parallelism.
runtime.GOMAXPROCS(runtime.NumCPU())
log.Printf("GOMAXPROCS set to %d", runtime.GOMAXPROCS(0))

// Shift binary name off argument list.
args := os.Args[1:]

Expand Down Expand Up @@ -78,11 +74,13 @@ func main() {
case "":
execRun(args)
case "backup":
setGoMaxProcs()
Copy link
Contributor

Choose a reason for hiding this comment

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

Do backup and restore really benefit from this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good question for @benbjohnson. Not sure if more procs helps out with any of the system packages we depend on.

Copy link
Contributor

Choose a reason for hiding this comment

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

Minor: why do it in the switch statement for some cases, but then do it explicitly in execRun for that case?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it's necessary. Backup & restore is single threaded since it builds a tar archive sequentially.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@otoolep looks like we can remove it from everywhere but run. However, the reason I didn't put it in the switch statement for the run is it printed above the logo, and felt out of place. I'll just leave that in the run and remove all of them from the switch, as well as the actual function now that we are clear on the use case.

cmd := NewBackupCommand()
if err := cmd.Run(args[1:]...); err != nil {
log.Fatalf("backup: %s", err)
}
case "restore":
setGoMaxProcs()
cmd := NewRestoreCommand()
if err := cmd.Run(args[1:]...); err != nil {
log.Fatalf("restore: %s", err)
Expand All @@ -98,6 +96,12 @@ func main() {
}
}

func setGoMaxProcs() {
// Set parallelism.
runtime.GOMAXPROCS(runtime.NumCPU())
log.Printf("GOMAXPROCS set to %d", runtime.GOMAXPROCS(0))
}

// execRun runs the "run" command.
func execRun(args []string) {
// Parse command flags.
Expand All @@ -121,6 +125,8 @@ func execRun(args []string) {
fmt.Print(logo)
writePIDFile(*pidPath)

setGoMaxProcs()

// Parse configuration file from disk.
config, err := parseConfig(*configPath, *hostname)
if err != nil {
Expand Down