diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-09-02 22:56:23 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-09-02 22:56:23 +0900 |
commit | 148ad5969714bb923d34971f1885d20381d81206 (patch) | |
tree | f0fb5bad9df11bd6009cd7e4d7ef60a020a4e06f /gobgpd | |
parent | d83a16ed00cd1e3617fe06d9a1b1a1002406ccef (diff) |
gobgpd: add command line option to specify #CPUs to be used
--cpus option can be used to specify to the number of CPUs to be
used. IOW, the specified number is passed to runtime.GOMAXPROCS().
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'gobgpd')
-rw-r--r-- | gobgpd/main.go | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/gobgpd/main.go b/gobgpd/main.go index bc274e6e..0ad19255 100644 --- a/gobgpd/main.go +++ b/gobgpd/main.go @@ -32,8 +32,6 @@ import ( ) func main() { - runtime.GOMAXPROCS(runtime.NumCPU()) - sigCh := make(chan os.Signal, 1) signal.Notify(sigCh, syscall.SIGHUP, syscall.SIGTERM) @@ -46,12 +44,23 @@ func main() { DisableStdlog bool `long:"disable-stdlog" description:"disable standard logging"` EnableZapi bool `short:"z" long:"enable-zapi" description:"enable zebra api"` ZapiURL string `long:"zapi-url" description:"specify zebra api url"` + CPUs int `long:"cpus" description:"specify the number of CPUs to be used"` } _, err := flags.Parse(&opts) if err != nil { os.Exit(1) } + if opts.CPUs == 0 { + runtime.GOMAXPROCS(runtime.NumCPU()) + } else { + if runtime.NumCPU() < opts.CPUs { + log.Errorf("Only %d CPUs are available but %d is specified", runtime.NumCPU(), opts.CPUs) + os.Exit(1) + } + runtime.GOMAXPROCS(opts.CPUs) + } + switch opts.LogLevel { case "debug": log.SetLevel(log.DebugLevel) |