From fa5fe8a325545def1bc0b54cb951d8119394a164 Mon Sep 17 00:00:00 2001 From: Mark Nadal Date: Wed, 29 Jan 2020 19:05:52 -0800 Subject: [PATCH] refine health --- axe.js | 6 +++--- examples/stats.html | 10 ++++++++++ gun.js | 5 +++-- lib/radisk.js | 15 +++++++++------ lib/store.js | 10 ++++------ 5 files changed, 29 insertions(+), 17 deletions(-) diff --git a/axe.js b/axe.js index 5058cacd..2c5e32ba 100644 --- a/axe.js +++ b/axe.js @@ -32,7 +32,7 @@ var AXE = USE('./root'), Gun = (AXE.window||{}).Gun || USE('./gun', 1); (Gun.AXE = AXE).GUN = AXE.Gun = Gun; - var LOG = console.LOG; + var LOG = console.LOG, ST = 0; Gun.on('opt', function(at){ start(at); @@ -203,7 +203,7 @@ meta.turn = (meta.turn || 0) + 1; if((old && old[id]) || false === mesh.say(msg, peer)){ ++c } } - LOG && Gun.log(S, +new Date - S, 'axe chat'); + LOG && (ST = +new Date - S) > 9 && Gun.log(S, ST, 'axe chat'); //console.log("AXE:", Gun.obj.copy(msg), meta.turn, c, ids, opt.peers === peers); if(0 < c){ if(peers === opt.peers){ return } // prevent infinite lack loop. @@ -230,7 +230,7 @@ if(!to){ return } Gun.obj.to(to, peers); }); - LOG && Gun.log(S, +new Date - S, 'axe put'); + LOG && (ST = +new Date - S) > 9 && Gun.log(S, ST, 'axe put'); mesh.say(msg, peers); return; } diff --git a/examples/stats.html b/examples/stats.html index 3f61233b..a208286e 100644 --- a/examples/stats.html +++ b/examples/stats.html @@ -94,6 +94,16 @@ // tbd later return chart; } +/* + Notes to Self about Debugging: + 1. Read Disks can spike up to 1min, I suspect other operations are blocking it from resolving as fast as it otherwise would. + 2. JSON parsing/stringifying sometimes way slower than other times, why? + 3. Looks like RAD lex read is not optimized. + 4. got prep + got emit = non-RAD problems, compare against read disk & got differentials (should be same). + 5. Radix map/place ops could be slow? + 6. SINGLE MESSAGE PROCESS TIME occasionally is huge, should get emailed. + 7. Watch out for get/put loops times, maybe indicating (5) issues? +*/ \ No newline at end of file diff --git a/gun.js b/gun.js index 3db24c19..58699262 100644 --- a/gun.js +++ b/gun.js @@ -2017,6 +2017,7 @@ } var tomap = function(k,i,m){m(k,true)}; mesh.hear.c = mesh.hear.d = 0; + var noop = function(){}; ;(function(){ var SMIA = 0; @@ -2076,10 +2077,10 @@ peer.batch = peer.tail = null; if(!tmp){ return } if(!tmp.length){ return } // if(3 > tmp.length){ return } // TODO: ^ - var S; LOG && (S = +new Date); + var S, ST; LOG && (S = +new Date); try{tmp = (1 === tmp.length? tmp[0] : JSON.stringify(tmp)); }catch(e){return opt.log('DAM JSON stringify error', e)} - LOG && opt.log(S, +new Date - S, 'say stringify', tmp.length); + LOG && (ST = +new Date - S) > 9 && opt.log(S, ST, 'say stringify', tmp.length); if(!tmp){ return } send(tmp, peer); } diff --git a/lib/radisk.js b/lib/radisk.js index c9ba8196..db8555a7 100644 --- a/lib/radisk.js +++ b/lib/radisk.js @@ -47,7 +47,7 @@ cb = val; var S; LOG && (S = +new Date); val = r.batch(key); - LOG && opt.log(S, +new Date - S, 'rad mem'); + LOG && (ST = +new Date - S) > 9 && opt.log(S, ST, 'rad mem'); if(u !== val){ cb(u, r.range(val, o), o); if(atomic(val)){ return } @@ -223,10 +223,13 @@ var tmp = ename(file); var S; LOG && (S = +new Date); r.list.add(tmp, function(err){ - LOG && opt.log(S, ST = +new Date - S, "wrote disk", tmp); - LOG && (ST > 500) && require('./email').send({text: ""+ST+"ms "+tmp, from: "mark@gun.eco", to: "mark@gun.eco", subject: "RAD DISK WROTE"}, noop); // this is ONLY turned on if ENV CONFIGS have email/password to send out from. if(err){ return cb(err) } - opt.store.put(tmp, f.text, cb); + //opt.store.put(tmp, f.text, cb); // revert to this after stats done below: + opt.store.put(tmp, f.text, function(err,ok){ + LOG && opt.log(S, ST = +new Date - S, "wrote disk", tmp); + LOG && (ST > 500) && require('./email').send({text: ""+ST+"ms "+tmp, from: "mark@gun.eco", to: "mark@gun.eco", subject: "RAD DISK WROTE"}, noop); // this is ONLY turned on if ENV CONFIGS have email/password to send out from. + cb(err,ok); + }); }); } f.slice = function(val, key){ @@ -326,7 +329,7 @@ if(!as.ack){ return } var S; LOG && (S = +new Date); var key = as.key, o = as.opt, info = g.info, rad = g.disk || noop, data = r.range(rad(key), o), last = rad.last || Radix.map(rad, rev, revo); - LOG && opt.log(S, +new Date - S, "rad range loaded"); + LOG && (ST = +new Date - S) > 9 && opt.log(S, ST, "rad range loaded"); o.parsed = (o.parsed || 0) + (info.parsed||0); o.chunks = (o.chunks || 0) + 1; o.more = true; @@ -432,7 +435,7 @@ try{ var json = JSON.parse(data); // TODO: this caused a out-of-memory crash! p.disk.$ = json; - LOG && opt.log(S, ST = +new Date - S, 'rad parsed JSON'); + LOG && (ST = +new Date - S) > 9 && opt.log(S, ST, 'rad parsed JSON'); map(q, p.ack); LOG && (ST > 500) && require('./email').send({text: ""+ST+"ms "+ename(file), from: "mark@gun.eco", to: "mark@gun.eco", subject: "RAD JSON parse"}, noop); // this is ONLY turned on if ENV CONFIGS have email/password to send out from. return; diff --git a/lib/store.js b/lib/store.js index c2b3fe74..68af264c 100644 --- a/lib/store.js +++ b/lib/store.js @@ -7,7 +7,7 @@ Gun.on('create', function(root){ if(false === opt.radisk){ return } var Radisk = (Gun.window && Gun.window.Radisk) || require('./radisk'); var Radix = Radisk.Radix; - var LOG = console.LOG; + var LOG = console.LOG, ST = 0; opt.store = opt.store || (!Gun.window && require('./rfs')(opt)); var rad = Radisk(opt), esc = String.fromCharCode(27); @@ -32,8 +32,7 @@ Gun.on('create', function(root){ rad(soul+esc+key, val, (track? ack : u)); C++; }); - LOG && Gun.log(S, +new Date - S, 'put loop'); - LOG && Gun.log(S, C, 'put loop #'); + if(LOG && (ST = +new Date - S) > 9){ Gun.log(S, ST, 'put loop'); Gun.log(S, C, 'put loop #') } function ack(err, ok){ acks--; if(ack.err){ return } @@ -105,11 +104,10 @@ Gun.on('create', function(root){ } if(!graph && data){ each(data, '') } } - LOG && Gun.log(S, +new Date - S, 'got prep time'); S = +new Date; - LOG && Gun.log(S, C, 'got prep #'); C = 0; + if(LOG && (ST = +new Date - S) > 9){ Gun.log(S, ST, 'got prep time'); Gun.log(S, C, 'got prep #') } C = 0; S = +new Date; var faith = function(){}; faith.faith = true; faith.rad = get; // HNPERF: We're testing performance improvement by skipping going through security again, but this should be audited. root.on('in', {'@': id, put: graph, '%': o.more? 1 : u, err: err? err : u, _: faith}); - LOG && Gun.log(S, +new Date - S, 'got emit', Object.keys(graph||{}).length); + LOG && (ST = +new Date - S) > 9 && Gun.log(S, ST, 'got emit', Object.keys(graph||{}).length); graph = u; // each is outside our scope, we have to reset graph to nothing! }, o); LOG && Gun.log(S, +new Date - S, 'get call');