Added memory limits for AsyncWorkers

This commit is contained in:
Dylan K. Taylor
2017-08-20 12:15:48 +01:00
parent 8475c63426
commit 17053389b0
4 changed files with 37 additions and 17 deletions

View File

@ -47,9 +47,11 @@ class AsyncPool{
$this->server = $server;
$this->size = $size;
$memoryLimit = (int) max(-1, (int) $this->server->getProperty("memory.async-worker-hard-limit", 1024));
for($i = 0; $i < $this->size; ++$i){
$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]->start();
}
@ -61,9 +63,12 @@ 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);
$this->workers[$i] = new AsyncWorker($this->server->getLogger(), $i + 1, $memoryLimit);
$this->workers[$i]->setClassLoader($this->server->getLoader());
$this->workers[$i]->start();
}