mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
A benchmark of its own (docs/Databases/FerretDB/1/SpeedTest/embedded, a Go module, no cgo) loads the speed test's cards into SQLite set up as FerretDB sets it and into Pebble, Badger, bbolt, BuntDB, Nutsdb and Clover, and asks each the six questions WeKan asks of cards, at 15,377 and 153,768 cards. A board's cards take the same time on every engine that is not slower, because decoding the JSON dominates; the key-value stores win single reads and writes by microseconds that a FerretDB call hides; Pebble is 12x slower on fetching a board, Clover 90-190x slower in total, and bbolt with its default fsync 100-160x slower on writes. The README accounts for every entry of the awesome-go section. Thanks to Raymond-Voogt and xet7 !
86 lines
4.4 KiB
JavaScript
86 lines
4.4 KiB
JavaScript
'use strict';
|
|
|
|
// docs/Databases/FerretDB/1/SpeedTest/embedded: which Go database could be linked
|
|
// into FerretDB beside its SQLite, and is any faster. The benchmark is Go and takes
|
|
// minutes; this checks what does not need Go: the data export is deterministic and
|
|
// has the parameters the benchmark reads, every engine the benchmark runs is in the
|
|
// README with its numbers, and the README keeps its conclusion honest.
|
|
//
|
|
// Run: node tests/embeddedEnginesBench.test.cjs
|
|
|
|
const assert = require('assert');
|
|
const fs = require('fs');
|
|
const os = require('os');
|
|
const path = require('path');
|
|
const { execFileSync } = require('child_process');
|
|
|
|
const DIR = path.join(__dirname, '..', 'docs/Databases/FerretDB/1/SpeedTest/embedded');
|
|
const read = f => fs.readFileSync(path.join(DIR, f), 'utf8');
|
|
let passed = 0;
|
|
function test(name, fn) { fn(); passed += 1; console.log(' ok -', name); }
|
|
console.log('embeddedEnginesBench:');
|
|
|
|
function exportTo(scale) {
|
|
const out = fs.mkdtempSync(path.join(process.env.TMPDIR || os.tmpdir(), 'embedded-'));
|
|
execFileSync(process.execPath, [path.join(DIR, 'export.cjs'), String(scale), out], { stdio: 'pipe' });
|
|
return out;
|
|
}
|
|
|
|
test('the export is deterministic and has the cards and the 15 parameter boards the benchmark reads', () => {
|
|
const a = exportTo(0.01);
|
|
const b = exportTo(0.01);
|
|
try {
|
|
assert.strictEqual(fs.readFileSync(path.join(a, 'cards.jsonl'), 'utf8'), fs.readFileSync(path.join(b, 'cards.jsonl'), 'utf8'));
|
|
const p = JSON.parse(fs.readFileSync(path.join(a, 'params.json'), 'utf8'));
|
|
assert.strictEqual(p.boards.length, 15, '3 biggest boards and 12 ordinary ones');
|
|
assert.strictEqual(new Set(p.boards).size, 15, 'no board twice');
|
|
const lines = fs.readFileSync(path.join(a, 'cards.jsonl'), 'utf8').trim().split('\n');
|
|
assert.strictEqual(lines.length, p.cards);
|
|
const first = JSON.parse(lines[0]);
|
|
for (const f of ['_id', 'boardId', 'listId', 'archived']) assert.ok(f in first, f);
|
|
// negative: every parameter board has cards, or its question would be empty.
|
|
const boards = new Set(lines.map(l => JSON.parse(l).boardId));
|
|
for (const board of p.boards) assert.ok(boards.has(board), board);
|
|
} finally {
|
|
fs.rmSync(a, { recursive: true, force: true });
|
|
fs.rmSync(b, { recursive: true, force: true });
|
|
}
|
|
});
|
|
|
|
test('every engine the benchmark runs is in the README, with its numbers at both sizes', () => {
|
|
const engines = read('engines.go');
|
|
const names = [...(engines.match(/openSQLite\("([^"]+)"/g) || []), ...(engines.match(/openBolt\("([^"]+)"/g) || [])].map(m => m.replace(/^[^"]*"|"$/g, ''));
|
|
assert.ok(names.length >= 5, 'SQLite three ways and bbolt twice');
|
|
const md = read('README.md');
|
|
for (const n of names) assert.ok(md.split(n).length - 1 >= 2, `${n}: in both tables`);
|
|
for (const n of ['Pebble', 'Badger', 'BuntDB', 'Nutsdb', 'Clover']) assert.ok(md.split(n).length - 1 >= 3, n);
|
|
assert.match(md, /15,377 cards \(scale 0\.05\)/);
|
|
assert.match(md, /153,768 cards \(scale 0\.5\)/);
|
|
});
|
|
|
|
test('the benchmark refuses a fast wrong answer, and the SQLite it measures is FerretDB\'s own setup', () => {
|
|
const run = read('run.go');
|
|
assert.match(run, /Correctness first: a fast wrong answer is no answer/);
|
|
assert.match(run, /the move was not stored/);
|
|
const sqlite = read('sqlite.go');
|
|
// FerretDB's defaults (internal/backends/sqlite/metadata/pool/uri.go).
|
|
for (const pragma of ['journal_mode(wal)', 'cache_size(-65536)', 'mmap_size(268435456)', 'temp_store(memory)', '_txlock=immediate']) {
|
|
assert.ok(sqlite.includes(pragma), pragma);
|
|
}
|
|
// negative: it is a module of its own, so FerretDB's and WeKan's builds never see these dependencies.
|
|
assert.match(read('go.mod'), /^module embeddedbench/m);
|
|
});
|
|
|
|
test('the README states the answer, and what the benchmark does not measure', () => {
|
|
const md = read('README.md');
|
|
assert.match(md, /\*\*Short answer: no\./);
|
|
assert.match(md, /fsync on every commit/);
|
|
assert.match(md, /does not measure what SQLite does in the engine/);
|
|
// Every entry of the awesome-go section is accounted for: tested, or a reason.
|
|
for (const name of ['go-sqlite', 'Pebble', 'Badger', 'bbolt', 'BuntDB', 'Nutsdb', 'Clover', 'goleveldb', 'rqlite', 'redka', 'Dolt', 'TiDB', 'CockroachDB', 'immudb', 'DiceDB', 'Dgraph', 'InfluxDB', 'Milvus', 'objectbox-go', 'CovenantSQL']) {
|
|
assert.ok(md.includes(name), name);
|
|
}
|
|
});
|
|
|
|
console.log(`embeddedEnginesBench: ${passed} tests passed`);
|