skip saving in-mem acks? thrash socket 0?

This commit is contained in:
Mark Nadal 2020-01-31 05:41:26 -08:00
parent e6b61f667e
commit 9dfdf608dc
4 changed files with 26 additions and 21 deletions

8
gun.js
View File

@ -819,7 +819,7 @@
}
node = Gun.graph.node(node);
tmp = (at||empty).ack;
var faith = function(){}; faith.faith = true; // HNPERF: We're testing performance improvement by skipping going through security again, but this should be audited.
var faith = function(){}; faith.ram = faith.faith = true; // HNPERF: We're testing performance improvement by skipping going through security again, but this should be audited.
root.on('in', {
'@': msg['#'],
how: 'mem',
@ -1963,7 +1963,7 @@
var mesh = function(){};
var opt = root.opt || {};
opt.log = opt.log || console.log;
opt.gap = opt.gap || opt.wait || 1;
opt.gap = opt.gap || opt.wait || 0;
opt.pack = opt.pack || (opt.memory? (opt.memory * 1000 * 1000) : 1399000000) * 0.3; // max_old_space_size defaults to 1400 MB.
var dup = root.dup;
@ -2009,9 +2009,9 @@
}
return;
}
var S, ST; LOG && (S = +new Date);
var S, ST; LOG && (S = +new Date); console.STAT = {};
root.on('in', msg);
if(LOG && !msg.nts && (ST = +new Date - S) > 9){ opt.log(S, ST, 'msg', msg['#']); if(ST > 500){ try{ require('./lib/email').send({text: ""+ST+"ms "+JSON.stringify(msg), 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.
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;
}
}

View File

@ -3,11 +3,14 @@ module.exports = function(opt, store){
var p = store.put;
var g = store.get;
store.put = function(file, data, cb){
rfs.put(file, data, function(err, ok){
if(err){ return cb(err) }
//console.log("rfs3 cached", file);
p(file, data, cb);
});
var a, b, c = function(err, ok){
if(b){ return cb(err || b) }
if(a){ return cb(err, ok) }
a = true;
b = err;
}
p(file, data, c); // parallel
rfs.put(file, data, c); // parallel
}
store.get = function(file, cb){
rfs.get(file, function(err, data){

View File

@ -8,10 +8,10 @@ function CDN(dir){
req.url = (req.url||'').replace(dot,'').replace(slash,'/');
if(serve(req, res)){ return } // filters GUN requests!
fs.createReadStream(path.join(dir, req.url)).on('error',function(tmp){ // static files!
try{ tmp = fs.readFileSync(path.join(dir, 'index.html')) }catch(e){}
try{ res.writeHead(200, {'Content-Type': 'text/html'});
res.end(tmp+''); }catch(e){} // or default to index
}).pipe(res); // stream
fs.readFile(path.join(dir, 'index.html'), function(err, tmp){
try{ res.writeHead(200, {'Content-Type': 'text/html'});
res.end(tmp+''); }catch(e){} // or default to index
})}).pipe(res); // stream
}
}
@ -28,12 +28,9 @@ function serve(req, res, next){ var tmp;
}
if(0 <= req.url.indexOf('gun/')){
res.writeHead(200, {'Content-Type': 'text/javascript'});
var path = __dirname + '/../' + req.url.split('/').slice(2).join('/'), file;
try{file = require('fs').readFileSync(path)}catch(e){}
if(file){
res.end(file);
return true;
}
var path = __dirname + '/../' + req.url.split('/').slice(2).join('/');
fs.readFile(path, function(err, file){ res.end((file || (err && 404))+'') });
return true;
}
if((tmp = req.socket) && (tmp = tmp.server) && (tmp = tmp.route)){ var url;
if(tmp = tmp[(((req.url||'').slice(1)).split('/')[0]||'').split('.')[0]]){

View File

@ -15,8 +15,10 @@ 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.
var got = (msg._||empty).rad, now = Gun.state();
var _ = (msg._||empty), got = _.rad;
if(_.ram){ return } // in-memory ACKs to GETs do not need to be written to disk again.
var S = (+new Date), C = 0; // STATS!
var now = Gun.state();
Gun.graph.is(msg.put, null, function(val, key, node, soul){
if(!track && got){
var at = (root.next||empty)[soul];
@ -33,6 +35,7 @@ Gun.on('create', function(root){
C++;
});
if(LOG && (ST = +new Date - S) > 9){ Gun.log(S, ST, 'put loop'); Gun.log(S, C, 'put loop #') }
console.STAT && (console.STAT.radputloop = ST) && (console.STAT.radputcount = C);
function ack(err, ok){
acks--;
if(ack.err){ return }
@ -104,13 +107,15 @@ Gun.on('create', function(root){
}
if(!graph && data){ each(data, '') }
}
console.STAT && (console.STAT.radgetcount = C);
if(LOG && (ST = +new Date - S) > 9){ Gun.log(S, ST, 'got prep time'); Gun.log(S, C, 'got prep #') } C = 0; S = +new Date;
var faith = function(){}; faith.faith = true; faith.rad = get; // HNPERF: We're testing performance improvement by skipping going through security again, but this should be audited.
root.on('in', {'@': id, put: graph, '%': o.more? 1 : u, err: err? err : u, _: faith});
LOG && (ST = +new Date - S) > 9 && Gun.log(S, ST, 'got emit', Object.keys(graph||{}).length);
graph = u; // each is outside our scope, we have to reset graph to nothing!
}, o);
LOG && Gun.log(S, +new Date - S, 'get call');
LOG && (ST = +new Date - S) > 9 && Gun.log(S, ST, 'get call');
console.STAT && (console.STAT.radget = ST);
function each(val, has, a,b){ // TODO: THIS CODE NEEDS TO BE FASTER!!!!
C++;
if(!val){ return }