From 74699f64f8f78f3c0371aa1e1d2a918518130843 Mon Sep 17 00:00:00 2001 From: Mark Nadal Date: Tue, 15 May 2018 11:02:18 -0700 Subject: [PATCH] debug mode print mem & peers --- lib/debug.js | 20 ++++++++++++++++++-- lib/evict.js | 27 +++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 lib/evict.js diff --git a/lib/debug.js b/lib/debug.js index c3562cd1..336b80b9 100644 --- a/lib/debug.js +++ b/lib/debug.js @@ -1,13 +1,29 @@ ;(function(){ if('debug' !== process.env.GUN_ENV){ return } + var db = {}; + console.log("start :)"); global.DEBUG = 1; setInterval(function(){ var mem = process.memoryUsage(); var used = mem.heapUsed / 1024 / 1024; + var print = ''; used = used.toFixed(1); - console.log(used, 'MB'); - }, 1000); + print += used +' MB. ' + if(db.root){ + db.concurrency = Object.keys(db.peers||{}).length; + print += db.concurrency +' peers. '; + } + console.log(print); + }, 2500); + + var Gun = require('../gun'); + Gun.on('opt', function(root){ + this.to.next(root); + if(root.once){ return } + db.root = root; + db.peers = root.opt.peers; + }) }()); \ No newline at end of file diff --git a/lib/evict.js b/lib/evict.js new file mode 100644 index 00000000..048a575a --- /dev/null +++ b/lib/evict.js @@ -0,0 +1,27 @@ +;(function(){ + var Gun = (typeof window !== 'undefined')? window.Gun : require('../gun'); + + var LRU = 1, empty = {}, u; + Gun.on('opt', function(root){ + this.to.next(root); + if(root.once){ return } + root.on('get', function(msg){ + + }) + /* + root.on('in', function(msg){ + this.to.next(msg); + if(msg.get){ + return; + } + Gun.graph.is(msg, function(node, soul){ + var meta = (root.next||empty)[soul]; + if(!meta){ return } + Gun.node.is(node, function(data, key){ + + }); + }); + }); + */ + }); +}()); \ No newline at end of file