42885b20a4
Use latest store modules from npm Update README Update docs Update examples Update benchmarks Update dependencies Add Getting Started guide Add new a screenshot Add a new live demo Add persistency tests for snapshot saving/loading and events Add network stress tests (but skip them by default as they're very heavy and lengthy) Add browser benchmarks Add log() alias for eventlog() database Add possibility to create database if it doesn't exist yet Add support for orbitdb addresses Add a test for starting replication when peers connect Add debug build Use IPFS nodeID as default user id Use ipfs-pubsub-room Handle closing of databases properly Handle cache errors Clean up tests, re-organize code files Clean up code style Support for CLI Remove obsolete scripts
136 lines
3.8 KiB
HTML
136 lines
3.8 KiB
HTML
<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',
|
|
// '/ip4/0.0.0.0/tcp/9090/wss/p2p-webrtc-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
|
|
})
|
|
|
|
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
|
|
}
|
|
}
|
|
|
|
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
|
|
const orbit1 = new OrbitDB(ipfs1, './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>
|