Преглед на файлове

etcdmain: explicitly set gomaxprocs and log its value

Prashanth Balasubramanian преди 10 години
родител
ревизия
1e15b05e4c
променени са 1 файла, в които са добавени 9 реда и са изтрити 0 реда
  1. 9 0
      etcdmain/etcd.go

+ 9 - 0
etcdmain/etcd.go

@@ -23,6 +23,8 @@ import (
 	"os"
 	"os"
 	"path"
 	"path"
 	"reflect"
 	"reflect"
+	"runtime"
+	"strconv"
 	"time"
 	"time"
 
 
 	"github.com/coreos/etcd/discovery"
 	"github.com/coreos/etcd/discovery"
@@ -70,6 +72,13 @@ func Main() {
 
 
 	var stopped <-chan struct{}
 	var stopped <-chan struct{}
 
 
+	GoMaxProcs := 1
+	if envMaxProcs, err := strconv.Atoi(os.Getenv("GOMAXPROCS")); err == nil {
+		GoMaxProcs = envMaxProcs
+	}
+	log.Printf("main: setting maximum number of CPUs to %d, total number of available CPUs is %d", GoMaxProcs, runtime.NumCPU())
+	runtime.GOMAXPROCS(GoMaxProcs)
+
 	// TODO: check whether fields are set instead of whether fields have default value
 	// TODO: check whether fields are set instead of whether fields have default value
 	if cfg.name != defaultName && cfg.initialCluster == initialClusterFromName(defaultName) {
 	if cfg.name != defaultName && cfg.initialCluster == initialClusterFromName(defaultName) {
 		cfg.initialCluster = initialClusterFromName(cfg.name)
 		cfg.initialCluster = initialClusterFromName(cfg.name)