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

@ -168,16 +168,6 @@ namespace pocketmine {
error_reporting(-1);
function error_handler($severity, $message, $file, $line){
if(error_reporting() & $severity){
throw new \ErrorException($message, 0, $severity, $file, $line);
}else{ //stfu operator
return true;
}
}
set_error_handler('\pocketmine\error_handler');
if(\Phar::running(true) !== ""){
define('pocketmine\PATH', \Phar::running(true) . "/");
}else{
@ -198,6 +188,8 @@ namespace pocketmine {
composer_error_die("Composer autoloader not found.");
}
set_error_handler([Utils::class, 'errorExceptionHandler']);
/*
* We now use the Composer autoloader, but this autoloader is still for loading plugins.
*/

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){

View File

@ -634,4 +634,21 @@ class Utils{
return array_combine($matches[1], array_map("trim", $matches[2]));
}
/**
* @param int $severity
* @param string $message
* @param string $file
* @param int $line
*
* @return bool
* @throws \ErrorException
*/
public static function errorExceptionHandler(int $severity, string $message, string $file, int $line) : bool{
if(error_reporting() & $severity){
throw new \ErrorException($message, 0, $severity, $file, $line);
}
return true; //stfu operator
}
}