mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-05-19 21:36:37 +00:00
Tweak benchmarks
This commit is contained in:
parent
3d59ec649c
commit
851e096904
@ -16,9 +16,16 @@ const channelName = process.argv[3] ? process.argv[3] : 'c1';
|
|||||||
|
|
||||||
const startIpfs = () => {
|
const startIpfs = () => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
ipfsd.disposableApi((err, ipfs) => {
|
// ipfsd.disposableApi((err, ipfs) => {
|
||||||
if(err) console.error(err);
|
// if(err) console.error(err);
|
||||||
resolve(ipfs);
|
// resolve(ipfs);
|
||||||
|
// });
|
||||||
|
ipfsd.local((err, node) => {
|
||||||
|
if(err) reject(err);
|
||||||
|
node.startDaemon((err, ipfs) => {
|
||||||
|
if(err) reject(err);
|
||||||
|
resolve(ipfs);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -29,47 +29,66 @@ const startIpfs = () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const util = require('util');
|
||||||
|
|
||||||
|
// Metrics
|
||||||
|
let totalQueries = 0;
|
||||||
|
let seconds = 0;
|
||||||
|
let queriesPerSecond = 0;
|
||||||
|
let lastTenSeconds = 0;
|
||||||
|
let store;
|
||||||
|
|
||||||
|
const queryLoop = (db) => {
|
||||||
|
// const queryLoop = (ipfs) => {
|
||||||
|
// const data = new Buffer(JSON.stringify({ Data: JSON.stringify({ hello: "world" }) }));
|
||||||
|
// ipfs.object.put(data).then(() => {
|
||||||
|
// totalQueries ++;
|
||||||
|
// lastTenSeconds ++;
|
||||||
|
// queriesPerSecond ++;
|
||||||
|
// process.nextTick(() => queryLoop(ipfs));
|
||||||
|
// })
|
||||||
|
// let timer = new Timer();
|
||||||
|
// timer.start();
|
||||||
|
store.add(username + totalQueries).then(() => {
|
||||||
|
// console.log(`${timer.stop(true)} ms - ${process._getActiveRequests().length} ${process._getActiveHandles().length}`);
|
||||||
|
// console.log(util.inspect(process.memoryUsage()));
|
||||||
|
totalQueries ++;
|
||||||
|
lastTenSeconds ++;
|
||||||
|
queriesPerSecond ++;
|
||||||
|
process.nextTick(queryLoop);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
let run = (() => {
|
let run = (() => {
|
||||||
// Metrics
|
|
||||||
let totalQueries = 0;
|
|
||||||
let seconds = 0;
|
|
||||||
let queriesPerSecond = 0;
|
|
||||||
let lastTenSeconds = 0;
|
|
||||||
|
|
||||||
const queryLoop = (db) => {
|
|
||||||
// const queryLoop = (ipfs) => {
|
|
||||||
// const data = new Buffer(JSON.stringify({ Data: JSON.stringify({ hello: "world" }) }));
|
|
||||||
// ipfs.object.put(data).then(() => {
|
|
||||||
// totalQueries ++;
|
|
||||||
// lastTenSeconds ++;
|
|
||||||
// queriesPerSecond ++;
|
|
||||||
// process.nextTick(() => queryLoop(ipfs));
|
|
||||||
// })
|
|
||||||
db.add(username + totalQueries).then(() => {
|
|
||||||
totalQueries ++;
|
|
||||||
lastTenSeconds ++;
|
|
||||||
queriesPerSecond ++;
|
|
||||||
process.nextTick(() => queryLoop(db));
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
// Connect
|
// Connect
|
||||||
console.log(`Connecting...`)
|
console.log(`Connecting...`)
|
||||||
startIpfs()
|
startIpfs()
|
||||||
// .then((ipfs) => queryLoop(ipfs))
|
// .then((ipfs) => queryLoop(ipfs))
|
||||||
.then((ipfs) => OrbitDB.connect(network, username, password, ipfs))
|
.then((ipfs) => OrbitDB.connect(network, username, password, ipfs))
|
||||||
.then((orbit) => orbit.eventlog(channelName))
|
.then((orbit) => {
|
||||||
.then((db) => {
|
console.log("OrbitDB")
|
||||||
return new Promise((resolve, reject) => {
|
orbit.events.on('load', () => console.log("loading log"))
|
||||||
db.events.on('load', () => console.log("loading log from history"))
|
orbit.events.on('ready', (db) => {
|
||||||
db.events.on('readable', () => {
|
console.log("log fetched from history for", db.dbname);
|
||||||
console.log("log fetched from history");
|
store = db;
|
||||||
queryLoop(db);
|
queryLoop();
|
||||||
resolve();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
return orbit;
|
||||||
})
|
})
|
||||||
|
.then((orbit) => orbit.eventlog(channelName))
|
||||||
|
// .then((db) => {
|
||||||
|
// console.log("OrbitDB")
|
||||||
|
// return new Promise((resolve, reject) => {
|
||||||
|
// db.events.on('load', () => console.log("loading log from history"))
|
||||||
|
// db.events.on('ready', (dbname) => {
|
||||||
|
// console.log("log fetched from history for", dbname);
|
||||||
|
// queryLoop(db);
|
||||||
|
// resolve();
|
||||||
|
// });
|
||||||
|
// });
|
||||||
|
// })
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
console.log("++")
|
||||||
// Metrics output
|
// Metrics output
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
seconds ++;
|
seconds ++;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user