|
|
|
@ -21,6 +21,7 @@ import ( |
|
|
|
|
"fmt" |
|
|
|
|
"math" |
|
|
|
|
"os" |
|
|
|
|
"runtime" |
|
|
|
|
godebug "runtime/debug" |
|
|
|
|
"sort" |
|
|
|
|
"strconv" |
|
|
|
@ -256,6 +257,9 @@ func init() { |
|
|
|
|
} |
|
|
|
|
// Cap the cache allowance and tune the garbage collector
|
|
|
|
|
var mem gosigar.Mem |
|
|
|
|
// Workaround until OpenBSD support lands into gosigar
|
|
|
|
|
// Check https://github.com/elastic/gosigar#supported-platforms
|
|
|
|
|
if runtime.GOOS != "openbsd" { |
|
|
|
|
if err := mem.Get(); err == nil { |
|
|
|
|
allowance := int(mem.Total / 1024 / 1024 / 3) |
|
|
|
|
if cache := ctx.GlobalInt(utils.CacheFlag.Name); cache > allowance { |
|
|
|
@ -263,6 +267,7 @@ func init() { |
|
|
|
|
ctx.GlobalSet(utils.CacheFlag.Name, strconv.Itoa(allowance)) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// Ensure Go's GC ignores the database cache for trigger percentage
|
|
|
|
|
cache := ctx.GlobalInt(utils.CacheFlag.Name) |
|
|
|
|
gogc := math.Max(20, math.Min(100, 100/(float64(cache)/1024))) |
|
|
|
|