Skip to content

Commit

Permalink
feature: check os file descriptor limit and num cpus
Browse files Browse the repository at this point in the history
Logs a warning if numbers below acceptable levels.

```
[Mar  2 18:36:55]  WARN File descriptor limit 4864 too low for production use. Min 80000 recommended.
	This could have a significant negative impact on performance.
	Please refer to https://tyk.io/docs/deploy-tyk-premise-production/#file-handles for further guidance.
[Mar  2 18:36:55]  WARN Num CPU(s) 1 too low for production use. Min 2 recommended.
	This could have a significant negative impact on performance.
	Please refer to https://tyk.io/docs/deploy-tyk-premise-production/#use-the-right-hardware for further guidance.
```
  • Loading branch information
asoorm authored and buger committed Mar 6, 2018
1 parent e406b74 commit 40bc2c0
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
36 changes: 36 additions & 0 deletions checkup/checkup.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package checkup

import (
"runtime"
"syscall"

logger "github.com/TykTechnologies/tyk/log"
)

var log = logger.Get()

const (
minCPU = 2
minFileDescriptors = 80000
)

func CheckFileDescriptors() {

rlimit := &syscall.Rlimit{}
err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, rlimit)
if err == nil && rlimit.Cur < minFileDescriptors {
log.Warningf("File descriptor limit %d too low for production use. Min %d recommended.\n"+
"\tThis could have a significant negative impact on performance.\n"+
"\tPlease refer to https://tyk.io/docs/deploy-tyk-premise-production/#file-handles for further guidance.", rlimit.Cur, minFileDescriptors)
}
}

func CheckCpus() {

cpus := runtime.NumCPU()
if cpus < minCPU {
log.Warningf("Num CPUs %d too low for production use. Min %d recommended.\n"+
"\tThis could have a significant negative impact on performance.\n"+
"\tPlease refer to https://tyk.io/docs/deploy-tyk-premise-production/#use-the-right-hardware for further guidance.", cpus, minCPU)
}
}
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (

"github.com/newrelic/go-agent"

"github.com/TykTechnologies/tyk/checkup"

"github.com/Sirupsen/logrus"
logrus_syslog "github.com/Sirupsen/logrus/hooks/syslog"
logstashHook "github.com/bshuster-repo/logrus-logstash-hook"
Expand Down Expand Up @@ -1070,6 +1072,9 @@ func main() {

start()

checkup.CheckFileDescriptors()
checkup.CheckCpus()

// Wait while Redis connection pools are ready before start serving traffic
if !storage.IsConnected() {
log.Fatal("Redis connection pools are not ready. Exiting...")
Expand Down

0 comments on commit 40bc2c0

Please sign in to comment.