Update examples and benchmarks

This commit is contained in:
shamb0t 2019-02-20 13:18:22 +00:00
parent 8e4f22e0f3
commit 39408d0e2a
11 changed files with 46 additions and 36 deletions

View File

@ -1,6 +1,6 @@
'use strict'
const IPFS = require('ipfs-api')
const IPFS = require('ipfs-http-client')
const OrbitDB = require('../src/OrbitDB')
// Metrics
@ -26,8 +26,8 @@ const ipfs = IPFS('127.0.0.1')
const run = async () => {
try {
const orbit = new OrbitDB(ipfs, './orbitdb/benchmarks')
const db = await orbit.eventlog('orbit-db.benchmark', {
const orbit = await OrbitDB.createInstance(ipfs, { directory: './orbitdb/benchmarks' })
const db = await orbit.eventlog('orbit-db.benchmark', {
replicate: false,
})

View File

@ -44,8 +44,8 @@ ipfs.on('error', (err) => console.error(err))
ipfs.on('ready', async () => {
const run = async () => {
try {
const orbit = new OrbitDB(ipfs, './orbitdb/benchmarks')
const db = await orbit.eventlog('orbit-db.benchmark', {
const orbit = await OrbitDB.createInstance(ipfs,{ directory: './orbitdb/benchmarks' })
const db = await orbit.eventlog('orbit-db.benchmark', {
replicate: false,
})

View File

@ -46,8 +46,8 @@ const defaultConfig = Object.assign({}, {
config: ipfsConf
})
const conf1 = Object.assign({}, defaultConfig, {
repo: new IPFSRepo('./orbitdb/benchmarks/replication/client1/ipfs', repoConf)
const conf1 = Object.assign({}, defaultConfig, {
repo: new IPFSRepo('./orbitdb/benchmarks/replication/client1/ipfs', repoConf)
})
// Write loop
@ -74,7 +74,7 @@ const outputMetrics = (name, db, metrics) => {
if(metrics.seconds % 10 === 0) {
console.log(`[${name}] --> Average of ${metrics.lastTenSeconds/10} q/s in the last 10 seconds`)
metrics.lastTenSeconds = 0
}
}
}
const database = 'benchmark-replication'
@ -87,7 +87,7 @@ pMapSeries([conf1,], d => startIpfs('js-ipfs', d))
.then(async ([ipfs1]) => {
try {
// Create the databases
const orbit1 = new OrbitDB(ipfs1.api, './orbitdb/benchmarks/replication/client1')
const orbit1 = await OrbitDB.createInstance(ipfs1.api, { directory: './orbitdb/benchmarks/replication/client1' })
const db1 = await orbit1.eventlog(database, { overwrite: true })
console.log(db1.address.toString())

View File

@ -46,8 +46,8 @@ const defaultConfig = Object.assign({}, {
config: ipfsConf
})
const conf2 = Object.assign({}, defaultConfig, {
repo: new IPFSRepo('./orbitdb/benchmarks/replication/client22faf/ipfs', repoConf)
const conf2 = Object.assign({}, defaultConfig, {
repo: new IPFSRepo('./orbitdb/benchmarks/replication/client22faf/ipfs', repoConf)
})
// Metrics output function
@ -59,7 +59,7 @@ const outputMetrics = (name, db, metrics) => {
if(metrics.seconds % 10 === 0) {
console.log(`[${name}] --> Average of ${metrics.lastTenSeconds/10} q/s in the last 10 seconds`)
metrics.lastTenSeconds = 0
}
}
}
const database = 'benchmark-replication'
@ -72,7 +72,7 @@ pMapSeries([conf2], d => startIpfs('js-ipfs', d))
.then(async ([ipfs2]) => {
try {
// Create the databases
const orbit2 = new OrbitDB(ipfs2.api, './orbitdb/benchmarks/replication/client2')
const orbit2 = await OrbitDB.createInstance(ipfs2.api, { directory: './orbitdb/benchmarks/replication/client2' })
const address = process.argv[2]
const db2 = await orbit2.eventlog(address)

View File

@ -32,7 +32,7 @@
}
let run = (() => {
ipfs = new Ipfs({
ipfs = new Ipfs({
repo: '/orbitdb/benchmarks/browser/benchmark-add/0.27.0',
start: false,
EXPERIMENTAL: {
@ -47,8 +47,8 @@
ipfs.on('ready', async () => {
const outputElm = document.getElementById('output')
try {
const orbit = new OrbitDB(ipfs, './orbitdb/benchmarks/browser')
const db = await orbit.eventlog('orbit-db.benchmark.add', {
const orbit = await OrbitDB.createInstance(ipfs, { directory: './orbitdb/benchmarks/browser' })
const db = await orbit.eventlog('orbit-db.benchmark.add', {
replicate: false,
})

View File

@ -53,7 +53,7 @@
config: ipfsConf
})
const conf1 = Object.assign({}, defaultConfig, {
const conf1 = Object.assign({}, defaultConfig, {
repo: './orbitdb/benchmarks/2replication3/client2/ipfs'
})
@ -77,7 +77,7 @@
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 = {}) => {
@ -98,7 +98,7 @@
let ipfs1 = await startIpfs(conf1)
try {
// Create the databases
const orbit1 = new OrbitDB(ipfs1, './orbitdb/benchmarks/replication/client1')
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())

View File

@ -60,11 +60,11 @@
config: ipfsConf
})
const conf1 = Object.assign({}, defaultConfig, {
const conf1 = Object.assign({}, defaultConfig, {
repo: './orbitdb/benchmarks/2replication3/client1/ipfs'
})
const conf2 = Object.assign({}, defaultConfig, {
const conf2 = Object.assign({}, defaultConfig, {
repo: './orbitdb/benchmarks/2replication3/client2/ipfs'
})
@ -88,7 +88,7 @@
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 = {}) => {
@ -109,8 +109,8 @@
let ipfs2 = await startIpfs(conf2)
try {
// Create the databases
const address = '/orbitdb/QmcPCAwwV1rw7cLQU7VcCaUXEuLYSCH8uUf6NPDLYbL6JT/benchmark-replication'
const orbit2 = new OrbitDB(ipfs2, './orbitdb/benchmarks/replication/client3')
const address = '/orbitdb/zdpuArNFJaH4Fk5dHH4rYSCtmbyaJLNHUyeFX4WszFxEqwJTE/benchmark-replication'
const orbit2 = await OrbitDB.createInstance(ipfs2, { directory: './orbitdb/benchmarks/replication/client3' })
const db2 = await orbit2.eventlog(address)
db2.events.on('peer', peer => console.log("PEER2!", peer))

View File

@ -51,8 +51,8 @@
</div>
<div id="writerText"></div>
<script type="text/javascript" src="lib/orbitdb.min.js" charset="utf-8"></script>
<script type="text/javascript" src="lib/ipfs.js" charset="utf-8"></script>
<script type="text/javascript" src="../../dist/orbitdb.js" charset="utf-8"></script>
<script type="text/javascript" src="../../node_modules/ipfs/dist/index.js" charset="utf-8"></script>
<script type="text/javascript" src="example.js" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
// Start the example

View File

@ -46,8 +46,11 @@ const main = (IPFS, ORBITDB) => {
// Create IPFS instance
const ipfs = new Ipfs({
repo: '/orbitdb/examples/browser/new/ipfs/0.27.3',
repo: '/orbitdb/examples/browser/new/ipfs/0.33.1',
start: true,
preload: {
enabled: false
},
EXPERIMENTAL: {
pubsub: true,
},
@ -65,11 +68,11 @@ const main = (IPFS, ORBITDB) => {
})
ipfs.on('error', (e) => handleError(e))
ipfs.on('ready', () => {
ipfs.on('ready', async () => {
openButton.disabled = false
createButton.disabled = false
statusElm.innerHTML = "IPFS Started"
orbitdb = new OrbitDB(ipfs)
orbitdb = await OrbitDB.createInstance(ipfs)
})
const load = async (db, statusText) => {
@ -89,8 +92,8 @@ const main = (IPFS, ORBITDB) => {
let maxTotal = 0, loaded = 0
db.events.on('load.progress', (address, hash, entry, progress, total) => {
loaded ++
maxTotal = Math.max.apply(null, [progress, maxTotal, progress, 0])
total = Math.max.apply(null, [progress, maxTotal, total, 0])
maxTotal = Math.max.apply(null, [maxTotal, progress, 0])
total = Math.max.apply(null, [progress, maxTotal, total, entry.clock.time, 0])
statusElm.innerHTML = `Loading database... ${maxTotal} / ${total}`
})
@ -158,7 +161,9 @@ const main = (IPFS, ORBITDB) => {
type: type,
// If "Public" flag is set, allow anyone to write to the database,
// otherwise only the creator of the database can write
write: publicAccess ? ['*'] : [],
accessController: {
write: publicAccess ? ['*'] : [identity.publicKey],
}
})
await load(db, 'Creating database...')
@ -255,7 +260,7 @@ const main = (IPFS, ORBITDB) => {
outputElm.innerHTML = `
<div><b>Peer ID:</b> ${orbitdb.id}</div>
<div><b>Peers (database/network):</b> ${databasePeers.length} / ${networkPeers.length}</div>
<div><b>Oplog Size:</b> ${db._replicationStatus.progress} / ${db._replicationStatus.max}</div>
<div><b>Oplog Size:</b> ${Math.max(db._replicationStatus.progress, db._oplog.length)} / ${db._replicationStatus.max}</div>
<h2>Results</h2>
<div id="results">
<div>

View File

@ -21,8 +21,11 @@ ipfs.on('ready', async () => {
let db
try {
const orbitdb = new OrbitDB(ipfs, './orbitdb/examples/eventlog')
const orbitdb = await OrbitDB.createInstance(ipfs, {
directory: './orbitdb/examples/eventlog'
})
db = await orbitdb.eventlog('example', { overwrite: true })
await db.load()
} catch (e) {
console.error(e)
process.exit(1)
@ -40,7 +43,7 @@ ipfs.on('ready', async () => {
output += `--------------------\n`
output += `ID | Visitor\n`
output += `--------------------\n`
output += latest.reverse().map((e) => e.payload.value.userId + ' | ' + e.payload.value.avatar + ')').join('\n') + `\n`
output += latest.reverse().map((e) => e.payload.value.userId + ' | ' + e.payload.value.avatar).join('\n') + `\n`
console.log(output)
} catch (e) {
console.error(e)

View File

@ -36,7 +36,9 @@ ipfs.on('error', (err) => console.error(err))
ipfs.on('ready', async () => {
let db
try {
const orbitdb = new OrbitDB(ipfs, './orbitdb/examples/eventlog')
const orbitdb = await OrbitDB.createInstance(ipfs, {
directory: './orbitdb/examples/keyvalue'
})
db = await orbitdb.kvstore('example', { overwrite: true })
await db.load()
// Query immediately after loading