diff --git a/src/pocketmine/MemoryManager.php b/src/pocketmine/MemoryManager.php index 318bc4d12..69ca142b4 100644 --- a/src/pocketmine/MemoryManager.php +++ b/src/pocketmine/MemoryManager.php @@ -68,8 +68,41 @@ class MemoryManager{ } private function init(){ - $this->memoryLimit = ((int) $this->server->getProperty("memory.main-limit", 320)) * 1024 * 1024; - $this->globalMemoryLimit = ((int) $this->server->getProperty("memory.global-limit", 512)) * 1024 * 1024; + $this->memoryLimit = ((int) $this->server->getProperty("memory.main-limit", 0)) * 1024 * 1024; + + $defaultMemory = 1024; + + if(preg_match("/([0-9]+)([KMGkmg])/", $this->server->getConfigString("memory-limit", ""), $matches) > 0){ + $m = (int) $matches[1]; + if($m <= 0){ + $defaultMemory = 0; + }else{ + switch(strtoupper($matches[2])){ + case "K": + $defaultMemory = $m / 1024; + break; + case "M": + $defaultMemory = $m; + break; + case "G": + $defaultMemory = $m * 1024; + break; + default: + $defaultMemory = $m; + break; + } + } + } + + $hardLimit = ((int) $this->server->getProperty("memory.main-hard-limit", $defaultMemory)); + + if($hardLimit <= 0){ + ini_set("memory_limit", -1); + }else{ + ini_set("memory_limit", $hardLimit . "M"); + } + + $this->globalMemoryLimit = ((int) $this->server->getProperty("memory.global-limit", 0)) * 1024 * 1024; $this->checkRate = (int) $this->server->getProperty("memory.check-rate", 20); $this->continuousTrigger = (bool) $this->server->getProperty("memory.continuous-trigger", true); $this->continuousTriggerRate = (int) $this->server->getProperty("memory.continuous-trigger-rate", 30); diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index e1a23d5f8..c50547258 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -1646,12 +1646,6 @@ class Server{ $this->maxPlayers = $this->getConfigInt("max-players", 20); $this->setAutoSave($this->getConfigBoolean("auto-save", true)); - if($this->getConfigString("memory-limit", false) !== false){ - $this->logger->notice("The memory-limit setting has been deprecated."); - $this->logger->notice("There are new memory settings on pocketmine.yml to tune memory and events."); - $this->logger->notice("You can also reduce the amount of threads and chunks loaded control the memory usage."); - } - if($this->getConfigBoolean("hardcore", false) === true and $this->getDifficulty() < 3){ $this->setConfigInt("difficulty", 3); } diff --git a/src/pocketmine/resources/pocketmine.yml b/src/pocketmine/resources/pocketmine.yml index f0348aec1..6cdb388f7 100644 --- a/src/pocketmine/resources/pocketmine.yml +++ b/src/pocketmine/resources/pocketmine.yml @@ -27,11 +27,15 @@ settings: memory: #Global soft memory limit in megabytes. Set to 0 to disable #This will trigger low-memory-triggers and fire an event to free memory when the usage goes over this - global-limit: 512 + global-limit: 0 #Main thread soft memory limit in megabytes. Set to 0 to disable #This will trigger low-memory-triggers and fire an event to free memory when the usage goes over this - main-limit: 320 + main-limit: 0 + + #Main thread hard memory limit in megabytes. Set to 0 to disable + #This will stop the server when the limit is surpassed + main-hard-limit: 1024 #Period in ticks to check memory (default 1 second) check-rate: 20 diff --git a/src/raklib b/src/raklib index b90c277f1..ab3ff4420 160000 --- a/src/raklib +++ b/src/raklib @@ -1 +1 @@ -Subproject commit b90c277f1a24fcda49e14510d83a0d956b0ebad7 +Subproject commit ab3ff4420f6dea3371bfc410bbb783159cd0560b