mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-16 10:49:10 +00:00
Added extra memory reportings (heap, stack), stop tasks faster, added extra timeouts fro ServerKiller
This commit is contained in:
parent
2ac27bd382
commit
33e312c7d0
@ -470,7 +470,7 @@ namespace pocketmine {
|
||||
$thread->quit();
|
||||
}
|
||||
|
||||
$killer = new ServerKiller();
|
||||
$killer = new ServerKiller(8);
|
||||
$killer->start();
|
||||
$killer->detach();
|
||||
|
||||
|
@ -106,6 +106,7 @@ use pocketmine\utils\Config;
|
||||
use pocketmine\utils\LevelException;
|
||||
use pocketmine\utils\MainLogger;
|
||||
use pocketmine\utils\ServerException;
|
||||
use pocketmine\utils\ServerKiller;
|
||||
use pocketmine\utils\Terminal;
|
||||
use pocketmine\utils\TextFormat;
|
||||
use pocketmine\utils\TextWrapper;
|
||||
@ -2069,6 +2070,11 @@ class Server{
|
||||
* Shutdowns the server correctly
|
||||
*/
|
||||
public function shutdown(){
|
||||
if($this->isRunning){
|
||||
$killer = new ServerKiller(90);
|
||||
$killer->start();
|
||||
$killer->detach();
|
||||
}
|
||||
$this->isRunning = false;
|
||||
}
|
||||
|
||||
@ -2423,9 +2429,11 @@ class Server{
|
||||
if(!Terminal::hasFormattingCodes()){
|
||||
return;
|
||||
}
|
||||
|
||||
$d = Utils::getRealMemoryUsage();
|
||||
|
||||
$u = Utils::getMemoryUsage(true);
|
||||
$usage = round(($u[0] / 1024) / 1024, 2) . "/" . round(($u[1] / 1024) / 1024, 2) . "/".round(($u[2] / 1024) / 1024, 2)." MB @ " . Utils::getThreadCount() . " threads";
|
||||
$usage = round(($u[0] / 1024) / 1024, 2) . "/" . round(($d[0] / 1024) / 1024, 2) . "/" . round(($u[1] / 1024) / 1024, 2) . "/".round(($u[2] / 1024) / 1024, 2)." MB @ " . Utils::getThreadCount() . " threads";
|
||||
|
||||
echo "\x1b]0;" . $this->getName() . " " .
|
||||
$this->getPocketMineVersion() .
|
||||
|
@ -41,6 +41,7 @@ class StatusCommand extends VanillaCommand{
|
||||
return true;
|
||||
}
|
||||
|
||||
$rUsage = Utils::getRealMemoryUsage(true);
|
||||
$mUsage = Utils::getMemoryUsage(true);
|
||||
|
||||
$server = $sender->getServer();
|
||||
@ -88,7 +89,9 @@ class StatusCommand extends VanillaCommand{
|
||||
$sender->sendMessage(TextFormat::GOLD . "Thread count: " . TextFormat::RED . Utils::getThreadCount());
|
||||
|
||||
$sender->sendMessage(TextFormat::GOLD . "Main thread memory: " . TextFormat::RED . number_format(round(($mUsage[0] / 1024) / 1024, 2)) . " MB.");
|
||||
$sender->sendMessage(TextFormat::GOLD . "Allocated memory: " . TextFormat::RED . number_format(round(($mUsage[1] / 1024) / 1024, 2)) . " MB.");
|
||||
$sender->sendMessage(TextFormat::GOLD . "Total memory: " . TextFormat::RED . number_format(round(($mUsage[1] / 1024) / 1024, 2)) . " MB.");
|
||||
$sender->sendMessage(TextFormat::GOLD . "Total virtual memory: " . TextFormat::RED . number_format(round(($mUsage[2] / 1024) / 1024, 2)) . " MB.");
|
||||
$sender->sendMessage(TextFormat::GOLD . "Heap memory: " . TextFormat::RED . number_format(round(($rUsage[0] / 1024) / 1024, 2)) . " MB.");
|
||||
$sender->sendMessage(TextFormat::GOLD . "Maximum memory (system): " . TextFormat::RED . number_format(round(($mUsage[2] / 1024) / 1024, 2)) . " MB.");
|
||||
|
||||
if($server->getProperty("memory.global-limit") > 0){
|
||||
|
@ -2544,7 +2544,7 @@ class Level implements ChunkManager, Metadatable{
|
||||
++$y;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$v->y = $y;
|
||||
}
|
||||
|
||||
|
@ -122,6 +122,7 @@ class AsyncPool{
|
||||
public function removeTasks(){
|
||||
do{
|
||||
foreach($this->tasks as $task){
|
||||
$task->cancelRun();
|
||||
$this->removeTask($task);
|
||||
}
|
||||
|
||||
@ -144,7 +145,9 @@ class AsyncPool{
|
||||
foreach($this->tasks as $task){
|
||||
if($task->isGarbage() and !$task->isRunning()){
|
||||
|
||||
$task->onCompletion($this->server);
|
||||
if(!$task->hasCancelledRun()){
|
||||
$task->onCompletion($this->server);
|
||||
}
|
||||
|
||||
$this->removeTask($task);
|
||||
}elseif($task->isTerminated()){
|
||||
|
@ -35,13 +35,16 @@ abstract class AsyncTask extends \Collectable{
|
||||
|
||||
private $result = null;
|
||||
private $serialized = false;
|
||||
private $cancelRun = false;
|
||||
/** @var int */
|
||||
private $taskId = null;
|
||||
|
||||
public function run(){
|
||||
$this->result = null;
|
||||
|
||||
$this->onRun();
|
||||
if($this->cancelRun !== true){
|
||||
$this->onRun();
|
||||
}
|
||||
|
||||
$this->setGarbage();
|
||||
}
|
||||
@ -62,6 +65,14 @@ abstract class AsyncTask extends \Collectable{
|
||||
return $this->serialized ? unserialize($this->result) : $this->result;
|
||||
}
|
||||
|
||||
public function cancelRun(){
|
||||
$this->cancelRun = true;
|
||||
}
|
||||
|
||||
public function hasCancelledRun(){
|
||||
return $this->cancelRun === true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
|
@ -139,7 +139,7 @@ class SendUsageTask extends AsyncTask{
|
||||
|
||||
public function onRun(){
|
||||
try{
|
||||
Utils::postURL($this->endpoint, $this->data, 10, [
|
||||
Utils::postURL($this->endpoint, $this->data, 5, [
|
||||
"Content-Type: application/json",
|
||||
"Content-Length: ". strlen($this->data)
|
||||
]);
|
||||
|
@ -25,8 +25,14 @@ use pocketmine\Thread;
|
||||
|
||||
class ServerKiller extends Thread{
|
||||
|
||||
public $time;
|
||||
|
||||
public function __construct($time = 15){
|
||||
$this->time = $time;
|
||||
}
|
||||
|
||||
public function run(){
|
||||
sleep(15);
|
||||
sleep($this->time);
|
||||
echo "\nTook to long to stop, server was killed forcefully!\n";
|
||||
@\pocketmine\kill(getmypid());
|
||||
}
|
||||
|
@ -216,6 +216,26 @@ class Utils{
|
||||
}
|
||||
|
||||
|
||||
public static function getRealMemoryUsage(){
|
||||
$stack = 0;
|
||||
$heap = 0;
|
||||
|
||||
if(Utils::getOS() === "linux" or Utils::getOS() === "android"){
|
||||
$mappings = file("/proc/self/maps");
|
||||
foreach($mappings as $line){
|
||||
if(preg_match("#([a-z0-9]+)\\-([a-z0-9]+) [rwxp\\-]{4} [a-z0-9]+ [^\\[]*\\[([a-zA-z0-9]+)\\]#", trim($line), $matches) > 0){
|
||||
if(strpos($matches[3], "heap") === 0){
|
||||
$heap += hexdec($matches[2]) - hexdec($matches[1]);
|
||||
}elseif(strpos($matches[3], "stack") === 0){
|
||||
$stack += hexdec($matches[2]) - hexdec($matches[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [$heap, $stack];
|
||||
}
|
||||
|
||||
public static function getMemoryUsage($advanced = false){
|
||||
$reserved = memory_get_usage();
|
||||
$VmSize = null;
|
||||
@ -482,6 +502,7 @@ class Utils{
|
||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, (int) $timeout);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, (int) $timeout);
|
||||
$ret = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
|
||||
@ -515,6 +536,7 @@ class Utils{
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array_merge(["User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0 PocketMine-MP"], $extraHeaders));
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, (int) $timeout);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, (int) $timeout);
|
||||
$ret = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user