diff --git a/pkg/modgearman/configuration_parser.go b/pkg/modgearman/configuration_parser.go index 10d6d51..50eb1c1 100644 --- a/pkg/modgearman/configuration_parser.go +++ b/pkg/modgearman/configuration_parser.go @@ -40,7 +40,7 @@ type config struct { loadLimit5 float64 loadLimit15 float64 loadCPUMulti float64 - memLimit int + memLimit uint64 backgroundingThreshold int showErrorOutput bool dupResultsArePassive bool @@ -277,7 +277,7 @@ func (config *config) parseConfigItem(raw string) error { case "load_cpu_multi": config.loadCPUMulti = getFloat(value) case "mem_limit": - config.memLimit = getInt(value) + config.memLimit = uint64(getFloat(value)) case "backgrounding-threshold": config.backgroundingThreshold = getInt(value) case "show_error_output": diff --git a/pkg/modgearman/mainWorker.go b/pkg/modgearman/mainWorker.go index 747f0cc..90305bd 100644 --- a/pkg/modgearman/mainWorker.go +++ b/pkg/modgearman/mainWorker.go @@ -414,7 +414,7 @@ func (w *mainWorker) checkMemory() (ok bool, reason string) { } usedPercent := 100 - (w.memFree*100)/w.memTotal - if w.cfg.memLimit > 0 && usedPercent >= uint64(w.cfg.memLimit) { + if w.cfg.memLimit > 0 && usedPercent >= w.cfg.memLimit { reason := fmt.Sprintf("cannot start any more worker, memory usage is too high: %d%% > %d%% (free: %s)", usedPercent, w.cfg.memLimit, @@ -621,5 +621,6 @@ func bytes2Human(num uint64) string { div *= unit exp++ } + return fmt.Sprintf("%.2f %cB", float64(num)/float64(div), "KMGTPE"[exp]) }