summaryrefslogtreecommitdiffhomepage
path: root/gobgpd
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-09-02 22:56:23 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-09-02 22:56:23 +0900
commit148ad5969714bb923d34971f1885d20381d81206 (patch)
treef0fb5bad9df11bd6009cd7e4d7ef60a020a4e06f /gobgpd
parentd83a16ed00cd1e3617fe06d9a1b1a1002406ccef (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.go13
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)