mirror of
https://github.com/minio/minio.git
synced 2025-04-28 13:48:00 -04:00
feat: add memlimit flags for setMaxResources (#19400)
This commit is contained in:
parent
95bf4a57b6
commit
272367ccd2
@ -172,6 +172,12 @@ var ServerFlags = []cli.Flag{
|
|||||||
Hidden: true,
|
Hidden: true,
|
||||||
EnvVar: "MINIO_CROSSDOMAIN_XML",
|
EnvVar: "MINIO_CROSSDOMAIN_XML",
|
||||||
},
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "memlimit",
|
||||||
|
Usage: "set global memory limit per server via GOMEMLIMIT",
|
||||||
|
Hidden: true,
|
||||||
|
EnvVar: "MINIO_MEMLIMIT",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
var gatewayCmd = cli.Command{
|
var gatewayCmd = cli.Command{
|
||||||
@ -731,7 +737,7 @@ func serverMain(ctx *cli.Context) {
|
|||||||
|
|
||||||
// Set system resources to maximum.
|
// Set system resources to maximum.
|
||||||
bootstrapTrace("setMaxResources", func() {
|
bootstrapTrace("setMaxResources", func() {
|
||||||
_ = setMaxResources()
|
_ = setMaxResources(ctx)
|
||||||
})
|
})
|
||||||
|
|
||||||
// Verify kernel release and version.
|
// Verify kernel release and version.
|
||||||
|
@ -21,6 +21,8 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
|
|
||||||
|
"github.com/dustin/go-humanize"
|
||||||
|
"github.com/minio/cli"
|
||||||
"github.com/minio/madmin-go/v3/kernel"
|
"github.com/minio/madmin-go/v3/kernel"
|
||||||
"github.com/minio/minio/internal/logger"
|
"github.com/minio/minio/internal/logger"
|
||||||
"github.com/minio/pkg/v2/sys"
|
"github.com/minio/pkg/v2/sys"
|
||||||
@ -43,7 +45,7 @@ func oldLinux() bool {
|
|||||||
return currentKernel < kernel.Version(4, 0, 0)
|
return currentKernel < kernel.Version(4, 0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func setMaxResources() (err error) {
|
func setMaxResources(ctx *cli.Context) (err error) {
|
||||||
// Set the Go runtime max threads threshold to 90% of kernel setting.
|
// Set the Go runtime max threads threshold to 90% of kernel setting.
|
||||||
sysMaxThreads, err := sys.GetMaxThreads()
|
sysMaxThreads, err := sys.GetMaxThreads()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@ -75,6 +77,27 @@ func setMaxResources() (err error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set debug memory limit instead of GOMEMLIMIT env
|
||||||
|
_ = setDebugMemoryLimit(ctx)
|
||||||
|
|
||||||
err = sys.SetMaxMemoryLimit(maxLimit, maxLimit)
|
err = sys.SetMaxMemoryLimit(maxLimit, maxLimit)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setDebugMemoryLimit(ctx *cli.Context) error {
|
||||||
|
if ctx == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if ctx.IsSet("memlimit") {
|
||||||
|
memlimit := ctx.String("memlimit")
|
||||||
|
if memlimit == "" {
|
||||||
|
memlimit = ctx.GlobalString("memlimit")
|
||||||
|
}
|
||||||
|
mlimit, err := humanize.ParseBytes(memlimit)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
debug.SetMemoryLimit(int64(mlimit))
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -106,7 +106,7 @@ func TestMain(m *testing.M) {
|
|||||||
// logger.AddTarget(console.New())
|
// logger.AddTarget(console.New())
|
||||||
|
|
||||||
// Set system resources to maximum.
|
// Set system resources to maximum.
|
||||||
setMaxResources()
|
setMaxResources(nil)
|
||||||
|
|
||||||
// Initialize globalConsoleSys system
|
// Initialize globalConsoleSys system
|
||||||
globalConsoleSys = NewConsoleLogger(context.Background())
|
globalConsoleSys = NewConsoleLogger(context.Background())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user