mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-12 12:55:21 +00:00
Added memory limits for AsyncWorkers
This commit is contained in:
parent
8475c63426
commit
17053389b0
@ -1439,6 +1439,18 @@ class Server{
|
|||||||
}
|
}
|
||||||
$this->config = new Config($this->dataPath . "pocketmine.yml", Config::YAML, []);
|
$this->config = new Config($this->dataPath . "pocketmine.yml", Config::YAML, []);
|
||||||
|
|
||||||
|
define('pocketmine\DEBUG', (int) $this->getProperty("debug.level", 1));
|
||||||
|
|
||||||
|
if(((int) ini_get('zend.assertions')) > 0 and ((bool) $this->getProperty("debug.assertions.warn-if-enabled", true)) !== false){
|
||||||
|
$this->logger->warning("Debugging assertions are enabled, this may impact on performance. To disable them, set `zend.assertions = -1` in php.ini.");
|
||||||
|
}
|
||||||
|
|
||||||
|
ini_set('assert.exception', '1');
|
||||||
|
|
||||||
|
if($this->logger instanceof MainLogger){
|
||||||
|
$this->logger->setLogDebug(\pocketmine\DEBUG > 1);
|
||||||
|
}
|
||||||
|
|
||||||
$this->logger->info("Loading server properties...");
|
$this->logger->info("Loading server properties...");
|
||||||
$this->properties = new Config($this->dataPath . "server.properties", Config::PROPERTIES, [
|
$this->properties = new Config($this->dataPath . "server.properties", Config::PROPERTIES, [
|
||||||
"motd" => "Minecraft: PE Server",
|
"motd" => "Minecraft: PE Server",
|
||||||
@ -1540,18 +1552,6 @@ class Server{
|
|||||||
$this->setConfigInt("difficulty", 3);
|
$this->setConfigInt("difficulty", 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
define('pocketmine\DEBUG', (int) $this->getProperty("debug.level", 1));
|
|
||||||
|
|
||||||
if(((int) ini_get('zend.assertions')) > 0 and ((bool) $this->getProperty("debug.assertions.warn-if-enabled", true)) !== false){
|
|
||||||
$this->logger->warning("Debugging assertions are enabled, this may impact on performance. To disable them, set `zend.assertions = -1` in php.ini.");
|
|
||||||
}
|
|
||||||
|
|
||||||
ini_set('assert.exception', '1');
|
|
||||||
|
|
||||||
if($this->logger instanceof MainLogger){
|
|
||||||
$this->logger->setLogDebug(\pocketmine\DEBUG > 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(\pocketmine\DEBUG >= 0){
|
if(\pocketmine\DEBUG >= 0){
|
||||||
@cli_set_process_title($this->getName() . " " . $this->getPocketMineVersion());
|
@cli_set_process_title($this->getName() . " " . $this->getPocketMineVersion());
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,11 @@ memory:
|
|||||||
#This will stop the server when the limit is surpassed
|
#This will stop the server when the limit is surpassed
|
||||||
main-hard-limit: 1024
|
main-hard-limit: 1024
|
||||||
|
|
||||||
|
#AsyncWorker threads' hard memory limit in megabytes. Set to 0 to disable
|
||||||
|
#This will stop the server if any worker exceeds this limit.
|
||||||
|
#NOTE: THIS LIMIT APPLIES PER WORKER, NOT TO THE WHOLE PROCESS.
|
||||||
|
async-worker-hard-limit: 1024
|
||||||
|
|
||||||
#Period in ticks to check memory (default 1 second)
|
#Period in ticks to check memory (default 1 second)
|
||||||
check-rate: 20
|
check-rate: 20
|
||||||
|
|
||||||
|
@ -47,9 +47,11 @@ class AsyncPool{
|
|||||||
$this->server = $server;
|
$this->server = $server;
|
||||||
$this->size = $size;
|
$this->size = $size;
|
||||||
|
|
||||||
|
$memoryLimit = (int) max(-1, (int) $this->server->getProperty("memory.async-worker-hard-limit", 1024));
|
||||||
|
|
||||||
for($i = 0; $i < $this->size; ++$i){
|
for($i = 0; $i < $this->size; ++$i){
|
||||||
$this->workerUsage[$i] = 0;
|
$this->workerUsage[$i] = 0;
|
||||||
$this->workers[$i] = new AsyncWorker($this->server->getLogger(), $i + 1);
|
$this->workers[$i] = new AsyncWorker($this->server->getLogger(), $i + 1, $memoryLimit);
|
||||||
$this->workers[$i]->setClassLoader($this->server->getLoader());
|
$this->workers[$i]->setClassLoader($this->server->getLoader());
|
||||||
$this->workers[$i]->start();
|
$this->workers[$i]->start();
|
||||||
}
|
}
|
||||||
@ -61,9 +63,12 @@ class AsyncPool{
|
|||||||
|
|
||||||
public function increaseSize(int $newSize){
|
public function increaseSize(int $newSize){
|
||||||
if($newSize > $this->size){
|
if($newSize > $this->size){
|
||||||
|
|
||||||
|
$memoryLimit = (int) max(-1, (int) $this->server->getProperty("memory.async-worker-hard-limit", 1024));
|
||||||
|
|
||||||
for($i = $this->size; $i < $newSize; ++$i){
|
for($i = $this->size; $i < $newSize; ++$i){
|
||||||
$this->workerUsage[$i] = 0;
|
$this->workerUsage[$i] = 0;
|
||||||
$this->workers[$i] = new AsyncWorker($this->server->getLogger(), $i + 1);
|
$this->workers[$i] = new AsyncWorker($this->server->getLogger(), $i + 1, $memoryLimit);
|
||||||
$this->workers[$i]->setClassLoader($this->server->getLoader());
|
$this->workers[$i]->setClassLoader($this->server->getLoader());
|
||||||
$this->workers[$i]->start();
|
$this->workers[$i]->start();
|
||||||
}
|
}
|
||||||
|
@ -31,17 +31,27 @@ class AsyncWorker extends Worker{
|
|||||||
private $logger;
|
private $logger;
|
||||||
private $id;
|
private $id;
|
||||||
|
|
||||||
public function __construct(MainLogger $logger, int $id){
|
/** @var int */
|
||||||
|
private $memoryLimit;
|
||||||
|
|
||||||
|
public function __construct(MainLogger $logger, int $id, int $memoryLimit){
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
$this->id = $id;
|
$this->id = $id;
|
||||||
|
$this->memoryLimit = $memoryLimit;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function run(){
|
public function run(){
|
||||||
$this->registerClassLoader();
|
$this->registerClassLoader();
|
||||||
$this->logger->registerStatic();
|
$this->logger->registerStatic();
|
||||||
|
|
||||||
gc_enable();
|
gc_enable();
|
||||||
ini_set("memory_limit", '-1');
|
|
||||||
|
if($this->memoryLimit > 0){
|
||||||
|
ini_set('memory_limit', $this->memoryLimit . 'M');
|
||||||
|
$this->logger->debug("Set memory limit to " . $this->memoryLimit . " MB");
|
||||||
|
}else{
|
||||||
|
ini_set('memory_limit', '-1');
|
||||||
|
$this->logger->debug("No memory limit set");
|
||||||
|
}
|
||||||
|
|
||||||
global $store;
|
global $store;
|
||||||
$store = [];
|
$store = [];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user