mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-07 20:28:31 +00:00
MemoryManager: Shut down idle workers during GC to reclaim memory
workers can be a major memory hog, especially if you have lots of them.
This commit is contained in:
parent
878dd3b842
commit
2e18fe710c
@ -243,6 +243,9 @@ class MemoryManager{
|
|||||||
|
|
||||||
if($this->garbageCollectionAsync){
|
if($this->garbageCollectionAsync){
|
||||||
$pool = $this->server->getAsyncPool();
|
$pool = $this->server->getAsyncPool();
|
||||||
|
if(($w = $pool->shutdownUnusedWorkers()) > 0){
|
||||||
|
$this->server->getLogger()->debug("Shut down $w idle async pool workers");
|
||||||
|
}
|
||||||
foreach($pool->getRunningWorkers() as $i){
|
foreach($pool->getRunningWorkers() as $i){
|
||||||
$pool->submitTaskToWorker(new GarbageCollectionTask(), $i);
|
$pool->submitTaskToWorker(new GarbageCollectionTask(), $i);
|
||||||
}
|
}
|
||||||
|
@ -317,6 +317,19 @@ class AsyncPool{
|
|||||||
$this->collectWorkers();
|
$this->collectWorkers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function shutdownUnusedWorkers() : int{
|
||||||
|
$ret = 0;
|
||||||
|
foreach($this->workerUsage as $i => $usage){
|
||||||
|
if($usage === 0){
|
||||||
|
$this->workers[$i]->quit();
|
||||||
|
unset($this->workers[$i], $this->workerUsage[$i]);
|
||||||
|
$ret++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cancels all pending tasks and shuts down all the workers in the pool.
|
* Cancels all pending tasks and shuts down all the workers in the pool.
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user