Set higher rlimit for logs and pipes

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby 2015-12-11 14:33:48 -08:00
parent 15080cda61
commit 25973db0c9

View file

@ -6,6 +6,7 @@ import (
"os" "os"
"runtime" "runtime"
"sync" "sync"
"syscall"
"time" "time"
"google.golang.org/grpc" "google.golang.org/grpc"
@ -19,7 +20,10 @@ import (
"github.com/rcrowley/go-metrics" "github.com/rcrowley/go-metrics"
) )
const Usage = `High performance conatiner daemon` const (
Usage = `High performance conatiner daemon`
minRlimit = 1024
)
var authors = []cli.Author{ var authors = []cli.Author{
{ {
@ -65,7 +69,12 @@ func main() {
app.Before = func(context *cli.Context) error { app.Before = func(context *cli.Context) error {
if context.GlobalBool("debug") { if context.GlobalBool("debug") {
logrus.SetLevel(logrus.DebugLevel) logrus.SetLevel(logrus.DebugLevel)
return debugMetrics(context.GlobalDuration("metrics-interval")) if err := debugMetrics(context.GlobalDuration("metrics-interval")); err != nil {
return err
}
}
if err := checkLimits(); err != nil {
return err
} }
return nil return nil
} }
@ -83,6 +92,22 @@ func main() {
} }
} }
func checkLimits() error {
var l syscall.Rlimit
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &l); err != nil {
return err
}
if l.Cur <= minRlimit {
logrus.WithFields(logrus.Fields{
"current": l.Cur,
"max": l.Max,
}).Warn("low RLIMIT_NOFILE changing to max")
l.Cur = l.Max
return syscall.Setrlimit(syscall.RLIMIT_NOFILE, &l)
}
return nil
}
func debugMetrics(interval time.Duration) error { func debugMetrics(interval time.Duration) error {
for name, m := range containerd.Metrics() { for name, m := range containerd.Metrics() {
if err := metrics.DefaultRegistry.Register(name, m); err != nil { if err := metrics.DefaultRegistry.Register(name, m); err != nil {