orbit-db/benchmarks/browser/benchmark-replication-sender.html

136 lines
3.8 KiB
HTML
Raw Normal View History

<html>
<head>
<meta charset="utf-8">
</head>
<body>
<h1>OrbitDB - Benchmark Replication</h1>
<h2>Description</h2>
<div>Two peers</div>
<h2>Results</h2>
<pre id="output"></pre>
<script type="text/javascript" src="../../dist/orbitdb.min.js" charset="utf-8"></script>
<script type="text/javascript" src="../../node_modules/ipfs/dist/index.min.js" charset="utf-8"></script>
<script type="text/javascript">
// Metrics
let metrics1 = {
totalQueries: 0,
seconds: 0,
queriesPerSecond: 0,
lastTenSeconds: 0,
}
const ipfsConf = {
Addresses: {
Swarm: [
// Use IPFS dev signal server
// '/dns4/star-signal.cloud.ipfs.team/wss/p2p-webrtc-star',
'/dns4/ws-star.discovery.libp2p.io/tcp/443/wss/p2p-websocket-star',
]
},
Bootstrap: [],
Discovery: {
MDNS: {
Enabled: false,
Interval: 10
},
webRTCStar: {
Enabled: false
}
},
}
const defaultConfig = Object.assign({}, {
start: true,
EXPERIMENTAL: {
pubsub: true,
sharding: false,
dht: false,
},
config: ipfsConf
})
2019-02-20 13:18:22 +00:00
const conf1 = Object.assign({}, defaultConfig, {
repo: './orbitdb/benchmarks/2replication3/client2/ipfs'
})
// Write loop
const queryLoop = async (db) => {
if (metrics1.totalQueries < updateCount) {
await db.add(metrics1.totalQueries)
metrics1.totalQueries ++
metrics1.lastTenSeconds ++
metrics1.queriesPerSecond ++
setImmediate(() => queryLoop(db))
}
}
// Metrics output function
const outputMetrics = (name, db, metrics) => {
metrics.seconds ++
console.log(`[${name}] ${metrics.queriesPerSecond} queries per second, ${metrics.totalQueries} queries in ${metrics.seconds} seconds (Oplog: ${db._oplog.length})`)
metrics.queriesPerSecond = 0
if(metrics.seconds % 10 === 0) {
console.log(`[${name}] --> Average of ${metrics.lastTenSeconds/10} q/s in the last 10 seconds`)
metrics.lastTenSeconds = 0
2019-02-20 13:18:22 +00:00
}
}
const startIpfs = (config = {}) => {
return new Promise((resolve, reject) => {
const ipfs = new Ipfs(config)
ipfs.on('error', reject)
ipfs.on('ready', () => resolve(ipfs))
})
}
const database = 'benchmark-replication'
const updateCount = 2000
// Start
console.log("Starting IPFS daemons...")
let run = (async () => {
let ipfs1 = await startIpfs(conf1)
try {
// Create the databases
2019-02-20 13:18:22 +00:00
const orbit1 = await OrbitDB.createInstance(ipfs1, { directory: './orbitdb/benchmarks/replication/client1' })
const db1 = await orbit1.eventlog(database, { overwrite: true, sync: false })
console.log("Database address is:", db1.address.toString())
db1.events.on('peer', peer => console.log("PEER1!", peer))
let db1Connected = false
db1.events.on('peer', () => {
db1Connected = true
})
const startInterval = setInterval(() => {
if (db1Connected) {
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)
}
}, 100)
} catch (e) {
console.error(e)
}
})()
</script>
</body>
</html>