mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-03 16:49:53 +00:00
Update to Snooze 0.5.0
This commit is contained in:
parent
4aba9d9725
commit
c66a3a8b3e
@ -48,7 +48,7 @@
|
|||||||
"pocketmine/nbt": "^0.3.2",
|
"pocketmine/nbt": "^0.3.2",
|
||||||
"pocketmine/raklib": "^0.15.0",
|
"pocketmine/raklib": "^0.15.0",
|
||||||
"pocketmine/raklib-ipc": "^0.2.0",
|
"pocketmine/raklib-ipc": "^0.2.0",
|
||||||
"pocketmine/snooze": "dev-master",
|
"pocketmine/snooze": "^0.5.0",
|
||||||
"ramsey/uuid": "^4.1",
|
"ramsey/uuid": "^4.1",
|
||||||
"symfony/filesystem": "^5.4"
|
"symfony/filesystem": "^5.4"
|
||||||
},
|
},
|
||||||
|
19
composer.lock
generated
19
composer.lock
generated
@ -4,7 +4,7 @@
|
|||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "812a98ecf031488987b3216e785fee19",
|
"content-hash": "4bccf431b24bf685b0829ea44e54e806",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "adhocore/json-comment",
|
"name": "adhocore/json-comment",
|
||||||
@ -774,16 +774,16 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "pocketmine/snooze",
|
"name": "pocketmine/snooze",
|
||||||
"version": "dev-master",
|
"version": "0.5.0",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/pmmp/Snooze.git",
|
"url": "https://github.com/pmmp/Snooze.git",
|
||||||
"reference": "3207a201cbb10eebb4a96749678f7adef216bb71"
|
"reference": "a86d9ee60ce44755d166d3c7ba4b8b8be8360915"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/pmmp/Snooze/zipball/3207a201cbb10eebb4a96749678f7adef216bb71",
|
"url": "https://api.github.com/repos/pmmp/Snooze/zipball/a86d9ee60ce44755d166d3c7ba4b8b8be8360915",
|
||||||
"reference": "3207a201cbb10eebb4a96749678f7adef216bb71",
|
"reference": "a86d9ee60ce44755d166d3c7ba4b8b8be8360915",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
@ -795,7 +795,6 @@
|
|||||||
"phpstan/phpstan": "1.10.3",
|
"phpstan/phpstan": "1.10.3",
|
||||||
"phpstan/phpstan-strict-rules": "^1.0"
|
"phpstan/phpstan-strict-rules": "^1.0"
|
||||||
},
|
},
|
||||||
"default-branch": true,
|
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
@ -809,9 +808,9 @@
|
|||||||
"description": "Thread notification management library for code using the pthreads extension",
|
"description": "Thread notification management library for code using the pthreads extension",
|
||||||
"support": {
|
"support": {
|
||||||
"issues": "https://github.com/pmmp/Snooze/issues",
|
"issues": "https://github.com/pmmp/Snooze/issues",
|
||||||
"source": "https://github.com/pmmp/Snooze/tree/master"
|
"source": "https://github.com/pmmp/Snooze/tree/0.5.0"
|
||||||
},
|
},
|
||||||
"time": "2023-05-19T23:38:19+00:00"
|
"time": "2023-05-22T23:43:01+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "ramsey/collection",
|
"name": "ramsey/collection",
|
||||||
@ -3205,9 +3204,7 @@
|
|||||||
],
|
],
|
||||||
"aliases": [],
|
"aliases": [],
|
||||||
"minimum-stability": "stable",
|
"minimum-stability": "stable",
|
||||||
"stability-flags": {
|
"stability-flags": [],
|
||||||
"pocketmine/snooze": 20
|
|
||||||
},
|
|
||||||
"prefer-stable": false,
|
"prefer-stable": false,
|
||||||
"prefer-lowest": false,
|
"prefer-lowest": false,
|
||||||
"platform": {
|
"platform": {
|
||||||
|
@ -39,7 +39,6 @@ use pocketmine\network\NetworkInterfaceStartException;
|
|||||||
use pocketmine\network\PacketHandlingException;
|
use pocketmine\network\PacketHandlingException;
|
||||||
use pocketmine\player\GameMode;
|
use pocketmine\player\GameMode;
|
||||||
use pocketmine\Server;
|
use pocketmine\Server;
|
||||||
use pocketmine\snooze\SleeperNotifier;
|
|
||||||
use pocketmine\timings\Timings;
|
use pocketmine\timings\Timings;
|
||||||
use pocketmine\utils\Utils;
|
use pocketmine\utils\Utils;
|
||||||
use raklib\generic\DisconnectReason;
|
use raklib\generic\DisconnectReason;
|
||||||
@ -79,7 +78,7 @@ class RakLibInterface implements ServerEventListener, AdvancedNetworkInterface{
|
|||||||
private RakLibToUserThreadMessageReceiver $eventReceiver;
|
private RakLibToUserThreadMessageReceiver $eventReceiver;
|
||||||
private UserToRakLibThreadMessageSender $interface;
|
private UserToRakLibThreadMessageSender $interface;
|
||||||
|
|
||||||
private SleeperNotifier $sleeper;
|
private int $sleeperNotifierId;
|
||||||
|
|
||||||
private PacketBroadcaster $packetBroadcaster;
|
private PacketBroadcaster $packetBroadcaster;
|
||||||
private EntityEventBroadcaster $entityEventBroadcaster;
|
private EntityEventBroadcaster $entityEventBroadcaster;
|
||||||
@ -104,7 +103,15 @@ class RakLibInterface implements ServerEventListener, AdvancedNetworkInterface{
|
|||||||
|
|
||||||
$this->rakServerId = mt_rand(0, PHP_INT_MAX);
|
$this->rakServerId = mt_rand(0, PHP_INT_MAX);
|
||||||
|
|
||||||
$this->sleeper = new SleeperNotifier();
|
$sleeperEntry = $this->server->getTickSleeper()->addNotifier(function() : void{
|
||||||
|
Timings::$connection->startTiming();
|
||||||
|
try{
|
||||||
|
while($this->eventReceiver->handle($this));
|
||||||
|
}finally{
|
||||||
|
Timings::$connection->stopTiming();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
$this->sleeperNotifierId = $sleeperEntry->getNotifierId();
|
||||||
|
|
||||||
/** @phpstan-var ThreadSafeArray<int, string> $mainToThreadBuffer */
|
/** @phpstan-var ThreadSafeArray<int, string> $mainToThreadBuffer */
|
||||||
$mainToThreadBuffer = new ThreadSafeArray();
|
$mainToThreadBuffer = new ThreadSafeArray();
|
||||||
@ -119,7 +126,7 @@ class RakLibInterface implements ServerEventListener, AdvancedNetworkInterface{
|
|||||||
$this->rakServerId,
|
$this->rakServerId,
|
||||||
$this->server->getConfigGroup()->getPropertyInt("network.max-mtu-size", 1492),
|
$this->server->getConfigGroup()->getPropertyInt("network.max-mtu-size", 1492),
|
||||||
self::MCPE_RAKNET_PROTOCOL_VERSION,
|
self::MCPE_RAKNET_PROTOCOL_VERSION,
|
||||||
$this->sleeper
|
$sleeperEntry
|
||||||
);
|
);
|
||||||
$this->eventReceiver = new RakLibToUserThreadMessageReceiver(
|
$this->eventReceiver = new RakLibToUserThreadMessageReceiver(
|
||||||
new PthreadsChannelReader($threadToMainBuffer)
|
new PthreadsChannelReader($threadToMainBuffer)
|
||||||
@ -130,14 +137,6 @@ class RakLibInterface implements ServerEventListener, AdvancedNetworkInterface{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function start() : void{
|
public function start() : void{
|
||||||
$this->server->getTickSleeper()->addNotifier($this->sleeper, function() : void{
|
|
||||||
Timings::$connection->startTiming();
|
|
||||||
try{
|
|
||||||
while($this->eventReceiver->handle($this));
|
|
||||||
}finally{
|
|
||||||
Timings::$connection->stopTiming();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
$this->server->getLogger()->debug("Waiting for RakLib to start...");
|
$this->server->getLogger()->debug("Waiting for RakLib to start...");
|
||||||
try{
|
try{
|
||||||
$this->rakLib->startAndWait();
|
$this->rakLib->startAndWait();
|
||||||
@ -182,7 +181,7 @@ class RakLibInterface implements ServerEventListener, AdvancedNetworkInterface{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function shutdown() : void{
|
public function shutdown() : void{
|
||||||
$this->server->getTickSleeper()->removeNotifier($this->sleeper);
|
$this->server->getTickSleeper()->removeNotifier($this->sleeperNotifierId);
|
||||||
$this->rakLib->quit();
|
$this->rakLib->quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\raklib;
|
|||||||
|
|
||||||
use pmmp\thread\Thread as NativeThread;
|
use pmmp\thread\Thread as NativeThread;
|
||||||
use pmmp\thread\ThreadSafeArray;
|
use pmmp\thread\ThreadSafeArray;
|
||||||
use pocketmine\snooze\SleeperNotifier;
|
use pocketmine\snooze\SleeperHandlerEntry;
|
||||||
use pocketmine\thread\log\ThreadSafeLogger;
|
use pocketmine\thread\log\ThreadSafeLogger;
|
||||||
use pocketmine\thread\NonThreadSafeValue;
|
use pocketmine\thread\NonThreadSafeValue;
|
||||||
use pocketmine\thread\Thread;
|
use pocketmine\thread\Thread;
|
||||||
@ -63,7 +63,7 @@ class RakLibServer extends Thread{
|
|||||||
protected int $serverId,
|
protected int $serverId,
|
||||||
protected int $maxMtuSize,
|
protected int $maxMtuSize,
|
||||||
protected int $protocolVersion,
|
protected int $protocolVersion,
|
||||||
protected SleeperNotifier $mainThreadNotifier
|
protected SleeperHandlerEntry $sleeperEntry
|
||||||
){
|
){
|
||||||
$this->mainPath = \pocketmine\PATH;
|
$this->mainPath = \pocketmine\PATH;
|
||||||
$this->address = new NonThreadSafeValue($address);
|
$this->address = new NonThreadSafeValue($address);
|
||||||
@ -133,7 +133,7 @@ class RakLibServer extends Thread{
|
|||||||
$this->maxMtuSize,
|
$this->maxMtuSize,
|
||||||
new SimpleProtocolAcceptor($this->protocolVersion),
|
new SimpleProtocolAcceptor($this->protocolVersion),
|
||||||
new UserToRakLibThreadMessageReceiver(new PthreadsChannelReader($this->mainToThreadBuffer)),
|
new UserToRakLibThreadMessageReceiver(new PthreadsChannelReader($this->mainToThreadBuffer)),
|
||||||
new RakLibToUserThreadMessageSender(new SnoozeAwarePthreadsChannelWriter($this->threadToMainBuffer, $this->mainThreadNotifier)),
|
new RakLibToUserThreadMessageSender(new SnoozeAwarePthreadsChannelWriter($this->threadToMainBuffer, $this->sleeperEntry->createNotifier())),
|
||||||
new ExceptionTraceCleaner($this->mainPath)
|
new ExceptionTraceCleaner($this->mainPath)
|
||||||
);
|
);
|
||||||
$this->synchronized(function() : void{
|
$this->synchronized(function() : void{
|
||||||
|
@ -26,7 +26,6 @@ namespace pocketmine\scheduler;
|
|||||||
use pmmp\thread\Thread as NativeThread;
|
use pmmp\thread\Thread as NativeThread;
|
||||||
use pmmp\thread\ThreadSafeArray;
|
use pmmp\thread\ThreadSafeArray;
|
||||||
use pocketmine\snooze\SleeperHandler;
|
use pocketmine\snooze\SleeperHandler;
|
||||||
use pocketmine\snooze\SleeperNotifier;
|
|
||||||
use pocketmine\thread\log\ThreadSafeLogger;
|
use pocketmine\thread\log\ThreadSafeLogger;
|
||||||
use pocketmine\thread\ThreadSafeClassLoader;
|
use pocketmine\thread\ThreadSafeClassLoader;
|
||||||
use pocketmine\utils\Utils;
|
use pocketmine\utils\Utils;
|
||||||
@ -52,8 +51,8 @@ class AsyncPool{
|
|||||||
private array $taskQueues = [];
|
private array $taskQueues = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var AsyncWorker[]
|
* @var AsyncPoolWorkerEntry[]
|
||||||
* @phpstan-var array<int, AsyncWorker>
|
* @phpstan-var array<int, AsyncPoolWorkerEntry>
|
||||||
*/
|
*/
|
||||||
private array $workers = [];
|
private array $workers = [];
|
||||||
/**
|
/**
|
||||||
@ -132,13 +131,12 @@ class AsyncPool{
|
|||||||
*/
|
*/
|
||||||
private function getWorker(int $worker) : AsyncWorker{
|
private function getWorker(int $worker) : AsyncWorker{
|
||||||
if(!isset($this->workers[$worker])){
|
if(!isset($this->workers[$worker])){
|
||||||
$notifier = new SleeperNotifier();
|
$sleeperEntry = $this->eventLoop->addNotifier(function() use ($worker) : void{
|
||||||
$this->workers[$worker] = new AsyncWorker($this->logger, $worker, $this->workerMemoryLimit, $notifier);
|
|
||||||
$this->eventLoop->addNotifier($notifier, function() use ($worker) : void{
|
|
||||||
$this->collectTasksFromWorker($worker);
|
$this->collectTasksFromWorker($worker);
|
||||||
});
|
});
|
||||||
$this->workers[$worker]->setClassLoaders([$this->classLoader]);
|
$this->workers[$worker] = new AsyncPoolWorkerEntry(new AsyncWorker($this->logger, $worker, $this->workerMemoryLimit, $sleeperEntry), $sleeperEntry->getNotifierId());
|
||||||
$this->workers[$worker]->start(self::WORKER_START_OPTIONS);
|
$this->workers[$worker]->worker->setClassLoaders([$this->classLoader]);
|
||||||
|
$this->workers[$worker]->worker->start(self::WORKER_START_OPTIONS);
|
||||||
|
|
||||||
$this->taskQueues[$worker] = new \SplQueue();
|
$this->taskQueues[$worker] = new \SplQueue();
|
||||||
|
|
||||||
@ -147,7 +145,7 @@ class AsyncPool{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->workers[$worker];
|
return $this->workers[$worker]->worker;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -270,7 +268,7 @@ class AsyncPool{
|
|||||||
break; //current task is still running, skip to next worker
|
break; //current task is still running, skip to next worker
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->workers[$worker]->collect();
|
$this->workers[$worker]->worker->collect();
|
||||||
return $more;
|
return $more;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -289,8 +287,8 @@ class AsyncPool{
|
|||||||
$time = time();
|
$time = time();
|
||||||
foreach($this->taskQueues as $i => $queue){
|
foreach($this->taskQueues as $i => $queue){
|
||||||
if((!isset($this->workerLastUsed[$i]) || $this->workerLastUsed[$i] + 300 < $time) && $queue->isEmpty()){
|
if((!isset($this->workerLastUsed[$i]) || $this->workerLastUsed[$i] + 300 < $time) && $queue->isEmpty()){
|
||||||
$this->workers[$i]->quit();
|
$this->workers[$i]->worker->quit();
|
||||||
$this->eventLoop->removeNotifier($this->workers[$i]->getNotifier());
|
$this->eventLoop->removeNotifier($this->workers[$i]->sleeperNotifierId);
|
||||||
unset($this->workers[$i], $this->taskQueues[$i], $this->workerLastUsed[$i]);
|
unset($this->workers[$i], $this->taskQueues[$i], $this->workerLastUsed[$i]);
|
||||||
$ret++;
|
$ret++;
|
||||||
}
|
}
|
||||||
@ -308,8 +306,8 @@ class AsyncPool{
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach($this->workers as $worker){
|
foreach($this->workers as $worker){
|
||||||
$worker->quit();
|
$worker->worker->quit();
|
||||||
$this->eventLoop->removeNotifier($worker->getNotifier());
|
$this->eventLoop->removeNotifier($worker->sleeperNotifierId);
|
||||||
}
|
}
|
||||||
$this->workers = [];
|
$this->workers = [];
|
||||||
$this->taskQueues = [];
|
$this->taskQueues = [];
|
||||||
|
@ -24,9 +24,11 @@ declare(strict_types=1);
|
|||||||
namespace pocketmine\scheduler;
|
namespace pocketmine\scheduler;
|
||||||
|
|
||||||
use pmmp\thread\Thread as NativeThread;
|
use pmmp\thread\Thread as NativeThread;
|
||||||
|
use pocketmine\snooze\SleeperHandlerEntry;
|
||||||
use pocketmine\snooze\SleeperNotifier;
|
use pocketmine\snooze\SleeperNotifier;
|
||||||
use pocketmine\thread\log\ThreadSafeLogger;
|
use pocketmine\thread\log\ThreadSafeLogger;
|
||||||
use pocketmine\thread\Worker;
|
use pocketmine\thread\Worker;
|
||||||
|
use pocketmine\utils\AssumptionFailedError;
|
||||||
use function gc_enable;
|
use function gc_enable;
|
||||||
use function ini_set;
|
use function ini_set;
|
||||||
|
|
||||||
@ -34,15 +36,21 @@ class AsyncWorker extends Worker{
|
|||||||
/** @var mixed[] */
|
/** @var mixed[] */
|
||||||
private static array $store = [];
|
private static array $store = [];
|
||||||
|
|
||||||
|
private const TLS_KEY_NOTIFIER = self::class . "::notifier";
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private ThreadSafeLogger $logger,
|
private ThreadSafeLogger $logger,
|
||||||
private int $id,
|
private int $id,
|
||||||
private int $memoryLimit,
|
private int $memoryLimit,
|
||||||
private SleeperNotifier $notifier
|
private SleeperHandlerEntry $sleeperEntry
|
||||||
){}
|
){}
|
||||||
|
|
||||||
public function getNotifier() : SleeperNotifier{
|
public function getNotifier() : SleeperNotifier{
|
||||||
return $this->notifier;
|
$notifier = $this->getFromThreadStore(self::TLS_KEY_NOTIFIER);
|
||||||
|
if(!$notifier instanceof SleeperNotifier){
|
||||||
|
throw new AssumptionFailedError("SleeperNotifier not found in thread-local storage");
|
||||||
|
}
|
||||||
|
return $notifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function onRun() : void{
|
protected function onRun() : void{
|
||||||
@ -57,6 +65,8 @@ class AsyncWorker extends Worker{
|
|||||||
ini_set('memory_limit', '-1');
|
ini_set('memory_limit', '-1');
|
||||||
$this->logger->debug("No memory limit set");
|
$this->logger->debug("No memory limit set");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->saveToThreadStore(self::TLS_KEY_NOTIFIER, $this->sleeperEntry->createNotifier());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getLogger() : ThreadSafeLogger{
|
public function getLogger() : ThreadSafeLogger{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user