Skip to content

Commit

Permalink
Update batch-put benchmark to use generator
Browse files Browse the repository at this point in the history
  • Loading branch information
vweevers committed Jun 30, 2019
1 parent 38f0f0c commit 208cb80
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 84 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ Yet to document.

### `put`

Perform concurrent `put()` operations on random or sequential string keys and values. Records the Simple Moving Average (SMA) of the duration of the last 1000 writes, as well as the Cumulative Moving Average (CMA) of the throughput in MB/s. Options:
Perform concurrent `put()` operations. Records the Simple Moving Average (SMA) of the duration of the last 1000 writes, as well as the Cumulative Moving Average (CMA) of the throughput in MB/s. Options:

- `-n`: amount of operations, default 1e6
- `--concurrency`: default 4
Expand All @@ -143,13 +143,12 @@ Tips:

### `batch-put`

Same as `put`, but in batches rather than singular puts. Perform concurrent `batch()` operations on random string keys and values. Options:
Perform concurrent `batch()` operations. Same as `put`, but in batches rather than singular puts. Options:

- `-n`: amount of operations, default 1e6
- `--batchSize`: default 1000
- `--batchSize`: default 1000, must be a multiple of 10, maximum 1000
- `--chained`: boolean flag, default false, use chained batch
- `--concurrency`: default 1
- `--valueSize`: size of value, as a number in bytes or string with unit (e.g. `--valueSize 1kb`)
- Other options are the same as of the `put` benchmark, see above.

### `self-distribution`

Expand Down
56 changes: 32 additions & 24 deletions benchmarks/batch-put.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,39 @@
'use strict'

const crypto = require('crypto')
const keyspace = require('keyspace')
const ldu = require('../lib/level-du')
const keyTmpl = '0000000000000000'
const window = 1000
const progressWindow = window * 100

exports.defaults = {
benchmark: {
n: 1e6,
batchSize: 1e3,
concurrency: 1,
valueSize: 100,
chained: false
chained: false,
keys: 'random',
values: 'random',
seed: 'seed'
}
}

exports.plot = require('./batch-put.plot')
exports.plot = require('./put.plot')

exports.run = function (factory, stream, options) {
stream.write('Elapsed (ms), Entries, Bytes, Last 1000 Avg Time, MB/s\n')
if (options.batchSize <= 0 || options.batchSize > window) {
throw new RangeError('The "batchSize" option must be > 0 <= ' + window)
} else if (options.batchSize % 10 !== 0) {
throw new Error('The "batchSize" option must be a multiple of 10')
} else if (options.batchSize > options.n) {
throw new RangeError('The "batchSize" option must be <= n')
} else if (options.n % options.batchSize !== 0) {
throw new Error('The "n" option must be a multiple of "batchSize"')
}

function make16CharPaddedKey () {
const r = Math.floor(Math.random() * options.n)
const k = keyTmpl + r
const generator = keyspace(options.n, options)

return k.substr(k.length - 16)
}
stream.write('Elapsed (ms), Entries, Bytes, SMA ms/write, CMA MB/s\n')

function start (db) {
const startTime = Date.now()
Expand All @@ -39,7 +48,7 @@ exports.run = function (factory, stream, options) {
function report () {
console.log(
'Wrote', options.n, 'entries in',
Math.floor((Date.now() - startTime) / 1000) + 's,',
Math.floor((Date.now() - startTime) / 1e3) + 's,',
(Math.floor((totalBytes / 1048576) * 100) / 100) + 'MB'
)

Expand All @@ -61,20 +70,19 @@ exports.run = function (factory, stream, options) {

inProgress++

if (totalWrites % 100000 === 0) {
if (totalWrites % progressWindow === 0) {
console.log('' + inProgress, totalWrites,
Math.round(totalWrites / options.n * 100) + '%')
}

// TODO: batchSize should be a multiple of 10
if (totalWrites % 1000 === 0) {
if (totalWrites % window === 0) {
elapsed = Date.now() - startTime
stream.write(
elapsed +
',' + totalWrites +
',' + totalBytes +
',' + Math.floor(timesAccum / 1000) +
',' + (Math.floor(((totalBytes / 1048576) / (elapsed / 1000)) * 100) / 100) +
',' + (timesAccum / window / 1e6).toFixed(3) +
',' + ((totalBytes / 1048576) / (elapsed / 1e3)).toFixed(3) +
'\n')
timesAccum = 0
}
Expand All @@ -85,10 +93,11 @@ exports.run = function (factory, stream, options) {
const batch = db.batch()

for (let i = 0; i < batchSize; i++) {
// TODO: see comment in write.js
const key = make16CharPaddedKey()
const value = crypto.randomBytes(options.valueSize).toString('hex')
const key = generator.key(totalWrites++)
const value = generator.value()

// TODO: see comment in put.js
totalBytes += Buffer.byteLength(key) + Buffer.byteLength(value)
batch.put(key, value)
}

Expand All @@ -98,10 +107,11 @@ exports.run = function (factory, stream, options) {
const ops = new Array(batchSize)

for (let i = 0; i < batchSize; i++) {
// TODO: see comment in write.js
const key = make16CharPaddedKey()
const value = crypto.randomBytes(options.valueSize).toString('hex')
const key = generator.key(totalWrites++)
const value = generator.value()

// TODO: see comment in put.js
totalBytes += Buffer.byteLength(key) + Buffer.byteLength(value)
ops[i] = { type: 'put', key, value }
}

Expand All @@ -115,8 +125,6 @@ exports.run = function (factory, stream, options) {
const duration = process.hrtime(start)
const nano = (duration[0] * 1e9) + duration[1]

totalBytes += (keyTmpl.length + options.valueSize) * batchSize
totalWrites += batchSize
timesAccum += nano
inProgress--

Expand Down
55 changes: 0 additions & 55 deletions benchmarks/batch-put.plot.js

This file was deleted.

1 change: 1 addition & 0 deletions benchmarks/put.plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const e = require('../lib/escape-gnuplot-string')

// Note: also used by the batch-put benchmark.
module.exports = function (title, description, results) {
const durations = results.map(function (res, i) {
const file = res.csvFile
Expand Down
1 change: 1 addition & 0 deletions lib/meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ function id (meta, peers, invert, opts) {
for (let k of sortKeys(Object.keys(node), ORDER)) {
if (opts && opts.include && opts.include.indexOf(k) < 0) continue
if (opts && opts.exclude && opts.exclude.indexOf(k) >= 0) continue
if (k === 'seed') continue

const v = node[k]

Expand Down

0 comments on commit 208cb80

Please sign in to comment.