mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-11 05:55:33 +00:00
AsyncPool: Parameterize worker memory limit instead of calling back into Server
This commit is contained in:
parent
7b17a83227
commit
1a21041d00
@ -1526,7 +1526,7 @@ class Server{
|
|||||||
$poolSize = (int) $poolSize;
|
$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){
|
if($this->getProperty("network.batch-threshold", 256) >= 0){
|
||||||
Network::$BATCH_THRESHOLD = (int) $this->getProperty("network.batch-threshold", 256);
|
Network::$BATCH_THRESHOLD = (int) $this->getProperty("network.batch-threshold", 256);
|
||||||
|
@ -31,6 +31,8 @@ class AsyncPool{
|
|||||||
private $server;
|
private $server;
|
||||||
|
|
||||||
protected $size;
|
protected $size;
|
||||||
|
/** @var int */
|
||||||
|
private $workerMemoryLimit;
|
||||||
|
|
||||||
/** @var AsyncTask[] */
|
/** @var AsyncTask[] */
|
||||||
private $tasks = [];
|
private $tasks = [];
|
||||||
@ -44,15 +46,14 @@ class AsyncPool{
|
|||||||
/** @var int[] */
|
/** @var int[] */
|
||||||
private $workerUsage = [];
|
private $workerUsage = [];
|
||||||
|
|
||||||
public function __construct(Server $server, int $size){
|
public function __construct(Server $server, int $size, int $workerMemoryLimit){
|
||||||
$this->server = $server;
|
$this->server = $server;
|
||||||
$this->size = $size;
|
$this->size = $size;
|
||||||
|
$this->workerMemoryLimit = $workerMemoryLimit;
|
||||||
$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, $memoryLimit);
|
$this->workers[$i] = new AsyncWorker($this->server->getLogger(), $i + 1, $this->workerMemoryLimit);
|
||||||
$this->workers[$i]->setClassLoader($this->server->getLoader());
|
$this->workers[$i]->setClassLoader($this->server->getLoader());
|
||||||
$this->workers[$i]->start();
|
$this->workers[$i]->start();
|
||||||
}
|
}
|
||||||
@ -64,12 +65,9 @@ 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, $memoryLimit);
|
$this->workers[$i] = new AsyncWorker($this->server->getLogger(), $i + 1, $this->workerMemoryLimit);
|
||||||
$this->workers[$i]->setClassLoader($this->server->getLoader());
|
$this->workers[$i]->setClassLoader($this->server->getLoader());
|
||||||
$this->workers[$i]->start();
|
$this->workers[$i]->start();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user