Improved memory output, logging, removed locks

This commit is contained in:
Shoghi Cervantes 2015-03-22 03:20:48 +01:00
parent d2bf92c3ed
commit 1666602652
No known key found for this signature in database
GPG Key ID: 78464DB0A7837F89
7 changed files with 34 additions and 41 deletions

View File

@ -1561,6 +1561,8 @@ class Server{
$this->logger->warning($this->getName() . " may not work right with less than 128MB of memory"); $this->logger->warning($this->getName() . " may not work right with less than 128MB of memory");
} }
@ini_set("memory_limit", $memory); @ini_set("memory_limit", $memory);
$this->logger->notice("The memory limit will only affect the main thread, and it's unreliable.");
$this->logger->notice("To control the memory usage, reduce the amount of threads and chunks loaded");
} }
if($this->getConfigBoolean("hardcore", false) === true and $this->getDifficulty() < 3){ if($this->getConfigBoolean("hardcore", false) === true and $this->getDifficulty() < 3){
@ -1855,6 +1857,8 @@ class Server{
$this->logger->warning($this->getName() . " may not work right with less than 256MB of memory", true, true, 0); $this->logger->warning($this->getName() . " may not work right with less than 256MB of memory", true, true, 0);
} }
@ini_set("memory_limit", $memory); @ini_set("memory_limit", $memory);
$this->logger->notice("The memory limit will only affect the main thread, and it's unreliable.");
$this->logger->notice("To control the memory usage, reduce the amount of threads and chunks loaded");
} }
if($this->getConfigBoolean("hardcore", false) === true and $this->getDifficulty() < 3){ if($this->getConfigBoolean("hardcore", false) === true and $this->getDifficulty() < 3){
@ -2192,14 +2196,8 @@ class Server{
return; return;
} }
$usage = $this->getMemoryUsage(); $u = $this->getMemoryUsage(true);
if($usage === null){ $usage = round(($u[0] / 1024) / 1024, 2) . "/".round(($u[1] / 1024) / 1024, 2)." MB @ " . $this->getThreadCount() . " threads";
$usage = round((memory_get_usage() / 1024) / 1024, 2) .
"/" . round((memory_get_usage(true) / 1024) / 1024, 2) .
" MB @ " . $this->getThreadCount() . " threads";
}else{
$usage = round(($usage / 1024) / 1024, 2) . " MB @ " . $this->getThreadCount() . " threads";
}
echo "\x1b]0;" . $this->getName() . " " . echo "\x1b]0;" . $this->getName() . " " .
$this->getPocketMineVersion() . $this->getPocketMineVersion() .
@ -2213,34 +2211,31 @@ class Server{
public function getMemoryUsage($advanced = false){ public function getMemoryUsage($advanced = false){
$VmSize = null; $VmSize = null;
$VmHWM = null; $VmRSS = null;
if(Utils::getOS() === "linux" or Utils::getOS() === "bsd"){ if(Utils::getOS() === "linux" or Utils::getOS() === "bsd"){
$status = file_get_contents("/proc/self/status"); $status = file_get_contents("/proc/self/status");
if(preg_match("/VmHWM:[ \t]+([0-9]+) kB/", $status, $matches) > 0){ if(preg_match("/VmRSS:[ \t]+([0-9]+) kB/", $status, $matches) > 0){
$VmHWM = $matches[1] * 1024; $VmRSS = $matches[1] * 1024;
} }
if(preg_match("/VmData:[ \t]+([0-9]+) kB/", $status, $matches) > 0){ if(preg_match("/VmSize:[ \t]+([0-9]+) kB/", $status, $matches) > 0){
$VmData = $matches[1] * 1024; $VmSize = $matches[1] * 1024;
} }
} }
if($VmHWM === null){ if($VmRSS === null){
$VmHWM = memory_get_usage(); $VmRSS = memory_get_usage();
} }
if(!$advanced){ if(!$advanced){
return $VmHWM; return $VmRSS;
} }
if($VmSize === null){ if($VmSize === null){
$VmSize = memory_get_usage(true); $VmSize = memory_get_usage(true);
} }
return [ return [$VmRSS, $VmSize];
"hardware" => $VmHWM,
"virtual" => $VmSize,
];
} }
public function getThreadCount(){ public function getThreadCount(){

View File

@ -25,10 +25,6 @@
namespace pocketmine\utils; namespace pocketmine\utils;
use pocketmine\entity\Entity; use pocketmine\entity\Entity;
/**
* WARNING: This class is available on the PocketMine-MP Zephir project.
* If this class is modified, remember to modify the PHP C extension.
*/
class Binary{ class Binary{
const BIG_ENDIAN = 0x00; const BIG_ENDIAN = 0x00;
const LITTLE_ENDIAN = 0x01; const LITTLE_ENDIAN = 0x01;

View File

@ -47,7 +47,7 @@ class MainLogger extends \AttachableThreadedLogger{
$this->logFile = $logFile; $this->logFile = $logFile;
$this->logDebug = (bool) $logDebug; $this->logDebug = (bool) $logDebug;
$this->logStream = ""; $this->logStream = "";
$this->start(PTHREADS_INHERIT_NONE); $this->start();
} }
/** /**
@ -190,7 +190,11 @@ class MainLogger extends \AttachableThreadedLogger{
$this->attachment->call($level, $message); $this->attachment->call($level, $message);
} }
$this->logStream .= date("Y-m-d", $now) . " " . $cleanMessage; $str = date("Y-m-d", $now) . " " . $cleanMessage . "\n";
$this->synchronized(function($str){
$this->logStream .= $str;
$this->notify();
}, $str);
} }
public function run(){ public function run(){
@ -201,15 +205,15 @@ class MainLogger extends \AttachableThreadedLogger{
} }
while($this->shutdown === false){ while($this->shutdown === false){
if(strlen($this->logStream) > 0){ $this->synchronized(function(){
$this->lock(); if(strlen($this->logStream) > 0){
$chunk = $this->logStream; $chunk = $this->logStream;
$this->logStream = ""; $this->logStream = "";
$this->unlock(); fwrite($this->logResource, $chunk);
fwrite($this->logResource, $chunk); }else{
}else{ $this->wait(250000);
usleep(250000); }
} });
} }
if(strlen($this->logStream) > 0){ if(strlen($this->logStream) > 0){

View File

@ -24,8 +24,6 @@ namespace pocketmine\utils;
/** /**
* Unsecure Random Number Noise, used for fast seeded values * Unsecure Random Number Noise, used for fast seeded values
* WARNING: This class is available on the PocketMine-MP Zephir project.
* If this class is modified, remember to modify the PHP C extension.
*/ */
class Random{ class Random{

View File

@ -70,9 +70,9 @@ abstract class TextFormat{
*/ */
public static function clean($string, $removeFormat = true){ public static function clean($string, $removeFormat = true){
if($removeFormat){ if($removeFormat){
return preg_replace(["/§[0123456789abcdefklmnor]/", "/\x1b\\[[0-9;]+m/"], "", $string); return preg_replace(["/§[0123456789abcdefklmnor]/", "/\x1b[\\(\\][[0-9;\\[\\(]+[Bm]/"], "", $string);
} }
return preg_replace("/\x1b\\[[0-9;]+m/", "", $string); return preg_replace("/\x1b[\\(\\][[0-9;\\[\\(]+[Bm]/", "", $string);
} }
/** /**

@ -1 +1 @@
Subproject commit 7c0888f4ad51c4eb9b695c38691b16aa08522493 Subproject commit 639108fb3aeb48a113df3b31516af6ac4f5ba402

@ -1 +1 @@
Subproject commit 695451daf403d86e9db11e6119a6c9cef7f85463 Subproject commit 5ad5b3535c9519b2e013a61a2d55fccae014e037