From 68f4308664ccbf95028fad94b14516ff0ef622f0 Mon Sep 17 00:00:00 2001 From: Mark Nadal Date: Tue, 17 Sep 2019 01:53:56 -0700 Subject: [PATCH 1/6] loopit --- gun.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/gun.js b/gun.js index a06a6c75..59a9b2c2 100644 --- a/gun.js +++ b/gun.js @@ -1295,19 +1295,18 @@ if(tmp = cat.soul || cat.link || cat.dub){ return cb(tmp, as, cat) } if(cat.jam){ return cat.jam.push([cb, as]) } cat.jam = [[cb,as]]; - gun.get(function(msg, eve){ + gun.get(function go(msg, eve){ if(u === msg.put && (tmp = Object.keys(cat.root.opt.peers).length) && ++acks < tmp){ return; } eve.rid(msg); - var at = ((at = msg.$) && at._) || {}; - tmp = cat.jam; Gun.obj.del(cat, 'jam'); - Gun.obj.map(tmp, function(as, cb){ - cb = as[0]; as = as[1]; - if(!cb){ return } - var id = at.link || at.soul || rel.is(msg.put) || node_soul(msg.put) || at.dub; - cb(id, as, msg, eve); - }); + var at = ((at = msg.$) && at._) || {}, i = 0, as; + tmp = cat.jam; delete cat.jam; // tmp = cat.jam.splice(0, 100); + //if(tmp.length){ process.nextTick(function(){ go(msg, eve) }) } + while(as = tmp[i++]){ //Gun.obj.map(tmp, function(as, cb){ + var cb = as[0], id; as = as[1]; + cb && cb(id = at.link || at.soul || rel.is(msg.put) || node_soul(msg.put) || at.dub, as, msg, eve); + } //); }, {out: {get: {'.':true}}}); return gun; } @@ -1701,7 +1700,7 @@ return; } if(link && u === link.put && (tmp = rel.is(data))){ data = Gun.node.ify({}, tmp) } - eve.rid(msg); + eve.rid? eve.rid(msg) : eve.off(); opt.ok.call(gun || opt.$, data, msg.get); } From 1f0d0d62b0b0ce0f0fbf6112c47455a3b4a38dc5 Mon Sep 17 00:00:00 2001 From: Mark Nadal Date: Tue, 17 Sep 2019 03:15:13 -0700 Subject: [PATCH 2/6] does puff help? --- gun.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/gun.js b/gun.js index 8c2b71f5..8661c693 100644 --- a/gun.js +++ b/gun.js @@ -1954,6 +1954,7 @@ ;USE(function(module){ var Type = USE('../type'); + var puff = (typeof setImmediate !== "undefined")? setImmediate : setTimeout; function Mesh(root){ var mesh = function(){}; @@ -1972,10 +1973,16 @@ if('[' === tmp){ try{msg = JSON.parse(raw);}catch(e){opt.log('DAM JSON parse error', e)} if(!msg){ return } - var i = 0, m; - while(m = msg[i++]){ - mesh.hear(m, peer); - } + (function go(){ + var S = +new Date; // STATS! + var m, c = 100; // hardcoded for now? + while(c-- && (m = msg.shift())){ + mesh.hear(m, peer); + } + (mesh.hear.long || (mesh.hear.long = [])).push(+new Date - S); + if(!msg.length){ return } + puff(go, 0); + }()); return; } if('{' === tmp || (Type.obj.is(raw) && (msg = raw))){ From 7cd19b3d676f80127cba7ce8e01fc72bcc9df4d6 Mon Sep 17 00:00:00 2001 From: Mark Nadal Date: Thu, 19 Sep 2019 17:00:16 -0700 Subject: [PATCH 3/6] debug info --- gun.js | 5 +++++ lib/evict.js | 2 ++ lib/radisk.js | 2 +- lib/store.js | 15 ++++++++++----- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/gun.js b/gun.js index 043bf192..554eb197 100644 --- a/gun.js +++ b/gun.js @@ -1972,12 +1972,14 @@ if('[' === tmp){ try{msg = JSON.parse(raw);}catch(e){opt.log('DAM JSON parse error', e)} if(!msg){ return } + console.log('hear batch length of', msg.length); (function go(){ var S = +new Date; // STATS! var m, c = 100; // hardcoded for now? while(c-- && (m = msg.shift())){ mesh.hear(m, peer); } + console.log(+new Date - S, 'hear batch'); (mesh.hear.long || (mesh.hear.long = [])).push(+new Date - S); if(!msg.length){ return } puff(go, 0); @@ -1988,6 +1990,7 @@ try{msg = msg || JSON.parse(raw); }catch(e){return opt.log('DAM JSON parse error', e)} if(!msg){ return } + if(msg.DBG_s){ console.log(+new Date - msg.DBG_s, 'to hear') } if(!(id = msg['#'])){ id = msg['#'] = Type.text.random(9) } if(dup.check(id)){ return } dup.track(id, true).it = msg; // GUN core also dedups, so `true` is needed. // Does GUN core need to dedup anymore? @@ -2004,7 +2007,9 @@ } return; } + var S = +new Date; root.on('in', msg); + !msg.nts && console.log(+new Date - S, 'msg', msg['#']); return; } } diff --git a/lib/evict.js b/lib/evict.js index 6aa2582a..89d3c3ff 100644 --- a/lib/evict.js +++ b/lib/evict.js @@ -20,10 +20,12 @@ var souls = Object.keys(root.graph||empty); var toss = Math.ceil(souls.length * 0.01); //var start = Gun.state(), i = toss; + var S = +new Date; Gun.list.map(souls, function(soul){ if(--toss < 0){ return } root.gun.get(soul).off(); }); + console.log(+new Date - S, 'gc'); //console.log("evicted", i, 'nodes in', ((Gun.state() - start)/1000).toFixed(2), 'sec.'); } /* diff --git a/lib/radisk.js b/lib/radisk.js index 5f6a5f09..1f2ba3ac 100644 --- a/lib/radisk.js +++ b/lib/radisk.js @@ -19,7 +19,7 @@ function ename(t){ return encodeURIComponent(t).replace(/\*/g, '%2A') } function atomic(v){ return u !== v && (!v || 'object' != typeof v) } var map = Gun.obj.map; - var LOG = false;//true; + var LOG = true; if(!opt.store){ return opt.log("ERROR: Radisk needs `opt.store` interface with `{get: fn, put: fn (, list: fn)}`!"); diff --git a/lib/store.js b/lib/store.js index 56c4dcda..124f0eb5 100644 --- a/lib/store.js +++ b/lib/store.js @@ -15,13 +15,14 @@ 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! + var S = (+new Date); // STATS! Gun.graph.is(msg.put, null, function(val, key, node, soul){ if(track){ ++acks } //console.log('put:', soul, key, val); val = Radisk.encode(val, null, esc)+'>'+Radisk.encode(Gun.state.is(node, key), null, esc); rad(soul+esc+key, val, (track? ack : u)); }); + console.log(+new Date - S, 'put loop'); function ack(err, ok){ acks--; if(ack.err){ return } @@ -31,11 +32,12 @@ Gun.on('create', function(root){ return; } if(acks){ return } - try{opt.store.stats.put.time[statp % 50] = (+new Date) - start; ++statp; + try{opt.store.stats.put.time[statp % 50] = (+new Date) - S; ++statp; opt.store.stats.put.count++; }catch(e){} // STATS! - //console.log("PAT!", id); + console.log(+new Date - S, 'put'); S = +new Date; root.on('in', {'@': id, ok: 1}); + console.log(+new Date - S, 'put sent'); } }); @@ -67,12 +69,13 @@ Gun.on('create', function(root){ o.limit = (tmp <= (o.pack || (1000 * 100)))? tmp : 1; } if(has['-'] || (soul||{})['-']){ o.reverse = true } - var start = (+new Date); // STATS! // console.log("GET!", id, JSON.stringify(key)); + var S = (+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; + try{opt.store.stats.get.time[statg % 50] = (+new Date) - S; ++statg; opt.store.stats.get.count++; if(err){ opt.store.stats.get.err = err } }catch(e){} // STATS! + console.log(+new Date - S, 'got'); S = +new Date; if(data){ if(typeof data !== 'string'){ if(o.atom){ @@ -83,7 +86,9 @@ Gun.on('create', function(root){ } if(!graph && data){ each(data, '') } } + console.log(+new Date - S, 'got prep'); S = +new Date; root.on('in', {'@': id, put: graph, err: err? err : u, rad: Radix}); + console.log(+new Date - S, 'got sent'); }, o); function each(val, has, a,b){ if(!val){ return } From 814d330b8a0e90d187c0bf5fe5ce3a600f5fba0d Mon Sep 17 00:00:00 2001 From: Mark Nadal Date: Fri, 20 Sep 2019 00:55:09 -0700 Subject: [PATCH 4/6] more logs --- gun.js | 12 ++++++++++++ lib/radisk.js | 13 ++++++++++++- lib/store.js | 1 + 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/gun.js b/gun.js index 554eb197..0fe78cf8 100644 --- a/gun.js +++ b/gun.js @@ -811,16 +811,20 @@ // Maybe... in case the in-memory key we have is a local write // we still need to trigger a pull/merge from peers. } else { + var S = +new Date; node = Gun.obj.copy(node); + console.log(+new Date - S, 'copy node'); } node = Gun.graph.node(node); tmp = (at||empty).ack; + var S = +new Date; root.on('in', { '@': msg['#'], how: 'mem', put: node, $: gun }); + console.log(+new Date - S, 'root got send'); //if(0 < tmp){ return } root.on('get', msg); } @@ -2023,6 +2027,7 @@ if(this.to){ this.to.next(msg) } // compatible with middleware adapters. if(!msg){ return false } var id, hash, tmp, raw; + var S = +new Date; var meta = msg._||(msg._=function(){}); if(!(id = msg['#'])){ id = msg['#'] = Type.text.random(9) } if(!(hash = msg['##']) && u !== msg.put){ hash = msg['##'] = Type.obj.hash(msg.put) } @@ -2036,12 +2041,15 @@ } } } + console.log(+new Date - S, 'mesh say prep'); dup.track(id).it = msg; // track for 9 seconds, default. Earth<->Mars would need more! if(!peer){ peer = (tmp = dup.s[msg['@']]) && (tmp = tmp.it) && (tmp = tmp._) && (tmp = tmp.via) } if(!peer && mesh.way){ return mesh.way(msg) } if(!peer || !peer.id){ message = msg; if(!Type.obj.is(peer || opt.peers)){ return false } + var S = +new Date; Type.obj.map(peer || opt.peers, each); // in case peer is a peer list. + console.log(+new Date - S, 'mesh say loop'); return; } if(!peer.wire && mesh.wire){ mesh.wire(peer) } @@ -2065,8 +2073,10 @@ peer.batch = peer.tail = null; if(!tmp){ return } if(!tmp.length){ return } // if(3 > tmp.length){ return } // TODO: ^ + var S = +new Date; try{tmp = (1 === tmp.length? tmp[0] : JSON.stringify(tmp)); }catch(e){return opt.log('DAM JSON stringify error', e)} + console.log(+new Date - S, 'mesh flush', tmp.length); if(!tmp){ return } send(tmp, peer); } @@ -2076,12 +2086,14 @@ // for now - find better place later. function send(raw, peer){ try{ var wire = peer.wire; + var S = +new Date; if(peer.say){ peer.say(raw); } else if(wire.send){ wire.send(raw); } + console.log(+new Date - S, 'wire send', raw.length); mesh.say.d += raw.length||0; ++mesh.say.c; // STATS! }catch(e){ (peer.queue = peer.queue || []).push(raw); diff --git a/lib/radisk.js b/lib/radisk.js index 1f2ba3ac..9eba437f 100644 --- a/lib/radisk.js +++ b/lib/radisk.js @@ -44,9 +44,14 @@ if(val instanceof Function){ var o = cb || {}; cb = val; + var S; LOG && (S = +new Date); val = r.batch(key); + LOG && console.log(+new Date - S, 'rad mem'); if(u !== val){ - cb(u, r.range(val, o), o); + LOG && (S = +new Date); + var v = r.range(val, o); + LOG && console.log(+new Date - S, 'rad range'); + cb(u, v, o); if(atomic(val)){ return } // if a node is requested and some of it is cached... the other parts might not be. } @@ -230,7 +235,9 @@ r.read = function(key, cb, o){ o = o || {}; if(RAD && !o.next){ // cache + var S; LOG && (S = +new Date); var val = RAD(key); + LOG && console.log(+new Date - S, 'rad cached'); //if(u !== val){ //cb(u, val, o); if(atomic(val)){ cb(u, val, o); return } @@ -243,6 +250,7 @@ file = (u === file)? u : decodeURIComponent(file); tmp = o.next || key || (o.reverse? o.end || '\uffff' : o.start || ''); if(!file || (o.reverse? file < tmp : file > tmp)){ + LOG && console.log(+new Date - S, 'rad read lex'); S = +new Date; if(o.next || o.reverse){ g.file = file } if(tmp = Q[g.file]){ tmp.push({key: key, ack: cb, file: g.file, opt: o}); @@ -263,7 +271,9 @@ g.info = info; if(disk){ RAD = g.disk = disk } disk = Q[g.file]; delete Q[g.file]; + LOG && console.log(+new Date - S, 'rad read it in, now ack to:', disk.length); S = +new Date; map(disk, g.ack); + console.log(+new Date - S, 'rad read acked'); } g.ack = function(as){ if(!as.ack){ return } @@ -282,6 +292,7 @@ r.read(tmp, as.ack, o); } if(o.reverse){ g.lex.reverse = true } + LOG && (S = +new Date); r.list(g.lex); } function rev(a,b){ return b } diff --git a/lib/store.js b/lib/store.js index 124f0eb5..0d0cdaf2 100644 --- a/lib/store.js +++ b/lib/store.js @@ -90,6 +90,7 @@ Gun.on('create', function(root){ root.on('in', {'@': id, put: graph, err: err? err : u, rad: Radix}); console.log(+new Date - S, 'got sent'); }, o); + console.log(+new Date - S, 'get call'); function each(val, has, a,b){ if(!val){ return } has = (key+has).split(esc); From 382cbc4798989b5644dda030eb94bfb3d469f92f Mon Sep 17 00:00:00 2001 From: Mark Nadal Date: Fri, 27 Sep 2019 01:52:35 -0700 Subject: [PATCH 5/6] does this work? don't read if already read? --- gun.js | 5 +++-- lib/radisk.js | 39 ++++++++++++++++++++++----------------- lib/store.js | 24 ++++++++++++++++++++---- test/rad/rad.js | 3 ++- 4 files changed, 47 insertions(+), 24 deletions(-) diff --git a/gun.js b/gun.js index 0fe78cf8..04e072f8 100644 --- a/gun.js +++ b/gun.js @@ -1994,8 +1994,8 @@ try{msg = msg || JSON.parse(raw); }catch(e){return opt.log('DAM JSON parse error', e)} if(!msg){ return } - if(msg.DBG_s){ console.log(+new Date - msg.DBG_s, 'to hear') } if(!(id = msg['#'])){ id = msg['#'] = Type.text.random(9) } + if(msg.DBG_s){ console.log(+new Date - msg.DBG_s, 'to hear', id) } if(dup.check(id)){ return } dup.track(id, true).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) } @@ -2027,7 +2027,7 @@ if(this.to){ this.to.next(msg) } // compatible with middleware adapters. if(!msg){ return false } var id, hash, tmp, raw; - var S = +new Date; + var S = +new Date; // msg.DBG_s = msg.DBG_s || +new Date; var meta = msg._||(msg._=function(){}); if(!(id = msg['#'])){ id = msg['#'] = Type.text.random(9) } if(!(hash = msg['##']) && u !== msg.put){ hash = msg['##'] = Type.obj.hash(msg.put) } @@ -2262,6 +2262,7 @@ wire.onerror = function(error){ reconnect(peer); }; + // it can take a while to open a socket, maybe no longer lazy load for perf reasons? wire.onopen = function(){ opt.mesh.hi(peer); } diff --git a/lib/radisk.js b/lib/radisk.js index 9eba437f..e918e6ce 100644 --- a/lib/radisk.js +++ b/lib/radisk.js @@ -244,7 +244,7 @@ // if a node is requested and some of it is cached... the other parts might not be. //} } - o.span = (u !== o.start) || (u !== o.end); + o.span = (u !== o.start) || (u !== o.end); // is there a start or end? var g = function Get(){}; g.lex = function(file){ var tmp; file = (u === file)? u : decodeURIComponent(file); @@ -277,19 +277,24 @@ } g.ack = function(as){ if(!as.ack){ return } - var tmp = as.key, o = as.opt, info = g.info, rad = g.disk || noop, data = r.range(rad(tmp), o), last = rad.last || Radix.map(rad, rev, revo); + 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); o.parsed = (o.parsed || 0) + (info.parsed||0); o.chunks = (o.chunks || 0) + 1; - if(!o.some){ o.some = (u !== data) } - if(u !== data){ as.ack(g.err, data, o) } - else if(!as.file){ !o.some && as.ack(g.err, u, o); return } - if(!o.span){ - if(/*!last || */last === tmp){ !o.some && as.ack(g.err, u, o); return } - if(last && last > tmp && 0 != last.indexOf(tmp)){ !o.some && as.ack(g.err, u, o); return } + o.more = true; + if((!as.file) // if no more places to look + || (!o.span && last === key) // if our key exactly matches the very last atomic record + || (!o.span && last && last > key && 0 != last.indexOf(key)) // 'zach' may be lexically larger than 'za', but there still might be more, like 'zane' in the 'za' prefix bucket so do not end here. + ){ + o.more = u; + as.ack(g.err, data, o); + return } - if(o.some && o.parsed >= o.limit){ return } + if(u !== data){ + as.ack(g.err, data, o); // more might be coming! + if(o.parsed >= o.limit){ return } // even if more, we've hit our limit, asking peer will need to make a new ask with a new starting point. + } o.next = as.file; - r.read(tmp, as.ack, o); + r.read(key, as.ack, o); } if(o.reverse){ g.lex.reverse = true } LOG && (S = +new Date); @@ -313,7 +318,7 @@ var p = function Parse(){}, info = {}; p.disk = Radix(); p.read = function(err, data){ var tmp; - LOG && console.log('read disk in', +new Date - start, ename(file)); // keep this commented out in + LOG && console.log('read disk in', +new Date - S, ename(file)); // keep this commented out in delete Q[file]; if((p.err = err) || (p.not = !data)){ return map(q, p.ack); @@ -330,12 +335,12 @@ } info.parsed = data.length; - LOG && (start = +new Date); // keep this commented out in production! - if(opt.jsonify){ // temporary testing idea + LOG && (S = +new Date); // keep this commented out in production! + if(opt.jsonify || '{' === data[0]){ // temporary testing idea try{ var json = JSON.parse(data); p.disk.$ = json; - LOG && console.log('parsed JSON in', +new Date - start); // keep this commented out in production! + LOG && console.log('parsed JSON in', +new Date - S); // keep this commented out in production! map(q, p.ack); return; }catch(e){ tmp = e } @@ -344,7 +349,7 @@ return map(q, p.ack); } } - LOG && (start = +new Date); // keep this commented out in production! + LOG && (S = +new Date); // keep this commented out in production! var tmp = p.split(data), pre = [], i, k, v; if(!tmp || 0 !== tmp[1]){ p.err = "File '"+file+"' does not have root radix! "; @@ -367,7 +372,7 @@ if(u !== k && u !== v){ p.disk(pre.join(''), v) } tmp = p.split(tmp[2]); } - LOG && console.log('parsed RAD in', +new Date - start); // keep this commented out in production! + LOG && console.log('parsed RAD in', +new Date - S); // keep this commented out in production! //cb(err, p.disk); map(q, p.ack); }; @@ -387,7 +392,7 @@ if(p.err || p.not){ return cb(p.err, u, info) } cb(u, p.disk, info); } - var start; LOG && (start = +new Date); // keep this commented out in production! + var S; LOG && (S = +new Date); // keep this commented out in production! if(raw){ return p.read(null, raw) } opt.store.get(ename(file), p.read); } diff --git a/lib/store.js b/lib/store.js index 0d0cdaf2..49559ea0 100644 --- a/lib/store.js +++ b/lib/store.js @@ -3,7 +3,7 @@ var Gun = (typeof window !== "undefined")? window.Gun : require('../gun'); Gun.on('create', function(root){ if(Gun.TESTING){ root.opt.file = 'radatatest' } this.to.next(root); - var opt = root.opt, u; + var opt = root.opt, empty = {}, u; if(false === opt.radisk){ return } var Radisk = (Gun.window && Gun.window.Radisk) || require('./radisk'); var Radix = Radisk.Radix; @@ -14,9 +14,17 @@ Gun.on('create', function(root){ root.on('put', function(msg){ 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 got = (msg._||empty).rad, now = Gun.state(); var S = (+new Date); // STATS! Gun.graph.is(msg.put, null, function(val, key, node, soul){ + if(!track && got){ + var at = (root.next||empty)[soul]; + if(!at){ return } + if(u !== got['.']){ at = (at.next||empty)[key] } + if(!at){ return } + at.rad = now; + return; + } if(track){ ++acks } //console.log('put:', soul, key, val); val = Radisk.encode(val, null, esc)+'>'+Radisk.encode(Gun.state.is(node, key), null, esc); @@ -69,17 +77,24 @@ Gun.on('create', function(root){ o.limit = (tmp <= (o.pack || (1000 * 100)))? tmp : 1; } if(has['-'] || (soul||{})['-']){ o.reverse = true } + if(tmp = (root.next||empty)[soul]){ + if(tmp && tmp.rad){ return } + if(o.atom){ tmp = (tmp.next||empty)[o.atom] } + if(tmp && tmp.rad){ return } + } var S = (+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) - S; ++statg; opt.store.stats.get.count++; 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. console.log(+new Date - S, 'got'); S = +new Date; if(data){ if(typeof data !== 'string'){ if(o.atom){ data = u; + Radix.map(data, each) } else { Radix.map(data, each) } @@ -87,7 +102,7 @@ Gun.on('create', function(root){ if(!graph && data){ each(data, '') } } console.log(+new Date - S, 'got prep'); S = +new Date; - root.on('in', {'@': id, put: graph, err: err? err : u, rad: Radix}); + root.on('in', {'@': id, put: graph, '%': o.more? 1 : u, err: err? err : u, _: each}); console.log(+new Date - S, 'got sent'); }, o); console.log(+new Date - S, 'get call'); @@ -97,12 +112,13 @@ Gun.on('create', function(root){ var soul = has.slice(0,1)[0]; has = has.slice(-1)[0]; o.count = (o.count || 0) + val.length; - tmp = val.lastIndexOf('>'); + var 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(o.limit && o.limit <= o.count){ return true } } + each.rad = get; }); opt.store.stats = {get:{time:{}, count:0}, put: {time:{}, count:0}}; // STATS! var statg = 0, statp = 0; // STATS! diff --git a/test/rad/rad.js b/test/rad/rad.js index 6d07686e..d1a638d2 100644 --- a/test/rad/rad.js +++ b/test/rad/rad.js @@ -190,12 +190,13 @@ var names = ["Adalard","Adora","Aia","Albertina","Alfie","Allyn","Amabil","Ammam if(opt.end < v){ return } if(v.indexOf(find) == 0){ all[v] = true } }); - rad(find, function(err, data){ + rad(find, function(err, data, o){ Radix.map(data, function(v,k){ //console.log(find+k, v); delete all[find+k]; }); if(!Gun.obj.empty(all)){ return } + if(!data){ return } // in case there is "more" that returned empty done(); }, opt); }); From 4de57d4014a78cf5b7e0ae25d6f8efc999e9699f Mon Sep 17 00:00:00 2001 From: Mark Nadal Date: Fri, 27 Sep 2019 02:22:20 -0700 Subject: [PATCH 6/6] reduce RAD chunk and try JSON serializing --- gun.js | 5 +++-- lib/radisk.js | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/gun.js b/gun.js index 04e072f8..c3ea73ab 100644 --- a/gun.js +++ b/gun.js @@ -2027,7 +2027,7 @@ if(this.to){ this.to.next(msg) } // compatible with middleware adapters. if(!msg){ return false } var id, hash, tmp, raw; - var S = +new Date; // msg.DBG_s = msg.DBG_s || +new Date; + var S = +new Date; //msg.DBG_s = msg.DBG_s || +new Date; var meta = msg._||(msg._=function(){}); if(!(id = msg['#'])){ id = msg['#'] = Type.text.random(9) } if(!(hash = msg['##']) && u !== msg.put){ hash = msg['##'] = Type.obj.hash(msg.put) } @@ -2262,7 +2262,6 @@ wire.onerror = function(error){ reconnect(peer); }; - // it can take a while to open a socket, maybe no longer lazy load for perf reasons? wire.onopen = function(){ opt.mesh.hi(peer); } @@ -2273,6 +2272,8 @@ return wire; }catch(e){}} + setTimeout(function(){ root.on('out', {dam:'hi'}) },1); // it can take a while to open a socket, so maybe no longer lazy load for perf reasons? + var wait = 2 * 1000; function reconnect(peer){ clearTimeout(peer.defer); diff --git a/lib/radisk.js b/lib/radisk.js index e918e6ce..c462b9ed 100644 --- a/lib/radisk.js +++ b/lib/radisk.js @@ -11,10 +11,10 @@ opt.pack = opt.pack || (opt.memory? (opt.memory * 1000 * 1000) : 1399000000) * 0.3; // max_old_space_size defaults to 1400 MB. opt.until = opt.until || opt.wait || 250; opt.batch = opt.batch || (10 * 1000); - opt.chunk = opt.chunk || (1024 * 1024 * 10); // 10MB + opt.chunk = opt.chunk || (1024 * 1024 * 1); // 1MB opt.code = opt.code || {}; opt.code.from = opt.code.from || '!'; - //opt.jsonify = true; if(opt.jsonify){ console.log("JSON RAD!!!") } // TODO: REMOVE!!!! + opt.jsonify = true; function ename(t){ return encodeURIComponent(t).replace(/\*/g, '%2A') } function atomic(v){ return u !== v && (!v || 'object' != typeof v) }