Skip to content

Commit c226ee0

Browse files
committed
Fix Linux comparison fixture cleanup and record CI revision
1 parent 75014c3 commit c226ee0

2 files changed

Lines changed: 37 additions & 3 deletions

File tree

‎benchmarks/KeyLoad.Comparisons/ReportWriter.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public static string Markdown(ComparisonReport report)
3232
text.AppendLine($"Run: {report.RunId}. Seed: {report.Options.Seed}. Corpus SHA256: `{report.DatasetSha256}`.");
3333
text.AppendLine($"\n{report.Options.Documents} documents, {report.Options.PayloadBytes} UTF-8 bytes/document, {report.Options.Dimensions} float32 dimensions, top-{report.Options.TopK}, {report.Options.Operations} attempts/case, concurrency {report.Options.Concurrency}, {report.Options.Warmup} warmup requests, {report.Options.Repetitions} repetitions.");
3434
text.AppendLine($"\nHost: {report.HostOs}; {report.Architecture}; {report.LogicalProcessors} logical processors; {report.Runtime}. Load: {report.LoadModel}. Storage: {report.Storage}. Source revision: {report.SourceRevision ?? "unrecorded"}.");
35-
text.AppendLine("\nExploratory development run. Engine topology, resource allocation, authorization, transports and write guarantees differ. These rows show observed speed, not an equal-durability or production winner. Docker VM overhead applies to external engines; KeyLoad voters run as host processes. Same-host voters do not represent independent failure domains. No primary performance target has been qualified.\n");
35+
text.AppendLine("\nExploratory development run. Engine topology, resource allocation, authorization, transports and write guarantees differ. These rows show observed speed, not an equal-durability or production winner. External engines run in containers; Docker Desktop adds VM overhead where used. KeyLoad voters run as host processes. Same-host voters do not represent independent failure domains. No primary performance target has been qualified.\n");
3636
text.AppendLine("| Engine | Version | Topology | Write acknowledgement | Read / transport / policy | Image |\n|---|---|---|---|---|---|");
3737
foreach (var target in report.Targets)
3838
text.AppendLine($"| {target.Name} | {target.Version} | {target.Topology} | {target.WriteAcknowledgement} | {target.ReadContract}; {target.Transport}; {target.Authorization} | {target.Image ?? "source checkout"} |");

‎tests/KeyLoad.ComparisonTests/ComparisonTests.cs‎

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Concurrent;
2+
using System.Diagnostics;
23
using System.Text.Json;
34
using Aspire.Hosting;
45
using Aspire.Hosting.ApplicationModel;
@@ -34,7 +35,8 @@ public async Task AspireRunsIdenticalScenariosAgainstRealRf3AndExternalEngines()
3435
$"--Benchmarks:Output={output}", $"--Benchmarks:Documents={options.Documents}", $"--Benchmarks:Operations={options.Operations}", $"--Benchmarks:Warmup={options.Warmup}",
3536
$"--Benchmarks:Repetitions={options.Repetitions}", $"--Benchmarks:Concurrency={options.Concurrency}", $"--Benchmarks:Dimensions={options.Dimensions}",
3637
$"--Benchmarks:TopK={options.TopK}", $"--Benchmarks:PayloadBytes={options.PayloadBytes}", $"--Benchmarks:Seed={options.Seed}",
37-
$"--Benchmarks:TimeoutSeconds={options.TimeoutSeconds}"], timeout.Token);
38+
$"--Benchmarks:TimeoutSeconds={options.TimeoutSeconds}",
39+
$"--Benchmarks:SourceRevision={Environment.GetEnvironmentVariable("GITHUB_SHA") ?? "unrecorded"}"], timeout.Token);
3840
builder.Services.AddLogging(logging =>
3941
{
4042
logging.ClearProviders(); logging.AddConsole(); logging.SetMinimumLevel(LogLevel.Warning);
@@ -105,8 +107,40 @@ await app.ResourceNotifications.WaitForResourceAsync("comparisons",
105107
await captureLifetime.CancelAsync(); await capture; await Task.WhenAll(logCaptures.Values);
106108
Directory.CreateDirectory(evidence);
107109
await File.WriteAllLinesAsync(Path.Combine(evidence, "runner.log"), lines, CancellationToken.None);
110+
var redis = app.Services.GetRequiredService<DistributedApplicationModel>().Resources
111+
.OfType<ContainerResource>().Single(resource => resource.Name == "benchmark-redis");
108112
await app.StopAsync(CancellationToken.None);
109-
if (Directory.Exists(root)) Directory.Delete(root, true);
113+
await DeleteDataAsync(root, redis);
110114
}
111115
}
116+
117+
private static async Task DeleteDataAsync(string root, ContainerResource redis)
118+
{
119+
if (!Directory.Exists(root)) return;
120+
try { Directory.Delete(root, true); return; }
121+
catch (UnauthorizedAccessException) when (OperatingSystem.IsLinux()) { }
122+
123+
// Native Linux bind mounts retain container UIDs. Use the already pinned image to remove
124+
// only this test's external data after all resources have stopped; never prune Docker data.
125+
var external = Path.Combine(root, "external");
126+
if (!Directory.Exists(external) || !redis.TryGetContainerImageName(out var image))
127+
throw new IOException("Cannot clean the comparison run's container-owned data.");
128+
var start = new ProcessStartInfo("docker") { RedirectStandardError = true, RedirectStandardOutput = true };
129+
foreach (var argument in new[]
130+
{
131+
"run", "--rm", "--pull", "never", "--network", "none", "--read-only", "--user", "0:0",
132+
"--cap-drop", "ALL", "--cap-add", "DAC_OVERRIDE", "--entrypoint", "/bin/sh",
133+
"--mount", $"type=bind,source={external},target=/data", image!, "-c", "rm -rf /data/*"
134+
}) start.ArgumentList.Add(argument);
135+
using var process = Process.Start(start) ?? throw new IOException("Cannot start comparison data cleanup.");
136+
var error = process.StandardError.ReadToEndAsync();
137+
var output = process.StandardOutput.ReadToEndAsync();
138+
using var timeout = new CancellationTokenSource(TimeSpan.FromSeconds(30));
139+
try { await process.WaitForExitAsync(timeout.Token); }
140+
catch (OperationCanceledException) { process.Kill(entireProcessTree: true); throw; }
141+
await output;
142+
if (process.ExitCode != 0) throw new IOException($"Comparison data cleanup failed: {await error}");
143+
await error;
144+
Directory.Delete(root, true);
145+
}
112146
}

0 commit comments

Comments
 (0)