11import { RocksDatabase , RocksDatabaseOptions } from '../dist/index.mjs' ;
2- import { tmpdir } from 'node:os' ;
32import { join } from 'node:path' ;
43import * as lmdb from 'lmdb' ;
54import { randomBytes } from 'node:crypto' ;
@@ -25,7 +24,8 @@ type BenchmarkOptions<T, U> = {
2524 name ?: string ,
2625 setup ?: ( ctx : BenchmarkContext < T > ) => void | Promise < void > ,
2726 timeout ?: number ,
28- teardown ?: ( ctx : BenchmarkContext < T > ) => void | Promise < void >
27+ teardown ?: ( ctx : BenchmarkContext < T > ) => void | Promise < void > ,
28+ mode ?: 'essential' | 'full'
2929} ;
3030
3131export function benchmark ( type : 'rocksdb' , options : BenchmarkOptions < RocksDatabase , RocksDatabaseOptions > ) : void ;
@@ -35,12 +35,14 @@ export function benchmark(type: string, options: any): void {
3535 throw new Error ( `Unsupported benchmark type: ${ type } ` ) ;
3636 }
3737
38- if ( ( process . env . ROCKSDB_ONLY && type !== 'rocksdb' ) || ( process . env . LMDB_ONLY && type !== 'lmdb' ) ) {
38+ if ( ( process . env . ROCKSDB_ONLY && type !== 'rocksdb' ) || ( process . env . LMDB_ONLY && type !== 'lmdb' ) ||
39+ ( process . env . BENCHMARK_MODE === 'essential' && options . mode !== 'essential' ) ) {
3940 return ;
4041 }
4142
4243 const { bench, setup, teardown, dbOptions, name } = options ;
43- const dbPath = join ( tmpdir ( ) , `rocksdb-benchmark-${ randomBytes ( 8 ) . toString ( 'hex' ) } ` ) ;
44+ // it is important to run benchmarks on a real filesystem (not a tempfs)
45+ const dbPath = join ( 'benchmark' , 'data' , `rocksdb-benchmark-${ randomBytes ( 8 ) . toString ( 'hex' ) } ` ) ;
4446 let ctx : BenchmarkContext < any > ;
4547
4648 vitestBench ( name || type , ( ) => {
@@ -65,7 +67,7 @@ export function benchmark(type: string, options: any): void {
6567 if ( type === 'rocksdb' ) {
6668 ctx = { db : RocksDatabase . open ( dbPath , dbOptions ) , mode } ;
6769 } else {
68- ctx = { db : lmdb . open ( { dbPath, compression : true , ...dbOptions } ) , mode } ;
70+ ctx = { db : lmdb . open ( { path : dbPath , compression : true , ...dbOptions } ) , mode } ;
6971 }
7072 }
7173 if ( typeof setup === 'function' ) {
@@ -291,7 +293,8 @@ export function workerBenchmark(type: string, options: any): void {
291293 throw new Error ( `Unsupported benchmark type: ${ type } ` ) ;
292294 }
293295
294- if ( ( process . env . ROCKSDB_ONLY && type !== 'rocksdb' ) || ( process . env . LMDB_ONLY && type !== 'lmdb' ) ) {
296+ if ( ( process . env . ROCKSDB_ONLY && type !== 'rocksdb' ) || ( process . env . LMDB_ONLY && type !== 'lmdb' ) ||
297+ ( process . env . BENCHMARK_MODE === 'essential' && options . mode !== 'essential' ) ) {
295298 return ;
296299 }
297300
@@ -335,7 +338,7 @@ export function workerBenchmark(type: string, options: any): void {
335338 throws : true ,
336339 async setup ( _task , mode ) {
337340 if ( mode === 'run' ) return ;
338- const path = join ( tmpdir ( ) , `rocksdb-benchmark-${ randomBytes ( 8 ) . toString ( 'hex' ) } ` ) ;
341+ const path = join ( 'benchmark' , 'data' , `rocksdb-benchmark-${ randomBytes ( 8 ) . toString ( 'hex' ) } ` ) ;
339342
340343 // launch all workers and wait for them to initialize
341344 await Promise . all ( Array . from ( { length : numWorkers } , ( _ , i ) => {
@@ -378,6 +381,7 @@ export function workerBenchmark(type: string, options: any): void {
378381 } ) ;
379382 } ) ) ;
380383 } ,
384+ time : 2000 ,
381385 async teardown ( _task , mode ) {
382386 if ( mode === 'warmup' ) return ;
383387 // tell all workers to teardown and wait
@@ -442,7 +446,7 @@ export async function workerInit() {
442446 if ( type === 'rocksdb' ) {
443447 ctx = { db : RocksDatabase . open ( path , dbOptions ) } ;
444448 } else {
445- ctx = { db : lmdb . open ( { path, compression : true , ...dbOptions } ) } ;
449+ ctx = { db : lmdb . open ( { path, ...dbOptions } ) } ;
446450 }
447451 if ( typeof setup === 'function' ) {
448452 await setup ( ctx ) ;
0 commit comments