mirror of
https://github.com/xuthus83/pigallery2.git
synced 2025-01-14 14:43:17 +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 */
|
/* tslint:disable:no-inferrable-types */
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import {ConfigClass, ConfigClassBuilder} from 'typeconfig/node';
|
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({
|
@ConfigClass({
|
||||||
configPath: path.join(__dirname, './../bm_config.json'),
|
configPath: path.join(__dirname, './../bm_config.json'),
|
||||||
saveIfNotExist: true,
|
saveIfNotExist: true,
|
||||||
@ -34,6 +53,8 @@ export class PrivateConfigClass {
|
|||||||
system: string = '';
|
system: string = '';
|
||||||
@ConfigProperty({description: 'Number of times to run the benchmark'})
|
@ConfigProperty({description: 'Number of times to run the benchmark'})
|
||||||
RUNS: number = 50;
|
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 {Express, NextFunction} from 'express';
|
||||||
import {Utils} from '../src/common/Utils';
|
import {Utils} from '../src/common/Utils';
|
||||||
import {Message} from '../src/common/entities/Message';
|
import {Message} from '../src/common/entities/Message';
|
||||||
|
import {ActiveExperiments, Experiments} from './Experiments';
|
||||||
|
|
||||||
export interface BenchmarkStep {
|
export interface BenchmarkStep {
|
||||||
name: string;
|
name: string;
|
||||||
@ -79,7 +80,20 @@ export class Benchmark {
|
|||||||
return (this.bmExpressApp as unknown) as Express;
|
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);
|
console.log('Running benchmark: ' + this.name);
|
||||||
const scanned = await this.scanSteps();
|
const scanned = await this.scanSteps();
|
||||||
const start = process.hrtime();
|
const start = process.hrtime();
|
||||||
|
@ -34,6 +34,7 @@ import {QueryKeywords, SearchQueryParser} from '../src/common/SearchQueryParser'
|
|||||||
|
|
||||||
export interface BenchmarkResult {
|
export interface BenchmarkResult {
|
||||||
name: string;
|
name: string;
|
||||||
|
experiment?: string;
|
||||||
duration: number;
|
duration: number;
|
||||||
contentWrapper?: ContentWrapper;
|
contentWrapper?: ContentWrapper;
|
||||||
items?: number;
|
items?: number;
|
||||||
@ -82,7 +83,7 @@ export class BenchmarkRunner {
|
|||||||
Config.Client.authenticationRequired = false;
|
Config.Client.authenticationRequired = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
async bmSaveDirectory(): Promise<BenchmarkResult> {
|
async bmSaveDirectory(): Promise<BenchmarkResult[]> {
|
||||||
await this.init();
|
await this.init();
|
||||||
await this.resetDB();
|
await this.resetDB();
|
||||||
const dir = await DiskMangerWorker.scanDirectory(this.biggestDirPath);
|
const dir = await DiskMangerWorker.scanDirectory(this.biggestDirPath);
|
||||||
@ -97,7 +98,7 @@ export class BenchmarkRunner {
|
|||||||
return await bm.run(this.RUNS);
|
return await bm.run(this.RUNS);
|
||||||
}
|
}
|
||||||
|
|
||||||
async bmScanDirectory(): Promise<BenchmarkResult> {
|
async bmScanDirectory(): Promise<BenchmarkResult[]> {
|
||||||
await this.init();
|
await this.init();
|
||||||
const bm = new Benchmark('Scanning directory');
|
const bm = new Benchmark('Scanning directory');
|
||||||
bm.addAStep({
|
bm.addAStep({
|
||||||
@ -107,7 +108,7 @@ export class BenchmarkRunner {
|
|||||||
return await bm.run(this.RUNS);
|
return await bm.run(this.RUNS);
|
||||||
}
|
}
|
||||||
|
|
||||||
async bmListDirectory(): Promise<BenchmarkResult> {
|
async bmListDirectory(): Promise<BenchmarkResult[]> {
|
||||||
Config.Server.Indexing.reIndexingSensitivity = ReIndexingSensitivity.low;
|
Config.Server.Indexing.reIndexingSensitivity = ReIndexingSensitivity.low;
|
||||||
await this.init();
|
await this.init();
|
||||||
await this.setupDB();
|
await this.setupDB();
|
||||||
@ -122,7 +123,7 @@ export class BenchmarkRunner {
|
|||||||
return await bm.run(this.RUNS);
|
return await bm.run(this.RUNS);
|
||||||
}
|
}
|
||||||
|
|
||||||
async bmListPersons(): Promise<BenchmarkResult> {
|
async bmListPersons(): Promise<BenchmarkResult[]> {
|
||||||
await this.setupDB();
|
await this.setupDB();
|
||||||
Config.Server.Indexing.reIndexingSensitivity = ReIndexingSensitivity.low;
|
Config.Server.Indexing.reIndexingSensitivity = ReIndexingSensitivity.low;
|
||||||
const bm = new Benchmark('Listing Faces', Utils.clone(this.requestTemplate), async (): Promise<void> => {
|
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);
|
return await bm.run(this.RUNS);
|
||||||
}
|
}
|
||||||
|
|
||||||
async bmAllSearch(): Promise<{ result: BenchmarkResult, searchQuery: SearchQueryDTO }[]> {
|
async bmAllSearch(): Promise<{ result: BenchmarkResult[], searchQuery: SearchQueryDTO }[]> {
|
||||||
await this.setupDB();
|
await this.setupDB();
|
||||||
|
|
||||||
const queryKeywords: QueryKeywords = {
|
const queryKeywords: QueryKeywords = {
|
||||||
@ -224,7 +225,7 @@ export class BenchmarkRunner {
|
|||||||
} as SomeOfSearchQuery, description: '<Contain at least 2 out of all names>'
|
} 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) {
|
for (const entry of queries) {
|
||||||
const req = Utils.clone(this.requestTemplate);
|
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();
|
await this.setupDB();
|
||||||
const req = Utils.clone(this.requestTemplate);
|
const req = Utils.clone(this.requestTemplate);
|
||||||
req.params.text = text;
|
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.Media.folder = BMConfig.path;
|
||||||
|
Config.Server.Database.dbFolder = 'db/bm_db';
|
||||||
ProjectPath.reset();
|
ProjectPath.reset();
|
||||||
const RUNS = BMConfig.RUNS;
|
const RUNS = BMConfig.RUNS;
|
||||||
|
|
||||||
@ -33,7 +34,7 @@ const printTableHeader = () => {
|
|||||||
printLine('| Action | Sub action | Average Duration | Result |');
|
printLine('| Action | Sub action | Average Duration | Result |');
|
||||||
printLine('|:------:|:----------:|:----------------:|:-------:|');
|
printLine('|:------:|:----------:|:----------------:|:-------:|');
|
||||||
};
|
};
|
||||||
const printResult = (result: BenchmarkResult, isSubResult = false) => {
|
const printExperimentResult = (result: BenchmarkResult, isSubResult = false) => {
|
||||||
console.log('benchmarked: ' + result.name);
|
console.log('benchmarked: ' + result.name);
|
||||||
let details = '-';
|
let details = '-';
|
||||||
if (result.items) {
|
if (result.items) {
|
||||||
@ -51,15 +52,22 @@ const printResult = (result: BenchmarkResult, isSubResult = false) => {
|
|||||||
if (isSubResult) {
|
if (isSubResult) {
|
||||||
printLine('| | ' + result.name + ' | ' + (result.duration).toFixed(1) + ' ms | ' + details + ' |');
|
printLine('| | ' + result.name + ' | ' + (result.duration).toFixed(1) + ' ms | ' + details + ' |');
|
||||||
} else {
|
} 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) {
|
if (result.subBenchmarks && result.subBenchmarks.length > 1) {
|
||||||
for (const item of result.subBenchmarks) {
|
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 () => {
|
const run = async () => {
|
||||||
console.log('Running, RUNS:' + RUNS);
|
console.log('Running, RUNS:' + RUNS);
|
||||||
const start = Date.now();
|
const start = Date.now();
|
||||||
@ -68,13 +76,28 @@ const run = async () => {
|
|||||||
// header
|
// header
|
||||||
await printHeader(await bm.getStatistic());
|
await printHeader(await bm.getStatistic());
|
||||||
printTableHeader();
|
printTableHeader();
|
||||||
|
if (BMConfig.Benchmarks.bmScanDirectory) {
|
||||||
|
printResult(await bm.bmScanDirectory());
|
||||||
|
}
|
||||||
|
if (BMConfig.Benchmarks.bmSaveDirectory) {
|
||||||
|
printResult(await bm.bmSaveDirectory());
|
||||||
|
}
|
||||||
|
|
||||||
printResult(await bm.bmScanDirectory());
|
if (BMConfig.Benchmarks.bmListDirectory) {
|
||||||
printResult(await bm.bmSaveDirectory());
|
printResult(await bm.bmListDirectory());
|
||||||
printResult(await bm.bmListDirectory());
|
}
|
||||||
printResult(await bm.bmListPersons());
|
|
||||||
(await bm.bmAllSearch()).forEach(res => printResult(res.result));
|
if (BMConfig.Benchmarks.bmListPersons) {
|
||||||
printResult(await bm.bmAutocomplete('a'));
|
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.');
|
printLine('*Measurements run ' + RUNS + ' times and an average was calculated.');
|
||||||
console.log(resultsText);
|
console.log(resultsText);
|
||||||
console.log('run for : ' + ((Date.now() - start)).toFixed(1) + 'ms');
|
console.log('run for : ' + ((Date.now() - start)).toFixed(1) + 'ms');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user