Skip to content

Commit 208cb80

Browse files
committed
Update batch-put benchmark to use generator
1 parent 38f0f0c commit 208cb80

5 files changed

Lines changed: 38 additions & 84 deletions

File tree

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ Yet to document.
117117

118118
### `put`
119119

120-
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:
120+
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:
121121

122122
- `-n`: amount of operations, default 1e6
123123
- `--concurrency`: default 4
@@ -143,13 +143,12 @@ Tips:
143143

144144
### `batch-put`
145145

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

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

154153
### `self-distribution`
155154

benchmarks/batch-put.js

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,39 @@
11
'use strict'
22

3-
const crypto = require('crypto')
3+
const keyspace = require('keyspace')
44
const ldu = require('../lib/level-du')
5-
const keyTmpl = '0000000000000000'
5+
const window = 1000
6+
const progressWindow = window * 100
67

78
exports.defaults = {
89
benchmark: {
910
n: 1e6,
1011
batchSize: 1e3,
1112
concurrency: 1,
1213
valueSize: 100,
13-
chained: false
14+
chained: false,
15+
keys: 'random',
16+
values: 'random',
17+
seed: 'seed'
1418
}
1519
}
1620

17-
exports.plot = require('./batch-put.plot')
21+
exports.plot = require('./put.plot')
1822

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

22-
function make16CharPaddedKey () {
23-
const r = Math.floor(Math.random() * options.n)
24-
const k = keyTmpl + r
34+
const generator = keyspace(options.n, options)
2535

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

2938
function start (db) {
3039
const startTime = Date.now()
@@ -39,7 +48,7 @@ exports.run = function (factory, stream, options) {
3948
function report () {
4049
console.log(
4150
'Wrote', options.n, 'entries in',
42-
Math.floor((Date.now() - startTime) / 1000) + 's,',
51+
Math.floor((Date.now() - startTime) / 1e3) + 's,',
4352
(Math.floor((totalBytes / 1048576) * 100) / 100) + 'MB'
4453
)
4554

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

6271
inProgress++
6372

64-
if (totalWrites % 100000 === 0) {
73+
if (totalWrites % progressWindow === 0) {
6574
console.log('' + inProgress, totalWrites,
6675
Math.round(totalWrites / options.n * 100) + '%')
6776
}
6877

69-
// TODO: batchSize should be a multiple of 10
70-
if (totalWrites % 1000 === 0) {
78+
if (totalWrites % window === 0) {
7179
elapsed = Date.now() - startTime
7280
stream.write(
7381
elapsed +
7482
',' + totalWrites +
7583
',' + totalBytes +
76-
',' + Math.floor(timesAccum / 1000) +
77-
',' + (Math.floor(((totalBytes / 1048576) / (elapsed / 1000)) * 100) / 100) +
84+
',' + (timesAccum / window / 1e6).toFixed(3) +
85+
',' + ((totalBytes / 1048576) / (elapsed / 1e3)).toFixed(3) +
7886
'\n')
7987
timesAccum = 0
8088
}
@@ -85,10 +93,11 @@ exports.run = function (factory, stream, options) {
8593
const batch = db.batch()
8694

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

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

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

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

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

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

118-
totalBytes += (keyTmpl.length + options.valueSize) * batchSize
119-
totalWrites += batchSize
120128
timesAccum += nano
121129
inProgress--
122130

benchmarks/batch-put.plot.js

Lines changed: 0 additions & 55 deletions
This file was deleted.

benchmarks/put.plot.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

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

5+
// Note: also used by the batch-put benchmark.
56
module.exports = function (title, description, results) {
67
const durations = results.map(function (res, i) {
78
const file = res.csvFile

lib/meta.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ function id (meta, peers, invert, opts) {
8585
for (let k of sortKeys(Object.keys(node), ORDER)) {
8686
if (opts && opts.include && opts.include.indexOf(k) < 0) continue
8787
if (opts && opts.exclude && opts.exclude.indexOf(k) >= 0) continue
88+
if (k === 'seed') continue
8889

8990
const v = node[k]
9091

0 commit comments

Comments
 (0)