From 328ae52c2c42f7be7e2c2cb9764237e2eca70f02 Mon Sep 17 00:00:00 2001 From: Mark Nadal Date: Sun, 2 Feb 2020 01:09:48 -0800 Subject: [PATCH] begin --- gun.js | 21 +++++++++++++-------- lib/evict.js | 2 +- lib/radisk.js | 6 ++++-- lib/store.js | 2 +- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/gun.js b/gun.js index 9a165f46..b4f81ef9 100644 --- a/gun.js +++ b/gun.js @@ -1957,7 +1957,7 @@ ;USE(function(module){ var Type = USE('../type'); - var puff = (typeof setImmediate !== "undefined")? setImmediate : setTimeout; + var puff = setTimeout; //(typeof setImmediate !== "undefined")? setImmediate : setTimeout; function Mesh(root){ var mesh = function(){}; @@ -1976,15 +1976,18 @@ if('{' != raw[2]){ mesh.hear.d += raw.length||0; ++mesh.hear.c; } // STATS! // ugh, stupid double JSON encoding if('[' === tmp){ try{msg = JSON.parse(raw);}catch(e){opt.log('DAM JSON parse error', e)} + raw = ''; if(!msg){ return } LOG && opt.log(+new Date, msg.length, '# on hear batch'); (function go(){ // stats on single msg is 99% spike of batch stats. - var m, c = 100; // hardcoded for now? - while(c-- && (m = msg.shift())){ + var m, i = 0, c = 100; // hardcoded for now? + while(c-- && (m = msg[i++])){ mesh.hear(m, peer); } + msg = msg.slice(i); + // TODO: consider triggering peer flush to response times speedier! if(!msg.length){ return } - puff(go, 0); + puff(go, 1); }()); return; } @@ -1995,14 +1998,15 @@ if(!(id = msg['#'])){ id = msg['#'] = Type.text.random(9) } if(msg.DBG_s){ opt.log(+new Date - msg.DBG_s, 'to hear', id) } if(dup.check(id)){ return } - dup.track(id, true).it = it(msg); // GUN core also dedups, so `true` is needed. // Does GUN core need to dedup anymore? - if(!(hash = msg['##']) && u !== msg.put){ hash = msg['##'] = Type.obj.hash(msg.put) } + dup.track(id, true); //.it = it(msg); // GUN core also dedups, so `true` is needed. // Does GUN core need to dedup anymore? + /*if(!(hash = msg['##']) && u !== msg.put){ hash = msg['##'] = Type.obj.hash(msg.put) } if(hash && (tmp = msg['@'] || (msg.get && id))){ // Reduces backward daisy in case varying hashes at different daisy depths are the same. if(dup.check(tmp+hash)){ return } dup.track(tmp+hash, true).it = it(msg); // GUN core also dedups, so `true` is needed. // Does GUN core need to dedup anymore? } - (msg._ = function(){}).via = peer; if(tmp = msg['><']){ (msg._).to = Type.obj.map(tmp.split(','), tomap) } + */ // TOOD: COME BACK TO THIS LATER!!! IMPORTANT MESH STUFF!! + (msg._ = function(){}).via = peer; if(msg.dam){ if(tmp = mesh.hear[msg.dam]){ tmp(msg, peer, root); @@ -2010,7 +2014,8 @@ return; } var S, ST; LOG && (S = +new Date); console.STAT = {}; - root.on('in', msg); + //root.on('in', msg); + root.on('in2', msg); if(LOG && !msg.nts && (ST = +new Date - S) > 9){ opt.log(S, ST, 'msg', msg['#'], JSON.stringify(console.STAT)); if(ST > 500){ try{ require('./lib/email').send({text: ""+ST+"ms "+JSON.stringify(msg)+" | "+JSON.stringify(console.STAT), from: "mark@gun.eco", to: "mark@gun.eco", subject: "GUN MSG"}, noop); }catch(e){} } } // this is ONLY turned on if ENV CONFIGS have email/password to send out from. return; } diff --git a/lib/evict.js b/lib/evict.js index 48e69437..8647f95e 100644 --- a/lib/evict.js +++ b/lib/evict.js @@ -10,7 +10,7 @@ try{ heap = require('v8').getHeapStatistics }catch(e){} if(!heap){ return } - ev.max = parseFloat(root.opt.memory || (heap().heap_size_limit / 1024 / 1024) || process.env.WEB_MEMORY || 1399) * 0.8; // max_old_space_size defaults to 1400 MB. Note: old space !== memory space though. + ev.max = parseFloat(root.opt.memory || (heap().heap_size_limit / 1024 / 1024) || process.env.WEB_MEMORY || 1399) * 0.8; // max_old_space_size defaults to 1400 MB. Note: old space !== memory space though. // KEEPING USED_HEA_SIZE < HEAP_SIZE_LIMIT ONLY THING TO BE BELOW TO PREVENT CRASH! setInterval(check, 1000); function check(){ diff --git a/lib/radisk.js b/lib/radisk.js index b08a56e8..3e7ac2f0 100644 --- a/lib/radisk.js +++ b/lib/radisk.js @@ -174,12 +174,14 @@ return; } disk = disk || Radix(); - var S; LOG && (S = +new Date); + var S, C = 0; LOG && (S = +new Date); Radix.map(mem, function(val, key){ + C++; // PLUGIN: consider adding HAM as an extra layer of protection disk(key, val); // merge batch[key] -> disk[key] }); - LOG && opt.log(S, +new Date - S, "rad merge mem & disk"); + LOG && opt.log(S, +new Date - S, "rad merge"); + LOG && opt.log(S, C, "rad merge #"); r.write(file, disk, s.pop); }) } diff --git a/lib/store.js b/lib/store.js index 55a32487..be5c5b0a 100644 --- a/lib/store.js +++ b/lib/store.js @@ -96,7 +96,7 @@ Gun.on('create', function(root){ if(err){ opt.store.stats.get.err = err } }catch(e){} // STATS! //if(u === data && o.chunks > 1){ return } // if we already sent a chunk, ignore ending empty responses. // this causes tests to fail. - LOG && Gun.log(S, +new Date - S, 'got'); S = +new Date; + LOG && Gun.log(S, +new Date - S, 'got', JSON.stringify(key)); S = +new Date; if(data){ if(typeof data !== 'string'){ if(o.atom){