mirror of
https://github.com/amark/gun.git
synced 2025-03-30 15:08:33 +00:00
RSE panic
This commit is contained in:
parent
db13b41474
commit
240aaeefec
@ -1,8 +1,11 @@
|
||||
var config = {
|
||||
IP: require('ip').address(),
|
||||
port: 8080,
|
||||
servers: 1,
|
||||
servers: 2,
|
||||
browsers: 2,
|
||||
each: 1000000,
|
||||
burst: 12000,
|
||||
wait: 1,
|
||||
dir: __dirname,
|
||||
route: {
|
||||
'/': __dirname + '/index.html',
|
||||
@ -31,6 +34,7 @@ manager.start({
|
||||
|
||||
var servers = clients.filter('Node.js');
|
||||
var server = servers.pluck(1);
|
||||
var spawn = servers.excluding(server).pluck(1);
|
||||
var browsers = clients.excluding(servers);
|
||||
var alice = browsers.pluck(1);
|
||||
var bob = browsers.excluding(alice).pluck(1);
|
||||
@ -70,41 +74,106 @@ describe("Make sure the Radix Storage Engine (RSE) works.", function(){
|
||||
return browsers.atLeast(config.browsers);
|
||||
});
|
||||
|
||||
it("Browsers initialized gun!", function(){
|
||||
var tests = [], i = 0;
|
||||
browsers.each(function(client, id){
|
||||
tests.push(client.run(function(test){
|
||||
localStorage.clear();
|
||||
var env = test.props;
|
||||
var gun = Gun('http://'+ env.config.IP + ':' + (env.config.port + 1) + '/gun');
|
||||
window.gun = gun;
|
||||
}, {i: i += 1, config: config}));
|
||||
});
|
||||
return Promise.all(tests);
|
||||
});
|
||||
|
||||
it("Alice save data", function(){
|
||||
return alice.run(function(test){
|
||||
console.log("I AM ALICE");
|
||||
test.async();
|
||||
var n = Gun.time.is();
|
||||
window.gun.get('foo').put({hello: "world!"}, function(ack){
|
||||
console.log("???", (Gun.time.is() - n)/1000, ack);
|
||||
console.log("I AM ALICE");
|
||||
localStorage.clear();
|
||||
var env = test.props;
|
||||
var gun = Gun({peers: 'http://'+ env.config.IP + ':' + (env.config.port + 1) + '/gun', localStorage: false});
|
||||
window.gun = gun;
|
||||
|
||||
var n = Gun.time.is(), i = 0, c = 0, b = env.config.burst, l = env.config.each;
|
||||
|
||||
function save(i){
|
||||
if(i > l){
|
||||
return clearTimeout(t);
|
||||
}
|
||||
var d;
|
||||
var ref = window.gun.get('asdf'+i);
|
||||
ref.put({hello: 'world' + i + '!'}, function(ack){
|
||||
if(d){ return } d = true;
|
||||
c++;
|
||||
!(i % b) && console.log(i+'/'+l);//, '@'+Math.floor(b/((-n + (n = Gun.time.is()))/1000))+'/sec');
|
||||
//localStorage.clear();
|
||||
ref.off();
|
||||
if(c < l){ return }
|
||||
setTimeout(function(){
|
||||
test.done();
|
||||
}, 1000);
|
||||
});
|
||||
}
|
||||
function burst(){
|
||||
for(var j = 0; j <= b; j++){
|
||||
save(++i);
|
||||
}
|
||||
}
|
||||
var t = setInterval(burst, env.config.wait);
|
||||
}, {i: 1, config: config});
|
||||
});
|
||||
|
||||
it("Shut server down!", function(){
|
||||
return server.run(function(test){
|
||||
process.exit();
|
||||
});
|
||||
});
|
||||
|
||||
it("GUN spawned!", function(){
|
||||
return spawn.run(function(test){
|
||||
var env = test.props;
|
||||
test.async();
|
||||
if(!require('fs').existsSync('radata')){
|
||||
console.log("Server data could not be found!");
|
||||
explode;
|
||||
return;
|
||||
}
|
||||
var port = env.config.port + env.i;
|
||||
var server = require('http').createServer(function(req, res){
|
||||
res.end("I am "+ env.i +"!");
|
||||
});
|
||||
var Gun = require('gun');
|
||||
require('gun/lib/store');
|
||||
var gun = Gun({web: server, localStorage: false, thrash: 6000});
|
||||
server.listen(port, function(){
|
||||
test.done();
|
||||
});
|
||||
});
|
||||
}, {i: 2, config: config});
|
||||
});
|
||||
|
||||
it("Bob read data", function(){
|
||||
return bob.run(function(test){
|
||||
console.log("I AM BOB");
|
||||
test.async();
|
||||
var n = Gun.time.is();
|
||||
window.gun.get('foo').on(function(data){
|
||||
console.log("???", (Gun.time.is() - n)/1000, data);
|
||||
test.done();
|
||||
});
|
||||
});
|
||||
console.log("I AM BOB");
|
||||
localStorage.clear();
|
||||
var env = test.props;
|
||||
var gun = Gun({peers: 'http://'+ env.config.IP + ':' + (env.config.port + 2) + '/gun', localStorage: false});
|
||||
window.gun = gun;
|
||||
|
||||
var n = Gun.time.is(), i = 0, c = 0, b = env.config.burst, l = env.config.each;
|
||||
|
||||
function check(i){
|
||||
var d;
|
||||
var ref = window.gun.get('asdf' + i);
|
||||
ref.on(function(data){
|
||||
if(('world'+i+'!') !== data.hello){ return test.fail('wrong ' + i) }
|
||||
if(d){ return } d = true;
|
||||
!(i % b) && console.log(i+'/'+l);//, '@'+Math.floor(b/((-n + (n = Gun.time.is()))/1000))+'/sec'));
|
||||
c++;
|
||||
//localStorage.clear();
|
||||
ref.off();
|
||||
if(c < l){ return }
|
||||
console.log("DONE!", c+'/'+l);
|
||||
test.done();
|
||||
});
|
||||
}
|
||||
function burst(){
|
||||
for(var j = 0; j <= b; j++){
|
||||
check(++i);
|
||||
}
|
||||
setTimeout(burst, env.config.wait);
|
||||
}
|
||||
burst();
|
||||
}, {i: 1, config: config});
|
||||
});
|
||||
|
||||
it("All finished!", function(done){
|
||||
|
@ -1,113 +0,0 @@
|
||||
var Radix = require('../../lib/radix');
|
||||
var Radisk = require('../../lib/radisk');
|
||||
//var Store = require('../../lib/rs3');
|
||||
var Gun = require('../../gun');
|
||||
var Store = require('../../lib/store');
|
||||
var fs = require('fs');
|
||||
|
||||
var TOTAL = 25000;
|
||||
var c = 0;
|
||||
var acked = 0;
|
||||
var start;
|
||||
var diff;
|
||||
|
||||
(function(){//return;
|
||||
//var opt = {size: 1024 * 1024};
|
||||
//opt.store = Store(opt);
|
||||
//var radix = Radisk();
|
||||
var gun = Gun();
|
||||
var gtr = gun._.opt.uuid;
|
||||
var l = 2000;
|
||||
var last = start;
|
||||
var t = Gun.time.is;
|
||||
var at = c;
|
||||
|
||||
;(function(){return;
|
||||
start = Gun.time.is();
|
||||
gun.get('j59an5jj2LUW8IJXl0u3').get('foo').on(function(data){
|
||||
/*Radix.map(data, function(val, key){
|
||||
console.log('>>>', key, val);
|
||||
})*/
|
||||
console.log("************", data, 'in', (Gun.time.is() - start)/1000);
|
||||
setTimeout(function(){
|
||||
console.debug.i=1;console.log("----------------------");
|
||||
start = Gun.time.is();
|
||||
gun.get('j59an5jj2LUW8IJXl0u3').on(function(data){
|
||||
console.log("*****", data, 'in', (Gun.time.is() - start)/1000);
|
||||
})
|
||||
},2000);
|
||||
});
|
||||
|
||||
}());
|
||||
var toc, alldone = function(){
|
||||
acked++;
|
||||
if(acked < TOTAL){ return }
|
||||
diff = (Gun.time.is() - start) / 1000;
|
||||
clearTimeout(toc);
|
||||
toc = setTimeout(CHECK,5000);
|
||||
}
|
||||
function bench(){
|
||||
for(var i = 0; i < l; i++){
|
||||
act(i);
|
||||
}
|
||||
}
|
||||
start = Gun.time.is();
|
||||
var it = setInterval(bench, 1);
|
||||
|
||||
function act(i){
|
||||
if(c >= (TOTAL)){ clearInterval(it); return; }
|
||||
++c;
|
||||
var ref = gun.get(gtr());
|
||||
ref.put({
|
||||
val: c,
|
||||
foo: 'hello ' + c,
|
||||
why: c + 'not?'
|
||||
}, alldone);
|
||||
setTimeout(function(){ ref.off(); },1);
|
||||
//radix(gtr(), Gun.text.random(3), alldone);
|
||||
//radix(c, Math.random()/* + '\n' + Gun.text.random(3)*/, alldone);
|
||||
//radix(Gun.text.random(5), Math.random(), alldone);
|
||||
if(c % 50000 === 0){
|
||||
var now = t();
|
||||
console.log(c);//, (now - last)/1000);
|
||||
at = c;
|
||||
last = now;
|
||||
}
|
||||
}
|
||||
}());
|
||||
|
||||
function CHECK(){
|
||||
console.log(Math.floor(c / diff), 'disk writes per second', acked, 'of', c);
|
||||
var opt = {batch: 5, wait: 500};
|
||||
opt.store = Store(opt);
|
||||
var radix = Radisk(opt);
|
||||
var all = {};
|
||||
var to;
|
||||
var i = c || TOTAL;
|
||||
/*while(--i){
|
||||
all[i] = true;
|
||||
}*/
|
||||
var dir = fs.readdirSync('radata'), i = 0;
|
||||
function readcheck(i){
|
||||
var file = dir[i];
|
||||
if(!file){
|
||||
var len = Object.keys(all).length;
|
||||
console.log("how many?", len);
|
||||
if(len < TOTAL){ return }
|
||||
var missing = [];
|
||||
var fail = Gun.obj.map(all, function(val, key){
|
||||
if(val){ missing.push(key); return true }
|
||||
});
|
||||
//console.log(all);
|
||||
console.log("DONE!", 'Verify ALL writes:', fail? '!!!FAIL!!!!' : 'YES');// '. Missing:', missing);
|
||||
return;
|
||||
}
|
||||
radix.parse(file, function(err, rad){
|
||||
Radix.map(rad, function(val, key){
|
||||
all[key] = false;
|
||||
});
|
||||
readcheck(++i);
|
||||
})
|
||||
}
|
||||
readcheck(i);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user