Skip to content
This repository has been archived by the owner on Sep 30, 2023. It is now read-only.

Add write permissions #110

Merged
merged 1 commit into from
Nov 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
node_modules/
coverage/
ipfs/
ipfs-log/
dist/*.js.map
examples/browser/bundle.js
test/keystore/
test-keys/
4 changes: 2 additions & 2 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ log.append({ some: 'data' })

#### join(log, [length], [id])

Join the log with another log. Returns a new `Log` instance. The size of the joined log can be specified by giving `length` argument.
Join the log with another log. Returns a Promise that resolves to a `Log` instance. The size of the joined log can be specified by giving `length` argument.

```javascript
// log1.values ==> ['A', 'B', 'C']
// log2.values ==> ['C', 'D', 'E']

log1.join(log2)
console.log(log1.values)
.then(() => console.log(log1.values))
// ['A', 'B', 'C', 'D', 'E']
```

Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ clean:
rm -rf ipfs-log-benchmarks/
rm -rf node_modules/
rm -rf coverage/
rm -rf test/keystore/
rm package-lock.json

.PHONY: test
75 changes: 75 additions & 0 deletions benchmarks/benchmark-append-signed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
'use strict'

const Log = require('../src/log')
const Keystore = require('orbit-db-keystore')
const IPFS = require('ipfs')
const IPFSRepo = require('ipfs-repo')
const DatastoreLevel = require('datastore-level')

// State
let ipfs
let log

// Metrics
let totalQueries = 0
let seconds = 0
let queriesPerSecond = 0
let lastTenSeconds = 0

const queryLoop = () => {
log.append(totalQueries.toString())
.then((res) => {
totalQueries++
lastTenSeconds++
queriesPerSecond++
setImmediate(queryLoop)
})
.catch((e) => console.error(e))
}

let run = (() => {
console.log('Starting benchmark...')

const repoConf = {
storageBackends: {
blocks: DatastoreLevel,
},
}

ipfs = new IPFS({
repo: new IPFSRepo('./ipfs-log-benchmarks/ipfs', repoConf),
start: false,
EXPERIMENTAL: {
pubsub: false,
sharding: false,
dht: false,
},
})

ipfs.on('error', (err) => {
console.error(err)
})

ipfs.on('ready', () => {
const keystore = new Keystore('./test-keys')
const key = keystore.createKey('benchmark-append-signed')
ipfs.keystore = keystore
log = new Log(ipfs, 'A', null, null, null, key, key.getPublic('hex'))

// Output metrics at 1 second interval
setInterval(() => {
seconds++
if (seconds % 10 === 0) {
console.log(`--> Average of ${lastTenSeconds / 10} q/s in the last 10 seconds`)
if (lastTenSeconds === 0) throw new Error('Problems!')
lastTenSeconds = 0
}
console.log(`${queriesPerSecond} queries per second, ${totalQueries} queries in ${seconds} seconds (Entry count: ${log.values.length})`)
queriesPerSecond = 0
}, 1000)

setImmediate(queryLoop)
})
})()

module.exports = run
108 changes: 0 additions & 108 deletions benchmarks/benchmark-expand.js

This file was deleted.

82 changes: 82 additions & 0 deletions benchmarks/benchmark-join-signed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
'use strict'

const Log = require('../src/log')
const Keystore = require('orbit-db-keystore')
const IPFS = require('ipfs')
const IPFSRepo = require('ipfs-repo')
const DatastoreLevel = require('datastore-level')

// State
let ipfs
let log1, log2

// Metrics
let totalQueries = 0
let seconds = 0
let queriesPerSecond = 0
let lastTenSeconds = 0

const queryLoop = async () => {
try {
const add1 = await log1.append('a' + totalQueries)
const add2 = await log2.append('b' + totalQueries)

await Promise.all([add1, add2])
log1.join(log2)
log2.join(log1)
totalQueries++
lastTenSeconds++
queriesPerSecond++
setImmediate(queryLoop)
} catch (e) {
console.error(e)
process.exit(0)
}
}

let run = (() => {
console.log('Starting benchmark...')

const repoConf = {
storageBackends: {
blocks: DatastoreLevel,
},
}

ipfs = new IPFS({
repo: new IPFSRepo('./ipfs-log-benchmarks/ipfs', repoConf),
start: false,
EXPERIMENTAL: {
pubsub: true
},
})

ipfs.on('error', (err) => {
console.error(err)
process.exit(1)
})

ipfs.on('ready', () => {
const keystore = new Keystore('./test-keys')
const key = keystore.createKey('benchmark-append-signed')
ipfs.keystore = keystore
log1 = new Log(ipfs, 'A', null, null, null, key, key.getPublic('hex'))
log2 = new Log(ipfs, 'B', null, null, null, key, key.getPublic('hex'))

// Output metrics at 1 second interval
setInterval(() => {
seconds++
if (seconds % 10 === 0) {
console.log(`--> Average of ${lastTenSeconds / 10} q/s in the last 10 seconds`)
if (lastTenSeconds === 0) throw new Error('Problems!')
lastTenSeconds = 0
}
console.log(`${queriesPerSecond} queries per second, ${totalQueries} queries in ${seconds} seconds. log1: ${log1.length}, log2: ${log2.length}`)
queriesPerSecond = 0
}, 1000)

queryLoop()
})
})()

module.exports = run
33 changes: 16 additions & 17 deletions benchmarks/benchmark-join.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,22 @@ let seconds = 0
let queriesPerSecond = 0
let lastTenSeconds = 0

const queryLoop = () => {
const add1 = log1.append('a' + totalQueries)
const add2 = log2.append('b' + totalQueries)
const queryLoop = async () => {
try {
const add1 = await log1.append('a' + totalQueries)
const add2 = await log2.append('b' + totalQueries)

Promise.all([add1, add2])
.then((res) => {
log1.join(res[1], 60)
log2.join(res[0], 60)
totalQueries++
lastTenSeconds++
queriesPerSecond++
setImmediate(queryLoop)
})
.catch((e) => {
console.error(e)
process.exit(0)
})
await Promise.all([add1, add2])
log1.join(log2)
log2.join(log1)
totalQueries++
lastTenSeconds++
queriesPerSecond++
setImmediate(queryLoop)
} catch (e) {
console.error(e)
process.exit(0)
}
}

let run = (() => {
Expand Down Expand Up @@ -68,7 +67,7 @@ let run = (() => {
if (lastTenSeconds === 0) throw new Error('Problems!')
lastTenSeconds = 0
}
console.log(`${queriesPerSecond} queries per second, ${totalQueries} queries in ${seconds} seconds. log1: ${log1.values.length}, log2: ${log2.values.length}`)
console.log(`${queriesPerSecond} queries per second, ${totalQueries} queries in ${seconds} seconds. log1: ${log1.length}, log2: ${log2.length}`)
queriesPerSecond = 0
}, 1000)

Expand Down
10 changes: 4 additions & 6 deletions benchmarks/browser/benchmark-append.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ <h2>Description</h2>
<div>Add an entry to a log. Measure throughput in operations per second.</div>
<pre><i>
let log = new Log(ipfs, 'id')
log.append(loopCount)
await log.append(loopCount)
</i></pre>

<h2>Results</h2>
Expand All @@ -28,9 +28,8 @@ <h2>Results</h2>
let lastTenSeconds = 0

const queryLoop = () => {
log.append(totalQueries.toString())
return log.append(totalQueries.toString())
.then((res) => {
log = res
totalQueries ++
lastTenSeconds ++
queriesPerSecond ++
Expand All @@ -41,7 +40,7 @@ <h2>Results</h2>

let run = (() => {
ipfs = new Ipfs({
repo: './ipfs-log/examples/browser/benchmark-append',
repo: './ipfs-log/examples/browser/benchmark-append/new',
start: false,
EXPERIMENTAL: {
pubsub: false,
Expand All @@ -64,8 +63,7 @@ <h2>Results</h2>
throw new Error("Problems!")
lastTenSeconds = 0
}
outputElm.innerHTML = `${queriesPerSecond} queries per second, ${totalQueries} queries in ${seconds} seconds - Log entries: ${log.values.length}<br>` + outputElm.innerHTML
console.log(`${queriesPerSecond} queries per second, ${totalQueries} queries in ${seconds} seconds`)
outputElm.innerHTML = `${queriesPerSecond} queries per second, ${totalQueries} queries in ${seconds} seconds - Log entries: ${log.length}<br>` + outputElm.innerHTML
queriesPerSecond = 0
}, 1000)

Expand Down
Loading