mirror of
https://github.com/amark/gun.git
synced 2025-03-30 15:08:33 +00:00
experimental GC
This commit is contained in:
parent
74699f64f8
commit
2015a01b65
12
lib/debug.js
12
lib/debug.js
@ -7,14 +7,17 @@
|
||||
global.DEBUG = 1;
|
||||
setInterval(function(){
|
||||
var mem = process.memoryUsage();
|
||||
var used = mem.heapUsed / 1024 / 1024;
|
||||
var used = mem.heapTotal / 1024 / 1024;
|
||||
var print = '';
|
||||
used = used.toFixed(1);
|
||||
print += used +' MB. '
|
||||
if(db.root){
|
||||
db.concurrency = Object.keys(db.peers||{}).length;
|
||||
print += db.concurrency +' peers. ';
|
||||
db.nodes = Object.keys(db.root.graph||{}).length;
|
||||
print += db.nodes + ' nodes. ';
|
||||
}
|
||||
if(db.count){ print += db.count + ' msgs. '}
|
||||
console.log(print);
|
||||
}, 2500);
|
||||
|
||||
@ -24,6 +27,13 @@
|
||||
if(root.once){ return }
|
||||
db.root = root;
|
||||
db.peers = root.opt.peers;
|
||||
|
||||
db.count = 0;
|
||||
root.on('in', function(msg){
|
||||
this.to.next(msg);
|
||||
db.last = msg;
|
||||
db.count++;
|
||||
})
|
||||
})
|
||||
|
||||
}());
|
27
lib/evict.js
27
lib/evict.js
@ -1,13 +1,32 @@
|
||||
;(function(){
|
||||
var Gun = (typeof window !== 'undefined')? window.Gun : require('../gun');
|
||||
|
||||
var LRU = 1, empty = {}, u;
|
||||
var ev = {}, empty = {}, u;
|
||||
Gun.on('opt', function(root){
|
||||
this.to.next(root);
|
||||
if(root.once){ return }
|
||||
root.on('get', function(msg){
|
||||
|
||||
})
|
||||
if(typeof process == 'undefined'){ return }
|
||||
var util = process.memoryUsage;
|
||||
if(!util){ return }
|
||||
|
||||
ev.max = parseFloat(root.opt.memory || process.env.WEB_MEMORY || 512) * 0.8;
|
||||
|
||||
setInterval(check, 250);
|
||||
function check(){
|
||||
var used = ev.used = util().heapTotal / 1024 / 1024;
|
||||
if(used < ev.max){ return }
|
||||
setTimeout(GC, 1);
|
||||
}
|
||||
function GC(){
|
||||
var souls = Object.keys(root.graph||empty);
|
||||
var toss = Math.ceil(souls.length * 0.1);
|
||||
//var start = Gun.state(), i = toss;
|
||||
Gun.list.map(souls, function(soul){
|
||||
if(--toss < 0){ return }
|
||||
root.gun(soul).off();
|
||||
});
|
||||
//console.log("evicted", i, 'nodes in', ((Gun.state() - start)/1000).toFixed(2), 'sec.');
|
||||
}
|
||||
/*
|
||||
root.on('in', function(msg){
|
||||
this.to.next(msg);
|
||||
|
@ -9,6 +9,7 @@
|
||||
require('./verify');
|
||||
require('./file');
|
||||
require('./bye');
|
||||
require('./evict');
|
||||
if('debug' === process.env.GUN_ENV){ require('./debug') }
|
||||
module.exports = Gun;
|
||||
}());
|
@ -10,7 +10,7 @@ Gun.on('opt', function(ctx){
|
||||
if(ctx.once){ return }
|
||||
if(false !== opt.localStorage && !process.env.AWS_S3_BUCKET){ return } // TODO: Remove this after migration.
|
||||
if(false === opt.radisk){ return }
|
||||
console.log("BUG WARNING: Radix Storage Engine (RSE) has a known rare edge case, if data gets split between file chunks, a GET may only return the first chunk!!!");
|
||||
console.log("BUG WARNING: Radix Storage Engine (RAD) has a known rare edge case, if data gets split between file chunks, a GET may only return the first chunk!!!");
|
||||
opt.store = opt.store || Store(opt);
|
||||
var rad = Radisk(opt);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user