Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bench tweaks #546

Merged
merged 3 commits into from
Dec 15, 2018
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
58 changes: 58 additions & 0 deletions bench/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,63 @@ bash bench/db-bench-plot.sh master.csv wip.csv
```

## `write-random`

Run the benchmark:

```
node bench/write-random.js
```

This writes results to `bench/write-random.csv` by default. To save results from multiple runs, add `--out <filename>`. For example, you could switch branches (assuming that both branches have the same benchmark code):

```
node bench/write-random.js --out master.csv

git checkout wip
node-gyp rebuild
node bench/write-random.js --out wip.csv
```

Then plot both runs with `write-random-plot.sh <file, ..>` (the basenames of the files are used for the legend):

```
./bench/write-random-plot.sh *.csv
```

If you are on Windows, you can use git bash:

```
bash bench/write-random-plot.sh master.csv wip.csv
```

## `write-sorted`

Run the benchmark:

```
node bench/write-sorted.js
```

This writes results to `bench/write-sorted.csv` by default. To save results from multiple runs, add `--out <filename>`. For example, you could switch branches (assuming that both branches have the same benchmark code):

```
node bench/write-sorted.js --out master.csv

git checkout wip
node-gyp rebuild
node bench/write-sorted.js --out wip.csv
```

Then plot both runs with `write-sorted-plot.sh <file, ..>` (the basenames of the files are used for the legend):

```
./bench/write-sorted-plot.sh *.csv
```

If you are on Windows, you can use git bash:

```
bash bench/write-sorted-plot.sh master.csv wip.csv
```

## `memory`
8 changes: 3 additions & 5 deletions bench/db-bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ const leveldown = require('../')
const fs = require('fs')
const du = require('du')
const path = require('path')
const rimraf = require('rimraf')
const argv = require('optimist').argv

const options = {
benchmark: argv.benchmark,
useExisting: argv.use_existing,
db: argv.db || path.join(__dirname, 'db'),
num: argv.num || 1000000,
concurrency: argv.concurrency || 4,
Expand All @@ -21,9 +20,7 @@ const options = {
const randomString = require('slump').string
const keyTmpl = '0000000000000000'

if (!options.useExisting) {
leveldown.destroy(options.db, function () {})
}
rimraf.sync(options.db)

const db = leveldown(options.db)
const timesStream = fs.createWriteStream(options.out, 'utf8')
Expand Down Expand Up @@ -56,6 +53,7 @@ function start () {
if (err) throw err
console.log('Database size:', Math.floor(size / 1024 / 1024) + 'M')
})
console.log('Wrote times to ', options.out)
}

function write () {
Expand Down
38 changes: 26 additions & 12 deletions bench/write-random-plot.sh
Original file line number Diff line number Diff line change
@@ -1,24 +1,38 @@
#!/bin/sh

num_writes=10M
num_files=$#
platform=$(node -p process.platform)
arch=$(node -p process.arch)
node=$(node -p process.version)
png_suffix=$(date '+%Y%m%d-%H.%M.%S')

gnuplot <<EOF
reset
set terminal png size 1920, 1080
set output "write_random_times.png"
set terminal pngcairo truecolor enhanced font "Ubuntu Mono,13" size 1920, 1080 background rgb "#1b1b1b"
set output "bench/write-random-$png_suffix.png"
set datafile separator ','

#set yrange [0:0.6]
set logscale y
set autoscale y

set xlabel "Seconds"
set ylabel "Milliseconds per write"
set xlabel "Time (seconds)" tc rgb "#777777"
set ylabel "Milliseconds/write" tc rgb "#888888"

set title "1.3G / 10,000,000 writes"
set key below
set key outside tc rgb "#777777"
set border lc rgb "#777777"
set grid

plot "write_random_times_g32.csv" using (\$1/1000):(\$2/1000000) title "Google LevelDB" lc rgb "red" lt 7 ps 0.3, \
"write_random_times_h32.csv" using (\$1/1000):(\$2/1000000) title "HyperDex LevelDB" lc rgb "green" lt 7 ps 0.3, \
"write_random_times_b32.csv" using (\$1/1000):(\$2/1000000) title "Basho LevelDB" lc rgb "blue" lt 7 ps 0.3, \
"write_random_times.csv" using (\$1/1000):(\$2/1000000) title "LMDB" lc rgb "black" lt 7 ps 0.3
# To plot more than 5 files, add more line styles
set style line 1 lt 7 ps 0.8 lc rgb "#00FFFF"
set style line 2 lt 7 ps 0.8 lc rgb "#D84797"
set style line 3 lt 7 ps 0.8 lc rgb "#23CE6B"
set style line 4 lt 7 ps 0.8 lc rgb "#F5B700"
set style line 5 lt 7 ps 0.8 lc rgb "#731DD8"

set title "leveldown write-random, $num_writes writes, $platform $arch, node $node" tc rgb "#cccccc"

filename(n) = word("$@", n)
basename(n) = substr(word("$@", n), 0, strstrt(word("$@", n), ".csv") - 1)

plot for [i=1:$num_files] filename(i) using (\$1/1000):(\$2/1000000) title basename(i) ls i axes x1y1
EOF
40 changes: 27 additions & 13 deletions bench/write-random.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,35 @@ const crypto = require('crypto')
const fs = require('fs')
const du = require('du')
const uuid = require('uuid')
const path = require('path')
const rimraf = require('rimraf')
const argv = require('optimist').argv

const options = {
db: argv.db || path.join(__dirname, 'db'),
num: argv.num || 10000000,
concurrency: argv.concurrency || 10,
cacheSize: argv.cacheSize || 8,
writeBufferSize: argv.writeBufferSize || 4,
valueSize: argv.valueSize || 100,
out: argv.out || path.join(__dirname, 'write-random.csv')
}

const entryCount = 10000000
const concurrency = 10
const timesFile = './write_random_times.csv'
const dbDir = './write_random.db'
const data = crypto.randomBytes(256) // buffer

const db = leveldown(dbDir)
const timesStream = fs.createWriteStream(timesFile, 'utf8')
rimraf.sync(options.db)

const db = leveldown(options.db)
const timesStream = fs.createWriteStream(options.out, 'utf8')

function report (ms) {
console.log('Wrote', entryCount, 'in', Math.floor(ms / 1000) + 's')
console.log('Wrote', options.num, 'in', Math.floor(ms / 1000) + 's')
timesStream.end()
du(dbDir, function (err, size) {
du(options.db, function (err, size) {
if (err) throw err
console.log('Database size:', Math.floor(size / 1024 / 1024) + 'M')
})
console.log('Wrote times to ', timesFile)
console.log('Wrote times to ', options.out)
}

db.open(function (err) {
Expand All @@ -39,15 +50,18 @@ db.open(function (err) {
writeBuf = ''
}

if (totalWrites++ === entryCount) return report(Date.now() - startTime)
if (inProgress >= concurrency || totalWrites > entryCount) return
if (totalWrites++ === options.num) return report(Date.now() - startTime)
if (inProgress >= options.concurrency || totalWrites > options.num) return

var time = process.hrtime()
var start = process.hrtime()
inProgress++

db.put(uuid.v4(), data, function (err) {
if (err) throw err
writeBuf += (Date.now() - startTime) + ',' + process.hrtime(time)[1] + '\n'
var duration = process.hrtime(start)
var nano = (duration[0] * 1e9) + duration[1]

writeBuf += (Date.now() - startTime) + ',' + nano + '\n'
inProgress--
process.nextTick(write)
})
Expand Down
39 changes: 28 additions & 11 deletions bench/write-sorted-plot.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,39 @@
#!/bin/sh

num_writes=10M
num_files=$#
platform=$(node -p process.platform)
arch=$(node -p process.arch)
node=$(node -p process.version)
png_suffix=$(date '+%Y%m%d-%H.%M.%S')

gnuplot <<EOF
reset
set terminal png size 1920, 1080
set output "write_sorted_times.png"
set terminal pngcairo truecolor enhanced font "Ubuntu Mono,13" size 1920, 1080 background rgb "#1b1b1b"
set output "bench/write-sorted-$png_suffix.png"
set datafile separator ','

#set yrange [0:0.6]
set autoscale y

set xlabel "Seconds"
set ylabel "Milliseconds per write"
set xlabel "Time (seconds)" tc rgb "#777777"
set ylabel "Milliseconds/write" tc rgb "#888888"

set title "1.3G / 10,000,000 writes"
set key below
set key outside tc rgb "#777777"
set border lc rgb "#777777"
set grid

plot "write_sorted_times_g.csv" using (\$1/1000):(\$2/1000000) title "Google LevelDB" lc rgb "red" lt 7 ps 0.3, \
"write_sorted_times_h.csv" using (\$1/1000):(\$2/1000000) title "HyperDex LevelDB" lc rgb "green" lt 7 ps 0.3, \
"write_sorted_times_b.csv" using (\$1/1000):(\$2/1000000) title "Basho LevelDB" lc rgb "blue" lt 7 ps 0.3
# To plot more than 5 files, add more line styles
set style line 1 lt 7 ps 0.8 lc rgb "#00FFFF"
set style line 2 lt 7 ps 0.8 lc rgb "#D84797"
set style line 3 lt 7 ps 0.8 lc rgb "#23CE6B"
set style line 4 lt 7 ps 0.8 lc rgb "#F5B700"
set style line 5 lt 7 ps 0.8 lc rgb "#731DD8"

set title "leveldown write-sorted, $num_writes writes, $platform $arch, node $node" tc rgb "#cccccc"

filename(n) = word("$@", n)
basename(n) = substr(word("$@", n), 0, strstrt(word("$@", n), ".csv") - 1)

plot for [i=1:$num_files] filename(i) using (\$1/1000):(\$2/1000000) title basename(i) ls i axes x1y1

EOF
EOF
42 changes: 28 additions & 14 deletions bench/write-sorted.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,38 @@ const timestamp = require('monotonic-timestamp')
const crypto = require('crypto')
const fs = require('fs')
const du = require('du')
const path = require('path')
const rimraf = require('rimraf')
const argv = require('optimist').argv

const options = {
db: argv.db || path.join(__dirname, 'db'),
num: argv.num || 10000000,
concurrency: argv.concurrency || 10,
cacheSize: argv.cacheSize || 8,
writeBufferSize: argv.writeBufferSize || 4,
valueSize: argv.valueSize || 100,
out: argv.out || path.join(__dirname, 'write-sorted.csv')
}

const entryCount = 10000000
const concurrency = 10
const timesFile = './write_sorted_times.csv'
const dbDir = './write_sorted.db'
const data = crypto.randomBytes(256) // buffer

const db = leveldown(dbDir)
const timesStream = fs.createWriteStream(timesFile, 'utf8')
rimraf.sync(options.db)

const db = leveldown(options.db)
const timesStream = fs.createWriteStream(options.out, 'utf8')

function report (ms) {
console.log('Wrote', entryCount, 'in', Math.floor(ms / 1000) + 's')
console.log('Wrote', options.num, 'in', Math.floor(ms / 1000) + 's')
timesStream.end()
du(dbDir, function (err, size) {
du(options.db, function (err, size) {
if (err) throw err
console.log('Database size:', Math.floor(size / 1024 / 1024) + 'M')
})
console.log('Wrote times to ', timesFile)
console.log('Wrote times to ', options.out)
}

db.open({ errorIfExists: true, createIfMissing: true }, function (err) {
db.open(function (err) {
if (err) throw err

let inProgress = 0
Expand All @@ -39,15 +50,18 @@ db.open({ errorIfExists: true, createIfMissing: true }, function (err) {
writeBuf = ''
}

if (totalWrites++ === entryCount) return report(Date.now() - startTime)
if (inProgress >= concurrency || totalWrites > entryCount) return
if (totalWrites++ === options.num) return report(Date.now() - startTime)
if (inProgress >= options.concurrency || totalWrites > options.num) return

var time = process.hrtime()
var start = process.hrtime()
inProgress++

db.put(timestamp(), data, function (err) {
if (err) throw err
writeBuf += (Date.now() - startTime) + ',' + process.hrtime(time)[1] + '\n'
var duration = process.hrtime(start)
var nano = (duration[0] * 1e9) + duration[1]

writeBuf += (Date.now() - startTime) + ',' + nano + '\n'
inProgress--
process.nextTick(write)
})
Expand Down