Reformat / cleanup
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.IO.Compression;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ZB.MOM.WW.CBDD.Bson;
|
||||
@@ -14,21 +15,21 @@ internal static class PerformanceGateSmoke
|
||||
private const int CompressionDocumentCount = 1_500;
|
||||
|
||||
/// <summary>
|
||||
/// Runs the performance gate smoke probes and writes a report.
|
||||
/// Runs the performance gate smoke probes and writes a report.
|
||||
/// </summary>
|
||||
/// <param name="logger">The logger.</param>
|
||||
public static void Run(ILogger logger)
|
||||
{
|
||||
var compaction = RunCompactionProbe();
|
||||
var compressionOff = RunCompressionGcProbe(enableCompression: false);
|
||||
var compressionOn = RunCompressionGcProbe(enableCompression: true);
|
||||
var compressionOff = RunCompressionGcProbe(false);
|
||||
var compressionOn = RunCompressionGcProbe(true);
|
||||
|
||||
var report = new PerformanceGateReport(
|
||||
DateTimeOffset.UtcNow,
|
||||
compaction,
|
||||
compressionOff,
|
||||
compressionOn);
|
||||
var reportPath = WriteReport(report);
|
||||
string reportPath = WriteReport(report);
|
||||
|
||||
logger.LogInformation("Performance gate smoke report written to {ReportPath}", reportPath);
|
||||
|
||||
@@ -52,8 +53,8 @@ internal static class PerformanceGateSmoke
|
||||
|
||||
private static CompactionProbeResult RunCompactionProbe()
|
||||
{
|
||||
var dbPath = NewDbPath("gate_compaction");
|
||||
var walPath = Path.ChangeExtension(dbPath, ".wal");
|
||||
string dbPath = NewDbPath("gate_compaction");
|
||||
string walPath = Path.ChangeExtension(dbPath, ".wal");
|
||||
|
||||
try
|
||||
{
|
||||
@@ -62,18 +63,12 @@ internal static class PerformanceGateSmoke
|
||||
var collection = new DocumentCollection<Person>(storage, transactionHolder, new PersonMapper());
|
||||
|
||||
var ids = new List<ObjectId>(CompactionDocumentCount);
|
||||
for (var i = 0; i < CompactionDocumentCount; i++)
|
||||
{
|
||||
ids.Add(collection.Insert(CreatePerson(i, includeLargeBio: true)));
|
||||
}
|
||||
for (var i = 0; i < CompactionDocumentCount; i++) ids.Add(collection.Insert(CreatePerson(i, true)));
|
||||
|
||||
transactionHolder.CommitAndReset();
|
||||
storage.Checkpoint();
|
||||
|
||||
for (var i = 0; i < ids.Count; i += 3)
|
||||
{
|
||||
collection.Delete(ids[i]);
|
||||
}
|
||||
for (var i = 0; i < ids.Count; i += 3) collection.Delete(ids[i]);
|
||||
|
||||
for (var i = 0; i < ids.Count; i += 5)
|
||||
{
|
||||
@@ -117,8 +112,8 @@ internal static class PerformanceGateSmoke
|
||||
|
||||
private static CompressionGcProbeResult RunCompressionGcProbe(bool enableCompression)
|
||||
{
|
||||
var dbPath = NewDbPath(enableCompression ? "gate_gc_on" : "gate_gc_off");
|
||||
var walPath = Path.ChangeExtension(dbPath, ".wal");
|
||||
string dbPath = NewDbPath(enableCompression ? "gate_gc_on" : "gate_gc_off");
|
||||
string walPath = Path.ChangeExtension(dbPath, ".wal");
|
||||
var compressionOptions = enableCompression
|
||||
? new CompressionOptions
|
||||
{
|
||||
@@ -140,16 +135,13 @@ internal static class PerformanceGateSmoke
|
||||
GC.WaitForPendingFinalizers();
|
||||
GC.Collect();
|
||||
|
||||
var g0Before = GC.CollectionCount(0);
|
||||
var g1Before = GC.CollectionCount(1);
|
||||
var g2Before = GC.CollectionCount(2);
|
||||
var allocBefore = GC.GetTotalAllocatedBytes(true);
|
||||
int g0Before = GC.CollectionCount(0);
|
||||
int g1Before = GC.CollectionCount(1);
|
||||
int g2Before = GC.CollectionCount(2);
|
||||
long allocBefore = GC.GetTotalAllocatedBytes(true);
|
||||
|
||||
var ids = new ObjectId[CompressionDocumentCount];
|
||||
for (var i = 0; i < CompressionDocumentCount; i++)
|
||||
{
|
||||
ids[i] = collection.Insert(CreatePerson(i, includeLargeBio: true));
|
||||
}
|
||||
for (var i = 0; i < CompressionDocumentCount; i++) ids[i] = collection.Insert(CreatePerson(i, true));
|
||||
|
||||
transactionHolder.CommitAndReset();
|
||||
|
||||
@@ -166,17 +158,17 @@ internal static class PerformanceGateSmoke
|
||||
|
||||
transactionHolder.CommitAndReset();
|
||||
|
||||
var readCount = collection.FindAll().Count();
|
||||
int readCount = collection.FindAll().Count();
|
||||
transactionHolder.CommitAndReset();
|
||||
|
||||
GC.Collect();
|
||||
GC.WaitForPendingFinalizers();
|
||||
GC.Collect();
|
||||
|
||||
var g0After = GC.CollectionCount(0);
|
||||
var g1After = GC.CollectionCount(1);
|
||||
var g2After = GC.CollectionCount(2);
|
||||
var allocAfter = GC.GetTotalAllocatedBytes(true);
|
||||
int g0After = GC.CollectionCount(0);
|
||||
int g1After = GC.CollectionCount(1);
|
||||
int g2After = GC.CollectionCount(2);
|
||||
long allocAfter = GC.GetTotalAllocatedBytes(true);
|
||||
|
||||
return new CompressionGcProbeResult(
|
||||
enableCompression,
|
||||
@@ -198,11 +190,11 @@ internal static class PerformanceGateSmoke
|
||||
|
||||
private static string WriteReport(PerformanceGateReport report)
|
||||
{
|
||||
var outputDirectory = Path.Combine(Directory.GetCurrentDirectory(), "BenchmarkDotNet.Artifacts", "results");
|
||||
string outputDirectory = Path.Combine(Directory.GetCurrentDirectory(), "BenchmarkDotNet.Artifacts", "results");
|
||||
Directory.CreateDirectory(outputDirectory);
|
||||
|
||||
var reportPath = Path.Combine(outputDirectory, "PerformanceGateSmoke-report.json");
|
||||
var json = JsonSerializer.Serialize(report, new JsonSerializerOptions { WriteIndented = true });
|
||||
string reportPath = Path.Combine(outputDirectory, "PerformanceGateSmoke-report.json");
|
||||
string json = JsonSerializer.Serialize(report, new JsonSerializerOptions { WriteIndented = true });
|
||||
File.WriteAllText(reportPath, json);
|
||||
return reportPath;
|
||||
}
|
||||
@@ -214,7 +206,7 @@ internal static class PerformanceGateSmoke
|
||||
Id = ObjectId.NewObjectId(),
|
||||
FirstName = $"First_{i}",
|
||||
LastName = $"Last_{i}",
|
||||
Age = 20 + (i % 50),
|
||||
Age = 20 + i % 50,
|
||||
Bio = includeLargeBio ? BuildBio(i) : $"bio-{i}",
|
||||
CreatedAt = DateTime.UnixEpoch.AddMinutes(i),
|
||||
Balance = 100 + i,
|
||||
@@ -239,7 +231,7 @@ internal static class PerformanceGateSmoke
|
||||
|
||||
private static string BuildBio(int seed)
|
||||
{
|
||||
var builder = new System.Text.StringBuilder(4500);
|
||||
var builder = new StringBuilder(4500);
|
||||
for (var i = 0; i < 150; i++)
|
||||
{
|
||||
builder.Append("bio-");
|
||||
@@ -253,14 +245,13 @@ internal static class PerformanceGateSmoke
|
||||
}
|
||||
|
||||
private static string NewDbPath(string prefix)
|
||||
=> Path.Combine(Path.GetTempPath(), $"{prefix}_{Guid.NewGuid():N}.db");
|
||||
{
|
||||
return Path.Combine(Path.GetTempPath(), $"{prefix}_{Guid.NewGuid():N}.db");
|
||||
}
|
||||
|
||||
private static void TryDelete(string path)
|
||||
{
|
||||
if (File.Exists(path))
|
||||
{
|
||||
File.Delete(path);
|
||||
}
|
||||
if (File.Exists(path)) File.Delete(path);
|
||||
}
|
||||
|
||||
private sealed record PerformanceGateReport(
|
||||
@@ -284,4 +275,4 @@ internal static class PerformanceGateSmoke
|
||||
int Gen1Delta,
|
||||
int Gen2Delta,
|
||||
long AllocatedBytesDelta);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user