Browse Source

Add -cpus option

Ask Bjørn Hansen 12 years ago
parent
commit
37d856bd98
2 changed files with 15 additions and 1 deletions
  1. 7 1
      README.md
  2. 8 0
      geodns.go

+ 7 - 1
README.md

@@ -85,7 +85,13 @@ cluster the server is part of, etc. This is used in (future) reporting/statistic
 
 * -log=false
 
-Enable to get lots of extra logging, only useful for testing and debugging.
+Enable to get lots of extra logging, only useful for testing and debugging. Absolutely not
+recommended in production unless you get very few queries (less than 1-200/second).
+
+* -cpus=1
+
+Maximum number of CPUs to use. Set to 0 to match the number of CPUs available on the system.
+Only "1" (the default) has been extensively tested.
 
 ## WebSocket interface
 

+ 8 - 0
geodns.go

@@ -24,6 +24,7 @@ import (
 	"os"
 	"os/signal"
 	"path/filepath"
+	"runtime"
 	"runtime/pprof"
 	"strings"
 	"time"
@@ -46,6 +47,7 @@ var (
 	flagport        = flag.String("port", "53", "default port number")
 	flaghttp        = flag.String("http", ":8053", "http listen address (:8053)")
 	flaglog         = flag.Bool("log", false, "be more verbose")
+	flagcpus        = flag.Int("cpus", 1, "Set the maximum number of CPUs to use")
 
 	cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
 	memprofile = flag.String("memprofile", "", "write memory profile to this file")
@@ -92,6 +94,12 @@ func main() {
 		return
 	}
 
+	if *flagcpus == 0 {
+		runtime.GOMAXPROCS(runtime.NumCPU())
+	} else {
+		runtime.GOMAXPROCS(*flagcpus)
+	}
+
 	log.Printf("Starting geodns %s\n", VERSION)
 
 	if *cpuprofile != "" {