mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 08:44:01 +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;
|
||||
}
|
||||
|
||||
$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);
|
||||
|
@ -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();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user