Benchmark logging

This commit is contained in:
斟酌 鵬兄 2022-04-03 21:52:44 +09:00
parent a7f5cdbeb5
commit 38f2911266
5 changed files with 35 additions and 18 deletions

View File

@ -93,7 +93,7 @@ class Dragonfly
var tag = cluster.isMaster ? "M" : "S";
this.ptag = "[ " + tag + ":" + process.pid + " ] ";
this.Info( "Dragonfly ready.", Dragonfly.Visibility.VISIBLE );
// this.Info( "Dragonfly ready.", Dragonfly.Visibility.VISIBLE );
}
Debug( mesg, visibility )

View File

@ -57,6 +57,7 @@ function AppDomain( handler, port, cluster )
var http = require( "http" );
var server = http.createServer(
function(req, res) {
res._hrtime = process.hrtime.bigint();
serverHandle( server, req, res, handler );
}
);

View File

@ -169,7 +169,7 @@ class WebFrame
this.HTTP.response.headers["Content-Length"] = data.length;
this.HTTP.response.write( data );
this.HTTP.response.end();
Dragonfly.Debug( "Result Planted" );
Dragonfly.Debug( `Result Planted: ${process.hrtime.bigint() - this.HTTP.response.raw._hrtime}ns` );
}
__storeCache( data, cache, ttl )

View File

@ -13,7 +13,20 @@ Package.prototype.rootNS = function( name, path )
rootNS[ name ] = fs.realpathSync( path ) + "/";
};
Package.prototype.load = function( _class, deCache )
var _reload = function( e, filename )
{
if( this._lock )
return;
this._lock = true;
setTimeout( () =>
{
global.Dragonfly.Info( `Change detected: ${this.src}, reloading` );
global.X_SERVER_CLUSTER.worker.destroy();
} , 200 );
};
Package.prototype.load = function( _class )
{
var fSep = _class.indexOf( "." );
var nsdomain = _class.substr( 0, fSep );
@ -21,14 +34,16 @@ Package.prototype.load = function( _class, deCache )
var file = rootNS[ nsdomain ] + _class;
var lClass = require( file );
// TODO: Implements filewatcher
if( deCache )
if( global.debug && global.X_SERVER_CLUSTER )
{
delete require.cache[ require.resolve( file ) ];
var src = require.resolve( file );
if(!( src in require.cache ))
{
fs.watch( src, _reload.bind({ "src": src }) );
}
}
return lClass;
return require( file );
};
global.botanLoader = new Package();

View File

@ -50,7 +50,7 @@ class PageCache
, headers: {
"Content-Length": res.headers[ "Content-Length" ]
, "Content-Type": res.headers[ "Content-Type" ]
, "X-Cache-Expires": new Date( expires )
, "X-Cache-Expirls": new Date( expires ).toISOString()
}
, statusCode: res.statusCode
, ttl: expires
@ -87,18 +87,19 @@ class PageCache
if( url in store )
{
Dragonfly.Info(
"[C] "
+ ( req.headers[ "x-forwarded-for" ] || req.connection.remoteAddress ) + " "
+ req.method + ": " + encodeURI( url )
+ " - " + req.headers["user-agent"]
, Dragonfly.Visibility.VISIBLE
);
var c = store[ url ];
res.writeHead( c.statusCode, c.headers );
res.end( c.data );
Dragonfly.Info(
"[C] "
+ ( req.headers[ "x-forwarded-for" ] || req.connection.remoteAddress ) + " "
+ req.method + ": " + url
+ " - " + req.headers["user-agent"]
+ ` in ${process.hrtime.bigint() - res._hrtime}ns`
, Dragonfly.Visibility.VISIBLE
);
return true;
}