Fix benchmark

This commit is contained in:
haad 2016-09-12 19:02:06 +02:00
parent e9bdbc7a92
commit de620d3cb9

View File

@ -1,83 +1,49 @@
'use strict'; 'use strict'
// const ipfsd = require('ipfsd-ctl');
// const IPFS = require('ipfs')
// const ipfsd = require('ipfsd-ctl');
const IpfsApi = require('ipfs-api') const IpfsApi = require('ipfs-api')
const OrbitDB = require('../src/OrbitDB'); const OrbitDB = require('../src/OrbitDB')
const Timer = require('./Timer');
// usage: benchmark.js <network hash> <username> <channel>; const username = process.argv[2] ? process.argv[2] : 'testrunner'
const channelName = process.argv[3] ? process.argv[3] : 'c1'
// orbit-server
const network = 'localhost:3333';
const username = process.argv[2] ? process.argv[2] : 'testrunner';
const password = '';
const channelName = process.argv[3] ? process.argv[3] : 'c1';
const startIpfs = () => {
return new Promise((resolve, reject) => {
// ipfsd.disposableApi((err, ipfs) => {
// if(err) console.error(err);
// resolve(ipfs);
// });
ipfsd.local((err, node) => {
if(err) reject(err);
node.startDaemon((err, ipfs) => {
if(err) reject(err);
resolve(ipfs);
});
});
// const ipfs = new IPFS('/tmp/benchmark')
// ipfs.goOnline(() => {
// resolve(ipfs)
// })
});
};
const util = require('util');
// Metrics // Metrics
let totalQueries = 0; let totalQueries = 0
let seconds = 0; let seconds = 0
let queriesPerSecond = 0; let queriesPerSecond = 0
let lastTenSeconds = 0; let lastTenSeconds = 0
// Main loop
const queryLoop = (db) => { const queryLoop = (db) => {
// let timer = new Timer();
// timer.start();
db.add(username + totalQueries).then(() => { db.add(username + totalQueries).then(() => {
// console.log(`${timer.stop(true)} ms - ${process._getActiveRequests().length} ${process._getActiveHandles().length}`); totalQueries ++
// console.log(util.inspect(process.memoryUsage())); lastTenSeconds ++
totalQueries ++; queriesPerSecond ++
lastTenSeconds ++;
queriesPerSecond ++;
process.nextTick(() => queryLoop(db)) process.nextTick(() => queryLoop(db))
}); })
}; }
let run = (() => { let run = (() => {
// Connect // Connect
console.log(`Connecting...`) console.log(`Connecting...`)
const ipfs = IpfsApi('localhost', '5002') const ipfs = IpfsApi('localhost', '5001')
const orbit = new OrbitDB(ipfs, 'benchmark') const orbit = new OrbitDB(ipfs, 'benchmark')
const db = orbit.eventlog(channelName) const db = orbit.eventlog(channelName)
// Metrics output // Metrics output
setInterval(() => { setInterval(() => {
seconds ++; seconds ++
if(seconds % 10 === 0) { if(seconds % 10 === 0) {
console.log(`--> Average of ${lastTenSeconds/10} q/s in the last 10 seconds`); console.log(`--> Average of ${lastTenSeconds/10} q/s in the last 10 seconds`)
if(lastTenSeconds === 0) if(lastTenSeconds === 0)
throw new Error("Problems!"); throw new Error("Problems!")
lastTenSeconds = 0; lastTenSeconds = 0
} }
console.log(`${queriesPerSecond} queries per second, ${totalQueries} queries in ${seconds} seconds`); console.log(`${queriesPerSecond} queries per second, ${totalQueries} queries in ${seconds} seconds`)
queriesPerSecond = 0; queriesPerSecond = 0
}, 1000); }, 1000)
// Start // Start
queryLoop(db); queryLoop(db)
})(); })()
module.exports = run; module.exports = run