mirror of
https://github.com/amark/gun.git
synced 2025-07-04 11:52:34 +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;
|
global.DEBUG = 1;
|
||||||
setInterval(function(){
|
setInterval(function(){
|
||||||
var mem = process.memoryUsage();
|
var mem = process.memoryUsage();
|
||||||
var used = mem.heapUsed / 1024 / 1024;
|
var used = mem.heapTotal / 1024 / 1024;
|
||||||
var print = '';
|
var print = '';
|
||||||
used = used.toFixed(1);
|
used = used.toFixed(1);
|
||||||
print += used +' MB. '
|
print += used +' MB. '
|
||||||
if(db.root){
|
if(db.root){
|
||||||
db.concurrency = Object.keys(db.peers||{}).length;
|
db.concurrency = Object.keys(db.peers||{}).length;
|
||||||
print += db.concurrency +' peers. ';
|
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);
|
console.log(print);
|
||||||
}, 2500);
|
}, 2500);
|
||||||
|
|
||||||
@ -24,6 +27,13 @@
|
|||||||
if(root.once){ return }
|
if(root.once){ return }
|
||||||
db.root = root;
|
db.root = root;
|
||||||
db.peers = root.opt.peers;
|
db.peers = root.opt.peers;
|
||||||
|
|
||||||
|
db.count = 0;
|
||||||
|
root.on('in', function(msg){
|
||||||
|
this.to.next(msg);
|
||||||
|
db.last = msg;
|
||||||
|
db.count++;
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
}());
|
}());
|
25
lib/evict.js
25
lib/evict.js
@ -1,13 +1,32 @@
|
|||||||
;(function(){
|
;(function(){
|
||||||
var Gun = (typeof window !== 'undefined')? window.Gun : require('../gun');
|
var Gun = (typeof window !== 'undefined')? window.Gun : require('../gun');
|
||||||
|
|
||||||
var LRU = 1, empty = {}, u;
|
var ev = {}, empty = {}, u;
|
||||||
Gun.on('opt', function(root){
|
Gun.on('opt', function(root){
|
||||||
this.to.next(root);
|
this.to.next(root);
|
||||||
if(root.once){ return }
|
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){
|
root.on('in', function(msg){
|
||||||
this.to.next(msg);
|
this.to.next(msg);
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
require('./verify');
|
require('./verify');
|
||||||
require('./file');
|
require('./file');
|
||||||
require('./bye');
|
require('./bye');
|
||||||
|
require('./evict');
|
||||||
if('debug' === process.env.GUN_ENV){ require('./debug') }
|
if('debug' === process.env.GUN_ENV){ require('./debug') }
|
||||||
module.exports = Gun;
|
module.exports = Gun;
|
||||||
}());
|
}());
|
@ -10,7 +10,7 @@ Gun.on('opt', function(ctx){
|
|||||||
if(ctx.once){ return }
|
if(ctx.once){ return }
|
||||||
if(false !== opt.localStorage && !process.env.AWS_S3_BUCKET){ return } // TODO: Remove this after migration.
|
if(false !== opt.localStorage && !process.env.AWS_S3_BUCKET){ return } // TODO: Remove this after migration.
|
||||||
if(false === opt.radisk){ return }
|
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);
|
opt.store = opt.store || Store(opt);
|
||||||
var rad = Radisk(opt);
|
var rad = Radisk(opt);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user