Skip to content

Commit c258770

Browse files
committed
improved batching
1 parent 1139a80 commit c258770

File tree

10 files changed

+1845
-2719
lines changed

10 files changed

+1845
-2719
lines changed

webdriver-ts-results/src/results.ts

Lines changed: 1699 additions & 2651 deletions
Large diffs are not rendered by default.

webdriver-ts-results/table.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

webdriver-ts/results.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

webdriver-ts/src/benchmarkRunner.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ import { resolve } from 'dns';
1313
function forkAndCallBenchmark(frameworks: FrameworkData[], frameworkName: string, keyed: boolean, benchmarkName: string, benchmarkOptions: BenchmarkOptions): Promise<ErrorAndWarning> {
1414
return new Promise((resolve, reject) => {
1515
const forked = fork('dist/forkedBenchmarkRunner.js');
16-
if (config.LOG_DEBUG) console.log("forked child process");
16+
console.log("FORKING: forked child process");
1717
forked.send({ config, frameworks, keyed, frameworkName, benchmarkName, benchmarkOptions });
1818
forked.on('message', async (msg: ErrorAndWarning) => {
19-
if (config.LOG_DEBUG) console.log("main process got message from child", msg);
19+
console.log("FORKING: main process got message from child", msg);
2020
resolve(msg);
2121
});
2222
forked.on('close', (msg) => {
23-
if (config.LOG_DEBUG) console.log("child closed", msg);
23+
console.log("FORKING: child closed", msg);
2424
});
2525
forked.on('error', (msg) => {
26-
if (config.LOG_DEBUG) console.log("child error", msg);
26+
console.log("FORKING: child error", msg);
2727
reject(msg);
2828
});
2929
forked.on('exit', (code, signal) => {
@@ -45,20 +45,28 @@ async function runBenchmakLoop(frameworks: FrameworkData[], frameworkName: strin
4545
let warnings : String[] = [];
4646
let errors : String[] = [];
4747

48-
let results: Array<number|LighthouseData> = [];
48+
let results: Array<number[]|LighthouseData> = [];
4949
let count = 0;
50+
5051
if (benchmark.type == BenchmarkType.CPU) {
5152
count = benchmarkOptions.numIterationsForCPUBenchmarks;
53+
benchmarkOptions.batchSize = config.ALLOW_BATCHING && benchmark.allowBatching ? count : 1;
5254
} else if (benchmark.type == BenchmarkType.MEM) {
5355
count = benchmarkOptions.numIterationsForMemBenchmarks;
56+
benchmarkOptions.batchSize = 1;
5457
} else {
5558
count = benchmarkOptions.numIterationsForStartupBenchmark
59+
benchmarkOptions.batchSize = 1;
5660
}
5761

58-
for (let i = 0; i < count; i++) {
62+
63+
while (results.length < count) {
64+
benchmarkOptions.batchSize = Math.min(benchmarkOptions.batchSize, count-results.length);
65+
console.log("FORKING: ", benchmark.id, " BatchSize ", benchmarkOptions.batchSize);
5966
let res = await forkAndCallBenchmark(frameworks, frameworkName, keyed, benchmarkName, benchmarkOptions);
6067
if (res.result) {
61-
results.push(res.result);
68+
if (Array.isArray(res.result)) { results = results.concat(res.result)}
69+
else results.push(res.result);
6270
}
6371
warnings = warnings.concat(res.warnings);
6472
if (res.error) {
@@ -96,14 +104,15 @@ async function runBench(runFrameworks: FrameworkData[], benchmarkNames: string[]
96104
chromeBinaryPath: args.chromeBinary,
97105
numIterationsForCPUBenchmarks: config.REPEAT_RUN,
98106
numIterationsForMemBenchmarks: config.REPEAT_RUN_MEM,
99-
numIterationsForStartupBenchmark: config.REPEAT_RUN_STARTUP
107+
numIterationsForStartupBenchmark: config.REPEAT_RUN_STARTUP,
108+
batchSize: 1
100109
}
101110

102111
for (let i = 0; i < runFrameworks.length; i++) {
103112
for (let j = 0; j < runBenchmarks.length; j++) {
104113
try {
105114
let result = await runBenchmakLoop(runFrameworks, runFrameworks[i].name, runFrameworks[i].keyed, runBenchmarks[j].id, benchmarkOptions);
106-
errors = warnings.concat(result.errors);
115+
errors = errors.concat(result.errors);
107116
warnings = warnings.concat(result.warnings);
108117
} catch (e) {
109118
console.log("UNHANDELED ERROR", e);

webdriver-ts/src/benchmarks.ts

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ export interface BenchmarkInfo {
1111
type: BenchmarkType;
1212
label: string;
1313
description: string;
14-
throttleCPU?: number
14+
throttleCPU?: number;
15+
allowBatching: boolean;
1516
}
1617

1718
export abstract class Benchmark {
@@ -20,13 +21,15 @@ export abstract class Benchmark {
2021
label: string;
2122
description: string;
2223
throttleCPU?: number;
24+
allowBatching: boolean;
2325

2426
constructor(public benchmarkInfo: BenchmarkInfo) {
2527
this.id = benchmarkInfo.id;
2628
this.type = benchmarkInfo.type;
2729
this.label = benchmarkInfo.label;
2830
this.description = benchmarkInfo.description;
2931
this.throttleCPU = benchmarkInfo.throttleCPU;
32+
this.allowBatching = benchmarkInfo.allowBatching;
3033
}
3134
abstract init(driver: WebDriver, framework: FrameworkData): Promise<any>;
3235
abstract run(driver: WebDriver, framework: FrameworkData): Promise<any>;
@@ -54,7 +57,8 @@ const benchRun = new class extends Benchmark {
5457
id: "01_run1k",
5558
label: "create rows",
5659
description: "creating 1,000 rows",
57-
type: BenchmarkType.CPU
60+
type: BenchmarkType.CPU,
61+
allowBatching: true
5862
})
5963
}
6064
async init(driver: WebDriver) { await testElementLocatedById(driver, "add", SHORT_TIMEOUT); }
@@ -70,7 +74,8 @@ const benchReplaceAll = new class extends Benchmark {
7074
id: "02_replace1k",
7175
label: "replace all rows",
7276
description: "updating all 1,000 rows (" + config.WARMUP_COUNT + " warmup runs).",
73-
type: BenchmarkType.CPU
77+
type: BenchmarkType.CPU,
78+
allowBatching: true
7479
})
7580
}
7681
async init(driver: WebDriver) {
@@ -93,7 +98,8 @@ const benchUpdate = new class extends Benchmark {
9398
label: "partial update",
9499
description: "updating every 10th row for 1,000 rows (3 warmup runs). 16x CPU slowdown.",
95100
type: BenchmarkType.CPU,
96-
throttleCPU: 16
101+
throttleCPU: 16,
102+
allowBatching: true
97103
})
98104
}
99105
async init(driver: WebDriver) {
@@ -118,14 +124,15 @@ const benchSelect = new class extends Benchmark {
118124
label: "select row",
119125
description: "highlighting a selected row. (" + config.WARMUP_COUNT + " warmup runs). 16x CPU slowdown.",
120126
type: BenchmarkType.CPU,
121-
throttleCPU: 16
127+
throttleCPU: 16,
128+
allowBatching: true
122129
})
123130
}
124131
async init(driver: WebDriver) {
125132
await testElementLocatedById(driver, "run", SHORT_TIMEOUT);
126133
await clickElementById(driver, 'run');
127134
await testElementLocatedByXpath(driver, "//tbody/tr[1]/td[2]/a");
128-
for (let i = 0; i <= config.WARMUP_COUNT; i++) {
135+
for (let i = 0; i <= 10; i++) {
129136
await clickElementByXPath(driver, `//tbody/tr[${i + 1}]/td[2]/a`);
130137
}
131138
}
@@ -142,7 +149,8 @@ const benchSwapRows = new class extends Benchmark {
142149
label: "swap rows",
143150
description: "swap 2 rows for table with 1,000 rows. (" + config.WARMUP_COUNT + " warmup runs). 4x CPU slowdown.",
144151
type: BenchmarkType.CPU,
145-
throttleCPU: 4
152+
throttleCPU: 4,
153+
allowBatching: true
146154
})
147155
}
148156
async init(driver: WebDriver) {
@@ -168,7 +176,8 @@ const benchRemove = new class extends Benchmark {
168176
id: "06_remove-one-1k",
169177
label: "remove row",
170178
description: "removing one row. (" + config.WARMUP_COUNT + " warmup runs).",
171-
type: BenchmarkType.CPU
179+
type: BenchmarkType.CPU,
180+
allowBatching: true
172181
})
173182
}
174183
async init(driver: WebDriver) {
@@ -201,7 +210,8 @@ const benchRunBig = new class extends Benchmark {
201210
id: "07_create10k",
202211
label: "create many rows",
203212
description: "creating 10,000 rows",
204-
type: BenchmarkType.CPU
213+
type: BenchmarkType.CPU,
214+
allowBatching: false
205215
})
206216
}
207217
async init(driver: WebDriver) {
@@ -220,7 +230,8 @@ const benchAppendToManyRows = new class extends Benchmark {
220230
label: "append rows to large table",
221231
description: "appending 1,000 to a table of 10,000 rows. 2x CPU slowdown",
222232
type: BenchmarkType.CPU,
223-
throttleCPU: 2
233+
throttleCPU: 2,
234+
allowBatching: false
224235
})
225236
}
226237
async init(driver: WebDriver) {
@@ -241,7 +252,8 @@ const benchClear = new class extends Benchmark {
241252
label: "clear rows",
242253
description: "clearing a table with 1,000 rows. 8x CPU slowdown",
243254
type: BenchmarkType.CPU,
244-
throttleCPU: 8
255+
throttleCPU: 8,
256+
allowBatching: true
245257
})
246258
}
247259
async init(driver: WebDriver) {
@@ -262,6 +274,7 @@ const benchReadyMemory = new class extends Benchmark {
262274
label: "ready memory",
263275
description: "Memory usage after page load.",
264276
type: BenchmarkType.MEM,
277+
allowBatching: true
265278
})
266279
}
267280
async init(driver: WebDriver) {
@@ -283,6 +296,7 @@ const benchRunMemory = new class extends Benchmark {
283296
label: "run memory",
284297
description: "Memory usage after adding 1000 rows.",
285298
type: BenchmarkType.MEM,
299+
allowBatching: true
286300
})
287301
}
288302
async init(driver: WebDriver) {
@@ -301,6 +315,7 @@ const benchUpdate5Memory = new class extends Benchmark {
301315
label: "update eatch 10th row for 1k rows (5 cycles)",
302316
description: "Memory usage after clicking update every 10th row 5 times",
303317
type: BenchmarkType.MEM,
318+
allowBatching: true
304319
})
305320
}
306321
async init(driver: WebDriver) {
@@ -322,6 +337,7 @@ const benchReplace5Memory = new class extends Benchmark {
322337
label: "replace 1k rows (5 cycles)",
323338
description: "Memory usage after clicking create 1000 rows 5 times",
324339
type: BenchmarkType.MEM,
340+
allowBatching: true
325341
})
326342
}
327343
async init(driver: WebDriver) {
@@ -342,6 +358,7 @@ const benchCreateClear5Memory = new class extends Benchmark {
342358
label: "creating/clearing 1k rows (5 cycles)",
343359
description: "Memory usage after creating and clearing 1000 rows 5 times",
344360
type: BenchmarkType.MEM,
361+
allowBatching: true
345362
})
346363
}
347364
async init(driver: WebDriver) {
@@ -362,31 +379,35 @@ const benchStartupConsistentlyInteractive: StartupBenchmarkResult = {
362379
label: "consistently interactive",
363380
description: "a pessimistic TTI - when the CPU and network are both definitely very idle. (no more CPU tasks over 50ms)",
364381
type: BenchmarkType.STARTUP,
365-
property: "TimeToConsistentlyInteractive"
382+
property: "TimeToConsistentlyInteractive",
383+
allowBatching: true
366384
}
367385

368386
const benchStartupBootup: StartupBenchmarkResult = {
369387
id: "32_startup-bt",
370388
label: "script bootup time",
371389
description: "the total ms required to parse/compile/evaluate all the page's scripts",
372390
type: BenchmarkType.STARTUP,
373-
property: "ScriptBootUpTtime"
391+
property: "ScriptBootUpTtime",
392+
allowBatching: true
374393
}
375394

376395
const benchStartupMainThreadWorkCost: StartupBenchmarkResult = {
377396
id: "33_startup-mainthreadcost",
378397
label: "main thread work cost",
379398
description: "total amount of time spent doing work on the main thread. includes style/layout/etc.",
380399
type: BenchmarkType.STARTUP,
381-
property: "MainThreadWorkCost"
400+
property: "MainThreadWorkCost",
401+
allowBatching: true
382402
}
383403

384404
const benchStartupTotalBytes: StartupBenchmarkResult = {
385405
id: "34_startup-totalbytes",
386406
label: "total kilobyte weight",
387407
description: "network transfer cost (post-compression) of all the resources loaded into the page.",
388408
type: BenchmarkType.STARTUP,
389-
property: "TotalKiloByteWeight"
409+
property: "TotalKiloByteWeight",
410+
allowBatching: true
390411
}
391412

392413
class BenchStartup extends Benchmark {
@@ -396,6 +417,7 @@ class BenchStartup extends Benchmark {
396417
label: "startup time",
397418
description: "Time for loading, parsing and starting up",
398419
type: BenchmarkType.STARTUP,
420+
allowBatching: true
399421
})
400422
}
401423
async init(driver: WebDriver) { // not used with lighthouse

webdriver-ts/src/common.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export type TBenchmarkStatus = 'OK'|'TEST_FAILED'|'TECHNICAL_ERROR';
1414
export interface ErrorAndWarning {
1515
error: String;
1616
warnings: String[];
17-
result?: number|LighthouseData;
17+
result?: number[]|LighthouseData;
1818
}
1919

2020
export interface BenchmarkDriverOptions {
@@ -26,17 +26,19 @@ export interface BenchmarkDriverOptions {
2626

2727
export interface BenchmarkOptions extends BenchmarkDriverOptions {
2828
port: string;
29+
batchSize: number;
2930
numIterationsForCPUBenchmarks: number;
3031
numIterationsForMemBenchmarks: number;
3132
numIterationsForStartupBenchmark: number;
33+
3234
}
3335

3436
export let config = {
3537
PORT: 8080,
3638
REMOTE_DEBUGGING_PORT: 9999,
3739
CHROME_PORT: 9998,
3840
REPEAT_RUN: 10,
39-
REPEAT_RUN_MEM: 5,
41+
REPEAT_RUN_MEM: 1,
4042
REPEAT_RUN_STARTUP: 4,
4143
DROP_WORST_RUN: 0,
4244
WARMUP_COUNT: 5,
@@ -50,7 +52,8 @@ export let config = {
5052
STARTUP_SLEEP_DURATION: 1000,
5153
FORK_CHROMEDRIVER: true,
5254
WRITE_RESULTS: true,
53-
RESULTS_DIRECTORY: "results"
55+
RESULTS_DIRECTORY: "results",
56+
ALLOW_BATCHING: false
5457
}
5558
export type TConfig = typeof config;
5659

0 commit comments

Comments
 (0)