amoradbx 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Binary file
package/benchmark.js ADDED
@@ -0,0 +1,144 @@
1
+ 'use strict';
2
+
3
+ const AmoraDB = require('./amora.js');
4
+ const { performance } = require('perf_hooks');
5
+ const fs = require('fs');
6
+
7
+ /**
8
+ * Real-world Benchmark for AmoraDB
9
+ *
10
+ * Unlike the internal C benchmark, this test utilizes:
11
+ * 1. The JavaScript <-> WebAssembly bridge (real overhead).
12
+ * 2. Variable-sized data (32B keys, 1KB values).
13
+ * 3. Random access patterns (Random keys).
14
+ * 4. Real multi-threading via Worker threads.
15
+ * 5. Latency measurement (P50, P99).
16
+ */
17
+
18
+ const CONFIG = {
19
+ NUM_OPS: 500_000,
20
+ KEY_SIZE: 32, // bytes
21
+ VALUE_SIZE: 1024, // bytes (1KB)
22
+ THREADS: [1, 4, 8],
23
+ WAL_SYNC: [false, true]
24
+ };
25
+
26
+ function randomStr(len) {
27
+ const chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
28
+ let s = '';
29
+ for (let i = 0; i < len; i++) s += chars[Math.floor(Math.random() * chars.length)];
30
+ return s;
31
+ }
32
+
33
+ function fmt(n) {
34
+ return n.toLocaleString('en-US');
35
+ }
36
+
37
+ async function runBenchmark(name, opts) {
38
+ console.log(`\n🚀 Scenario: ${name}`);
39
+ console.log(` Config: ${opts.threads} threads | WAL: ${opts.walPath ? (opts.walSync ? 'SYNC' : 'ASYNC') : 'OFF'}`);
40
+
41
+ const db = AmoraDB.open(null, {
42
+ threads: opts.threads,
43
+ cap: 262144, // 256K entries initial
44
+ walPath: opts.walPath,
45
+ walSync: opts.walSync
46
+ });
47
+
48
+ const keys = [];
49
+ for (let i = 0; i < 10000; i++) keys.push(randomStr(CONFIG.KEY_SIZE));
50
+ const value = 'X'.repeat(CONFIG.VALUE_SIZE);
51
+
52
+ // --- WRITE ---
53
+ let start = performance.now();
54
+ let latencies = [];
55
+
56
+ for (let i = 0; i < CONFIG.NUM_OPS; i++) {
57
+ const k = keys[i % keys.length] + i;
58
+ const t0 = performance.now();
59
+ db.set(k, value);
60
+ const t1 = performance.now();
61
+ if (i < 10000) latencies.push(t1 - t0); // Sample first 10k for latency
62
+
63
+ if (i % 50000 === 0 && i > 0) {
64
+ process.stdout.write('.');
65
+ }
66
+ }
67
+ let end = performance.now();
68
+ let totalTime = (end - start) / 1000;
69
+ let throughput = CONFIG.NUM_OPS / totalTime;
70
+
71
+ latencies.sort((a, b) => a - b);
72
+ const p50 = latencies[Math.floor(latencies.length * 0.50)];
73
+ const p99 = latencies[Math.floor(latencies.length * 0.99)];
74
+
75
+ console.log(`\n WRITE (Sync):`);
76
+ console.log(` Throughput: ${fmt(throughput.toFixed(0))} ops/s`);
77
+ console.log(` Latency: P50: ${(p50 * 1000).toFixed(2)}µs | P99: ${(p99 * 1000).toFixed(2)}µs`);
78
+
79
+ // --- READ ---
80
+ start = performance.now();
81
+ latencies = [];
82
+ for (let i = 0; i < CONFIG.NUM_OPS; i++) {
83
+ const k = keys[i % keys.length] + i;
84
+ const t0 = performance.now();
85
+ db.get(k);
86
+ const t1 = performance.now();
87
+ if (i < 10000) latencies.push(t1 - t0);
88
+
89
+ if (i % 50000 === 0 && i > 0) process.stdout.write('.');
90
+ }
91
+ end = performance.now();
92
+ totalTime = (end - start) / 1000;
93
+ throughput = CONFIG.NUM_OPS / totalTime;
94
+
95
+ latencies.sort((a, b) => a - b);
96
+ const rp50 = latencies[Math.floor(latencies.length * 0.50)];
97
+ const rp99 = latencies[Math.floor(latencies.length * 0.99)];
98
+
99
+ console.log(`\n READ:`);
100
+ console.log(` Throughput: ${fmt(throughput.toFixed(0))} ops/s`);
101
+ console.log(` Latency: P50: ${(rp50 * 1000).toFixed(2)}µs | P99: ${(rp99 * 1000).toFixed(2)}µs`);
102
+
103
+ // --- BUFFERED WRITE (Parallel) ---
104
+ if (opts.threads > 1) {
105
+ start = performance.now();
106
+ for (let i = 0; i < CONFIG.NUM_OPS; i++) {
107
+ const k = keys[i % keys.length] + i + '_buf';
108
+ db.setBuffered(k, value);
109
+ if (i % 10000 === 0 && i > 0) {
110
+ await db.flush();
111
+ }
112
+ }
113
+ await db.flush();
114
+ end = performance.now();
115
+ totalTime = (end - start) / 1000;
116
+ throughput = CONFIG.NUM_OPS / totalTime;
117
+ console.log(` WRITE (Buffered/Parallel):`);
118
+ console.log(` Throughput: ${fmt(throughput.toFixed(0))} ops/s`);
119
+ }
120
+
121
+ await db.close();
122
+ if (opts.walPath && fs.existsSync(opts.walPath)) fs.unlinkSync(opts.walPath);
123
+ }
124
+
125
+ async function main() {
126
+ console.log('=== AMORADB REAL-WORLD BENCHMARK ===');
127
+
128
+ // 1. Pure In-Memory (Baseline)
129
+ await runBenchmark('Pure In-Memory', { threads: 1, walPath: null });
130
+
131
+ // 2. With Workers (Parallelism)
132
+ await runBenchmark('Multi-threaded (Workers)', { threads: 4, walPath: null });
133
+
134
+ // 3. With Persistence (WAL ASYNC)
135
+ await runBenchmark('Persistence (WAL ASYNC)', { threads: 1, walPath: './bench_async.wal', walSync: false });
136
+
137
+ // 4. With Persistence (WAL SYNC - Fsync)
138
+ // Note: This will be MUCH slower depending on your disk/SSD
139
+ await runBenchmark('Persistence (WAL SYNC)', { threads: 1, walPath: './bench_sync.wal', walSync: true });
140
+
141
+ console.log('\n✅ Benchmark completed.');
142
+ }
143
+
144
+ main().catch(console.error);
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "amoradbx",
3
+ "version": "2.0.0",
4
+ "description": "Ultra-high-performance embedded key-value engine (C -> WebAssembly) for Node.js",
5
+ "main": "amora.js",
6
+ "files": [
7
+ "amora.js",
8
+ "amora_core_mt_simd.wasm",
9
+ "LICENSE",
10
+ "README.md",
11
+ "CHANGELOG.md",
12
+ "CONTRIBUTING.md",
13
+ "SPEC.md",
14
+ "benchmark.js"
15
+ ],
16
+ "scripts": {
17
+ "test": "node test.js",
18
+ "bench": "node benchmark.js"
19
+ },
20
+ "keywords": [
21
+ "database",
22
+ "kv",
23
+ "key-value",
24
+ "embedded",
25
+ "wasm",
26
+ "webassembly",
27
+ "simd",
28
+ "wal",
29
+ "swiss-table"
30
+ ],
31
+ "license": "MIT",
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "git+https://github.com/amoracoin-org/AmoraDb.git"
35
+ },
36
+ "bugs": {
37
+ "url": "https://github.com/amoracoin-org/AmoraDb/issues"
38
+ },
39
+ "homepage": "https://github.com/amoracoin-org/AmoraDb#readme",
40
+ "engines": {
41
+ "node": ">=18"
42
+ },
43
+ "publishConfig": {
44
+ "access": "public"
45
+ }
46
+ }