peer duration time

This commit is contained in:
Mark Nadal 2019-05-20 04:40:26 -07:00
parent 455e9f9c91
commit 5b1a2d1b28
5 changed files with 39 additions and 31 deletions

View File

@ -15,31 +15,32 @@
}
.ct-series-a .ct-line,
.ct-series-a .ct-point {
stroke: blue;
str-oke: blue !important;
}
.ct-series-b .ct-line,
.ct-series-b .ct-point {
stroke: green;
stroke: green !important;
}
.tall { height: 10em; }
</style>
<input id="url" class="center none" placeholder="enter peer stats source url">
<div class="center"><span class="shout" id="peers">0</span> peers <span class="shout" id="nodes">0</span> nodes <span class="shout" id="hours">0</span> hours</div>
<div class="center"><span class="shout" id="peers">0</span> peers <span class="shout" id="time">0</span> min <span class="shout" id="nodes">0</span> nodes <span class="shout" id="hours">0</span> hours</div>
<div class="leak" style="padding: 0 2em;">
<div class="leak ct-mem ct-perfect-fourth tall"></div>
<div class="leak ct-mem ct-chart ct-perfect-fourth tall"></div>
</div>
<div class="center leak" style="padding: 0 2em;">
<div class="unit col leak ct-damc tall" style="width: 49%;"></div>
<div class="unit col leak ct-damd tall" style="width: 49%;"></div>
<div class="unit col leak ct-damc ct-chart tall" style="width: 49%;"></div>
<div class="unit col leak ct-damd ct-chart tall" style="width: 49%;"></div>
</div>
<div class="center leak" style="padding: 0 2em;">
<div class="leak ct-cpu ct-perfect-fourth tall"></div>
<div class="leak ct-cpu ct-chart ct-perfect-fourth tall"></div>
</div>
<script src="./jquery.js"></script>
@ -52,6 +53,7 @@ setInterval(function(){
}, 1000 * 15);
stats.show = function(){ $.getJSON(url.value||(location.origin+'/gun/stats.radata'), function(data){ console.log(data);
$('#peers').text(data.peers.count);
$('#time').text((data.peers.time / 1000 / 60).toFixed(0));
$('#nodes').text(data.node.count);
$('#hours').text((data.up.time / 60 / 60).toFixed(0));
@ -76,8 +78,8 @@ stats.show = function(){ $.getJSON(url.value||(location.origin+'/gun/stats.radat
// A labels array that can contain any sort of values
labels: ['-1min', '-45s', '-30s', '-15s', '0'],
// Our series array that contains series objects or in this case series data arrays
series: [stats.din, stats.dout]
}, {fullWidth: true, low: 0, axisY: {
series: [stats.dout, stats.din]
}, {fullWidth: true, axisY: {
labelInterpolationFnc: function(v) { return v+'msgs' }
}});
@ -87,8 +89,8 @@ stats.show = function(){ $.getJSON(url.value||(location.origin+'/gun/stats.radat
// A labels array that can contain any sort of values
labels: ['-1min', '-45s', '-30s', '-15s', '0'],
// Our series array that contains series objects or in this case series data arrays
series: [stats.dind, stats.doutd]
}, {fullWidth: true, low: 0, axisY: {
series: [stats.doutd, stats.dind]
}, {fullWidth: true, axisY: {
labelInterpolationFnc: function(v) { return v+'MB' }
}});

41
gun.js
View File

@ -2017,21 +2017,14 @@
;(function(){
var message;
function each(peer){ mesh.say(message, peer) }
mesh.say = function(msg, peer, o){
mesh.say = function(msg, peer, o){ var tmp;
/*
TODO: Plenty of performance optimizations
that can be made just based off of ordering,
and reducing function calls for cached writes.
*/
if(!peer){ message = msg;
Type.obj.map(opt.peers, each);
return;
}
var tmp, wire = peer.wire || ((opt.wire) && opt.wire(peer)), msh, raw;// || open(peer, ctx); // TODO: Reopen!
if(!wire){ return }
msh = (msg._) || empty;
if(peer === msh.via){ return }
if(!(raw = msh.raw)){ raw = mesh.raw(msg) }
var meta = (msg._) || empty, raw;
if(!(raw = meta.raw)){ raw = mesh.raw(msg) }
if((tmp = msg['@'])
&& (tmp = ctx.dup.s[tmp])
&& (tmp = tmp.it)){
@ -2039,7 +2032,14 @@
return; // TODO: this still needs to be tested in the browser!
}
}
if((tmp = msh.to) && (tmp[peer.url] || tmp[peer.id]) && !o){ return } // TODO: still needs to be tested
if(!peer){ message = msg;
Type.obj.map(opt.peers, each);
return;
}
var wire = peer.wire || ((opt.wire) && opt.wire(peer));// || open(peer, ctx); // TODO: Reopen!
if(!wire){ return }
if(peer === meta.via){ return }
if((tmp = meta.to) && (tmp[peer.url] || tmp[peer.id]) && !o){ return } // TODO: still needs to be tested
if(peer.batch){
peer.tail = (peer.tail || 0) + raw.length;
if(peer.tail <= opt.pack){
@ -2082,8 +2082,8 @@
mesh.raw = function(msg){
if(!msg){ return '' }
var dup = ctx.dup, msh = (msg._) || {}, put, hash, tmp;
if(tmp = msh.raw){ return tmp }
var dup = ctx.dup, meta = (msg._) || {}, put, hash, tmp;
if(tmp = meta.raw){ return tmp }
if(typeof msg === 'string'){ return msg }
if(msg['@'] && (tmp = msg.put)){
if(!(hash = msg['##'])){
@ -2095,17 +2095,19 @@
msg['#'] = hash || msg['#'];
if(put){ (msg = Type.obj.to(msg)).put = _ }
}
var i = 0, to = []; Type.obj.map(opt.peers, function(p){
to.push(p.url || p.id); if(++i > 9){ return true } // limit server, fast fix, improve later!
}); msg['><'] = to.join();
if(!msg.dam){
var i = 0, to = []; Type.obj.map(opt.peers, function(p){
to.push(p.url || p.id); if(++i > 9){ return true } // limit server, fast fix, improve later!
}); msg['><'] = to.join();
}
var raw = $(msg);
if(u !== put){
tmp = raw.indexOf(_, raw.indexOf('put'));
raw = raw.slice(0, tmp-1) + put + raw.slice(tmp + _.length + 1);
//raw = raw.replace('"'+ _ +'"', put); // https://github.com/amark/gun/wiki/@$$ Heisenbug
}
if(msh){
msh.raw = raw;
if(meta){
meta.raw = raw;
}
return raw;
}
@ -2135,6 +2137,7 @@
tmp = peer.id = tmp.pid = peer.id || Type.text.random(9);
mesh.say({dam: '?'}, opt.peers[tmp] = peer);
}
peer.met = peer.met || +(new Date);
if(!tmp.hied){ ctx.on(tmp.hied = 'hi', peer) }
// @rogowski I need this here by default for now to fix go1dfish's bug
tmp = peer.queue; peer.queue = [];
@ -2145,6 +2148,8 @@
mesh.bye = function(peer){
Type.obj.del(opt.peers, peer.id); // assume if peer.url then reconnect
ctx.on('bye', peer);
var tmp = +(new Date); tmp = (tmp - (peer.met||tmp));
mesh.bye.time = ((mesh.bye.time || tmp) + tmp) / 2;
}
mesh.hear['!'] = function(msg, peer){ opt.log('Error:', msg.err) }
mesh.hear['?'] = function(msg, peer){

2
gun.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -41,6 +41,7 @@ Gun.on('opt', function(root){
if(dam){
stats.dam = {'in': {count: dam.hear.c, done: dam.hear.d}, 'out': {count: dam.say.c, done: dam.say.d}};
dam.hear.c = dam.hear.d = dam.say.c = dam.say.d = 0;
stats.peers.time = dam.bye.time || 0;
}
fs.writeFile(__dirname+'/../stats.'+root.opt.file, JSON.stringify(stats, null, 2), function(err){});

View File

@ -14,7 +14,7 @@
"e2e": "mocha e2e/distributed.js",
"docker": "hooks/build",
"minify": "uglifyjs gun.js -o gun.min.js -c -m",
"unbuild": "node lib/unbuild.js"
"unbuild": "node lib/unbuild.js & npm run minify"
},
"repository": {
"type": "git",