Skip to content

Commit 1e62df1

Browse files
committed
Try self-contained
1 parent dd524df commit 1e62df1

File tree

10 files changed

+85
-36
lines changed

10 files changed

+85
-36
lines changed

src/Components/benchmarkapps/Wasm.Performance/Driver/BenchmarkResultsStartup.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Text.Json;
66
using Microsoft.AspNetCore.Builder;
77
using Microsoft.AspNetCore.Hosting;
8+
using Microsoft.AspNetCore.Http;
89
using Microsoft.Extensions.DependencyInjection;
910
using Microsoft.Extensions.Hosting;
1011

@@ -22,12 +23,13 @@ public void Configure(IApplicationBuilder app)
2223
{
2324
app.UseCors();
2425

25-
app.Run(async request =>
26+
app.Run(async context =>
2627
{
27-
var result = await JsonSerializer.DeserializeAsync<List<BenchmarkResult>>(request.Request.Body, new JsonSerializerOptions
28+
var result = await JsonSerializer.DeserializeAsync<List<BenchmarkResult>>(context.Request.Body, new JsonSerializerOptions
2829
{
2930
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
3031
});
32+
await context.Response.WriteAsync("OK");
3133
Program.SetBenchmarkResult(result);
3234
});
3335
}

src/Components/benchmarkapps/Wasm.Performance/Driver/Program.cs

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using System;
55
using System.Collections.Generic;
6-
using System.Diagnostics;
76
using System.IO;
87
using System.Linq;
98
using System.Runtime.ExceptionServices;
@@ -40,8 +39,10 @@ public static async Task<int> Main(string[] args)
4039
// This write is required for the benchmarking infrastructure.
4140
Console.WriteLine("Application started.");
4241

43-
using var browser = await Selenium.CreateBrowser(seleniumPort);
42+
var cancellationToken = new CancellationTokenSource(Timeout);
43+
cancellationToken.Token.Register(() => benchmarkResult.TrySetException(new TimeoutException($"Timed out after {Timeout}")));
4444

45+
using var browser = await Selenium.CreateBrowser(seleniumPort, cancellationToken.Token);
4546
using var testApp = StartTestApp();
4647
using var benchmarkReceiver = StartBenchmarkResultReceiver();
4748

@@ -54,9 +55,6 @@ public static async Task<int> Main(string[] args)
5455
browser.Url = launchUrl;
5556
browser.Navigate();
5657

57-
var cancellationToken = new CancellationTokenSource(Timeout);
58-
cancellationToken.Token.Register(() => benchmarkResult.TrySetException(new TimeoutException($"Timed out after {Timeout}")));
59-
6058
var results = await benchmarkResult.Task;
6159
FormatAsBenchmarksOutput(results);
6260

@@ -96,24 +94,45 @@ private static void FormatAsBenchmarksOutput(List<BenchmarkResult> results)
9694
output.Metadata.Add(new BenchmarkMetadata
9795
{
9896
Source = "BlazorWasm",
99-
Name = "Publish size (linked)",
100-
ShortDescription = "Publish size - linked app (MB)",
101-
LongDescription = "Publish size - linked app (MB)",
97+
Name = "Publish size",
98+
ShortDescription = "Publish size (KB)",
99+
LongDescription = "Publish size (KB)",
102100
Format = "n2",
103101
});
104102

105103
var testAssembly = typeof(TestApp.Startup).Assembly;
104+
var testAssemblyLocation = new FileInfo(testAssembly.Location);
106105
var testApp = new DirectoryInfo(Path.Combine(
107-
Path.GetDirectoryName(testAssembly.Location),
106+
testAssemblyLocation.Directory.FullName,
108107
testAssembly.GetName().Name));
109108

110109
output.Measurements.Add(new BenchmarkMeasurement
111110
{
112111
Timestamp = DateTime.UtcNow,
113-
Name = "Publish size (linked)",
112+
Name = "Publish size",
114113
Value = GetDirectorySize(testApp) / 1024,
115114
});
116115

116+
output.Metadata.Add(new BenchmarkMetadata
117+
{
118+
Source = "BlazorWasm",
119+
Name = "Publish size (compressed)",
120+
ShortDescription = "Publish size compressed app (KB)",
121+
LongDescription = "Publish size - compressed app (KB)",
122+
Format = "n2",
123+
});
124+
125+
var gzip = new FileInfo(Path.Combine(
126+
testAssemblyLocation.Directory.FullName,
127+
$"{testAssembly.GetName().Name}.gzip"));
128+
129+
output.Measurements.Add(new BenchmarkMeasurement
130+
{
131+
Timestamp = DateTime.UtcNow,
132+
Name = "Publish size (compressed)",
133+
Value = (gzip.Exists ? gzip.Length : 0) / 1024,
134+
});
135+
117136
Console.WriteLine("#StartJobStatistics");
118137
Console.WriteLine(JsonSerializer.Serialize(output));
119138
Console.WriteLine("#EndJobStatistics");

src/Components/benchmarkapps/Wasm.Performance/Driver/Selenium.cs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
5+
using System.Linq;
56
using System.Net;
67
using System.Net.Http;
8+
using System.Threading;
79
using System.Threading.Tasks;
810
using OpenQA.Selenium;
911
using OpenQA.Selenium.Chrome;
@@ -14,8 +16,9 @@ namespace Wasm.Performance.Driver
1416
class Selenium
1517
{
1618
static bool RunHeadlessBrowser = true;
19+
static bool PoolForBrowserLogs = true;
1720

18-
private static async ValueTask<Uri> WaitForServerAsync(int port)
21+
private static async ValueTask<Uri> WaitForServerAsync(int port, CancellationToken cancellationToken)
1922
{
2023
var uri = new UriBuilder("http", "localhost", port, "/wd/hub/").Uri;
2124
var httpClient = new HttpClient
@@ -34,7 +37,7 @@ private static async ValueTask<Uri> WaitForServerAsync(int port)
3437
retries++;
3538
try
3639
{
37-
var response = (await httpClient.GetAsync("status")).EnsureSuccessStatusCode();
40+
var response = (await httpClient.GetAsync("status", cancellationToken)).EnsureSuccessStatusCode();
3841
Console.WriteLine("Connected to Selenium");
3942
return uri;
4043
}
@@ -52,9 +55,9 @@ private static async ValueTask<Uri> WaitForServerAsync(int port)
5255
throw new Exception($"Unable to connect to selenium-server at {uri}");
5356
}
5457

55-
public static async Task<RemoteWebDriver> CreateBrowser(int port)
58+
public static async Task<RemoteWebDriver> CreateBrowser(int port, CancellationToken cancellationToken)
5659
{
57-
var uri = await WaitForServerAsync(port);
60+
var uri = await WaitForServerAsync(port, cancellationToken);
5861

5962
var options = new ChromeOptions();
6063

@@ -82,6 +85,25 @@ public static async Task<RemoteWebDriver> CreateBrowser(int port)
8285

8386
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(1);
8487

88+
if (PoolForBrowserLogs)
89+
{
90+
// Run in background.
91+
var logs = new RemoteLogs(driver);
92+
_ = Task.Run(async () =>
93+
{
94+
while (!cancellationToken.IsCancellationRequested)
95+
{
96+
await Task.Delay(TimeSpan.FromSeconds(3));
97+
98+
var consoleLogs = logs.GetLog(LogType.Browser);
99+
foreach (var entry in consoleLogs)
100+
{
101+
Console.WriteLine($"[Browser Log]: {entry.Timestamp}: {entry.Message}");
102+
}
103+
}
104+
});
105+
}
106+
85107
return driver;
86108
}
87109
catch (Exception ex)

src/Components/benchmarkapps/Wasm.Performance/README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ See https://github.com/aspnet/Benchmarks#benchmarks for usage guidance on using
55

66
### Running the benchmarks
77

8-
The TestApp is a regular BlazorWASM project and can be run using `dotnet run`. The Driver is an app that speaks the Benchmark protocol. You generally do not need to run the Driver locally, but if you were to do so, you require docker. Here are the commands you would need to run it locally:
8+
The TestApp is a regular BlazorWASM project and can be run using `dotnet run`. The Driver is an app that connects against an existing Selenium server, and speaks the Benchmark protocol. You generally do not need to run the Driver locally, but if you were to do so, you can either start a selenium-server instance and run using `dotnet run [<selenium-server-port>]` or run it inside a Linux-based docker container.
9+
10+
Here are the commands you would need to run it locally inside docker:
911

1012
1. `dotnet publish -c Release -r linux-x64 Driver/Wasm.Performance.Driver.csproj`
1113
2. `docker build -t blazor-local -f ./local.dockerfile . `
@@ -14,5 +16,5 @@ The TestApp is a regular BlazorWASM project and can be run using `dotnet run`. T
1416
To run the benchmark app in the Benchmark server, run
1517

1618
```
17-
dotnet run -- --config aspnetcore/src/Components/benchmarkapps/Wasm.Performance/benchmarks.compose.json --services.blazorwasmbenchmark.endpoints <BenchmarkServerUri>
18-
```
19+
dotnet run -- --config aspnetcore/src/Components/benchmarkapps/Wasm.Performance/benchmarks.compose.json application.endpoints <BenchmarkServerUri> --scenario blazorwasmbenchmark
20+
```

src/Components/benchmarkapps/Wasm.Performance/TestApp/wwwroot/benchmarks/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { groups, BenchmarkEvent, onBenchmarkEvent } from './lib/minibench/minibench.js';
22
import { HtmlUI } from './lib/minibench/minibench.ui.js';
3-
// import './appStartup.js';
4-
// import './renderList.js';
3+
import './appStartup.js';
4+
import './renderList.js';
55
import './jsonHandling.js';
66

77
new HtmlUI('E2E Performance', '#display');
@@ -21,6 +21,7 @@ if (location.href.indexOf('#automated') !== -1) {
2121
break;
2222
case BenchmarkEvent.benchmarkCompleted:
2323
case BenchmarkEvent.benchmarkError:
24+
console.log(`Completed benchmark ${args.name}`);
2425
benchmarksResults.push(args);
2526
break;
2627
case BenchmarkEvent.runCompleted:

src/Components/benchmarkapps/Wasm.Performance/TestApp/wwwroot/benchmarks/lib/minibench/minibench.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ class Group extends EventEmitter {
302302
}
303303

304304
const groups = [];
305-
let reportBenchmarkEvent;
305+
let reportBenchmarkEvent = () => {};
306306

307307
function group(name, configure) {
308308
groups.push(new Group(name));
Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
{
2-
"dependencies": [
3-
"blazorwasmbenchmark"
4-
],
5-
"services": {
2+
"$schema": "https://raw.githubusercontent.com/aspnet/Benchmarks/master/src/BenchmarksDriver2/benchmarks.schema.json",
3+
"scenarios": {
4+
"blazorwasmbenchmark": {
5+
"application": {
6+
"job": "blazorwasmbenchmark"
7+
}
8+
}
9+
},
10+
"jobs": {
611
"blazorwasmbenchmark": {
712
"source": {
813
"repository": "https://github.com/dotnet/AspNetCore.git",
9-
"branchOrCommit": "prkrishn/blazor-benchmarking",
14+
"branchOrCommit": "blazor-wasm",
1015
"dockerfile": "src/Components/benchmarkapps/Wasm.Performance/dockerfile"
1116
},
1217
"waitForExit": true,
1318
"readyStateText": "Application started."
1419
}
1520
}
16-
}
21+
}

src/Components/benchmarkapps/Wasm.Performance/dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ RUN apt-get update \
1111
nodejs \
1212
git
1313

14-
ARG gitBranch=prkrishn/blazor-benchmarking
14+
ARG gitBranch=blazor-wasm
1515

1616
WORKDIR /src
1717
ADD https://api.github.com/repos/dotnet/aspnetcore/git/ref/heads/${gitBranch} /aspnetcore.commit
@@ -29,4 +29,4 @@ FROM selenium/standalone-chrome:3.141.59-mercury as final
2929
COPY --from=build ./app ./
3030
COPY ./exec.sh ./
3131

32-
ENTRYPOINT [ "bash", "./exec.sh" ]
32+
ENTRYPOINT [ "bash", "./exec.sh" ]

src/Components/benchmarkapps/Wasm.Performance/local.dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ FROM selenium/standalone-chrome:3.141.59-mercury as final
22

33
WORKDIR /app
44
COPY ./Driver/bin/Release/netcoreapp3.1/linux-x64/publish ./
5-
COPY ./exec.sh ./exec.sh
5+
COPY ./exec.sh ./
66

7-
ENTRYPOINT [ "bash", "./exec.sh" ]
7+
ENTRYPOINT [ "bash", "./exec.sh" ]

src/Components/test/E2ETest/Tests/PerformanceTest.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,8 @@ public void BenchmarksRunWithoutError()
5252
() => runAllButton.Displayed || Browser.FindElements(By.CssSelector(".benchmark-error")).Any(),
5353
TimeSpan.FromSeconds(60));
5454

55-
var finishedBenchmarks = Browser.FindElements(By.CssSelector(".benchmark-idle"));
56-
var failedBenchmarks = Browser.FindElements(By.CssSelector(".benchmark-error"));
57-
Assert.NotEmpty(finishedBenchmarks);
58-
Assert.Empty(failedBenchmarks);
55+
Browser.DoesNotExist(By.CssSelector(".benchmark-error")); // no failures
56+
Browser.Exists(By.CssSelector(".benchmark-idle")); // everything's done
5957
}
6058
}
6159
}

0 commit comments

Comments
 (0)