Fix replication benchmark

This commit is contained in:
haad 2018-03-31 15:07:28 +02:00
parent 27a7b2bf70
commit 96df2ded99
2 changed files with 5 additions and 98 deletions

View File

@ -15,13 +15,6 @@ let metrics1 = {
lastTenSeconds: 0,
}
let metrics2 = {
totalQueries: 0,
seconds: 0,
queriesPerSecond: 0,
lastTenSeconds: 0,
}
const ipfsConf = {
Addresses: {
API: '/ip4/127.0.0.1/tcp/0',
@ -57,10 +50,6 @@ const conf1 = Object.assign({}, defaultConfig, {
repo: new IPFSRepo('./orbitdb/benchmarks/replication/client1/ipfs', repoConf)
})
const conf2 = Object.assign({}, defaultConfig, {
repo: new IPFSRepo('./orbitdb/benchmarks/replication/client2/ipfs', repoConf)
})
// Write loop
const queryLoop = async (db) => {
if (metrics1.totalQueries < updateCount) {
@ -94,22 +83,15 @@ const updateCount = 20000
// Start
console.log("Starting IPFS daemons...")
pMapSeries([conf1,], d => startIpfs(d))
pMapSeries([conf1,], d => startIpfs('js-ipfs', d))
.then(async ([ipfs1]) => {
try {
// await ipfs2.swarm.connect(ipfs1._peerInfo.multiaddrs._multiaddrs[0].toString())
// await ipfs1.swarm.connect(ipfs2._peerInfo.multiaddrs._multiaddrs[0].toString())
// Create the databases
const orbit1 = new OrbitDB(ipfs1, './orbitdb/benchmarks/replication/client1')
// const orbit2 = new OrbitDB(ipfs2, './orbitdb/benchmarks/replication/client2')
const orbit1 = new OrbitDB(ipfs1.api, './orbitdb/benchmarks/replication/client1')
const db1 = await orbit1.eventlog(database, { overwrite: true })
console.log(db1.address.toString())
// const db2 = await orbit2.eventlog(db1.address.toString())
let db1Connected = false
// let db2Connected = false
console.log('Waiting for peers to connect...')
@ -118,13 +100,7 @@ pMapSeries([conf1,], d => startIpfs(d))
console.log('Peer 1 connected')
})
// db2.events.on('peer', () => {
// db2Connected = true
// console.log('Peer 2 connected')
// })
const startInterval = setInterval(() => {
// if (db1Connected && db2Connected) {
if (db1Connected) {
clearInterval(startInterval)
// Start the write loop
@ -137,26 +113,6 @@ pMapSeries([conf1,], d => startIpfs(d))
clearInterval(writeInterval)
}
}, 1000)
// Metrics output for the reader
let prevCount = 0
// setInterval(() => {
// try {
// metrics2.totalQueries = db2._oplog.length
// metrics2.queriesPerSecond = metrics2.totalQueries - prevCount
// metrics2.lastTenSeconds += metrics2.queriesPerSecond
// prevCount = metrics2.totalQueries
// outputMetrics("READ", db2, metrics2)
// if (db2._oplog.length === updateCount) {
// console.log("Finished")
// process.exit(0)
// }
// } catch (e) {
// console.error(e)
// }
// }, 1000)
}
}, 100)
} catch (e) {

View File

@ -8,13 +8,6 @@ const startIpfs = require('../test/utils/start-ipfs')
const pMapSeries = require('p-map-series')
// Metrics
let metrics1 = {
totalQueries: 0,
seconds: 0,
queriesPerSecond: 0,
lastTenSeconds: 0,
}
let metrics2 = {
totalQueries: 0,
seconds: 0,
@ -53,29 +46,10 @@ const defaultConfig = Object.assign({}, {
config: ipfsConf
})
const conf1 = Object.assign({}, defaultConfig, {
repo: new IPFSRepo('./orbitdb/benchmarks/replication/client1/ipfs', repoConf)
})
const conf2 = Object.assign({}, defaultConfig, {
repo: new IPFSRepo('./orbitdb/benchmarks/replication/client2/ipfs', repoConf)
repo: new IPFSRepo('./orbitdb/benchmarks/replication/client22faf/ipfs', repoConf)
})
// Write loop
const queryLoop = async (db) => {
if (metrics1.totalQueries < updateCount) {
try {
await db.add(metrics1.totalQueries)
} catch (e) {
console.error(e)
}
metrics1.totalQueries ++
metrics1.lastTenSeconds ++
metrics1.queriesPerSecond ++
setImmediate(() => queryLoop(db))
}
}
// Metrics output function
const outputMetrics = (name, db, metrics) => {
metrics.seconds ++
@ -94,49 +68,26 @@ const updateCount = 20000
// Start
console.log("Starting IPFS daemons...")
pMapSeries([conf2], d => startIpfs(d))
pMapSeries([conf2], d => startIpfs('js-ipfs', d))
.then(async ([ipfs2]) => {
try {
// await ipfs2.swarm.connect(ipfs1._peerInfo.multiaddrs._multiaddrs[0].toString())
// await ipfs1.swarm.connect(ipfs2._peerInfo.multiaddrs._multiaddrs[0].toString())
// Create the databases
// const orbit1 = new OrbitDB(ipfs1, './orbitdb/benchmarks/replication/client1')
const orbit2 = new OrbitDB(ipfs2, './orbitdb/benchmarks/replication/client2')
const orbit2 = new OrbitDB(ipfs2.api, './orbitdb/benchmarks/replication/client2')
const address = process.argv[2]
// const db1 = await orbit1.eventlog(database, { overwrite: true })
const db2 = await orbit2.eventlog(address)
// let db1Connected = false
let db2Connected = false
console.log('Waiting for peers to connect...')
// db1.events.on('peer', () => {
// db1Connected = true
// console.log('Peer 1 connected')
// })
db2.events.on('peer', () => {
db2Connected = true
console.log('Peer 2 connected')
})
const startInterval = setInterval(() => {
// if (db1Connected && db2Connected) {
if (db2Connected) {
clearInterval(startInterval)
// Start the write loop
// queryLoop(db1)
// // Metrics output for the writer, once/sec
// const writeInterval = setInterval(() => {
// outputMetrics("WRITE", db1, metrics1)
// if (metrics1.totalQueries === updateCount) {
// clearInterval(writeInterval)
// }
// }, 1000)
// Metrics output for the reader
let prevCount = 0
setInterval(() => {