aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--coredns.1.md3
-rw-r--r--coremain/run.go44
-rw-r--r--coremain/run_test.go44
3 files changed, 0 insertions, 91 deletions
diff --git a/coredns.1.md b/coredns.1.md
index 6fe61e388..4784e9697 100644
--- a/coredns.1.md
+++ b/coredns.1.md
@@ -24,9 +24,6 @@ Available options:
: specify Corefile to load, if not given CoreDNS will look for a `Corefile` in the current
directory.
-**-cpu** **CAP**
-: specify maximum CPU capacity in percent.
-
**-dns.port** **PORT**
: override default port (53) to listen on.
diff --git a/coremain/run.go b/coremain/run.go
index e6f51295f..5f3b610bd 100644
--- a/coremain/run.go
+++ b/coremain/run.go
@@ -2,14 +2,12 @@
package coremain
import (
- "errors"
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"runtime"
- "strconv"
"strings"
"github.com/coredns/coredns/core/dnsserver"
@@ -24,7 +22,6 @@ func init() {
setVersion()
flag.StringVar(&conf, "conf", "", "Corefile to load (default \""+caddy.DefaultConfigFile+"\")")
- flag.StringVar(&cpu, "cpu", "100%", "CPU cap")
flag.BoolVar(&plugins, "plugins", false, "List installed plugins")
flag.StringVar(&caddy.PidFile, "pidfile", "", "Path to write pid file")
flag.BoolVar(&version, "version", false, "Show version")
@@ -73,11 +70,6 @@ func Run() {
os.Exit(0)
}
- // Set CPU cap
- if err := setCPU(cpu); err != nil {
- mustLogFatal(err)
- }
-
// Get Corefile input
corefile, err := caddy.LoadCaddyfile(serverType)
if err != nil {
@@ -194,45 +186,9 @@ func setVersion() {
}
}
-// setCPU parses string cpu and sets GOMAXPROCS
-// according to its value. It accepts either
-// a number (e.g. 3) or a percent (e.g. 50%).
-func setCPU(cpu string) error {
- var numCPU int
-
- availCPU := runtime.NumCPU()
-
- if strings.HasSuffix(cpu, "%") {
- // Percent
- var percent float32
- pctStr := cpu[:len(cpu)-1]
- pctInt, err := strconv.Atoi(pctStr)
- if err != nil || pctInt < 1 || pctInt > 100 {
- return errors.New("invalid CPU value: percentage must be between 1-100")
- }
- percent = float32(pctInt) / 100
- numCPU = int(float32(availCPU) * percent)
- } else {
- // Number
- num, err := strconv.Atoi(cpu)
- if err != nil || num < 1 {
- return errors.New("invalid CPU value: provide a number or percent greater than 0")
- }
- numCPU = num
- }
-
- if numCPU > availCPU {
- numCPU = availCPU
- }
-
- runtime.GOMAXPROCS(numCPU)
- return nil
-}
-
// Flags that control program flow or startup
var (
conf string
- cpu string
logfile bool
version bool
plugins bool
diff --git a/coremain/run_test.go b/coremain/run_test.go
deleted file mode 100644
index da01637d8..000000000
--- a/coremain/run_test.go
+++ /dev/null
@@ -1,44 +0,0 @@
-package coremain
-
-import (
- "runtime"
- "testing"
-)
-
-func TestSetCPU(t *testing.T) {
- currentCPU := runtime.GOMAXPROCS(-1)
- maxCPU := runtime.NumCPU()
- halfCPU := int(0.5 * float32(maxCPU))
- if halfCPU < 1 {
- halfCPU = 1
- }
- for i, test := range []struct {
- input string
- output int
- shouldErr bool
- }{
- {"1", 1, false},
- {"-1", currentCPU, true},
- {"0", currentCPU, true},
- {"100%", maxCPU, false},
- {"50%", halfCPU, false},
- {"110%", currentCPU, true},
- {"-10%", currentCPU, true},
- {"invalid input", currentCPU, true},
- {"invalid input%", currentCPU, true},
- {"9999", maxCPU, false}, // over available CPU
- } {
- err := setCPU(test.input)
- if test.shouldErr && err == nil {
- t.Errorf("Test %d: Expected error, but there wasn't any", i)
- }
- if !test.shouldErr && err != nil {
- t.Errorf("Test %d: Expected no error, but there was one: %v", i, err)
- }
- if actual, expected := runtime.GOMAXPROCS(-1), test.output; actual != expected {
- t.Errorf("Test %d: GOMAXPROCS was %d but expected %d", i, actual, expected)
- }
- // teardown
- runtime.GOMAXPROCS(currentCPU)
- }
-}