Set memory overheads higher than the limit so that hard crashes are less likely

This commit is contained in:
Dane Everitt 2020-04-25 18:20:20 -07:00
parent 46056dbce9
commit b2f6863399
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53

View File

@ -17,6 +17,7 @@ import (
"github.com/pterodactyl/wings/config" "github.com/pterodactyl/wings/config"
"go.uber.org/zap" "go.uber.org/zap"
"io" "io"
"math"
"os" "os"
"strconv" "strconv"
"strings" "strings"
@ -824,9 +825,18 @@ func (d *DockerEnvironment) exposedPorts() nat.PortSet {
// Formats the resources available to a server instance in such as way that Docker will // Formats the resources available to a server instance in such as way that Docker will
// generate a matching environment in the container. // generate a matching environment in the container.
func (d *DockerEnvironment) getResourcesForServer() container.Resources { func (d *DockerEnvironment) getResourcesForServer() container.Resources {
overhead := 1.05
// Set the hard limit for memory usage to be 5% more than the amount of memory assigned to
// the server. If the memory limit for the server is < 4G, use 10%, if less than 2G use
// 15%. This avoids unexpected crashes from processes like Java which run over the limit.
if d.Server.Build.MemoryLimit <= 2048 {
overhead = 1.15
} else if d.Server.Build.MemoryLimit <= 4096 {
overhead = 1.10;
}
return container.Resources{ return container.Resources{
// @todo memory limit should be slightly higher than the reservation Memory: int64(math.Round(float64(d.Server.Build.MemoryLimit) * 1000000.0 * overhead)),
Memory: d.Server.Build.MemoryLimit * 1000000,
MemoryReservation: d.Server.Build.MemoryLimit * 1000000, MemoryReservation: d.Server.Build.MemoryLimit * 1000000,
MemorySwap: d.Server.Build.ConvertedSwap(), MemorySwap: d.Server.Build.ConvertedSwap(),
CPUQuota: d.Server.Build.ConvertedCpuLimit(), CPUQuota: d.Server.Build.ConvertedCpuLimit(),