AsyncPool: Parameterize worker memory limit instead of calling back into Server

This commit is contained in:
Dylan K. Taylor 2018-06-06 18:00:56 +01:00
parent 7b17a83227
commit 1a21041d00
2 changed files with 7 additions and 9 deletions

View File

@ -1526,7 +1526,7 @@ class Server{
$poolSize = (int) $poolSize;
}
$this->asyncPool = new AsyncPool($this, $poolSize);
$this->asyncPool = new AsyncPool($this, $poolSize, (int) max(-1, (int) $this->getProperty("memory.async-worker-hard-limit", 1024)));
if($this->getProperty("network.batch-threshold", 256) >= 0){
Network::$BATCH_THRESHOLD = (int) $this->getProperty("network.batch-threshold", 256);

View File

@ -31,6 +31,8 @@ class AsyncPool{
private $server;
protected $size;
/** @var int */
private $workerMemoryLimit;
/** @var AsyncTask[] */
private $tasks = [];
@ -44,15 +46,14 @@ class AsyncPool{
/** @var int[] */
private $workerUsage = [];
public function __construct(Server $server, int $size){
public function __construct(Server $server, int $size, int $workerMemoryLimit){
$this->server = $server;
$this->size = $size;
$memoryLimit = (int) max(-1, (int) $this->server->getProperty("memory.async-worker-hard-limit", 1024));
$this->workerMemoryLimit = $workerMemoryLimit;
for($i = 0; $i < $this->size; ++$i){
$this->workerUsage[$i] = 0;
$this->workers[$i] = new AsyncWorker($this->server->getLogger(), $i + 1, $memoryLimit);
$this->workers[$i] = new AsyncWorker($this->server->getLogger(), $i + 1, $this->workerMemoryLimit);
$this->workers[$i]->setClassLoader($this->server->getLoader());
$this->workers[$i]->start();
}
@ -64,12 +65,9 @@ class AsyncPool{
public function increaseSize(int $newSize){
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){
$this->workerUsage[$i] = 0;
$this->workers[$i] = new AsyncWorker($this->server->getLogger(), $i + 1, $memoryLimit);
$this->workers[$i] = new AsyncWorker($this->server->getLogger(), $i + 1, $this->workerMemoryLimit);
$this->workers[$i]->setClassLoader($this->server->getLoader());
$this->workers[$i]->start();
}