AsyncPool: Slightly reduce worker memory usage with more conservative start options

this results in a memory footprint reduction of maybe 4MB for a total of 8 workers. Not much, but it's something.
This commit is contained in:
Dylan K. Taylor
2018-06-10 10:18:07 +01:00
parent f3a84b332b
commit 3725bea3e5
4 changed files with 32 additions and 13 deletions

View File

@ -26,6 +26,7 @@ namespace pocketmine\scheduler;
use pocketmine\Server;
class AsyncPool{
private const WORKER_START_OPTIONS = PTHREADS_INHERIT_INI | PTHREADS_INHERIT_CONSTANTS;
/** @var Server */
private $server;
@ -62,7 +63,7 @@ class AsyncPool{
$this->workerUsage[$i] = 0;
$this->workers[$i] = new AsyncWorker($this->logger, $i + 1, $this->workerMemoryLimit);
$this->workers[$i]->setClassLoader($this->classLoader);
$this->workers[$i]->start();
$this->workers[$i]->start(self::WORKER_START_OPTIONS);
}
}
@ -76,7 +77,7 @@ class AsyncPool{
$this->workerUsage[$i] = 0;
$this->workers[$i] = new AsyncWorker($this->logger, $i + 1, $this->workerMemoryLimit);
$this->workers[$i]->setClassLoader($this->classLoader);
$this->workers[$i]->start();
$this->workers[$i]->start(self::WORKER_START_OPTIONS);
}
$this->size = $newSize;
}

View File

@ -23,6 +23,8 @@ declare(strict_types=1);
namespace pocketmine\scheduler;
use pocketmine\utils\MainLogger;
use pocketmine\utils\Utils;
use pocketmine\Worker;
class AsyncWorker extends Worker{
@ -43,9 +45,16 @@ class AsyncWorker extends Worker{
public function run(){
error_reporting(-1);
set_error_handler('\pocketmine\error_handler');
$this->registerClassLoader();
//set this after the autoloader is registered
set_error_handler([Utils::class, 'errorExceptionHandler']);
if($this->logger instanceof MainLogger){
$this->logger->registerStatic();
}
gc_enable();
if($this->memoryLimit > 0){