automemlimit

Go Reference

Automatically set GOMEMLIMIT to match Linux container memory quota.

See more details about GOMEMLIMIT here.

Installation

go get -u github.com/KimMachineGun/automemlimit

Usage

package main

// By default, it sets `GOMEMLIMIT` to 90% of memory quota.
// You can configure it with `AUTOMEMLIMIT=(0,1]` environment variable.
import _ "github.com/KimMachineGun/automemlimit"

or

package main

import "github.com/KimMachineGun/automemlimit/memlimit"

func init() {
	memlimit.SetGoMemLimit(0.9)
	memlimit.SetGoMemLimitWithProvider(memlimit.Limit(1024*1024), 0.9)
	memlimit.SetGoMemLimitWithProvider(memlimit.FromCgroup, 0.9)
	memlimit.SetGoMemLimitWithProvider(memlimit.FromCgroupV1, 0.9)
	memlimit.SetGoMemLimitWithProvider(memlimit.FromCgroupV2, 0.9)
}

GitHub

View Github