rad stats

This commit is contained in:
Mark 2019-06-13 12:55:47 -07:00
parent 48f9d10e2a
commit 6eaa0f5fa6
3 changed files with 71 additions and 21 deletions

View File

@ -39,6 +39,12 @@
<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="unit col leak ct-radc ct-chart tall" style="width: 49%;"></div>
<div class="unit col leak ct-radt ct-chart tall" style="width: 49%;"></div>
</div>
<div class="center"><span id="rerr"></span></div>
<div class="center leak" style="padding: 0 2em;">
<div class="leak ct-cpu ct-chart ct-perfect-fourth tall"></div>
</div>
@ -47,7 +53,7 @@
<link rel="stylesheet" href="https://cdn.jsdelivr.net/chartist.js/latest/chartist.min.css">
<script src="https://cdn.jsdelivr.net/chartist.js/latest/chartist.min.js"></script>
<script>
var stats = {slide: [0,0,0,0,0], din: [0,0,0,0,0], dout: [0,0,0,0,0], dind: [0,0,0,0,0], doutd: [0,0,0,0,0]};
var stats = {slide: [0,0,0,0,0], din: [0,0,0,0,0], dout: [0,0,0,0,0], dind: [0,0,0,0,0], doutd: [0,0,0,0,0], rgetc: [0,0,0,0,0], rputc: [0,0,0,0,0]};
setInterval(function(){
stats.show();
}, 1000 * 15);
@ -94,6 +100,34 @@ stats.show = function(){ $.getJSON(url.value||(location.origin+'/gun/stats.radat
labelInterpolationFnc: function(v) { return v+'MB' }
}});
try{ $('#rerr').text(data.rad.put.err || data.rad.get.err) }catch(e){}
try{
stats.rgetc.push(data.rad.get.count); stats.rgetc = stats.rgetc.slice(1);
stats.rputc.push(data.rad.put.count); stats.rputc = stats.rputc.slice(1);
new Chartist.Line('.ct-radc', {
// 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.rputc, stats.rgetc]
}, {fullWidth: true, axisY: {
labelInterpolationFnc: function(v) { return v+'io' }
}});
}catch(e){}
try{
stats.radgt = Object.values(data.rad.get.time).map(function(n){ return n/1000 });
stats.radpt = Object.values(data.rad.put.time).map(function(n){ return n/1000 });
new Chartist.Line('.ct-radt', {
// 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.radpt, stats.radgt]
}, {fullWidth: true, axisY: {
labelInterpolationFnc: function(v) { return v+'sec' }
}});
}catch(e){}
new Chartist.Line('.ct-cpu', {
// A labels array that can contain any sort of values
labels: ['-15min', '-5min', '1min'],

View File

@ -40,9 +40,14 @@ Gun.on('opt', function(root){
var dam = root.opt.mesh;
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;
dam.hear.c = dam.hear.d = dam.say.c = dam.say.d = 0; // reset
stats.peers.time = dam.bye.time || 0;
}
var rad = root.opt.store; rad = rad && rad.stats;
if(rad){
stats.rad = rad;
root.opt.store.stats = {get:{time:{}, count:0}, put: {time:{}, count:0}}; // reset
}
fs.writeFile(__dirname+'/../stats.'+root.opt.file, JSON.stringify(stats, null, 2), function(err){});
}, 1000 * 15);

View File

@ -15,6 +15,7 @@ Gun.on('create', function(root){
this.to.next(msg);
var id = msg['#'] || Gun.text.random(3), track = !msg['@'], acks = track? 0 : u; // only ack non-acks.
if(msg.rad && !track){ return } // don't save our own acks
var start = (+new Date); // STATS!
Gun.graph.is(msg.put, null, function(val, key, node, soul){
if(track){ ++acks }
//console.log('put:', soul, key, val);
@ -25,10 +26,14 @@ Gun.on('create', function(root){
acks--;
if(ack.err){ return }
if(ack.err = err){
try{opt.store.stats.put.err = err}catch(e){} // STATS!
root.on('in', {'@': id, err: err});
return;
}
if(acks){ return }
try{opt.store.stats.put.time[statp % 50] = (+new Date) - start; ++statp;
opt.store.stats.put.count++;
}catch(e){} // STATS!
//console.log("PAT!", id);
root.on('in', {'@': id, ok: 1});
}
@ -36,39 +41,43 @@ Gun.on('create', function(root){
root.on('get', function(msg){
this.to.next(msg);
var id = msg['#'], get = msg.get, soul = msg.get['#'], has = msg.get['.']||'', opt = {}, graph, lex, key, tmp, force;
var id = msg['#'], get = msg.get, soul = msg.get['#'], has = msg.get['.']||'', o = {}, graph, lex, key, tmp, force;
if('string' == typeof soul){
key = soul;
} else
if(soul){
if(u !== (tmp = soul['*'])){ opt.limit = force = 1 }
if(u !== soul['>']){ opt.start = soul['>'] }
if(u !== soul['<']){ opt.end = soul['<'] }
if(u !== (tmp = soul['*'])){ o.limit = force = 1 }
if(u !== soul['>']){ o.start = soul['>'] }
if(u !== soul['<']){ o.end = soul['<'] }
key = force? (''+tmp) : tmp || soul['='];
force = null;
}
if(key && !opt.limit){ // a soul.has must be on a soul, and not during soul*
if(key && !o.limit){ // a soul.has must be on a soul, and not during soul*
if('string' == typeof has){
key = key+esc+(opt.atom = has);
key = key+esc+(o.atom = has);
} else
if(has){
if(u !== has['>']){ opt.start = has['>']; opt.limit = 1 }
if(u !== has['<']){ opt.end = has['<']; opt.limit = 1 }
if(u !== (tmp = has['*'])){ opt.limit = force = 1 }
if(key){ key = key+esc + (force? (''+(tmp||'')) : tmp || (opt.atom = has['='] || '')) }
if(u !== has['>']){ o.start = has['>']; o.limit = 1 }
if(u !== has['<']){ o.end = has['<']; o.limit = 1 }
if(u !== (tmp = has['*'])){ o.limit = force = 1 }
if(key){ key = key+esc + (force? (''+(tmp||'')) : tmp || (o.atom = has['='] || '')) }
}
}
if((tmp = get['%']) || opt.limit){
opt.limit = (tmp <= (opt.pack || (1000 * 100)))? tmp : 1;
if((tmp = get['%']) || o.limit){
o.limit = (tmp <= (o.pack || (1000 * 100)))? tmp : 1;
}
if(has['-'] || (soul||{})['-']){ opt.reverse = true }
//console.log("RAD get:", key, opt);
//var start = (+new Date); // console.log("GET!", id, JSON.stringify(key));
if(has['-'] || (soul||{})['-']){ o.reverse = true }
//console.log("RAD get:", key, o);
var start = (+new Date); // STATS! // console.log("GET!", id, JSON.stringify(key));
rad(key||'', function(err, data, o){
try{opt.store.stats.get.time[statg % 50] = (+new Date) - start; ++statg;
opt.store.stats.get.count++;
if(err){ opt.store.stats.get.err = err }
}catch(e){} // STATS!
//console.log("RAD gat:", err, data, o);
if(data){
if(typeof data !== 'string'){
if(opt.atom){
if(o.atom){
data = u;
} else {
Radix.map(data, each)
@ -78,18 +87,20 @@ Gun.on('create', function(root){
}
//console.log("GOT!", id, JSON.stringify(key), ((+new Date) - start));
root.on('in', {'@': id, put: graph, err: err? err : u, rad: Radix});
}, opt);
}, o);
function each(val, has, a,b){
if(!val){ return }
has = (key+has).split(esc);
var soul = has.slice(0,1)[0];
has = has.slice(-1)[0];
opt.count = (opt.count || 0) + val.length;
o.count = (o.count || 0) + val.length;
tmp = val.lastIndexOf('>');
var state = Radisk.decode(val.slice(tmp+1), null, esc);
val = Radisk.decode(val.slice(0,tmp), null, esc);
(graph = graph || {})[soul] = Gun.state.ify(graph[soul], has, state, val, soul);
if(opt.limit && opt.limit <= opt.count){ return true }
if(o.limit && o.limit <= o.count){ return true }
}
});
opt.store.stats = {get:{time:{}, count:0}, put: {time:{}, count:0}}; // STATS!
var statg = 0, statp = 0; // STATS!
});