mirror of
https://github.com/xuthus83/pigallery2.git
synced 2024-11-03 21:04:03 +08:00
Adding experiment support and disable ability to benchmark
(cherry picked from commit dba4c8bf75ed76f41ba24d945bf7d22efb9665c2)
This commit is contained in:
parent
b2049d81c1
commit
315c174ff9
@ -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();
|
||||
|
||||
|
||||
}
|
||||
|
@ -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<BenchmarkResult> {
|
||||
async run(RUNS: number): Promise<BenchmarkResult[]> {
|
||||
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<BenchmarkResult> {
|
||||
console.log('Running benchmark: ' + this.name);
|
||||
const scanned = await this.scanSteps();
|
||||
const start = process.hrtime();
|
||||
|
@ -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<BenchmarkResult> {
|
||||
async bmSaveDirectory(): Promise<BenchmarkResult[]> {
|
||||
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<BenchmarkResult> {
|
||||
async bmScanDirectory(): Promise<BenchmarkResult[]> {
|
||||
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<BenchmarkResult> {
|
||||
async bmListDirectory(): Promise<BenchmarkResult[]> {
|
||||
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<BenchmarkResult> {
|
||||
async bmListPersons(): Promise<BenchmarkResult[]> {
|
||||
await this.setupDB();
|
||||
Config.Server.Indexing.reIndexingSensitivity = ReIndexingSensitivity.low;
|
||||
const bm = new Benchmark('Listing Faces', Utils.clone(this.requestTemplate), async (): Promise<void> => {
|
||||
@ -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: '<Contain at least 2 out of all names>'
|
||||
});
|
||||
}
|
||||
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<BenchmarkResult> {
|
||||
async bmAutocomplete(text: string): Promise<BenchmarkResult[]> {
|
||||
await this.setupDB();
|
||||
const req = Utils.clone(this.requestTemplate);
|
||||
req.params.text = text;
|
||||
|
10
benchmark/Experiments.ts
Normal file
10
benchmark/Experiments.ts
Normal file
@ -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 } = {};
|
@ -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');
|
||||
|
Loading…
Reference in New Issue
Block a user