diff --git a/benchmark/BMConfig.ts b/benchmark/BMConfig.ts index e5c24c6a..57c2940c 100644 --- a/benchmark/BMConfig.ts +++ b/benchmark/BMConfig.ts @@ -1,9 +1,28 @@ /* tslint:disable:no-inferrable-types */ import * as path from 'path'; import {ConfigClass, ConfigClassBuilder} from 'typeconfig/node'; -import {ConfigProperty} from 'typeconfig/common'; +import {ConfigProperty, SubConfigClass} from 'typeconfig/common'; +import {JobTrigger, JobTriggerType} from '../src/common/entities/job/JobScheduleDTO'; +import {ServerVideoConfig} from '../src/common/config/private/PrivateConfig'; + +@SubConfigClass() +export class BenchmarksConfig { + @ConfigProperty() + bmScanDirectory: boolean = true; + @ConfigProperty() + bmSaveDirectory: boolean = true; + @ConfigProperty() + bmListDirectory: boolean = true; + @ConfigProperty() + bmListPersons: boolean = true; + @ConfigProperty() + bmAllSearch: boolean = true; + @ConfigProperty() + bmAutocomplete: boolean = true; +} + @ConfigClass({ configPath: path.join(__dirname, './../bm_config.json'), saveIfNotExist: true, @@ -34,6 +53,8 @@ export class PrivateConfigClass { system: string = ''; @ConfigProperty({description: 'Number of times to run the benchmark'}) RUNS: number = 50; + @ConfigProperty({description: 'Enables / disables benchmarks'}) + Benchmarks: BenchmarksConfig = new BenchmarksConfig(); } diff --git a/benchmark/Benchmark.ts b/benchmark/Benchmark.ts index a4ccfdd5..2c2000ca 100644 --- a/benchmark/Benchmark.ts +++ b/benchmark/Benchmark.ts @@ -3,6 +3,7 @@ import {ContentWrapper} from '../src/common/entities/ConentWrapper'; import {Express, NextFunction} from 'express'; import {Utils} from '../src/common/Utils'; import {Message} from '../src/common/entities/Message'; +import {ActiveExperiments, Experiments} from './Experiments'; export interface BenchmarkStep { name: string; @@ -79,7 +80,20 @@ export class Benchmark { return (this.bmExpressApp as unknown) as Express; } - async run(RUNS: number): Promise { + async run(RUNS: number): Promise { + const ret = [await this.runAnExperiment(RUNS)]; + for (const exp of Object.values(Experiments)) { + for (const group of Object.values(exp.groups)) { + ActiveExperiments[exp.name] = group; + ret.push(await this.runAnExperiment(RUNS)); + ret[ret.length - 1].experiment = exp.name + '=' + group; + } + delete ActiveExperiments[exp.name]; + } + return ret; + } + + async runAnExperiment(RUNS: number): Promise { console.log('Running benchmark: ' + this.name); const scanned = await this.scanSteps(); const start = process.hrtime(); diff --git a/benchmark/BenchmarkRunner.ts b/benchmark/BenchmarkRunner.ts index 85056ede..e89e7813 100644 --- a/benchmark/BenchmarkRunner.ts +++ b/benchmark/BenchmarkRunner.ts @@ -34,6 +34,7 @@ import {QueryKeywords, SearchQueryParser} from '../src/common/SearchQueryParser' export interface BenchmarkResult { name: string; + experiment?: string; duration: number; contentWrapper?: ContentWrapper; items?: number; @@ -82,7 +83,7 @@ export class BenchmarkRunner { Config.Client.authenticationRequired = false; } - async bmSaveDirectory(): Promise { + async bmSaveDirectory(): Promise { await this.init(); await this.resetDB(); const dir = await DiskMangerWorker.scanDirectory(this.biggestDirPath); @@ -97,7 +98,7 @@ export class BenchmarkRunner { return await bm.run(this.RUNS); } - async bmScanDirectory(): Promise { + async bmScanDirectory(): Promise { await this.init(); const bm = new Benchmark('Scanning directory'); bm.addAStep({ @@ -107,7 +108,7 @@ export class BenchmarkRunner { return await bm.run(this.RUNS); } - async bmListDirectory(): Promise { + async bmListDirectory(): Promise { Config.Server.Indexing.reIndexingSensitivity = ReIndexingSensitivity.low; await this.init(); await this.setupDB(); @@ -122,7 +123,7 @@ export class BenchmarkRunner { return await bm.run(this.RUNS); } - async bmListPersons(): Promise { + async bmListPersons(): Promise { await this.setupDB(); Config.Server.Indexing.reIndexingSensitivity = ReIndexingSensitivity.low; const bm = new Benchmark('Listing Faces', Utils.clone(this.requestTemplate), async (): Promise => { @@ -133,7 +134,7 @@ export class BenchmarkRunner { return await bm.run(this.RUNS); } - async bmAllSearch(): Promise<{ result: BenchmarkResult, searchQuery: SearchQueryDTO }[]> { + async bmAllSearch(): Promise<{ result: BenchmarkResult[], searchQuery: SearchQueryDTO }[]> { await this.setupDB(); const queryKeywords: QueryKeywords = { @@ -224,7 +225,7 @@ export class BenchmarkRunner { } as SomeOfSearchQuery, description: '' }); } - const results: { result: BenchmarkResult, searchQuery: SearchQueryDTO }[] = []; + const results: { result: BenchmarkResult[], searchQuery: SearchQueryDTO }[] = []; for (const entry of queries) { const req = Utils.clone(this.requestTemplate); @@ -239,7 +240,7 @@ export class BenchmarkRunner { } - async bmAutocomplete(text: string): Promise { + async bmAutocomplete(text: string): Promise { await this.setupDB(); const req = Utils.clone(this.requestTemplate); req.params.text = text; diff --git a/benchmark/Experiments.ts b/benchmark/Experiments.ts new file mode 100644 index 00000000..fb5e9a70 --- /dev/null +++ b/benchmark/Experiments.ts @@ -0,0 +1,10 @@ +export const Experiments = { + loadPhotoMetadata: { + name: 'loadPhotoMetadata', + groups: { + exifr: 'exifr', exifrAll: 'exifrAll', exifrSelected: 'exifrSelected', exifreader: 'exifreader', exiftool: 'exiftool' + } + } +}; + +export const ActiveExperiments: { [key: string]: string } = {}; diff --git a/benchmark/index.ts b/benchmark/index.ts index 324dd32a..7bbaaf13 100644 --- a/benchmark/index.ts +++ b/benchmark/index.ts @@ -6,6 +6,7 @@ import {BMConfig} from './BMConfig'; Config.Server.Media.folder = BMConfig.path; +Config.Server.Database.dbFolder = 'db/bm_db'; ProjectPath.reset(); const RUNS = BMConfig.RUNS; @@ -33,7 +34,7 @@ const printTableHeader = () => { printLine('| Action | Sub action | Average Duration | Result |'); printLine('|:------:|:----------:|:----------------:|:-------:|'); }; -const printResult = (result: BenchmarkResult, isSubResult = false) => { +const printExperimentResult = (result: BenchmarkResult, isSubResult = false) => { console.log('benchmarked: ' + result.name); let details = '-'; if (result.items) { @@ -51,15 +52,22 @@ const printResult = (result: BenchmarkResult, isSubResult = false) => { if (isSubResult) { printLine('| | ' + result.name + ' | ' + (result.duration).toFixed(1) + ' ms | ' + details + ' |'); } else { - printLine('| **' + result.name + '** | | **' + (result.duration).toFixed(1) + ' ms** | **' + details + '** |'); + printLine('| **' + (result.experiment ? '`[' + result.experiment + ']`' : '') + result.name + '** | | **' + (result.duration).toFixed(1) + ' ms** | **' + details + '** |'); } if (result.subBenchmarks && result.subBenchmarks.length > 1) { for (const item of result.subBenchmarks) { - printResult(item, true); + printExperimentResult(item, true); } } }; + +const printResult = (results: BenchmarkResult[]) => { + for (const result of results) { + printExperimentResult(result); + } +}; + const run = async () => { console.log('Running, RUNS:' + RUNS); const start = Date.now(); @@ -68,13 +76,28 @@ const run = async () => { // header await printHeader(await bm.getStatistic()); printTableHeader(); + if (BMConfig.Benchmarks.bmScanDirectory) { + printResult(await bm.bmScanDirectory()); + } + if (BMConfig.Benchmarks.bmSaveDirectory) { + printResult(await bm.bmSaveDirectory()); + } - printResult(await bm.bmScanDirectory()); - printResult(await bm.bmSaveDirectory()); - printResult(await bm.bmListDirectory()); - printResult(await bm.bmListPersons()); - (await bm.bmAllSearch()).forEach(res => printResult(res.result)); - printResult(await bm.bmAutocomplete('a')); + if (BMConfig.Benchmarks.bmListDirectory) { + printResult(await bm.bmListDirectory()); + } + + if (BMConfig.Benchmarks.bmListPersons) { + printResult(await bm.bmListPersons()); + } + + if (BMConfig.Benchmarks.bmAllSearch) { + (await bm.bmAllSearch()).forEach(res => printResult(res.result)); + } + + if (BMConfig.Benchmarks.bmAutocomplete) { + printResult(await bm.bmAutocomplete('a')); + } printLine('*Measurements run ' + RUNS + ' times and an average was calculated.'); console.log(resultsText); console.log('run for : ' + ((Date.now() - start)).toFixed(1) + 'ms');