Merge pull request #173 from vmarmol/master
Allow cAdvisor to use as many cores as exist on the machine.
This commit is contained in:
commit
78cb882ebd
22
cadvisor.go
22
cadvisor.go
@ -18,6 +18,7 @@ import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"runtime"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"github.com/google/cadvisor/api"
|
||||
@ -30,12 +31,15 @@ import (
|
||||
)
|
||||
|
||||
var argPort = flag.Int("port", 8080, "port to listen")
|
||||
var maxProcs = flag.Int("max_procs", 0, "max number of CPUs that can be used simultaneously. Less than 1 for default (number of cores).")
|
||||
|
||||
var argDbDriver = flag.String("storage_driver", "memory", "storage driver to use. Options are: memory (default) and influxdb")
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
setMaxProcs()
|
||||
|
||||
storageDriver, err := NewStorageDriver(*argDbDriver)
|
||||
if err != nil {
|
||||
glog.Fatalf("Failed to connect to database: %s", err)
|
||||
@ -93,3 +97,21 @@ func main() {
|
||||
|
||||
glog.Fatal(http.ListenAndServe(addr, nil))
|
||||
}
|
||||
|
||||
func setMaxProcs() {
|
||||
// TODO(vmarmol): Consider limiting if we have a CPU mask in effect.
|
||||
// Allow as many threads as we have cores unless the user specified a value.
|
||||
var numProcs int
|
||||
if *maxProcs < 1 {
|
||||
numProcs = runtime.NumCPU()
|
||||
} else {
|
||||
numProcs = *maxProcs
|
||||
}
|
||||
runtime.GOMAXPROCS(numProcs)
|
||||
|
||||
// Check if the setting was successful.
|
||||
actualNumProcs := runtime.GOMAXPROCS(0)
|
||||
if actualNumProcs != numProcs {
|
||||
glog.Warningf("Specified max procs of %v but using %v", numProcs, actualNumProcs)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user